We are going to use potentiometers and PID to control the position of an arm, which we have never done. I’m looking at the example from the WPI Lib

and I understand most of it, but can’t figure out how the code knows what height correlates with the potentiometer output. Any clarification would be helpful.

Okay, I think I understand this correctly: AnalogPotentiometer takes up to three inputs: channel that the pot is plugged into, the physical measurement that corresponds to the full range of the potentiometer, and an offset to the 0 position. (line 45)

Physical measurement could be linear distance, it could be # of turns, it could be degrees. It’s up to you, but it has to be linearly proportional to the % of potentiometer rotation. So, I think if you want the height for the end of an arm on a pivot, you’ll need to insert some trigonometry. (though what you might do is solve the trigonometry in advance and just control more directly through rotation)

It returns the potentiometer output (a fraction between 0 and 1) times the full physical range plus the offset (line 126)

So what you need to do is figure out what position A corresponds to a% on the pot, and what position B corresponds to b% on the pot, and then solve the line from those two points to figure out the max and min positions that theoretically correspond to 0% and 100% on the pot, and that’s what you’ll put in for the second variable in AnalogPotentiometer.

The example you linked assumes that the min height of the elevator is 0 on the pot, and the max height is 1 on the pot, so it doesn’t have the above extra math step to convert physical measurements to pot values.

Thank you for the link to the analogPotentiometer and the explanation. It’s making more sense in my head now. I can’t wait to get a test board set up and play around with it a little!

no problem! I’m a mechanical engineer so I’m learning how to code alongside my team’s fresh programming team. Let me know if things go wrong for you so I know if I did bad

I’m very much in the same boat- far more comfortable in front of SolidWorks than I am in front of VS code, but I know just enough to make me “the expert”, which is scary! I was able to get the potentiometer to PID control our test mechanism so I appreciate the help!