Skip to content

Commit e861885

Browse files
committed
Finished commenting DriveLibraries.py
1 parent 295042e commit e861885

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

FLLMaster/DriveLibraries.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,13 @@ def AuxMotorBumpStop(self, Speed, Threshold, Port):
411411
"""
412412
Similar to DriveBump, will run an auxillary motor until the speed drops below ``Threshold``% of ``Speed``.
413413
414-
``Speed``: Speed at which to run the motor.
414+
``Speed``: Speed at which to run the motor, in motor percentage (Same units as EV3-G).
415415
``Threshold``: Percentage of ``Speed`` that the motor speed must drop below before shutting off.
416416
``Port``: Motor port.
417417
"""
418+
# Most if statments are only because there are two possible ports; one case for each port
418419

420+
# Ensure values are within reasonable, and adjust/reject as necessary
419421
if Speed > 75:
420422
Speed = 75
421423
print("Speed must be between -75 and 75 (inclusive).")
@@ -429,23 +431,31 @@ def AuxMotorBumpStop(self, Speed, Threshold, Port):
429431
print("Threshold must be greater than zero and less than or equal to 100")
430432
return
431433

434+
# Different commands for different motors, check which motor to use
432435
if Port == self.AuxMotor1:
436+
# Find the target speed in encoder ticks per second
433437
target = abs((self.m1.max_speed * Speed) / 100)
434-
msNative = (Speed * self.m1.max_speed) / 100
435-
self.m1.on(SpeedNativeUnits(msNative))
438+
# Start the motor, with the calculated speed
439+
self.m1.on(SpeedNativeUnits(target))
440+
# Wait for the motor to get up to speed
436441
time.sleep(0.5)
442+
# Set motrspeed to the current motor speed
437443
motrspeed = abs(self.m1.speed)
438444
else:
445+
# Everything here is the same as the first case statement, but using m2 instead of m1 (motor 2, not motor 1)
439446
target = abs((self.m2.max_speed * Speed) / 100)
440-
msNative = (Speed * self.m2.max_speed) / 100
441-
self.m2.on(SpeedNativeUnits(msNative))
447+
self.m2.on(SpeedNativeUnits(target))
442448
time.sleep(0.5)
443449
motrspeed = abs(self.m2.speed)
450+
# Keep the motor on until the motor speed drops below Threshold% of Speed
444451
while motrspeed > (target * Threshold) / 100:
445452
if Port == self.AuxMotor1:
453+
# Update motrspeed until the motor slows down enough to stop
446454
motrspeed = abs(self.m1.speed)
447455
else:
456+
# Same as before, just for the other motor
448457
motrspeed = abs(self.m2.speed)
458+
# Shut off the motor
449459
if Port == self.AuxMotor1:
450460
self.m1.off()
451461
else:

0 commit comments

Comments
 (0)