mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
artf4127: Implemented velocity PID controller
Change-Id: I8c0f84422f7ca0ac5c50fddb282fb3452ee1d491
This commit is contained in:
@@ -167,7 +167,8 @@ public class MotorEncoderTest extends AbstractComsSetup {
|
||||
|
||||
|
||||
@Test
|
||||
public void testPIDController() {
|
||||
public void testPositionPIDController() {
|
||||
me.getEncoder().setPIDSourceType(PIDSourceType.kDisplacement);
|
||||
PIDController pid = new PIDController(0.003, 0.001, 0, me.getEncoder(), me.getMotor());
|
||||
pid.setAbsoluteTolerance(50);
|
||||
pid.setOutputRange(-0.2, 0.2);
|
||||
@@ -184,6 +185,24 @@ public class MotorEncoderTest extends AbstractComsSetup {
|
||||
pid.free();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVelocityPIDController() {
|
||||
me.getEncoder().setPIDSourceType(PIDSourceType.kRate);
|
||||
PIDController pid = new PIDController(0.002, 0, 0.0001, me.getEncoder(), me.getMotor());
|
||||
pid.setAbsoluteTolerance(50);
|
||||
pid.setOutputRange(-0.2, 0.2);
|
||||
pid.setSetpoint(30);
|
||||
|
||||
pid.enable();
|
||||
Timer.delay(10.0);
|
||||
pid.disable();
|
||||
|
||||
assertTrue(
|
||||
"PID loop did not reach setpoint within 10 seconds. The error was: " + pid.getError(),
|
||||
pid.onTarget());
|
||||
|
||||
pid.free();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the encoders and counters are appropriately reset to zero
|
||||
|
||||
Reference in New Issue
Block a user