Skip to content

Commit 4537be8

Browse files
committed
Fix monotonic time issue
1 parent 798594c commit 4537be8

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

XRPLib/differential_drive.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_default_differential_drive(cls):
2626

2727
return cls._DEFAULT_DIFFERENTIAL_DRIVE_INSTANCE
2828

29-
def __init__(self, left_motor: EncodedMotor, right_motor: EncodedMotor, imu: IMU | None = None, wheel_diam:float = 6.0, wheel_track:float = 13.5):
29+
def __init__(self, left_motor: EncodedMotor, right_motor: EncodedMotor, imu: IMU | None = None, wheel_diam:float = 6.0, wheel_track:float = 15.5):
3030
"""
3131
A Differential Drive class designed for the XRP two-wheeled drive robot.
3232
@@ -36,9 +36,9 @@ def __init__(self, left_motor: EncodedMotor, right_motor: EncodedMotor, imu: IMU
3636
:type rightMotor: EncodedMotor
3737
:param imu: The IMU of the robot. If None, the robot will not use the IMU for turning or maintaining heading.
3838
:type imu: IMU
39-
:param wheelDiam: The diameter of the wheels in inches. Defaults to 6 inches.
39+
:param wheelDiam: The diameter of the wheels in inches. Defaults to 6 cm.
4040
:type wheelDiam: float
41-
:param wheelTrack: The distance between the wheels in inches. Defaults to 13.5 inches.
41+
:param wheelTrack: The distance between the wheels in inches. Defaults to 15.5 cm.
4242
:type wheelTrack: float
4343
"""
4444

@@ -110,12 +110,12 @@ def get_right_encoder_position(self) -> float:
110110
def straight(self, distance: float, max_effort: float = 0.5, timeout: float = None, main_controller: Controller = None, secondary_controller: Controller = None) -> bool:
111111
"""
112112
Go forward the specified distance in centimeters, and exit function when distance has been reached.
113-
Speed is bounded from -1 (reverse at full speed) to 1 (forward at full speed)
113+
Max_effort is bounded from -1 (reverse at full speed) to 1 (forward at full speed)
114114
115115
:param distance: The distance for the robot to travel (In Centimeters)
116116
:type distance: float
117-
:param speed: The speed for which the robot to travel (Bounded from -1 to 1). Default is half speed forward
118-
:type speed: float
117+
:param max_effort: The max effort for which the robot to travel (Bounded from -1 to 1). Default is half effort forward
118+
:type max_effort: float
119119
:param timeout: The amount of time before the robot stops trying to move forward and continues to the next step (In Seconds)
120120
:type timeout: float
121121
:param main_controller: The main controller, for handling the distance driven forwards
@@ -125,8 +125,8 @@ def straight(self, distance: float, max_effort: float = 0.5, timeout: float = No
125125
:return: if the distance was reached before the timeout
126126
:rtype: bool
127127
"""
128-
# ensure distance is always positive while speed could be either positive or negative
129-
if distance < 0:
128+
# ensure effort is always positive while distance could be either positive or negative
129+
if max_effort < 0:
130130
max_effort *= -1
131131
distance *= -1
132132

@@ -199,8 +199,8 @@ def turn(self, turn_degrees: float, max_effort: float = 0.5, timeout: float = No
199199
200200
:param turnDegrees: The number of angle for the robot to turn (In Degrees)
201201
:type turnDegrees: float
202-
:param speed: The speed for which the robot to travel (Bounded from -1 to 1). Default is half speed forward.
203-
:type speed: float
202+
:param max_effort: The max effort for which the robot to travel (Bounded from -1 to 1). Default is half effort forward.
203+
:type max_effort: float
204204
:param timeout: The amount of time before the robot stops trying to turn and continues to the next step (In Seconds)
205205
:type timeout: float
206206
:param main_controller: The main controller, for handling the angle turned

XRPLib/timeout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ def __init__(self, timeout):
99
:type timeout: float
1010
"""
1111
self.timeout = timeout
12-
self.start_time = time.monotonic()
12+
self.start_time = time.time()
1313

1414
def is_done(self):
1515
"""
1616
:return: True if the timeout has expired, False otherwise
1717
"""
1818
if self.timeout is None:
1919
return False
20-
return time.monotonic() - self.start_time > self.timeout
20+
return time.time() - self.start_time > self.timeout

0 commit comments

Comments
 (0)