Constants
The Constants file
After finishing the tuning process, your Constants file should have three types of constants configured.
- Foresight (Algorithm) constants contain values from the Foresight automatic tuner and Constraints.
- Drivetrain constants contain constants specific to your drivetrain type. For example, mecanum drivetrain constants contain the motor names.
- Localizer constants contain constants specific to your localizer. For example, OTOS constants include the hardware map name of the OTOS and the offset.
After adding all of your constants, you need to actually use them for follower creation.
For that, we have the create method that takes HardwareMap and returns a Follower.
Your create function should look like this:
public static Follower create(HardwareMap h) {
return new Follower(
new PinpointLocalizer(h, localizerConfig),
new Mecanum(h, drivetrainConfig),
new Foresight(foresightConfig)
);
}Important
Ensure that the Localizer and Drivetrain that you send into the new Follower match your own.
Below is an example of a complete Constants file. The different tuning pages will guide
you through modifying it to suit your robot.
package org.firstinspires.ftc.teamcode.pedro;
import com.pedropathing.algorithm.Foresight;
import com.pedropathing.algorithm.ForesightConfig;
import com.pedropathing.controllers.Controller;
import com.pedropathing.follower.Follower;
import com.pedropathing.math.Matrix;
import com.pedropathing.math.Vector2D;
import com.pedropathing.revhub.drivetrains.Mecanum;
import com.pedropathing.revhub.drivetrains.MecanumConfig;
import com.pedropathing.revhub.localizers.PinpointConfig;
import com.pedropathing.revhub.localizers.PinpointLocalizer;
import com.qualcomm.hardware.gobilda.GoBildaPinpointDriver;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.HardwareMap;
public class Constants {
public static MecanumConfig drivetrainConfig = new MecanumConfig(
c -> {
c.frontLeftName.set("lf");
c.backLeftName.set("lr");
c.frontRightName.set("rf");
c.backRightName.set("rr");
c.frontLeftDirection.set(DcMotorSimple.Direction.REVERSE);
c.backLeftDirection.set(DcMotorSimple.Direction.REVERSE);
c.frontRightDirection.set(DcMotorSimple.Direction.FORWARD);
c.backRightDirection.set(DcMotorSimple.Direction.FORWARD);
c.manualBrakeMode.set(true);
}
);
public static PinpointConfig localizerConfig = new PinpointConfig(
c -> {
c.name.set("pinpoint");
c.xPodOffset.set(2.187);
c.yPodOffset.set(-4.572);
c.xPodDirection.set(GoBildaPinpointDriver.EncoderDirection.FORWARD);
c.yPodDirection.set(GoBildaPinpointDriver.EncoderDirection.FORWARD);
}
);
public static ForesightConfig foresightConfig = new ForesightConfig(
c -> {
Controller primaryTranslationalForward = Controller.proportional(0.3);
Controller secondaryTranslationalForward = Controller.proportional(0.1);
Controller primaryTranslationalLateral = Controller.proportional(0.3);
Controller secondaryTranslationalLateral = Controller.proportional(0.1);
c.forwardTranslational.set(Controller.piecewise(secondaryTranslationalForward).put(2.5, primaryTranslationalForward));
c.strafeTranslational.set(Controller.piecewise(secondaryTranslationalLateral).put(2.5, primaryTranslationalLateral));
c.coast.set(Controller.proportionalFeedforward(0.010978350889324107));
c.brake.set(Controller.proportionalFeedforward(0.008731598255925491));
c.headingFeedback.set(Controller.proportional(5.258721785960744));
c.headingBrakeCoefficients.set(Vector2D.cartesian(0.05642143125655298, 0.0063829525363003695));
c.linearBrakeCoefficients.set(Matrix.diag(0.10605894992901523, 0.08719146175596092));
c.quadraticBrakeCoefficients.set(Matrix.diag(0.0014663966976606565, 0.0013837064502458813));
c.maxAchievableForwardVelocity.set(72.72923108818539);
c.maxAchievableStrafeVelocity.set(52.34323936525474);
c.naturalForwardDeceleration.set(85.01144677379789);
c.naturalStrafeDeceleration.set(104.49787535782846);
}
);
public static Follower create(HardwareMap h) {
return new Follower(
new PinpointLocalizer(h, localizerConfig),
new Mecanum(h, drivetrainConfig),
new Foresight(foresightConfig)
);
}
}
After tuning the robot, we can now [test](/docs/pathing/tuning/test) everything combined.Last updated on