Revision e3691d2d client/python/hlrc_client/MiddlewareRSB.py
client/python/hlrc_client/MiddlewareRSB.py | ||
---|---|---|
44 | 44 |
"""initialise |
45 | 45 |
:param scope: base scope we want to listen on |
46 | 46 |
""" |
47 |
#init base settings |
|
48 |
Middleware.__init__(self,scope,loglevel)
|
|
47 |
# init base settings
|
|
48 |
Middleware.__init__(self, scope, loglevel)
|
|
49 | 49 |
#call mw init |
50 | 50 |
self.init_middleware() |
51 | 51 |
|
... | ... | |
58 | 58 |
def init_middleware(self): |
59 | 59 |
"""initialise middleware |
60 | 60 |
""" |
61 |
#mute rsb logging: |
|
61 |
# mute rsb logging:
|
|
62 | 62 |
logging.getLogger("rsb").setLevel(logging.ERROR) |
63 | 63 |
|
64 | 64 |
#initialise RSB stuff |
65 |
self.logger.info("initialising RSB middleware connection on scope %s, registering rst converters..." % (self.base_scope)) |
|
65 |
self.logger.info( |
|
66 |
"initialising RSB middleware connection on scope %s, registering rst converters..." % (self.base_scope)) |
|
66 | 67 |
|
67 |
self.EmotionExpression_converter = rsb.converter.ProtocolBufferConverter(messageClass = EmotionExpression)
|
|
68 |
self.EmotionExpression_converter = rsb.converter.ProtocolBufferConverter(messageClass=EmotionExpression)
|
|
68 | 69 |
rsb.converter.registerGlobalConverter(self.EmotionExpression_converter) |
69 | 70 |
|
70 |
self.HeadAnimation_converter = rsb.converter.ProtocolBufferConverter(messageClass = HeadAnimation)
|
|
71 |
self.HeadAnimation_converter = rsb.converter.ProtocolBufferConverter(messageClass=HeadAnimation)
|
|
71 | 72 |
rsb.converter.registerGlobalConverter(self.HeadAnimation_converter) |
72 | 73 |
|
73 |
self.BinocularHeadGaze_converter = rsb.converter.ProtocolBufferConverter(messageClass = BinocularHeadGaze)
|
|
74 |
self.BinocularHeadGaze_converter = rsb.converter.ProtocolBufferConverter(messageClass=BinocularHeadGaze)
|
|
74 | 75 |
rsb.converter.registerGlobalConverter(self.BinocularHeadGaze_converter) |
75 | 76 |
|
76 | 77 |
try: |
... | ... | |
88 | 89 |
:param blocking: True if this call should block until execution finished on robot |
89 | 90 |
""" |
90 | 91 |
|
91 |
#create emotion & fill it with values: |
|
92 |
# create emotion & fill it with values:
|
|
92 | 93 |
rsb_em = EmotionExpression() |
93 | 94 |
|
94 | 95 |
#set value |
... | ... | |
114 | 115 |
else: |
115 | 116 |
future = server.currentEmotion.async(rsb_em) |
116 | 117 |
|
117 |
#we could block here for a incoming result with a timeout in s |
|
118 |
#print '> server reply: "%s"' % future.get(timeout = 10); |
|
118 |
#we could block here for a incoming result with a timeout in s
|
|
119 |
#print '> server reply: "%s"' % future.get(timeout = 10);
|
|
119 | 120 |
self.logger.debug("emotion rpc done") |
120 | 121 |
|
121 | 122 |
def publish_head_HeadAnimation(self, HeadAnimation, blocking): |
... | ... | |
126 | 127 |
|
127 | 128 |
self.logger.debug("calling the HeadAnimation rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING")) |
128 | 129 |
|
129 |
#create HeadAnimation & fill it with values: |
|
130 |
# create HeadAnimation & fill it with values:
|
|
130 | 131 |
rsb_ani = HeadAnimation() |
131 | 132 |
|
132 | 133 |
#select ani |
133 | 134 |
rsb_ani.target = self.convert_HeadAnimationtype_to_rsbval(HeadAnimation.value) |
134 | 135 |
rsb_ani.repetitions = HeadAnimation.repetitions |
135 | 136 |
rsb_ani.duration_each = HeadAnimation.time_ms |
136 |
rsb_ani.scale = HeadAnimation.scale
|
|
137 |
rsb_ani.scale = HeadAnimation.scale |
|
137 | 138 |
|
138 | 139 |
if (blocking): |
139 | 140 |
#blocking: |
... | ... | |
159 | 160 |
""" |
160 | 161 |
self.logger.debug("calling the gaze rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING")) |
161 | 162 |
|
162 |
#create gaze target & fill it with values: |
|
163 |
# create gaze target & fill it with values:
|
|
163 | 164 |
rsb_gaze = BinocularHeadGaze() |
164 | 165 |
|
165 | 166 |
#fill proto |
166 |
rsb_gaze.target = SphericalDirectionFloat()
|
|
167 |
rsb_gaze.target.elevation = gaze.tilt
|
|
168 |
rsb_gaze.target.azimuth = gaze.pan
|
|
167 |
rsb_gaze.target = SphericalDirectionFloat()
|
|
168 |
rsb_gaze.target.elevation = gaze.tilt
|
|
169 |
rsb_gaze.target.azimuth = gaze.pan
|
|
169 | 170 |
|
170 | 171 |
rsb_gaze.vergence = gaze.vergence |
171 | 172 |
|
172 |
|
|
173 |
rsb_gaze.offset = SphericalDirectionFloat() |
|
174 |
rsb_gaze.offset.elevation = gaze.tilt_offset |
|
175 |
rsb_gaze.offset.azimuth = gaze.pan_offset |
|
173 |
rsb_gaze.offset = SphericalDirectionFloat() |
|
174 |
rsb_gaze.offset.elevation = gaze.tilt_offset |
|
175 |
rsb_gaze.offset.azimuth = gaze.pan_offset |
|
176 | 176 |
|
177 | 177 |
if (blocking): |
178 |
#blocking: |
|
178 |
# blocking:
|
|
179 | 179 |
result = self.server.gaze(rsb_gaze) |
180 | 180 |
self.logger.debug("server reply: '%s'" % result) |
181 | 181 |
else: |
182 | 182 |
future = self.server.gaze.async(rsb_gaze) |
183 |
#we can block here for a incoming result with a timeout in s |
|
183 |
# we can block here for a incoming result with a timeout in s
|
|
184 | 184 |
#print '> server reply: "%s"' % future.get(timeout = 10); |
185 | 185 |
|
186 | 186 |
self.logger.debug("gaze rpc done") |
187 | 187 |
|
188 |
""" |
|
189 |
def publish_mouth_target(self, mouth, blocking): |
|
190 |
publish a mouth target via mw |
|
191 |
:param mouth: mouth value to set |
|
192 |
:param blocking: True if this call should block until execution finished on robot |
|
193 |
|
|
194 |
self.logger.debug("calling the mouth rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING")) |
|
195 |
|
|
196 |
#create mouth state & fill it with values: |
|
197 |
rsb_mouth = MouthTarget() |
|
198 |
|
|
199 |
#fill proto |
|
200 |
rsb_mouth.opening_left = mouth.opening_left |
|
201 |
rsb_mouth.opening_center = mouth.opening_center |
|
202 |
rsb_mouth.opening_right = mouth.opening_right |
|
203 |
rsb_mouth.position_left = mouth.position_left |
|
204 |
rsb_mouth.position_center = mouth.position_center |
|
205 |
rsb_mouth.position_right = mouth.position_right |
|
188 |
""" |
|
189 |
def publish_mouth_target(self, mouth, blocking): |
|
190 |
publish a mouth target via mw |
|
191 |
:param mouth: mouth value to set |
|
192 |
:param blocking: True if this call should block until execution finished on robot |
|
193 |
|
|
194 |
self.logger.debug("calling the mouth rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING")) |
|
195 |
|
|
196 |
#create mouth state & fill it with values: |
|
197 |
rsb_mouth = MouthTarget() |
|
198 |
|
|
199 |
#fill proto |
|
200 |
rsb_mouth.opening_left = mouth.opening_left |
|
201 |
rsb_mouth.opening_center = mouth.opening_center |
|
202 |
rsb_mouth.opening_right = mouth.opening_right |
|
203 |
rsb_mouth.position_left = mouth.position_left |
|
204 |
rsb_mouth.position_center = mouth.position_center |
|
205 |
rsb_mouth.position_right = mouth.position_right |
|
206 |
|
|
207 |
if (blocking): |
|
208 |
#blocking: |
|
209 |
result = self.server.mouth(rsb_mouth) |
|
210 |
self.logger.debug("server reply: '%s'" % result) |
|
211 |
else: |
|
212 |
future = self.server.mouth.async(rsb_mouth) |
|
213 |
#we can block here for a incoming result with a timeout in s |
|
214 |
#print '> server reply: "%s"' % future.get(timeout = 10); |
|
215 |
|
|
216 |
self.logger.debug("mouth rpc done") |
|
217 |
""" |
|
206 | 218 |
|
207 |
if (blocking): |
|
208 |
#blocking: |
|
209 |
result = self.server.mouth(rsb_mouth) |
|
210 |
self.logger.debug("server reply: '%s'" % result) |
|
211 |
else: |
|
212 |
future = self.server.mouth.async(rsb_mouth) |
|
213 |
#we can block here for a incoming result with a timeout in s |
|
214 |
#print '> server reply: "%s"' % future.get(timeout = 10); |
|
215 | 219 |
|
216 |
self.logger.debug("mouth rpc done") |
|
220 |
def publish_speech(self, text, blocking): |
|
221 |
"""publish a tts request via mw |
|
222 |
:param text: text to synthesize and speak |
|
223 |
:param blocking: True if this call should block until execution finished on robot |
|
217 | 224 |
""" |
225 |
self.logger.debug("calling the speech rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING")) |
|
218 | 226 |
|
219 |
def publish_speech(self, text, blocking): |
|
220 |
"""publish a tts request via mw |
|
221 |
:param text: text to synthesize and speak |
|
222 |
:param blocking: True if this call should block until execution finished on robot |
|
223 |
""" |
|
224 |
self.logger.debug("calling the speech rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING")) |
|
227 |
if (blocking): |
|
228 |
# blocking: |
|
229 |
result = self.server.speech(text) |
|
230 |
self.logger.debug("server reply: '%s'" % result) |
|
231 |
else: |
|
232 |
future = self.server.speech.async(text) |
|
233 |
# we can block here for a incoming result with a timeout in s |
|
234 |
#print '> server reply: "%s"' % future.get(timeout = 10); |
|
225 | 235 |
|
226 |
if (blocking): |
|
227 |
#blocking: |
|
228 |
result = self.server.speech(text) |
|
229 |
self.logger.debug("server reply: '%s'" % result) |
|
230 |
else: |
|
231 |
future = self.server.speech.async(text) |
|
232 |
#we can block here for a incoming result with a timeout in s |
|
233 |
#print '> server reply: "%s"' % future.get(timeout = 10); |
|
236 |
self.logger.debug("speech rpc done") |
|
234 | 237 |
|
235 |
self.logger.debug("speech rpc done") |
|
236 |
####################################################################### |
|
237 |
def is_running(self): |
|
238 |
return True |
|
239 | 238 |
|
240 |
####################################################################### |
|
241 |
# some helpers |
|
242 |
def convert_HeadAnimationtype_to_rsbval(self, value): |
|
243 |
"""convert RobotHeadAnimation.value to RSB HeadAnimation value |
|
244 |
:param value: RobotHeadAnimation.* id to convert to rsb id |
|
245 |
""" |
|
246 |
#NOTE: this convertion is important as the actual integer values of |
|
247 |
# thy python api and the protobuf might be different |
|
248 |
|
|
249 |
if (value == RobotHeadAnimation.IDLE): |
|
250 |
return HeadAnimation().IDLE |
|
251 |
elif (value == RobotHeadAnimation.HEAD_NOD): |
|
252 |
return HeadAnimation().HEAD_NOD |
|
253 |
elif (value == RobotHeadAnimation.HEAD_SHAKE): |
|
254 |
return HeadAnimation().HEAD_SHAKE |
|
255 |
elif (value == RobotHeadAnimation.EYEBLINK_L): |
|
256 |
return HeadAnimation().EYEBLINK_L |
|
257 |
elif (value == RobotHeadAnimation.EYEBLINK_R): |
|
258 |
return HeadAnimation().EYEBLINK_R |
|
259 |
elif (value == RobotHeadAnimation.EYEBLINK_BOTH): |
|
260 |
return HeadAnimation().EYEBLINK_BOTH |
|
261 |
elif (value == RobotHeadAnimation.EYEBROWS_RAISE): |
|
262 |
return HeadAnimation().EYEBROWS_RAISE |
|
263 |
elif (value == RobotHeadAnimation.EYEBROWS_LOWER): |
|
264 |
return HeadAnimation().EYEBROWS_LOWER |
|
265 |
else: |
|
266 |
self.logger.error("invalid HeadAnimation type %d\n" % (value)) |
|
267 |
return HeadAnimation().NEUTRAL |
|
239 |
####################################################################### |
|
240 |
def is_running(self): |
|
241 |
return True |
|
268 | 242 |
|
269 |
def convert_emotiontype_to_rsbval(self, value): |
|
270 |
"""convert RobotEmotion.value to RSB HeadAnimation value |
|
271 |
:param value: RobotEmotion.* id to convert to rsb id |
|
272 |
""" |
|
273 |
#NOTE: this convertion is important as the actual integer values of |
|
274 |
# thy python api and the protobuf might be different |
|
275 |
|
|
276 |
if (value == RobotEmotion.NEUTRAL): |
|
277 |
return EmotionExpression().NEUTRAL |
|
278 |
elif (value == RobotEmotion.HAPPY): |
|
279 |
return EmotionExpression().HAPPY |
|
280 |
elif (value == RobotEmotion.SAD): |
|
281 |
return EmotionExpression().SAD |
|
282 |
elif (value == RobotEmotion.ANGRY): |
|
283 |
return EmotionExpression().ANGRY |
|
284 |
elif (value == RobotEmotion.SURPRISED): |
|
285 |
return EmotionExpression().SURPRISED |
|
286 |
elif (value == RobotEmotion.FEAR): |
|
287 |
return EmotionExpression().FEAR |
|
288 |
else: |
|
289 |
self.logger.error("invalid emotion type %d\n" % (value)) |
|
290 |
return EmotionExpression().NEUTRAL |
|
243 |
|
|
244 |
####################################################################### |
|
245 |
# some helpers |
|
246 |
def convert_HeadAnimationtype_to_rsbval(self, value): |
|
247 |
"""convert RobotHeadAnimation.value to RSB HeadAnimation value |
|
248 |
:param value: RobotHeadAnimation.* id to convert to rsb id |
|
249 |
""" |
|
250 |
# NOTE: this convertion is important as the actual integer values of |
|
251 |
# thy python api and the protobuf might be different |
|
252 |
|
|
253 |
if (value == RobotHeadAnimation.IDLE): |
|
254 |
return HeadAnimation().IDLE |
|
255 |
elif (value == RobotHeadAnimation.HEAD_NOD): |
|
256 |
return HeadAnimation().HEAD_NOD |
|
257 |
elif (value == RobotHeadAnimation.HEAD_SHAKE): |
|
258 |
return HeadAnimation().HEAD_SHAKE |
|
259 |
elif (value == RobotHeadAnimation.EYEBLINK_L): |
|
260 |
return HeadAnimation().EYEBLINK_L |
|
261 |
elif (value == RobotHeadAnimation.EYEBLINK_R): |
|
262 |
return HeadAnimation().EYEBLINK_R |
|
263 |
elif (value == RobotHeadAnimation.EYEBLINK_BOTH): |
|
264 |
return HeadAnimation().EYEBLINK_BOTH |
|
265 |
elif (value == RobotHeadAnimation.EYEBROWS_RAISE): |
|
266 |
return HeadAnimation().EYEBROWS_RAISE |
|
267 |
elif (value == RobotHeadAnimation.EYEBROWS_LOWER): |
|
268 |
return HeadAnimation().EYEBROWS_LOWER |
|
269 |
else: |
|
270 |
self.logger.error("invalid HeadAnimation type %d\n" % (value)) |
|
271 |
return HeadAnimation().NEUTRAL |
|
272 |
|
|
273 |
|
|
274 |
def convert_emotiontype_to_rsbval(self, value): |
|
275 |
"""convert RobotEmotion.value to RSB HeadAnimation value |
|
276 |
:param value: RobotEmotion.* id to convert to rsb id |
|
277 |
""" |
|
278 |
# NOTE: this convertion is important as the actual integer values of |
|
279 |
# thy python api and the protobuf might be different |
|
280 |
|
|
281 |
if (value == RobotEmotion.NEUTRAL): |
|
282 |
return EmotionExpression().NEUTRAL |
|
283 |
elif (value == RobotEmotion.HAPPY): |
|
284 |
return EmotionExpression().HAPPY |
|
285 |
elif (value == RobotEmotion.SAD): |
|
286 |
return EmotionExpression().SAD |
|
287 |
elif (value == RobotEmotion.ANGRY): |
|
288 |
return EmotionExpression().ANGRY |
|
289 |
elif (value == RobotEmotion.SURPRISED): |
|
290 |
return EmotionExpression().SURPRISED |
|
291 |
elif (value == RobotEmotion.FEAR): |
|
292 |
return EmotionExpression().FEAR |
|
293 |
else: |
|
294 |
self.logger.error("invalid emotion type %d\n" % (value)) |
|
295 |
return EmotionExpression().NEUTRAL |
Also available in: Unified diff