mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
artf4127: Implemented velocity PID controller
Change-Id: I8c0f84422f7ca0ac5c50fddb282fb3452ee1d491
This commit is contained in:
@@ -122,11 +122,12 @@ TEST_P(MotorEncoderTest, ClampSpeed) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if PID loops work
|
||||
* Test if position PID loop works
|
||||
*/
|
||||
TEST_P(MotorEncoderTest, PIDController) {
|
||||
TEST_P(MotorEncoderTest, PositionPIDController) {
|
||||
Reset();
|
||||
|
||||
m_encoder->SetPIDSourceType(PIDSourceType::kDisplacement);
|
||||
PIDController pid(0.001f, 0.0005f, 0.0f, m_encoder, m_speedController);
|
||||
pid.SetAbsoluteTolerance(20.0f);
|
||||
pid.SetOutputRange(-0.3f, 0.3f);
|
||||
@@ -142,6 +143,29 @@ TEST_P(MotorEncoderTest, PIDController) {
|
||||
EXPECT_TRUE(pid.OnTarget()) << "PID loop did not converge within 10 seconds.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if velocity PID loop works
|
||||
*/
|
||||
TEST_P(MotorEncoderTest, VelocityPIDController) {
|
||||
Reset();
|
||||
|
||||
m_encoder->SetPIDSourceType(PIDSourceType::kRate);
|
||||
PIDController pid(0.002f, 0.0f, 0.0001f, m_encoder, m_speedController);
|
||||
pid.SetAbsoluteTolerance(20.0f);
|
||||
pid.SetOutputRange(-0.3f, 0.3f);
|
||||
pid.SetSetpoint(30);
|
||||
|
||||
/* 10 seconds should be plenty time to get to the setpoint */
|
||||
pid.Enable();
|
||||
Wait(10.0);
|
||||
|
||||
RecordProperty("PIDError", pid.GetError());
|
||||
|
||||
EXPECT_TRUE(pid.OnTarget()) << "PID loop did not converge within 10 seconds.";
|
||||
|
||||
pid.Disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test resetting encoders
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user