Skip to content

PIDF Tips and Bits

12sliu edited this page Dec 19, 2023 · 3 revisions

What is PID and Feedforward?

The simplest explanation without any technical terminology is that a PID controller takes a setpoint (where it should be) and a position (where it is now) and then gives you what speed you need to go to the setpoint perfectly.

The video is very highly recommended, as it provides a intuitive explanation of what PID is.

Tuning PIDF

NOTE: If you are from the 2023-2024 season, FTC dashboard has already been installed. If you are reading this, the ftc-dashboard branch should have been merged into main - check if these changes have appeared in your build.dependencies.gradle file, if not contact your senior and ask them to merge main into your branch.

1. Install FTC Dashboard by adding the lines with a plus in front of them to your build.dependencies.gradle file.

 repositories {
     mavenCentral()
     google() // Needed for androidx
+    maven{url = "https://maven.brott.dev/"}
 }

 dependencies {
     implementation 'org.tensorflow:tensorflow-lite-task-vision:0.4.3'
     runtimeOnly 'org.tensorflow:tensorflow-lite:2.12.0'
     implementation 'androidx.appcompat:appcompat:1.2.0'
+    implementation "com.acmerobotics.dashboard:dashboard:0.4.9"
 }

Remember to sync your Gradle, or the changes won't go through.

2. Create an OpMode for tuning the PID using FTC Dashboard.

@Config
@TeleOp( name = "Linear Slide PIDF", group = "linear-slide-test")
public class LinearSlidePIDF extends OpMode {
    public static int POSITION_ERROR = 5;

    private PIDController controller;

    public static double p = 0;
    public static double i = 0;
    public static double d = 0;
    public static double f = 0;

    public static int target = 0;

    private final double ticks_in_degrees = 700.0 / 360.0;

    private DcMotorEx slide_motor;

    public static boolean atsetpoint = false;


    @Override
    public void init() {
        controller = new PIDController(p, i, d);
        telemetry = new MultipleTelemetry(telemetry, FtcDashboard.getInstance().getTelemetry());

        slide_motor = hardwareMap.get(DcMotorEx.class, "linear_slide_motor");
    }

    @Override
    public void loop() {
        int slidePos = slide_motor.getCurrentPosition();

        controller.setPID(p, i, d);
        double pid = controller.calculate(slidePos, target);
        double ff = Math.cos(Math.toRadians(target / ticks_in_degrees)) * f;

        double power = pid + ff;

        slide_motor.setPower(power);

        telemetry.addData("at setpoint?: ", atsetpoint);
        telemetry.addData("pos ", slidePos);
        telemetry.addData("target ", target);
        telemetry.update();
    }
}

This example uses a linear slide, but can be modified easily for any other mechanism (i.e. arm).

  • The most important parts of this OpMode include the @Config decorator, which allows for static variables to be edited from FTC Dashboard on your computer.

3. Open FTC Dashboard

a. Connect to your Control Hub's WiFi.

b. Go to http://192.168.43.1:8080/dash in any browser of your choice.

4. Use FTC Dashboard and Your OpMode to Tune

a. Use your Driver Hub to initialize and run the PID Tuner OpMode you have made. (Do not run the OpMode from the Dashboard, as previous attempts have not worked with it)

b. Check all the telemetry boxes so they appear on your graph.

c. Make edits to the static variables by changing the values in the boxes and pressing the Save (flash drive) button. From there, follow conventional tuning advice.

Video Source

Clone this wiki locally