I am having difficulty with checking if my setPoint on a Velocity pidController on a CanSparkMax has been reached.
In my periodic method, I have this line of code and get appropriate velocity output to the dashboard:
SmartDashboard.putNumber(“RearVelocity”, m_encoder.getVelocity());
In the isFlywheelAtVelocity method, I have the following lines of code, but my velocity from m_encoder is 0:
double closedLoopError = m_encoder.getVelocity() - targetShooterVelocity;
SmartDashboard.putNumber(“RearShooterActualVelocity”, m_encoder.getVelocity());
SmartDashboard.putNumber(“RearShooterTargetVelocity”, targetShooterVelocity);
SmartDashboard.putNumber(“RearClosedLoopError”, closedLoopError);
if (Math.abs(closedLoopError) < 100 ) return true;
else return false;
I am sure that this is caused by a silly programming mistake, but cannot put my finger on it. Any help would be appreciated.
NOTE: I realize that we always return true; we had an immediate need for the command to finish (competition was imminent) so we just set it to true and our operators held the prep button down for 3 seconds to make sure it was at speed.
Out of desperation, I changed the code to break out the call to getVelocity – this code works – any idea why this would be the case?
/* Break Up the definition of closed loop error
* A shot in the dark -- there is no reason this should make a difference
*/
public boolean isFlywheelAtVelocity(){
double error = 0;
double actual = 0;
actual = m_encoder.getVelocity();
error = actual - targetRPM;
SmartDashboard.putNumber("RearCheckActual", actual);
SmartDashboard.putNumber("RearCheckTarget", targetRPM);
SmartDashboard.putNumber("RearCheckError", error);
if (Math.abs(error) < 100 ) return true;
else return false;
}