From 4537be8199670a5680bf8165e00dd43a8db1f9a8 Mon Sep 17 00:00:00 2001 From: Kevin Siegall Date: Tue, 11 Jul 2023 15:07:06 -0400 Subject: [PATCH] Fix monotonic time issue --- XRPLib/differential_drive.py | 20 ++++++++++---------- XRPLib/timeout.py | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/XRPLib/differential_drive.py b/XRPLib/differential_drive.py index d9bf711..31e257f 100644 --- a/XRPLib/differential_drive.py +++ b/XRPLib/differential_drive.py @@ -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. @@ -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 """ @@ -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 @@ -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 @@ -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 diff --git a/XRPLib/timeout.py b/XRPLib/timeout.py index ab65c1e..bc4e6a6 100644 --- a/XRPLib/timeout.py +++ b/XRPLib/timeout.py @@ -9,7 +9,7 @@ def __init__(self, timeout): :type timeout: float """ self.timeout = timeout - self.start_time = time.monotonic() + self.start_time = time.time() def is_done(self): """ @@ -17,4 +17,4 @@ def is_done(self): """ if self.timeout is None: return False - return time.monotonic() - self.start_time > self.timeout \ No newline at end of file + return time.time() - self.start_time > self.timeout \ No newline at end of file