Setting Up Your Drive Encoder Localizer
Prerequisites
- Encoders attached to all drive motors.
Default Values
These are the default values of the DriveEncoderConstants. You can copy and paste this into your static{}
block within LConstants
:
DriveEncoderConstants.forwardTicksToInches = 1;
DriveEncoderConstants.strafeTicksToInches = 1;
DriveEncoderConstants.turnTicksToInches = 1;
DriveEncoderConstants.robot_Width = 1;
DriveEncoderConstants.robot_Length = 1;
DriveEncoderConstants.leftFrontEncoderDirection = Encoder.REVERSE;
DriveEncoderConstants.rightFrontEncoderDirection = Encoder.FORWARD;
DriveEncoderConstants.leftRearEncoderDirection = Encoder.REVERSE;
DriveEncoderConstants.rightRearEncoderDirection = Encoder.FORWARD;
Steps
1. Encoder Setup
Open the file LConstants
. The motor names are already defined in FConstants
, so you don't need to modify them here.
2. Robot Width and Length
Measure your robot's wheelbase in inches, the length - the distance from the forward and back wheels - and width - the distance between the left and right wheels.
Set DriveEncoderConstants.robot_Width
and DriveEncoderConstants.robot_Length
to the values you found above.
3. Encoder Direction Calibration
- Ensure all encoders tick up when the robot moves forward. Reverse the direction of any encoders that don't follow this convention.
You can do this by changing the Encoder.FORWARD
and Encoder.REVERSE
values for each motor in the LConstants
file.
4. Localizer Tuning
We need to adjust multipliers that convert encoder ticks into real-world measurements (inches or radians). This ensures your localizer's readings are accurate.
a) Forward Localizer Tuner
-
Position a ruler alongside your robot.
-
Push the robot forward by the desired distance (default is 48 inches).
-
The tuner will display two numbers:
-
First number: Distance the robot thinks it has traveled.
-
Second number (multiplier)
-
-
(Optional) Run multiple tests and average the multipliers for better accuracy.
-
Input this value in
LConstants
asDriveEncoderConstants.forwardTicksToInches = [multiplier]
, where[multiplier]
is the value you obtained from the tuner.
b) Lateral Localizer Tuner
-
Position a ruler alongside your robot.
-
Push the robot sideways (strafing) by the desired distance (default is 48 inches).
-
The tuner will display two numbers:
-
First number: Distance the robot thinks it has traveled laterally.
-
Second number (multiplier)
-
-
(Optional) Run multiple tests and average the multipliers for better accuracy.
-
Input this value in
LConstants
asDriveEncoderConstants.strafeTicksToInches = [multiplier]
, where[multiplier]
is the value you obtained from the tuner.
c) Turn Localizer Tuner
-
Position your robot facing a recognizable landmark, like a field tile edge.
-
Spin the robot counterclockwise for one full rotation (or your desired angle).
-
The tuner will display two numbers:
-
First number: Distance the robot thinks it has spun.
-
Second number (multiplier)
-
-
(Optional) Run multiple tests and average the multipliers for better accuracy.
-
Input this value in
LConstants
asDriveEncoderConstants.turnTicksToInches = [multiplier]
, where[multiplier]
is the value you obtained from the tuner.
Testing Your Localizer
After completing the tuning steps, you can test your localizer's accuracy.
-
Go to
Localization Test
and drive your robot around. -
Open the FTC Dashboard at http://192.168.43.1:8080/dash.
-
Switch the view to "field view" from the top right corner dropdown.
-
The dashboard should display the robot's position on the field.
-
Observe the movements, moving the robot forward should make
x
increase and strafing left should makey
increase.