@@ -27,6 +27,21 @@ def get_default_differential_drive(cls):
27
27
return cls ._DEFAULT_DIFFERENTIAL_DRIVE_INSTANCE
28
28
29
29
def __init__ (self , left_motor : EncodedMotor , right_motor : EncodedMotor , imu : IMU | None = None , wheel_diam :float = 6.0 , wheel_track :float = 13.5 ):
30
+ """
31
+ A Differential Drive class designed for the XRP two-wheeled drive robot.
32
+
33
+ :param leftMotor: The left motor of the drivetrain
34
+ :type leftMotor: EncodedMotor
35
+ :param rightMotor: The right motor of the drivetrain
36
+ :type rightMotor: EncodedMotor
37
+ :param imu: The IMU of the robot. If None, the robot will not use the IMU for turning or maintaining heading.
38
+ :type imu: IMU
39
+ :param wheelDiam: The diameter of the wheels in inches. Defaults to 6 inches.
40
+ :type wheelDiam: float
41
+ :param wheelTrack: The distance between the wheels in inches. Defaults to 13.5 inches.
42
+ :type wheelTrack: float
43
+ """
44
+
30
45
self .left_motor = left_motor
31
46
self .right_motor = right_motor
32
47
self .imu = imu
@@ -38,10 +53,10 @@ def set_effort(self, left_effort: float, right_effort: float) -> None:
38
53
"""
39
54
Set the raw effort of both motors individually
40
55
41
- : param leftEffort: The power (Bounded from -1 to 1) to set the left motor to.
42
- : type leftEffort: float
43
- : param rightEffort: The power (Bounded from -1 to 1) to set the right motor to.
44
- : type rightEffort: float
56
+ :param leftEffort: The power (Bounded from -1 to 1) to set the left motor to.
57
+ :type leftEffort: float
58
+ :param rightEffort: The power (Bounded from -1 to 1) to set the right motor to.
59
+ :type rightEffort: float
45
60
"""
46
61
47
62
self .left_motor .set_effort (left_effort )
@@ -51,10 +66,10 @@ def set_speed(self, left_speed: float, right_speed: float) -> None:
51
66
"""
52
67
Set the speed of both motors individually
53
68
54
- : param leftSpeed: The speed (In Centimeters per Second) to set the left motor to.
55
- : type leftSpeed: float
56
- : param rightSpeed: The speed (In Centimeters per Second) to set the right motor to.
57
- : type rightSpeed: float
69
+ :param leftSpeed: The speed (In Centimeters per Second) to set the left motor to.
70
+ :type leftSpeed: float
71
+ :param rightSpeed: The speed (In Centimeters per Second) to set the right motor to.
72
+ :type rightSpeed: float
58
73
"""
59
74
# Convert from cm/s to RPM
60
75
cmpsToRPM = 60 / (math .pi * self .wheel_diam )
@@ -80,13 +95,15 @@ def reset_encoder_position(self) -> None:
80
95
81
96
def get_left_encoder_position (self ) -> float :
82
97
"""
83
- Return the current position of the left motor's encoder in revolutions.
98
+ :return: the current position of the left motor's encoder in revolutions.
99
+ :rtype: float
84
100
"""
85
101
return self .left_motor .get_position ()
86
102
87
103
def get_right_encoder_position (self ) -> float :
88
104
"""
89
- Return the current position of the right motor's encoder in revolutions.
105
+ :return: the current position of the right motor's encoder in revolutions.
106
+ :rtype: float
90
107
"""
91
108
return self .right_motor .get_position ()
92
109
@@ -96,18 +113,18 @@ def straight(self, distance: float, max_effort: float = 0.5, timeout: float = No
96
113
Go forward the specified distance in centimeters, and exit function when distance has been reached.
97
114
Speed is bounded from -1 (reverse at full speed) to 1 (forward at full speed)
98
115
99
- : param distance: The distance for the robot to travel (In Centimeters)
100
- : type distance: float
101
- : param speed: The speed for which the robot to travel (Bounded from -1 to 1). Default is half speed forward
102
- : type speed: float
103
- : param timeout: The amount of time before the robot stops trying to move forward and continues to the next step (In Seconds)
104
- : type timeout: float
105
- : param main_controller: The main controller, for handling the distance driven forwards
106
- : type main_controller: Controller
107
- : param secondary_controller: The secondary controller, for correcting heading error that may result during the drive.
108
- : type secondary_controller: Controller
109
- : return: if the distance was reached before the timeout
110
- : rtype: bool
116
+ :param distance: The distance for the robot to travel (In Centimeters)
117
+ :type distance: float
118
+ :param speed: The speed for which the robot to travel (Bounded from -1 to 1). Default is half speed forward
119
+ :type speed: float
120
+ :param timeout: The amount of time before the robot stops trying to move forward and continues to the next step (In Seconds)
121
+ :type timeout: float
122
+ :param main_controller: The main controller, for handling the distance driven forwards
123
+ :type main_controller: Controller
124
+ :param secondary_controller: The secondary controller, for correcting heading error that may result during the drive.
125
+ :type secondary_controller: Controller
126
+ :return: if the distance was reached before the timeout
127
+ :rtype: bool
111
128
"""
112
129
# ensure distance is always positive while speed could be either positive or negative
113
130
if distance < 0 :
@@ -181,19 +198,19 @@ def turn(self, turn_degrees: float, max_effort: float = 0.5, timeout: float = No
181
198
Speed is bounded from -1 (turn counterclockwise the relative heading at full speed) to 1 (turn clockwise the relative heading at full speed)
182
199
Uses the IMU to determine the heading of the robot and P control for the motor controller.
183
200
184
- : param turnDegrees: The number of angle for the robot to turn (In Degrees)
185
- : type turnDegrees: float
186
- : param speed: The speed for which the robot to travel (Bounded from -1 to 1). Default is half speed forward.
187
- : type speed: float
188
- : param timeout: The amount of time before the robot stops trying to turn and continues to the next step (In Seconds)
189
- : type timeout: float
190
- : param main_controller: The main controller, for handling the angle turned
191
- : type main_controller: Controller
192
- : param secondary_controller: The secondary controller, for maintaining position during the turn by controlling the encoder count difference
193
- : type secondary_controller: Controller
194
- : param use_imu: A boolean flag that changes if the main controller bases it's movement off of
195
- : return: if the distance was reached before the timeout
196
- : rtype: bool
201
+ :param turnDegrees: The number of angle for the robot to turn (In Degrees)
202
+ :type turnDegrees: float
203
+ :param speed: The speed for which the robot to travel (Bounded from -1 to 1). Default is half speed forward.
204
+ :type speed: float
205
+ :param timeout: The amount of time before the robot stops trying to turn and continues to the next step (In Seconds)
206
+ :type timeout: float
207
+ :param main_controller: The main controller, for handling the angle turned
208
+ :type main_controller: Controller
209
+ :param secondary_controller: The secondary controller, for maintaining position during the turn by controlling the encoder count difference
210
+ :type secondary_controller: Controller
211
+ :param use_imu: A boolean flag that changes if the main controller bases it's movement off of
212
+ :return: if the distance was reached before the timeout
213
+ :rtype: bool
197
214
"""
198
215
199
216
if max_effort < 0 :
0 commit comments