Can you use a potentiometer to control motor position?

We are driving a Banebot motor with a JAG to move an arm and coding in JAVA. Is it possible to command position of the motor using a potentiometer? We’ve connected the POT to an analog channel, but we’re not sure how to feedback that value to the JAG to control position.

Sure. but you will need some way of measuring the arm’s position ie an encoder or if its rotation is limited another potentiometer on the robots arm wired to a analog input on the CRIO. Then in code you can compare the value of the potentiometer with the position of the arm and figuer out what direction to move. a simple way to do this is to subtract the two potentiometers (desired position - actual position) the result is how far off you are and the sign represtent the direction you need to go.

We only planned on having one POT coupled to the gear shaft. I understand the idea of using a pot to identify the position by poling the value returned from the analog channel, but I don’t know how to feed that data back to the JAG to control position.

this is psuedocode
this is assuming that the pot gives a value from 0-360 (sorry, but I’ve nvr used a potentiometer befor, so bear with me)


if(desiredAngle==pot.getAngle)
//stops motor from moving arm if you're at the angle you need to be at
jag.set(0);
else
/*moves jag forward or backward to get you at the desired angle
does it so fast if far away and slow if close
it will ultimately slow to a stop after it start moving*/
jag.set((desiredAngle-180)/360);

Ok so it is still the same principle the value of the potentiometer represents the position of the arm and I assume you have some way of inputting the position you want the arm to be at so a simplified proportional control could be

MotorSpeed = (PotentiometerReading - DesiredPosition) *K;
Jag.Set(MotorSpeed);

K is a constant that scales the value you can just play with it till the arm stop at the appropriate position with out much oscillation.

You will also want to
A. constrain the value of MotorSpeed to max and min values of the motor
B. create some margin for error so it does not have to get to the exact value or else it will keep bouncing up and down till something breaks

In Java you can look into using the PIDController class and start out with the I and D values equal to 0.

NOTE - to do this you’ll have to implement a version of PIDInput (i think that’s the correct name of the class) that reads from the potentiometer.

If I’m not mistaken, AnalogChannel already implements PIDSource.

Very likely. I didn’t have my laptop on me to check :slight_smile: