@@ -46,6 +46,10 @@ def __init__(self):
46
46
self .version = [None , None , None ]
47
47
48
48
def begin (self ) -> int :
49
+ """
50
+ Begins all Alvik operations
51
+ :return:
52
+ """
49
53
if not CHECK_STM32 .value ():
50
54
print ("\n Turn on your Arduino Alvik!\n " )
51
55
return - 1
@@ -97,6 +101,10 @@ def _reset_hw():
97
101
sleep_ms (100 )
98
102
99
103
def get_wheels_speed (self ) -> (float , float ):
104
+ """
105
+ Returns the speed of the wheels
106
+ :return: left_wheel_speed, right_wheel_speed
107
+ """
100
108
return self .left_wheel .get_speed (), self .right_wheel .get_speed ()
101
109
102
110
def set_wheels_speed (self , left_speed : float , right_speed : float , unit : str = 'rpm' ):
@@ -133,15 +141,15 @@ def set_pid(self, side: str, kp: float, ki: float, kd: float):
133
141
def get_orientation (self ) -> (float , float , float ):
134
142
"""
135
143
Returns the orientation of the IMU
136
- :return:
144
+ :return: roll, pitch, yaw
137
145
"""
138
146
139
147
return self .roll , self .pitch , self .yaw
140
148
141
149
def get_line_sensors (self ) -> (int , int , int ):
142
150
"""
143
151
Returns the line sensors readout
144
- :return:
152
+ :return: left_line, center_line, right_line
145
153
"""
146
154
147
155
return self .left_line , self .center_line , self .right_line
@@ -307,36 +315,72 @@ def _parse_message(self) -> int:
307
315
return 0
308
316
309
317
def _get_touch (self ) -> int :
318
+ """
319
+ Returns the touch sensor's state
320
+ :return: touch_bits
321
+ """
310
322
return self .touch_bits
311
323
312
324
def get_touch_any (self ) -> bool :
325
+ """
326
+ Returns true if any button is pressed
327
+ :return:
328
+ """
313
329
return bool (self .touch_bits & 0b00000001 )
314
330
315
331
def get_touch_ok (self ) -> bool :
332
+ """
333
+ Returns true if ok button is pressed
334
+ :return:
335
+ """
316
336
return bool (self .touch_bits & 0b00000010 )
317
337
318
338
def get_touch_cancel (self ) -> bool :
339
+ """
340
+ Returns true if cancel button is pressed
341
+ :return:
342
+ """
319
343
return bool (self .touch_bits & 0b00000100 )
320
344
321
345
def get_touch_center (self ) -> bool :
346
+ """
347
+ Returns true if center button is pressed
348
+ :return:
349
+ """
322
350
return bool (self .touch_bits & 0b00001000 )
323
351
324
352
def get_touch_up (self ) -> bool :
353
+ """
354
+ Returns true if up button is pressed
355
+ :return:
356
+ """
325
357
return bool (self .touch_bits & 0b00010000 )
326
358
327
359
def get_touch_left (self ) -> bool :
360
+ """
361
+ Returns true if left button is pressed
362
+ :return:
363
+ """
328
364
return bool (self .touch_bits & 0b00100000 )
329
365
330
366
def get_touch_down (self ) -> bool :
367
+ """
368
+ Returns true if down button is pressed
369
+ :return:
370
+ """
331
371
return bool (self .touch_bits & 0b01000000 )
332
372
333
373
def get_touch_right (self ) -> bool :
374
+ """
375
+ Returns true if right button is pressed
376
+ :return:
377
+ """
334
378
return bool (self .touch_bits & 0b10000000 )
335
379
336
380
def get_color (self ) -> (int , int , int ):
337
381
"""
338
- Returns the RGB color readout
339
- :return:
382
+ Returns the RGB color (raw) readout
383
+ :return: red, green, blue
340
384
"""
341
385
342
386
return self .red , self .green , self .blue
@@ -345,12 +389,24 @@ def get_color(self) -> (int, int, int):
345
389
# int((self.blue/COLOR_FULL_SCALE)*255))
346
390
347
391
def get_distance (self ) -> (int , int , int , int , int , int ):
392
+ """
393
+ Returns the distance readout of the TOF sensor
394
+ :return: left_tof, center_left_tof, center_tof, center_right_tof, right_tof
395
+ """
348
396
return self .left_tof , self .center_left_tof , self .center_tof , self .center_right_tof , self .right_tof
349
397
350
398
def get_version (self ) -> str :
399
+ """
400
+ Returns the firmware version of the Alvik
401
+ :return:
402
+ """
351
403
return f'{ self .version [0 ]} .{ self .version [1 ]} .{ self .version [2 ]} '
352
404
353
405
def print_status (self ):
406
+ """
407
+ Prints the Alvik status
408
+ :return:
409
+ """
354
410
for a in vars (self ):
355
411
if str (a ).startswith ('_' ):
356
412
continue
@@ -366,6 +422,11 @@ def __init__(self, packeter: ucPack, label: int, wheel_diameter_mm: float = WHEE
366
422
self ._speed = None
367
423
368
424
def reset (self , initial_position : float = 0.0 ):
425
+ """
426
+ Resets the wheel reference position
427
+ :param initial_position:
428
+ :return:
429
+ """
369
430
pass
370
431
371
432
def set_pid_gains (self , kp : float = MOTOR_KP_DEFAULT , ki : float = MOTOR_KI_DEFAULT , kd : float = MOTOR_KD_DEFAULT ):
@@ -389,7 +450,7 @@ def stop(self):
389
450
390
451
def set_speed (self , velocity : float , unit : str = 'rpm' ):
391
452
"""
392
- Sets left/right motor speed
453
+ Sets the motor speed
393
454
:param velocity: the speed of the motor
394
455
:param unit: the unit of measurement
395
456
:return:
@@ -403,9 +464,9 @@ def set_speed(self, velocity: float, unit: str = 'rpm'):
403
464
self ._packeter .packetC2B1F (ord ('W' ), self ._label & 0xFF , ord ('V' ), velocity )
404
465
uart .write (self ._packeter .msg [0 :self ._packeter .msg_size ])
405
466
406
- def get_speed (self ):
467
+ def get_speed (self ) -> float :
407
468
"""
408
- Gets the current RPM speed of the wheel
469
+ Returns the current RPM speed of the wheel
409
470
:return:
410
471
"""
411
472
return self ._speed
@@ -461,8 +522,18 @@ def set_color(self, red: bool, green: bool, blue: bool):
461
522
462
523
463
524
def perc_to_rpm (percent : float ) -> float :
525
+ """
526
+ Converts percent of max_rpm to rpm
527
+ :param percent:
528
+ :return:
529
+ """
464
530
return (percent / 100.0 )* MOTOR_MAX_RPM
465
531
466
532
467
533
def rad_to_deg (rad : float ) -> float :
534
+ """
535
+ Converts radians to degrees
536
+ :param rad:
537
+ :return:
538
+ """
468
539
return rad * 180 / math .pi
0 commit comments