EasyC Potentiometers Help

Hi,
My team are currently trying to work out how to programme potentiometers on easyC. We want to be able to push a button on the controller and for the lift to raze to pre-determined height (trough, floor and high goal.) We had assumed there would be a simple function block for it but we have been unable to find one.

We have never used potentiometers before, but having watched the robotC tutorials I think I pretty much know how they work. However, I don’t know how to start programming them on easyc.

Any help would be much appreciated

Tall668

Hello Tall668!

You’re going to want to add a control-feedback mechanism into your main program loop. One of the easiest ways to do this is by adding a p-controller:

You could use this to tell the robot where to put the arm.

You’ll probably also need some code to perform a “If this button is pressed, set the lift to go to X height” routine. Experiment with that and post back your results!

In simple terms, the robot will move the arm fast when it is faraway from the point you want and slow down as it gets closer.

so if the arm is at 200 and you want it to goto 700 the robot would do this
error = target - po

so we get

error = 700 - 200

Error is now 500
Error is how far away the target is. We will now set the motors to error.

but we can not set the motors to 500. The max is 127.

so we say

if (error > 127){
error = 127;
}
else if (error < -127){
error = -127;
}

So if the error is larger than the max set it to the max. Also if the error is lower than the min set it to the min.

Now we set the motors to error. We need to set one of the motors to the opposite direction of the other so we times error by -1.

The motors get set to the max and your arm moves up. Now lets say the potentiometer is at 600. 700 - 600 is 100. So the motors are set to 100. The arm moves up more and now the potentiometer reads 680. 700 - 680 is 20. Unless your arm is geared at 1:100, your arm is going to not be moving at this point, so you might need to set your target to a bit higher to get exactly 700.

You can get more control over how quickly the motors are slowed down by multiplying error.

Lets say you run this code and your arm bounces up and down around the target. If you multiply error by 0.5 the arm will slow down closer to the target. This is called gain.

error = 0.5 * (700 - 500)
error = 0.5 * 200
error = 100

Here is a sample code

I hope this helps