Hello everyone,
We are working on a PID velocity controller for our flywheel. We have spent around 2 weeks or so trying to get our flywheel to accurately shoot from a distance. However, we’re having some trouble getting it to shoot at a consistent speed. We’ve tried using the inbulit PID velocity loop provided with the V5 motors and playing around with its constants. We’ve also made a custom loop in which we also adjusted the constants. We also tried adding stabilizing code that waits for the flywheel’s speed to be within a certain range for a certain amount of time before shooting. Even that didn’t too much though.
Currently, the best we’ve gotten it is that when the flywheel starts, it oscillates for about 5-7 seconds and then appears to stabilize. We’re not really sure how to get rid of this oscillation in the beginning. We would appreciate some advice on how to get rid of this oscillation and other advice on how to get a consistent shot.
Here is our PID loop:
//Constants//
float kp = .07;
float ki = 0;
float kd = .11;
//PID Variables Here//
int currentVelocity = flywheel.get_actual_velocity();
int error = targetFlywheelSpeed - currentVelocity;
int lastError = 0;
int totalError = 0;
int integralActiveZone = 15;
int onTargetCount = 0;
float finalAdjustment = error * kp; //add the rest of PID to this calculation
//Temp Variable//
int deltaTime = 0;
while (true)
{
if (maintainFlywheelSpeedRequested == true)
{
currentVelocity = flywheel.get_actual_velocity();
error = targetFlywheelSpeed - currentVelocity;
if (error == 0)
{
lastError = 0;
}
if (abs(error) < integralActiveZone && error != 0)
{
totalError += error;
}
else
{
totalError = 0;
}
finalAdjustment = ((error * kp) + (totalError * ki) + ((error - lastError) * kd));
currentFlywheelVoltage += finalAdjustment;
if (currentFlywheelVoltage > 127)
{
currentFlywheelVoltage = 127;
}
else if (currentFlywheelVoltage < 0)
{
currentFlywheelVoltage = 0;
}
flywheel.move(currentFlywheelVoltage);
lastError = error;
}