Skip to content

Commit 295042e

Browse files
committed
Added comments to DriveLibraries.py; fixed minor bugs with AuxMotorBumpStop and ArcTurn.
1 parent da0dc7d commit 295042e

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

FLLMaster/DriveLibraries.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ def GyroTurn(self, Heading):
287287
self.tank.stop()
288288

289289
def ArcTurn(self, Degrees, Radius, Speed):
290+
"""
291+
Drive the robot in an arc with a specified radius, for a certain number of degrees.
292+
293+
``Degrees``: The number or degrees to drive around the arc. Positive will turn the front of the robot right, negative left (car turn).
294+
``Radius``: The radius of the arc to drive, in cm. Must be positive.
295+
``Speed``: The speed at which to drive around the arc, in percentage of full power (same units as EV3-G). Negative will drive
296+
backwards.
297+
"""
298+
299+
# Ensure the parameters are within reasonable limits, and adjust/reject as necessary.
290300
if Speed > 75:
291301
Speed = 75
292302
print("Speed must be between -75 and 75 (inclusive).")
@@ -296,22 +306,29 @@ def ArcTurn(self, Degrees, Radius, Speed):
296306
if Radius <= 0:
297307
print("Radius must be greater than zero. Use negative degrees to turn the opposite direction.")
298308
return
299-
math.fmod(Degrees, 360)
309+
# No point in driving in circles
310+
Degrees = math.fmod(Degrees, 360)
300311

312+
# Read the angle of the robot, and store in startHeading
301313
startHeading = self.correctedAngle
302314

315+
# If both Degrees and Speed have the same sign, the right wheel should be slowed down.
316+
# Otherwise, slow down the left wheel.
303317
if ((Degrees > 0) and (Speed > 0)) or ((Degrees < 0) and (Speed < 0)):
304318
self.tank.on(Speed, (Radius - self.WidthBetweenWheels) * Speed / Radius)
305319
else:
306320
self.tank.on((Radius - self.WidthBetweenWheels) * Speed / Radius, Speed)
307321

322+
# If Degrees is positive, wait for the degrees turned to become >= Degrees (to turn).
323+
# Otherwise, wait for the degrees turned to become <= Degrees
308324
if Degrees > 0:
309325
while (self.correctedAngle - startHeading) < Degrees:
310326
dummy = 1
311327
else:
312328
while (self.correctedAngle - startHeading) > Degrees:
313329
dummy = 1
314330

331+
# Stop the motors
315332
self.tank.stop()
316333

317334
def DriveBump(self, Heading, Speed):
@@ -352,7 +369,7 @@ def DriveBump(self, Heading, Speed):
352369
turn_native_units = sign * max([min([(self.kp * error) + (self.ki * integral) + (self.kd * derivative), 100]), -100])
353370

354371
# Start the motors without speed regulation, using the Steering value and Speed
355-
lsrs = self.steer.get_speed_steering(turn_native_units, Speed)
372+
lsrs = self.steer.get_speed_steering(turn_native_units, Speed) # lsrs = left-speed right-speed
356373
lsNative = lsrs[0]
357374
rsNative = lsrs[1]
358375
self.lm.on(SpeedNativeUnits(lsNative))
@@ -391,6 +408,14 @@ def DriveBump(self, Heading, Speed):
391408
self.rm.stop()
392409

393410
def AuxMotorBumpStop(self, Speed, Threshold, Port):
411+
"""
412+
Similar to DriveBump, will run an auxillary motor until the speed drops below ``Threshold``% of ``Speed``.
413+
414+
``Speed``: Speed at which to run the motor.
415+
``Threshold``: Percentage of ``Speed`` that the motor speed must drop below before shutting off.
416+
``Port``: Motor port.
417+
"""
418+
394419
if Speed > 75:
395420
Speed = 75
396421
print("Speed must be between -75 and 75 (inclusive).")
@@ -404,14 +429,14 @@ def AuxMotorBumpStop(self, Speed, Threshold, Port):
404429
print("Threshold must be greater than zero and less than or equal to 100")
405430
return
406431

407-
target = abs((self.lm.max_speed * Speed) / 100)
408-
409432
if Port == self.AuxMotor1:
433+
target = abs((self.m1.max_speed * Speed) / 100)
410434
msNative = (Speed * self.m1.max_speed) / 100
411435
self.m1.on(SpeedNativeUnits(msNative))
412436
time.sleep(0.5)
413437
motrspeed = abs(self.m1.speed)
414438
else:
439+
target = abs((self.m2.max_speed * Speed) / 100)
415440
msNative = (Speed * self.m2.max_speed) / 100
416441
self.m2.on(SpeedNativeUnits(msNative))
417442
time.sleep(0.5)

0 commit comments

Comments
 (0)