REVrobotics / SPARK-MAX-Examples

Example code for SPARK MAX
BSD 3-Clause "New" or "Revised" License
104 stars 104 forks source link

Position PID Control strange behavior #23

Closed slylockfox closed 2 years ago

slylockfox commented 2 years ago

Using the Position PID Control example as-is, we observed some strange behavior that is serious if we can't find a workaround. When we set a value for target rotations in shuffleboard, the motor moves to that position and holds. If we then change the target rotations in shuffleboard, the motor does not immediately move. It continues to hold the previous setpoint. If we manually rotate the motor shaft a tiny bit, then it immediately acts like it should, and spins to the new setpoint.

We adjusted the P value down a little bit, and we are using a min/max range of -0.1 to 0.1. The same behavior happens with I and D both set to 0. It is almost as if the motor controller is optimized to not check the position against the setpoint unless the motor moves, which is a good optimization if you assume the setpoint will not change. Of course, in our autonomous code, we want to give multiple setpoints. Is the example code missing something that would cause the motor controller to check its status after a setpoint change?

A second minor problem is that the example code generates errors to the driver station about not updating the motor frequently enough. We determined this was because the call to SetReference was happening every time through the loop, and we changed it to be more like the other set lines, so that it executes only when the target rotations is changed from the dashboard, and the error went away. But the above weird behavior of the motor not moving until we nudge it happens with or without our change.

slylockfox commented 2 years ago

We are using the C++ example. We looked at the Java version, and it doesn't appear to be any different.

slylockfox commented 2 years ago

@NoahAndrews

jfabellera commented 2 years ago

Thanks for reaching out.

Unfortunately, we have not been able to reproduce this behavior ourselves with similar gains and output levels. The motor runs to the setpoint when changed on shuffleboard as expected without any external intervention or nudging.

I have a couple of questions to try and diagnose what is happening here:

  1. Are you able to reproduce issue this consistently?
  2. Have you tried swapping out the motor and the controller to see if its an issue with either component?
  3. Did you double check that all connections are secure and connectors are crimped correctly?
  4. Do you mind sharing details about what type of mechanism this is for?
  5. Lastly, can you share a photos of the hardware configuration i.e. wiring
slylockfox commented 2 years ago

Thanks for looking into it. We set up to reproduce it, and could not reproduce it ourselves. Perhaps the PID had become confused in our first test.