Revision 78cc756c client/python/hlrc_client/MiddlewareRSB.py

View differences:

client/python/hlrc_client/MiddlewareRSB.py
32 32
import rsb.converter
33 33
import rst
34 34

  
35
#This is untested for now (flier), RST has been refactored during "GGB", so these are the new types (names and packages)
36
from rstsandbox.animation.EmotionExpression_pb2 import EmotionExpression as EmotionState
37
from rstsandbox.animation.HeadAnimation_pb2 import HeadAnimation as Animation
38
from rstsandbox.robot.HumotionGazeTarget_pb2 import HumotionGazeTarget as GazeTarget
39
from rstsandbox.robot.MouthTarget_pb2 import MouthTarget
35
from rstsandbox.animation.EmotionExpression_pb2 import EmotionExpression
36
from rstsandbox.animation.HeadAnimation_pb2 import HeadAnimation
37
from rstsandbox.animation.BinocularHeadGaze_pb2 import BinocularHeadGaze
38
from rstsandbox.geometry.SphericalDirectionFloat_pb2 import SphericalDirectionFloat
40 39

  
41 40

  
42 41
class MiddlewareRSB(Middleware):
......
65 64
        #initialise RSB stuff
66 65
        self.logger.info("initialising RSB middleware connection on scope %s, registering rst converters..." % (self.base_scope))
67 66

  
68
        self.emotionstate_converter = rsb.converter.ProtocolBufferConverter(messageClass = EmotionState)
69
        rsb.converter.registerGlobalConverter(self.emotionstate_converter)
67
        self.EmotionExpression_converter = rsb.converter.ProtocolBufferConverter(messageClass = EmotionExpression)
68
        rsb.converter.registerGlobalConverter(self.EmotionExpression_converter)
70 69

  
71
        self.animation_converter = rsb.converter.ProtocolBufferConverter(messageClass = Animation)
72
        rsb.converter.registerGlobalConverter(self.animation_converter)
70
        self.HeadAnimation_converter = rsb.converter.ProtocolBufferConverter(messageClass = HeadAnimation)
71
        rsb.converter.registerGlobalConverter(self.HeadAnimation_converter)
73 72

  
74
        self.gaze_converter = rsb.converter.ProtocolBufferConverter(messageClass = GazeTarget)
75
        rsb.converter.registerGlobalConverter(self.gaze_converter)
76

  
77
        self.mouth_converter = rsb.converter.ProtocolBufferConverter(messageClass = MouthTarget)
78
        rsb.converter.registerGlobalConverter(self.mouth_converter)
73
        self.BinocularHeadGaze_converter = rsb.converter.ProtocolBufferConverter(messageClass = BinocularHeadGaze)
74
        rsb.converter.registerGlobalConverter(self.BinocularHeadGaze_converter)
79 75

  
80 76
        try:
81 77
            self.server = rsb.createRemoteServer(self.base_scope + '/set')
......
93 89
        """
94 90

  
95 91
        #create emotion & fill it with values:
96
        rsb_em = EmotionState()
92
        rsb_em = EmotionExpression()
97 93

  
98 94
        #set value
99 95
        rsb_em.value = self.convert_emotiontype_to_rsbval(emotion.value)
......
106 102

  
107 103
            if (blocking):
108 104
                #blocking rpc call:
109
                if (em_type == RobotEmotion.TYPE_DEFAULT):
105
                if (em_type == EmotionExpression.TYPE_DEFAULT):
110 106
                    result = server.defaultEmotion(rsb_em)
111 107
                else:
112 108
                    result = server.currentEmotion(rsb_em)
113 109

  
114 110
                self.logger.debug("server reply: '%s'" % result)
115 111
            else:
116
                if (em_type == RobotEmotion.TYPE_DEFAULT):
112
                if (em_type == EmotionExpression.TYPE_DEFAULT):
117 113
                    future = server.defaultEmotion.async(rsb_em)
118 114
                else:
119 115
                    future = server.currentEmotion.async(rsb_em)
......
122 118
                #print '> server reply: "%s"' % future.get(timeout = 10);
123 119
            self.logger.debug("emotion rpc done")
124 120

  
125
    def publish_head_animation(self, animation, blocking):
126
        """publish an head animation via mw
127
        :param animation: animation to set
121
    def publish_head_HeadAnimation(self, HeadAnimation, blocking):
122
        """publish an head HeadAnimation via mw
123
        :param HeadAnimation: HeadAnimation to set
128 124
        :param blocking: True if this call should block until execution finished on robot
129 125
        """
130 126

  
131
        self.logger.debug("calling the animation rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING"))
127
        self.logger.debug("calling the HeadAnimation rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING"))
132 128

  
133
        #create animation & fill it with values:
134
        rsb_ani = Animation()
129
        #create HeadAnimation & fill it with values:
130
        rsb_ani = HeadAnimation()
135 131

  
136 132
        #select ani
137
        rsb_ani.target = self.convert_animationtype_to_rsbval(animation.value)
138
        rsb_ani.repetitions = animation.repetitions
139
        rsb_ani.duration_each = animation.time_ms
140
        rsb_ani.scale       = animation.scale
133
        rsb_ani.target = self.convert_HeadAnimationtype_to_rsbval(HeadAnimation.value)
134
        rsb_ani.repetitions = HeadAnimation.repetitions
135
        rsb_ani.duration_each = HeadAnimation.time_ms
136
        rsb_ani.scale       = HeadAnimation.scale
141 137

  
142 138
        if (blocking):
143 139
            #blocking:
144
            result = self.server.animation(rsb_ani)
140
            result = self.server.HeadAnimation(rsb_ani)
145 141
            self.logger.debug("server reply: '%s'" % result)
146 142
        else:
147
            future = self.server.animation.async(rsb_ani)
143
            future = self.server.HeadAnimation.async(rsb_ani)
148 144
            #we can block here for a incoming result with a timeout in s
149 145
            #print '> server reply: "%s"' % future.get(timeout = 10);
150 146

  
151
        self.logger.debug("animation rpc done")
147
        self.logger.debug("HeadAnimation rpc done")
152 148

  
153 149
    def publish_default_emotion(self, emotion, blocking):
154 150
        self.publish_emotion(RobotEmotion.TYPE_DEFAULT, emotion, blocking)
......
164 160
        self.logger.debug("calling the gaze rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING"))
165 161

  
166 162
        #create gaze target & fill it with values:
167
        rsb_gaze = GazeTarget()
163
        rsb_gaze = BinocularHeadGaze()
168 164

  
169 165
        #fill proto
170
        rsb_gaze.pan  = gaze.pan
171
        rsb_gaze.tilt = gaze.tilt
172
        rsb_gaze.roll = gaze.roll
166
	rsb_gaze.target = SphericalDirectionFloat()
167
	rsb_gaze.target.elevation = gaze.tilt
168
	rsb_gaze.target.azimuth   = gaze.pan
169

  
173 170
        rsb_gaze.vergence = gaze.vergence
174
        rsb_gaze.pan_offset  = gaze.pan_offset
175
        rsb_gaze.tilt_offset = gaze.tilt_offset
171

  
172
	
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 178
            #blocking:
......
185 185

  
186 186
        self.logger.debug("gaze rpc done")
187 187

  
188
"""
188 189
    def publish_mouth_target(self, mouth, blocking):
189
        """publish a mouth target via mw
190
        publish a mouth target via mw
190 191
        :param mouth: mouth value to set
191 192
        :param blocking: True if this call should block until execution finished on robot
192
        """
193
        
193 194
        self.logger.debug("calling the mouth rpc (%s)..." % ("BLOCKING" if blocking else "NON-BLOCKING"))
194 195

  
195 196
        #create mouth state & fill it with values:
......
213 214
            #print '> server reply: "%s"' % future.get(timeout = 10);
214 215

  
215 216
        self.logger.debug("mouth rpc done")
217
"""
216 218

  
217 219
    def publish_speech(self, text, blocking):
218 220
        """publish a tts request via mw
......
237 239

  
238 240
    #######################################################################
239 241
    # some helpers
240
    def convert_animationtype_to_rsbval(self, value):
241
        """convert RobotAnimation.value to RSB animation value
242
        :param value: RobotAnimation.* id to convert to rsb id
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
243 245
        """
244 246
        #NOTE: this convertion is important as the actual integer values of
245 247
        #      thy python api and the protobuf might be different
246 248

  
247
        if (value == RobotAnimation.IDLE):
248
            return Animation().IDLE
249
        elif (value == RobotAnimation.HEAD_NOD):
250
            return Animation().HEAD_NOD
251
        elif (value == RobotAnimation.HEAD_SHAKE):
252
            return Animation().HEAD_SHAKE
253
        elif (value == RobotAnimation.EYEBLINK_L):
254
            return Animation().EYEBLINK_L
255
        elif (value == RobotAnimation.EYEBLINK_R):
256
            return  Animation().EYEBLINK_R
257
        elif (value == RobotAnimation.EYEBLINK_BOTH):
258
            return  Animation().EYEBLINK_BOTH
259
        elif (value == RobotAnimation.EYEBROWS_RAISE):
260
            return  Animation().EYEBROWS_RAISE
261
        elif (value == RobotAnimation.EYEBROWS_LOWER):
262
            return  Animation().EYEBROWS_LOWER
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
263 265
        else:
264
            self.logger.error("invalid animation type %d\n" % (value))
265
            return  Animation().NEUTRAL
266
            self.logger.error("invalid HeadAnimation type %d\n" % (value))
267
            return  HeadAnimation().NEUTRAL
266 268

  
267 269
    def convert_emotiontype_to_rsbval(self, value):
268
        """convert RobotEmotion.value to RSB animation value
270
        """convert RobotEmotion.value to RSB HeadAnimation value
269 271
        :param value: RobotEmotion.* id to convert to rsb id
270 272
        """
271 273
        #NOTE: this convertion is important as the actual integer values of
272 274
        #      thy python api and the protobuf might be different
273 275

  
274 276
        if (value == RobotEmotion.NEUTRAL):
275
            return EmotionState().NEUTRAL
277
            return EmotionExpression().NEUTRAL
276 278
        elif (value == RobotEmotion.HAPPY):
277
            return EmotionState().HAPPY
279
            return EmotionExpression().HAPPY
278 280
        elif (value == RobotEmotion.SAD):
279
            return EmotionState().SAD
281
            return EmotionExpression().SAD
280 282
        elif (value == RobotEmotion.ANGRY):
281
            return EmotionState().ANGRY
283
            return EmotionExpression().ANGRY
282 284
        elif (value == RobotEmotion.SURPRISED):
283
            return  EmotionState().SURPRISED
285
            return  EmotionExpression().SURPRISED
284 286
        elif (value == RobotEmotion.FEAR):
285
            return EmotionState().FEAR
287
            return EmotionExpression().FEAR
286 288
        else:
287 289
            self.logger.error("invalid emotion type %d\n" % (value))
288
            return  EmotionState().NEUTRAL
290
            return  EmotionExpression().NEUTRAL

Also available in: Unified diff