Skip to content

Commit 98e89c3

Browse files
committed
Added support for GearRatio.
Made auxillary sensor instantiation dynamic.
1 parent 6525d50 commit 98e89c3

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

FLLMaster/DriveLibraries.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ def __init__(self, filename):
5555
# values are incorrect, and they are the first things to check if the drive functions do not work correctly.
5656
self.MotorInverted = bool(conf.get('Drivebase', 'MotorInverted') == "TRUE")
5757
self.GyroInverted = bool(conf.get('Drivebase', 'GyroInverted') == "TRUE")
58-
# Reads and stores the gear ratio value. Currently not used, except for motor direction.
59-
# (1 and -1 work, with -1 meaning a 1:1 ratio that reverses the motor direction)
58+
# Reads and stores the gear ratio value.
6059
self.GearRatio = float(conf.get('Drivebase', 'GearRatio'))
6160
# Reads and stores the PID gains for driving in a straight line.
6261
self.kp = float(conf.get('Drivebase', 'kp'))
@@ -96,14 +95,18 @@ def __init__(self, filename):
9695
sleep(0.3)
9796
self.spkr.beep('-f 220')
9897

99-
10098
# Instantiate the sensor objects
10199
self.cs = ColorSensor(self.ColorPort)
102100
self.gs = GyroSensor(self.GyroPort)
103-
self.ir = InfraredSensor(self.InfraredPort)
104-
self.us = UltrasonicSensor(self.UltrasonicPort)
105-
106-
# Instantiate the drive motor objecta, as well as the motorset objects for controlling both simultainiously
101+
# Only instantiate auxillary sensors if the config file shows they exist
102+
if self.InfraredPort is not None:
103+
self.ir = InfraredSensor(self.InfraredPort)
104+
if self.UltrasonicPort is not None:
105+
self.us = UltrasonicSensor(self.UltrasonicPort)
106+
if self.TouchPort is not None:
107+
self.ts = TouchSensor(self.TouchPort)
108+
109+
# Instantiate the drive motor objects, as well as the motorset objects for controlling both simultainiously
107110
self.tank = MoveTank(self.LeftMotor, self.RightMotor)
108111
self.steer = MoveSteering(self.LeftMotor, self.RightMotor)
109112
self.lm = LargeMotor(self.LeftMotor)
@@ -237,7 +240,7 @@ def DriveAtHeading(self, Heading, Distance, Speed, Stop):
237240
sign = Speed / abs(Speed)
238241

239242
# Find number of degrees that motors need to rotate to reach the desired number of cm.
240-
target = (Distance * 360) / self.WheelCircumference
243+
target = (Distance * 360) / self.WheelCircumference * abs(self.GearRatio)
241244

242245
# Find the average of the left and right encoders, as they could be different from PID correction
243246
avg = abs((left_motor_change + right_motor_change) / 2)
@@ -604,7 +607,7 @@ def LineFollow(self, Distance, Speed, Stop):
604607
sign = Speed / abs(Speed)
605608

606609
# Find number of degrees that motors need to rotate to reach the desired number of cm.
607-
target = (Distance * 360) / self.WheelCircumference
610+
target = (Distance * 360) / self.WheelCircumference * abs(self.GearRatio)
608611

609612
# Find the average of the left and right encoders, as they could be different from PID correction
610613
avg = abs((left_motor_change + right_motor_change) / 2)

0 commit comments

Comments
 (0)