hlrc / client / python / hlrc_client / Middleware.py @ dec1ec7a
History | View | Annotate | Download (5.363 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 | 3877047d | Simon Schulz | #######################################################################
|
37 | def __init__(self, scope, loglevel=logging.WARNING): |
||
38 | 70c54617 | Simon Schulz | """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 | def __del__(self): |
||
56 | """destructor
|
||
57 | """
|
||
58 | self.logger.debug("destructor of Middleware called") |
||
59 | |||
60 | def config_logger(self, level): |
||
61 | formatter = logging.Formatter('%(asctime)s %(name)-30s %(levelname)-8s > %(message)s')
|
||
62 | ch = logging.StreamHandler() |
||
63 | #ch.setLevel(level)
|
||
64 | ch.setFormatter(formatter) |
||
65 | self.logger.setLevel(level)
|
||
66 | self.logger.addHandler(ch)
|
||
67 | |||
68 | #######################################################################
|
||
69 | #abstract/virtual functions
|
||
70 | def die_virtual(self, funcname): |
||
71 | raise NotImplementedError(funcname + "() is virtual, must be overwritten") |
||
72 | |||
73 | def init_middleware(self): |
||
74 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
75 | |||
76 | def publish_default_emotion(self, emotion, blocking): |
||
77 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
78 | |||
79 | def publish_current_emotion(self, emotion, blocking): |
||
80 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
81 | |||
82 | def publish_gaze_target(self, gaze, blocking): |
||
83 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
84 | |||
85 | def publish_mouth_target(self, mouth, blocking): |
||
86 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
87 | |||
88 | def publish_head_animation(self, animation, blocking): |
||
89 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
90 | |||
91 | def publish_speech(self, text, blocking): |
||
92 | self.die_virtual(sys._getframe().f_code.co_name)
|
||
93 | |||
94 | #######################################################################
|
||
95 | #finally some implemented functions
|
||
96 | def set_default_emotion(self, emotion, blocking): |
||
97 | """set the default emotion
|
||
98 | :param emotion: RobotEmotion to set
|
||
99 | :param blocking: True if this call should block until execution finished on robot
|
||
100 | """
|
||
101 | self.default_emotion = emotion
|
||
102 | self.publish_default_emotion(emotion, blocking)
|
||
103 | |||
104 | def set_current_emotion(self, emotion, blocking): |
||
105 | """set a temporary emotion (duration: see emotion.time_ms)
|
||
106 | :param emotion: RobotEmotion to set temporarily
|
||
107 | :param blocking: True if this call should block until execution finished on robot
|
||
108 | """
|
||
109 | self.current_emotion = emotion
|
||
110 | self.publish_current_emotion(emotion, blocking)
|
||
111 | |||
112 | def set_head_animation(self, animation, blocking): |
||
113 | """trigger a head animation
|
||
114 | :param animation: RobotAnimation to set
|
||
115 | :param blocking: True if this call should block until execution finished on robot
|
||
116 | """
|
||
117 | self.animation = animation
|
||
118 | self.publish_head_animation(animation, blocking)
|
||
119 | |||
120 | def set_mouth_target(self, mouth, blocking): |
||
121 | """set a mouth target
|
||
122 | :param mouth: RobotMouth to set
|
||
123 | :param blocking: True if this call should block until execution finished on robot
|
||
124 | """
|
||
125 | self.mouth_target = mouth
|
||
126 | self.publish_mouth_target(mouth, blocking)
|
||
127 | |||
128 | def set_speak(self, text, blocking): |
||
129 | """trigger a tts speech output
|
||
130 | :param text: text to synthesize and speak
|
||
131 | :param blocking: True if this call should block until execution finished on robot
|
||
132 | """
|
||
133 | self.publish_speech(text, blocking)
|
||
134 | |||
135 | def set_gaze_target(self, gaze, blocking): |
||
136 | """set a new gaze
|
||
137 | :param gaze: RobotGaze to set
|
||
138 | :param blocking: True if this call should block until execution finished on robot
|
||
139 | """
|
||
140 | self.gaze_target = gaze
|
||
141 | self.publish_gaze_target(gaze, blocking)
|
||
142 | |||
143 | #######################################################################
|
||
144 | #some get methods
|
||
145 | #def get_current_emotion(self):
|
||
146 | # return self.current_emotion
|
||
147 | #
|
||
148 | #def get_default_emotion(self):
|
||
149 | # return self.default_emotion
|
||
150 | # |