Skip to content

Commit

Permalink
Fix monotonic time issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ksiegall committed Jul 11, 2023
1 parent 798594c commit 4537be8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions XRPLib/differential_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_default_differential_drive(cls):

return cls._DEFAULT_DIFFERENTIAL_DRIVE_INSTANCE

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

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

Expand Down Expand Up @@ -199,8 +199,8 @@ def turn(self, turn_degrees: float, max_effort: float = 0.5, timeout: float = No
:param turnDegrees: The number of angle for the robot to turn (In Degrees)
:type turnDegrees: float
:param speed: The speed for which the robot to travel (Bounded from -1 to 1). Default is half speed forward.
:type speed: float
:param max_effort: The max effort for which the robot to travel (Bounded from -1 to 1). Default is half effort forward.
:type max_effort: float
:param timeout: The amount of time before the robot stops trying to turn and continues to the next step (In Seconds)
:type timeout: float
:param main_controller: The main controller, for handling the angle turned
Expand Down
4 changes: 2 additions & 2 deletions XRPLib/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ def __init__(self, timeout):
:type timeout: float
"""
self.timeout = timeout
self.start_time = time.monotonic()
self.start_time = time.time()

def is_done(self):
"""
:return: True if the timeout has expired, False otherwise
"""
if self.timeout is None:
return False
return time.monotonic() - self.start_time > self.timeout
return time.time() - self.start_time > self.timeout

0 comments on commit 4537be8

Please sign in to comment.