-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPIDTest
More file actions
47 lines (37 loc) · 1.62 KB
/
Copy pathPIDTest
File metadata and controls
47 lines (37 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package org.firstinspires.ftc.teamcode.drive.opmode;
import com.acmerobotics.dashboard.FtcDashboard;
import com.acmerobotics.dashboard.config.Config;
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
import com.arcrobotics.ftclib.controller.PIDController;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorEx;
import org.firstinspires.ftc.teamcode.drive.SampleMecanumDrive;
@Config
@TeleOp
public class PIDTest extends LinearOpMode {
public static double p=0, i=0, d=0, f=0;
public static double goal = 0;
public static double curr = 0;
private PIDController slideController;
private DcMotor swingBar;
@Override
public void runOpMode() throws InterruptedException {
SampleMecanumDrive drive = new SampleMecanumDrive(hardwareMap);
swingBar = hardwareMap.get(DcMotor.class, "swingBar");
swingBar.setDirection(DcMotorEx.Direction.REVERSE);
swingBar.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
slideController = new PIDController(p,i,d);
telemetry = new MultipleTelemetry(telemetry, FtcDashboard.getInstance().getTelemetry());
waitForStart();
while (opModeIsActive()) {
slideController.setPID(p,i,d);
curr = swingBar.getCurrentPosition();
swingBar.setPower(slideController.calculate(curr, goal) + f);
telemetry.addData("curr: ", curr);
telemetry.addData("goal: ", goal);
telemetry.update();
}
}
}