Super Confused about PID

Hey all, we’re attempting to use a PID loop for our intake arm, and seem to be running into some issues.

First one being I can get it mostly working, though once it gets to it’s position to takes too long to realize it needs to stop pushing it in that direction, and has almost caused our intake to snap itself.

I was told to look at doing the PID loop through the Spark Max controller that we are using for that motor, but I don’t think we’d be able to as we’re using an absolute encoder (REV through bore) but don’t have the part to connect it directly to the Spark Max.

The actual code is located here. I need to push up the changes that were made at yesterday’s event still.

Any help would be greatly appreciated, I’m super confused and would really like to be able to get this to work for the team.

https://docs.wpilib.org/en/stable/docs/software/advanced-controls/introduction/tuning-vertical-arm.html

2 Likes

Even if you don’t have the absolute encoder adapter, you can set soft limits in your code, so that once the motor gets at or past a certain value, it will stop.

So you can zero your intake arm in it’s retracted position on code startup. And then command it to go from there to whatever value corresponds to the deployed position.

OMG I think I just realised what part of my problem was. I was never setting the motor to 0 once it passed a point.

Also note that since your I gain is nonzero, you may see windup and overshoot behavior where the mechanism does not stop at target. The link oblarg posted should help show the effects so you get a sense of what each knob should be doing.

2 Likes

You shouldn’t have to manually do that if you set soft limits. Also if you’ve tuned PID correctly it shouldn’t go very far past your desired setpoint.

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