Skip to content

Commit 3f17f18

Browse files
committed
Minor API improvements
1 parent 08a45e9 commit 3f17f18

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

Examples/misc_examples.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,6 @@
77
as well as control a servo that may be connected.
88
"""
99

10-
# Does nothing until any button input is found
11-
def wait_for_button():
12-
print("Waiting for button signal from either button")
13-
14-
# Wait until user command before running
15-
while not board.is_button_pressed():
16-
time.sleep(.01)
17-
18-
# Wait until user to release button before running
19-
while board.is_button_pressed():
20-
time.sleep(.01)
21-
22-
print("Button input found; Program starting")
23-
2410
def test_leds():
2511
board.led_blink(3)
2612
time.sleep(1)
@@ -50,8 +36,8 @@ def ivp():
5036
print("Testing Servo")
5137
test_servo()
5238
print("Testing LEDs")
53-
wait_for_button()
39+
board.wait_for_button()
5440
test_leds()
5541
print("Testing Drivetrain:")
56-
wait_for_button()
42+
board.wait_for_button()
5743
test_drive()

XRPLib/board.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from machine import Pin, ADC, Timer
2+
import time
23

34
class Board:
45

@@ -65,6 +66,20 @@ def is_button_pressed(self) -> bool:
6566
"""
6667
return not self.button.value()
6768

69+
def wait_for_button(self):
70+
"""
71+
Halts the program until the button is pressed
72+
"""
73+
74+
# Wait until user command before running
75+
while not self.is_button_pressed():
76+
time.sleep(.01)
77+
78+
# Wait until user to release button before running
79+
while self.is_button_pressed():
80+
time.sleep(.01)
81+
82+
6883
def led_on(self):
6984
"""
7085
Turns the LED on

XRPLib/differential_drive.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ def reset_encoder_position(self) -> None:
9494

9595
def get_left_encoder_position(self) -> float:
9696
"""
97-
:return: the current position of the left motor's encoder in revolutions.
97+
:return: the current position of the left motor's encoder in cm.
9898
:rtype: float
9999
"""
100-
return self.left_motor.get_position()
100+
return self.left_motor.get_position()*math.pi*self.wheel_diam
101101

102102
def get_right_encoder_position(self) -> float:
103103
"""
104-
:return: the current position of the right motor's encoder in revolutions.
104+
:return: the current position of the right motor's encoder in cm.
105105
:rtype: float
106106
"""
107-
return self.right_motor.get_position()
107+
return self.right_motor.get_position()*math.pi*self.wheel_diam
108108

109109

110110
def straight(self, distance: float, max_effort: float = 0.5, timeout: float = None, main_controller: Controller = None, secondary_controller: Controller = None) -> bool:

0 commit comments

Comments
 (0)