Revision 5eb9025f

View differences:

client/python/hlrc_client/MiddlewareRSB.py
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
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
"""
188
    def publish_speech(self, text, blocking):
189
        """publish a tts request via mw
190
        :param text: text to synthesize and speak
191
        :param blocking: True if this call should block until execution finished on robot
192
        """
193
        self.logger.debug("calling the speech rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING"))
218 194

  
195
        if (blocking):
196
            # blocking:
197
            result = self.server.speech(text)
198
            self.logger.debug("server reply: '%s'" % result)
199
        else:
200
            future = self.server.speech.async(text)
201
            # we can block here for a incoming result with a timeout in s
202
            #print '> server reply: "%s"' % future.get(timeout = 10);
219 203

  
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
224
    """
225
    self.logger.debug("calling the speech rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING"))
204
        self.logger.debug("speech rpc done")
226 205

  
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);
235 206

  
236
    self.logger.debug("speech rpc done")
207
    #######################################################################
208
    def is_running(self):
209
        return True
237 210

  
238 211

  
239
#######################################################################
240
def is_running(self):
241
    return True
212
    #######################################################################
213
    # some helpers
214
    def convert_HeadAnimationtype_to_rsbval(self, value):
215
        """convert RobotHeadAnimation.value to RSB HeadAnimation value
216
        :param value: RobotHeadAnimation.* id to convert to rsb id
217
        """
218
        # NOTE: this convertion is important as the actual integer values of
219
        #      thy python api and the protobuf might be different
220

  
221
        if (value == RobotHeadAnimation.IDLE):
222
            return HeadAnimation().IDLE
223
        elif (value == RobotHeadAnimation.HEAD_NOD):
224
            return HeadAnimation().HEAD_NOD
225
        elif (value == RobotHeadAnimation.HEAD_SHAKE):
226
            return HeadAnimation().HEAD_SHAKE
227
        elif (value == RobotHeadAnimation.EYEBLINK_L):
228
            return HeadAnimation().EYEBLINK_L
229
        elif (value == RobotHeadAnimation.EYEBLINK_R):
230
            return HeadAnimation().EYEBLINK_R
231
        elif (value == RobotHeadAnimation.EYEBLINK_BOTH):
232
            return HeadAnimation().EYEBLINK_BOTH
233
        elif (value == RobotHeadAnimation.EYEBROWS_RAISE):
234
            return HeadAnimation().EYEBROWS_RAISE
235
        elif (value == RobotHeadAnimation.EYEBROWS_LOWER):
236
            return HeadAnimation().EYEBROWS_LOWER
237
        else:
238
            self.logger.error("invalid HeadAnimation type %d\n" % (value))
239
            return HeadAnimation().NEUTRAL
242 240

  
241
    def convert_emotiontype_to_rsbval(self, value):
242
        """convert RobotEmotion.value to RSB HeadAnimation value
243
        :param value: RobotEmotion.* id to convert to rsb id
244
        """
245
        # NOTE: this convertion is important as the actual integer values of
246
        #      thy python api and the protobuf might be different
247

  
248
        if (value == RobotEmotion.NEUTRAL):
249
            return EmotionExpression().NEUTRAL
250
        elif (value == RobotEmotion.HAPPY):
251
            return EmotionExpression().HAPPY
252
        elif (value == RobotEmotion.SAD):
253
            return EmotionExpression().SAD
254
        elif (value == RobotEmotion.ANGRY):
255
            return EmotionExpression().ANGRY
256
        elif (value == RobotEmotion.SURPRISED):
257
            return EmotionExpression().SURPRISED
258
        elif (value == RobotEmotion.FEAR):
259
            return EmotionExpression().FEAR
260
        else:
261
            self.logger.error("invalid emotion type %d\n" % (value))
262
            return EmotionExpression().NEUTRAL
243 263

  
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 264
    """
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
265
    def publish_mouth_target(self, mouth, blocking):
266
        publish a mouth target via mw
267
        :param mouth: mouth value to set
268
        :param blocking: True if this call should block until execution finished on robot
269

  
270
        self.logger.debug("calling the mouth rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING"))
271

  
272
        #create mouth state & fill it with values:
273
        rsb_mouth = MouthTarget()
274

  
275
        #fill proto
276
        rsb_mouth.opening_left   = mouth.opening_left
277
        rsb_mouth.opening_center = mouth.opening_center
278
        rsb_mouth.opening_right  = mouth.opening_right
279
        rsb_mouth.position_left  = mouth.position_left
280
        rsb_mouth.position_center = mouth.position_center
281
        rsb_mouth.position_right = mouth.position_right
282

  
283
        if (blocking):
284
            #blocking:
285
            result = self.server.mouth(rsb_mouth)
286
            self.logger.debug("server reply: '%s'" % result)
287
        else:
288
            future = self.server.mouth.async(rsb_mouth)
289
            #we can block here for a incoming result with a timeout in s
290
            #print '> server reply: "%s"' % future.get(timeout = 10);
291

  
292
        self.logger.debug("mouth rpc done")
293
    """

Also available in: Unified diff