Skip to content

Commit bb43223

Browse files
committed
documentation
1 parent baedaa0 commit bb43223

File tree

1 file changed

+78
-7
lines changed

1 file changed

+78
-7
lines changed

arduino_alvik.py

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def __init__(self):
4646
self.version = [None, None, None]
4747

4848
def begin(self) -> int:
49+
"""
50+
Begins all Alvik operations
51+
:return:
52+
"""
4953
if not CHECK_STM32.value():
5054
print("\nTurn on your Arduino Alvik!\n")
5155
return -1
@@ -97,6 +101,10 @@ def _reset_hw():
97101
sleep_ms(100)
98102

99103
def get_wheels_speed(self) -> (float, float):
104+
"""
105+
Returns the speed of the wheels
106+
:return: left_wheel_speed, right_wheel_speed
107+
"""
100108
return self.left_wheel.get_speed(), self.right_wheel.get_speed()
101109

102110
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):
133141
def get_orientation(self) -> (float, float, float):
134142
"""
135143
Returns the orientation of the IMU
136-
:return:
144+
:return: roll, pitch, yaw
137145
"""
138146

139147
return self.roll, self.pitch, self.yaw
140148

141149
def get_line_sensors(self) -> (int, int, int):
142150
"""
143151
Returns the line sensors readout
144-
:return:
152+
:return: left_line, center_line, right_line
145153
"""
146154

147155
return self.left_line, self.center_line, self.right_line
@@ -307,36 +315,72 @@ def _parse_message(self) -> int:
307315
return 0
308316

309317
def _get_touch(self) -> int:
318+
"""
319+
Returns the touch sensor's state
320+
:return: touch_bits
321+
"""
310322
return self.touch_bits
311323

312324
def get_touch_any(self) -> bool:
325+
"""
326+
Returns true if any button is pressed
327+
:return:
328+
"""
313329
return bool(self.touch_bits & 0b00000001)
314330

315331
def get_touch_ok(self) -> bool:
332+
"""
333+
Returns true if ok button is pressed
334+
:return:
335+
"""
316336
return bool(self.touch_bits & 0b00000010)
317337

318338
def get_touch_cancel(self) -> bool:
339+
"""
340+
Returns true if cancel button is pressed
341+
:return:
342+
"""
319343
return bool(self.touch_bits & 0b00000100)
320344

321345
def get_touch_center(self) -> bool:
346+
"""
347+
Returns true if center button is pressed
348+
:return:
349+
"""
322350
return bool(self.touch_bits & 0b00001000)
323351

324352
def get_touch_up(self) -> bool:
353+
"""
354+
Returns true if up button is pressed
355+
:return:
356+
"""
325357
return bool(self.touch_bits & 0b00010000)
326358

327359
def get_touch_left(self) -> bool:
360+
"""
361+
Returns true if left button is pressed
362+
:return:
363+
"""
328364
return bool(self.touch_bits & 0b00100000)
329365

330366
def get_touch_down(self) -> bool:
367+
"""
368+
Returns true if down button is pressed
369+
:return:
370+
"""
331371
return bool(self.touch_bits & 0b01000000)
332372

333373
def get_touch_right(self) -> bool:
374+
"""
375+
Returns true if right button is pressed
376+
:return:
377+
"""
334378
return bool(self.touch_bits & 0b10000000)
335379

336380
def get_color(self) -> (int, int, int):
337381
"""
338-
Returns the RGB color readout
339-
:return:
382+
Returns the RGB color (raw) readout
383+
:return: red, green, blue
340384
"""
341385

342386
return self.red, self.green, self.blue
@@ -345,12 +389,24 @@ def get_color(self) -> (int, int, int):
345389
# int((self.blue/COLOR_FULL_SCALE)*255))
346390

347391
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+
"""
348396
return self.left_tof, self.center_left_tof, self.center_tof, self.center_right_tof, self.right_tof
349397

350398
def get_version(self) -> str:
399+
"""
400+
Returns the firmware version of the Alvik
401+
:return:
402+
"""
351403
return f'{self.version[0]}.{self.version[1]}.{self.version[2]}'
352404

353405
def print_status(self):
406+
"""
407+
Prints the Alvik status
408+
:return:
409+
"""
354410
for a in vars(self):
355411
if str(a).startswith('_'):
356412
continue
@@ -366,6 +422,11 @@ def __init__(self, packeter: ucPack, label: int, wheel_diameter_mm: float = WHEE
366422
self._speed = None
367423

368424
def reset(self, initial_position: float = 0.0):
425+
"""
426+
Resets the wheel reference position
427+
:param initial_position:
428+
:return:
429+
"""
369430
pass
370431

371432
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):
389450

390451
def set_speed(self, velocity: float, unit: str = 'rpm'):
391452
"""
392-
Sets left/right motor speed
453+
Sets the motor speed
393454
:param velocity: the speed of the motor
394455
:param unit: the unit of measurement
395456
:return:
@@ -403,9 +464,9 @@ def set_speed(self, velocity: float, unit: str = 'rpm'):
403464
self._packeter.packetC2B1F(ord('W'), self._label & 0xFF, ord('V'), velocity)
404465
uart.write(self._packeter.msg[0:self._packeter.msg_size])
405466

406-
def get_speed(self):
467+
def get_speed(self) -> float:
407468
"""
408-
Gets the current RPM speed of the wheel
469+
Returns the current RPM speed of the wheel
409470
:return:
410471
"""
411472
return self._speed
@@ -461,8 +522,18 @@ def set_color(self, red: bool, green: bool, blue: bool):
461522

462523

463524
def perc_to_rpm(percent: float) -> float:
525+
"""
526+
Converts percent of max_rpm to rpm
527+
:param percent:
528+
:return:
529+
"""
464530
return (percent / 100.0)*MOTOR_MAX_RPM
465531

466532

467533
def rad_to_deg(rad: float) -> float:
534+
"""
535+
Converts radians to degrees
536+
:param rad:
537+
:return:
538+
"""
468539
return rad*180/math.pi

0 commit comments

Comments
 (0)