@@ -49,6 +49,8 @@ def __init__(self):
49
49
self .right_tof = None
50
50
self .top_tof = None
51
51
self .bottom_tof = None
52
+ self .linear_velocity = None
53
+ self .angular_velocity = None
52
54
self .version = [None , None , None ]
53
55
54
56
def begin (self ) -> int :
@@ -174,6 +176,13 @@ def drive(self, linear_velocity: float, angular_velocity: float):
174
176
self .packeter .packetC2F (ord ('V' ), linear_velocity , angular_velocity )
175
177
uart .write (self .packeter .msg [0 :self .packeter .msg_size ])
176
178
179
+ def get_drive_speed (self ) -> (float , float ):
180
+ """
181
+ Returns linear and angular velocity of the robot
182
+ :return: linear_velocity, angular_velocity
183
+ """
184
+ return self .linear_velocity , self .angular_velocity
185
+
177
186
def set_servo_positions (self , a_position : int , b_position : int ):
178
187
"""
179
188
Sets A/B servomotor angle
@@ -286,9 +295,12 @@ def _parse_message(self) -> int:
286
295
elif code == ord ('q' ):
287
296
# imu position
288
297
_ , self .roll , self .pitch , self .yaw = self .packeter .unpacketC3F ()
289
- if code == ord ('w' ):
298
+ elif code == ord ('w' ):
290
299
# wheels position
291
300
_ , self .left_wheel ._position , self .right_wheel ._position = self .packeter .unpacketC2F ()
301
+ elif code == ord ('v' ):
302
+ # robot velocity
303
+ _ , self .linear_velocity , self .angular_velocity = self .packeter .unpacketC2F ()
292
304
elif code == 0x7E :
293
305
# firmware version
294
306
_ , * self .version = self .packeter .unpacketC3B ()
0 commit comments