Drive By Encoders
Last updated
Was this helpful?
Last updated
Was this helpful?
Autonomous Navigation with Motor Encoders
Part 1: Plugging in Your Encoders:
REV Expansion Hub with AndyMark Motors
REV Expansion Hub with CORE HEX Motors
Modern Robotics
Part 2: Autonomous OpMode with Encoders
- Create a new file by selecting the “+” button:
- Use the settings shown below:
- Since this is an autonomous program, you will want to REMOVE the main loop:
- Next, you will want to add an “encoderDrive” method to the area OUTSIDE the runOpmode method, but inside the main java class.
- Copy and paste the following method into the highlighted space in your encoder program above:
Part 3: Setting Your Constants Right
Motor
NevRest 20
NevRest 40
NevRest 60
Tetrix
REV
COREHEX
Counts Per Rev
560
1120
1680
1440
288
- Finally, you will need to calculate your DRIVE_GEAR_REDUCTION. To do this, you will need to take the number of gear/sprocket teeth on your wheel and divide them by the number of gear/sprocket teeth on your motor shaft.
For example, you might have 30 teeth on your wheel and 20 on your motor, so your DRIVE_GEAR_REDUCTION would be: 30 ��������ℎ
20 ��������ℎ= 1.5
- At this point, you should build your OpMode again and measure your robot’s path. If your constants are correct, then the number of inches you put in the code should match the inches your robot travelled.
Part 4: Making your Robot Go Where YOU Want
- As you can see above, the encoderDrive() method accepts a few parameters.
o Speed
o Left Inches
o Right Inches
o Timeout*
So if I wanted to drive forward for 48 inches, at half speed I would call:
encoderDrive(.5,48,48,5);
*The Timeout variable just makes sure the motors don’t stall out for a super long amount of time if they can’t spin.
You can call this method over and over again with new distances and speeds. A turn might look like this: encoderDrive(.5,9,-9,2);
Backing up:
encoderDrive(.5,-24,-24,6);
It is worth noting that the inches values will only be accurate if you have the correct constant variables entered for your motors, wheels, and gear drive train.
Using some trial and error (and some calculations) do your best to make your robot navigate the courses set up by your instructor using your motor encoders.
- Measure the diameter of your wheel and change its value in the list of variables below… - You will also need to change the COUNTS_PER_MOTOR_REV value to match your motors.