Potentiometer presets

My team is using a potentiometer for our lift. However we are having trouble programming it to stop at a certain value. Some times it will go too far and other times it will go to short.

Our lift is on a 5:1 gear ratio with the potentiometer on the 60 tooth gear. We want the lift to raise to the middle height of the fence. Also, our lift rests at around a 30 degree angle, and is about and 1 1/2 inches below the 18" Limit.

Any estimations of the value we need would be helpful.

What you want if you need precision is to slow down the lift as it gets closer to the desired value.

I’m not sure that we can afford to do that as we are planning on using the potentiometers for our autonomous. But I see where your coming from.

You can slow it down a slight enough amount while close enough to the target angle that you barely notice the extra time it takes.

How would we trigger the slow down though? Our potentiometer is having trouble getting consistent values.

here’s our way of doing it,

when value<(.8endvalue)
{go full speed}
however when end value>value >.8
end value
go {go .8*fullspeed}

this allows you to do kinda pid without all the work

You are looking to control the power sent to the arm motors proportionally… which is the P in PID. It doesn’t have to be super complicated. Here is an example of a task to apply P control to an arm motor based on potentiometer values:

// PD control constants
static float armP_Kp = 0.28; // arm proportion
static int max_Error = 25; 		// maximum error allowed

int armTarget; // global variable that holds the desired arm potentiometer value

task armControl()
	while (true)
		// calculate armError... how far is the arm from armTarget
		int armError = (armTarget - SensorValue[arm_Pot]); 
		if (abs(armError) > max_Error) // if pot value is off by max_Error+
			int armPower = (armP_Kp * armError); // P control for arm motor

			// set motors to armPower
			motor[arm_R1] = motor[arm_R2] = motor[arm_R3] = armPower; 
			motor[arm_L1] = motor[arm_L2] = motor[arm_L3] = armPower;
		wait1Msec(25); // don't hog cpu

task main()

	while (true)
		// arm control on 8
		if (vexRT[Btn8R] == 1) {armTarget = 3450;}
		if (vexRT[Btn8U] == 1) {armTarget = 1900;}
		if (vexRT[Btn8L] == 1) {armTarget = 1200;}
		if (vexRT[Btn8D] == 1) {armTarget = 1000;}

This is relatively simple control, and will not work as well as full PID. You will need to fiddle with the value for the armP_Kp constant to work for your particular bot. You might also find you want to limit armPower when the arm is moving down. This control will likely overshoot going down, then adjust itself back to the target.

Also, if you’re having trouble getting consistent values, consider working with the reading divided by 10. It’s generally still precise enough, but the values become less noisy.

PID does work well for arm control. The down direction does have the help of gravity along the way, so a second set of constants and additional tuning can be an option to fix that. More rubber bands is another method, but not always feasible.

But that example should work very well. Start with a small armP_Kp and work up from there. 0.15 is a good low number on arms. Arm values on a P controller that I have seen our kids do were in the 0.2 - 0.35 range depending upon the arm.

I have a question. I have the exact same program but I am not able to stop an arm with a potentiometer at resting position. What do you all suggest?

@PNayak Do you mean the arm is swinging past the desired point over and over? If that is the case, you need to adjust the P constant until it meets the goal. The code I posted above has run correctly on an actual bot. If I were to change the constant to .5, it would fail comically.

If you are using something like PID control, it will reach the target while the motors are at some low value and the arm will rest in that position with the motors remaining at that value. In fact, if you forcibly lift or lower the arm, it will return to the last target value.

I guess I don’t understand what your exact problem is, but hope this reply might steer you in the right direction.