hlrc / client / python / hlrc_client / Middleware.py @ 62d50515
History | View | Annotate | Download (4.842 KB)
1 | 0c286af0 | Simon Schulz | """
|
---|---|---|---|
2 | This file is part of hlrc
|
||
3 |
|
||
4 | Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
|
||
5 | http://opensource.cit-ec.de/projects/hlrc
|
||
6 |
|
||
7 | This file may be licensed under the terms of the
|
||
8 | GNU General Public License Version 3 (the ``GPL''),
|
||
9 | or (at your option) any later version.
|
||
10 |
|
||
11 | Software distributed under the License is distributed
|
||
12 | on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
|
||
13 | express or implied. See the GPL for the specific language
|
||
14 | governing rights and limitations.
|
||
15 |
|
||
16 | You should have received a copy of the GPL along with this
|
||
17 | program. If not, go to http://www.gnu.org/licenses/gpl.html
|
||
18 | or write to the Free Software Foundation, Inc.,
|
||
19 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
20 |
|
||
21 | The development of this software was supported by the
|
||
22 | Excellence Cluster EXC 277 Cognitive Interaction Technology.
|
||
23 | The Excellence Cluster EXC 277 is a grant of the Deutsche
|
||
24 | Forschungsgemeinschaft (DFG) in the context of the German
|
||
25 | Excellence Initiative.
|
||
26 | """
|
||
27 | |||
28 | import sys |
||
29 | import logging |
||
30 | from RobotEmotion import * |
||
31 | from RobotGaze import * |
||
32 | from RobotMouth import * |
||
33 | from RobotAnimation import * |
||
34 | |||
35 | class Middleware: |
||
36 | #######################################################################
|
||
37 | def __init__(self, scope, loglevel=logging.WARNING): |
||
38 | """initialise
|
||
39 | :param scope: base scope we want to listen on
|
||
40 | """
|
||
41 | self.base_scope = scope
|
||
42 | |||
43 | self.logger = logging.getLogger(__name__)
|
||
44 | |||
45 | # create nice and actually usable formatter and add it to the handler
|
||
46 | self.config_logger(loglevel)
|
||
47 | |||
48 | #initialise defaults
|
||
49 | self.default_emotion = RobotEmotion()
|
||
50 | self.current_emotion = RobotEmotion()
|
||
51 | self.gaze_target = RobotGaze()
|
||
52 | self.mouth_target = RobotMouth()
|
||
53 | self.robot_animation = RobotAnimation()
|
||
54 | |||
55 | |||
56 | def config_logger(self, level): |
||
57 | formatter = logging.Formatter('%(asctime)s %(name)-30s %(levelname)-8s > %(message)s')
|
||
58 | ch = logging.StreamHandler() |
||
59 | #ch.setLevel(level)
|
||
60 | ch.setFormatter(formatter) |
||
61 | self.logger.setLevel(level)
|
||
62 | self.logger.addHandler(ch)
|
||
63 | |||
64 | #######################################################################
|
||
65 | #abstract/virtual functions
|
||
66 | def die_virtual(self, funcname): |
||
67 | raise NotImplementedError(funcname + "() is virtual, must be overwritten") |
||
68 | |||
69 | def init_middleware(self): |
||
70 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
71 | |||
72 | def publish_default_emotion(self, emotion, blocking): |
||
73 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
74 | |||
75 | def publish_current_emotion(self, emotion, blocking): |
||
76 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
77 | |||
78 | def publish_gaze_target(self, gaze, blocking): |
||
79 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
80 | |||
81 | def publish_mouth_target(self, mouth, blocking): |
||
82 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
83 | |||
84 | def publish_head_animation(self, animation, blocking): |
||
85 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
86 | |||
87 | def publish_speech(self, text, blocking): |
||
88 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
89 | |||
90 | #######################################################################
|
||
91 | #finally some implemented functions
|
||
92 | def set_default_emotion(self, emotion, blocking): |
||
93 | """set the default emotion
|
||
94 | :param emotion: RobotEmotion to set
|
||
95 | :param blocking: True if this call should block until execution finished on robot
|
||
96 | """
|
||
97 | self.default_emotion = emotion
|
||
98 | self.publish_default_emotion(emotion, blocking)
|
||
99 | |||
100 | def set_current_emotion(self, emotion, blocking): |
||
101 | """set a temporary emotion (duration: see emotion.time_ms)
|
||
102 | :param emotion: RobotEmotion to set temporarily
|
||
103 | :param blocking: True if this call should block until execution finished on robot
|
||
104 | """
|
||
105 | self.current_emotion = emotion
|
||
106 | self.publish_current_emotion(emotion, blocking)
|
||
107 | |||
108 | def set_head_animation(self, animation, blocking): |
||
109 | """trigger a head animation
|
||
110 | :param animation: RobotAnimation to set
|
||
111 | :param blocking: True if this call should block until execution finished on robot
|
||
112 | """
|
||
113 | self.animation = animation
|
||
114 | self.publish_head_animation(animation, blocking)
|
||
115 | |||
116 | def set_mouth_target(self, mouth, blocking): |
||
117 | """set a mouth target
|
||
118 | :param mouth: RobotMouth to set
|
||
119 | :param blocking: True if this call should block until execution finished on robot
|
||
120 | """
|
||
121 | self.mouth_target = mouth
|
||
122 | self.publish_mouth_target(mouth, blocking)
|
||
123 | |||
124 | def set_speak(self, text, blocking): |
||
125 | """trigger a tts speech output
|
||
126 | :param text: text to synthesize and speak
|
||
127 | :param blocking: True if this call should block until execution finished on robot
|
||
128 | """
|
||
129 | self.publish_speech(text, blocking)
|
||
130 | |||
131 | def set_gaze_target(self, gaze, blocking): |
||
132 | """set a new gaze
|
||
133 | :param gaze: RobotGaze to set
|
||
134 | :param blocking: True if this call should block until execution finished on robot
|
||
135 | """
|
||
136 | self.gaze_target = gaze
|
||
137 | self.publish_gaze_target(gaze, blocking)
|
||
138 | |||
139 | #######################################################################
|
||
140 | #some get methods
|
||
141 | #def get_current_emotion(self):
|
||
142 | # return self.current_emotion
|
||
143 | #
|
||
144 | #def get_default_emotion(self):
|
||
145 | # return self.default_emotion
|
||
146 | # |