Potentiometer limit

Hey, i was just wondering how could we make our program tell the cortex that when the potentiometer reaches a certain amount of degrees de arm can’t go up but it can go down?

i was thinking this:

f(SensorValue[pot] > desired degrees && VexRT[Ch2] > 0)
{
//stop motors
}
else 
{
//let motors run on vex rt ch 2
}

If your pot is returning lower numbers when the arm is up, then your code will work.

@Doug Moyers, i ran this code, but when the arm is going up it starts to bug and when it goes down it doesn’t. And thanks for always helping us!

If your code is using degrees as your value, it will not work without converting to the range of the potentiometer. The pot has a signal range of 0 to 4095, and covers ~270 degrees, so each degree is ~15 units. When you are looking at the side that has Vex on it, i think the 0 is to the left and 4095 to the right. You do not reset pot values to zero… every point in the rotation has a specific value.

Depending on how you mount it for your arm control, you will have high or low numbers when your arm is at the top. If you have a programming cable, you can download to your bot over vexnet and drive the arm with the Robot > Debugger Windows > Sensors open and see what the sensor is reading at a given position.

Assuming you did that and your sensor read 2900 at the bottom and 800 at the top, you could use your code concept in this way:


if(SensorValue[pot] > 800 && VexRT[Ch2] > 0)
{
//stop motors
}
else 
{
//let motors run on vex rt ch 2
}

If you wanted to use actual degrees, you could do the math to convert the range… It’s just not necessary to do so.

Actually Im not converting the values to degrees, but i just used ‘‘desired degrees’’ for fun jajaja, but i will try the code and see how it plays out.

Well, as what I see if the value is higher than 0 AND is higher than the VEX channel AND is above 800, then stop the motors, but the only way for the motors to be on if it is truly exactly 0 AND below the VEX channel AND below 800, which I think just as a start, that is WAY too many. Just a heads up, 0 isn’t the middle rotational value of the potentiometer, it’s the end of a side of the potentiometer. Another thing, converting the value to degrees isn’t really necessary when programming your robot(Edit//: What’s said above), the conversion will be useful only if you’re doing some super advanced coding for angles or to see the exact angle of the arm. Have you done a simple


motor[port1]=vexRT[Ch5];

?

That just isn’t what the code says. && divides the if conditional test into two separate components that must both be true. However, you are right that it would fail… the pot test needs to be less than:

if(SensorValue[pot] < 800 && VexRT[Ch2] > 0) // is the arm above the upper limit and the Ch2 signal positive

Oh, I completely forgot about that… My bad, I just came from a week-long trip last week and I got a bit rusty of programming.

Ohhhh OK, I see what you’re missing. The VEX joystick channels go from a range from a positive number (example:127) to a negative number (example:-127) with 0 being the joystick moved to the center. So what you’re saying is that if the joystick value is above 0(and value above designated number) then stop the motors, but if it’s below 0 then then set the motors to the desired speed by the joystick.

Positive joystick values would also be used for motor power, so long as the range limit is not exceeded.

I was just wondering if there was a way to program a potentiometer to stop the arm during auton if the motors are moving, but the potentiometer value isn’t changing, as our robot has a tendency to drive too far forward during autonomous, making our arm catch under the fence.

I have given pseudocode here:

void raiseArm()
{
    if (Arm motors are moving at 127 power && Potentiometer Value is not increasing)
    {
        stop all arm motors
        endif
    }
    else
    {
        raise the arm at 127 power for 2 seconds
        endelse
    }
}

@Riley

Well, I’m not the best programmer around jaja, but let me see.

I think it should look like this;

 void RaiseArm(int time, int speed)
{

if(motor/*set here the motors you have in the arm/*] = speed && pot == the certain amount of ''degrees'' where it isnt moving)
{
stop all arm motors
}

else 
{
motor[w] = speed;
motor[x] = speed;
motor[y] = speed;
motor[z] =speed;
wait1Msec(time);
}
}
 

@Doug Moyers @CATaclysm Delta_II thanks for answering