SparkMaxPIDController Help (When is it done)

I’m using the following code and working to adapt it for a command.

SPARK-MAX-Examples/Robot.java at master · REVrobotics/SPARK-MAX-Examples (github.com)

What I cannot find is a method to determine if it has reached its goal so I can mark the command finished. WPILib PIDController give the method “getController().atSetpoint()” so we can close a command.

Any ideas?

Look at the implementation of atSetpoint() in WPILib. Do you think you could re-implement something similar around the REV API? Give it a try!

1 Like

I am definitely considering that. I’m surprised it isn’t in there already.

2 Likes

This is certainly something that should be added in the code example from REV…

I’ve never worked with SparkMax APIs, but according to their javadoc it appears that you should be able to get your current measurement, you know or can query your desired measurement, and you know or can query the allowable error in the measurement that would be considered success.

With those three pieces of information you should be able to get where you need in terms of knowing when it has completed.

2 Likes

I can’t find any method that reports the current error calculation.

I think when @NewtonCrosby mentioned measurement, they meant current sensor measurement. From there, it should be easy to get the error calculation.

So the important things to know about PIDs is really you’re just measuring (more or less) the following:

  1. Where am I? → current measurement
  2. Where do I want to be? → set point
  3. How far away am I? → error, (setpoint - current = error)

The PID controller is doing that rough calculation, and then based on the error measurements is applying corrections (positive or negative) to get you where you want to be efficiently.

I switched to using WPILibj PIDController. It works better (at least from our perspective). We are good to go!

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.