Using Potentiometer for position control on an arm

We have a potentiometer for position reading and use a 393 motor to move it up and down. And we want to have 3 stored positions: A home position, a midway position, and a “dump” position.

Each button on the controller corresponds to a different position, (we are only using 3 for 3 positions) and we just want to have it go to a specific value on the potentiometer and stay there, (the 3 positions on the potentiometer are: 3800, 2800, and 1100) without the button having to be held or anything. Basically just 3 presets. I have no idea where to start about doing this.

I am inexperienced with ROBOTC and VEX as I participate in FRC and don’t do any programming there. I am volunteering in a summer camp for the middle school level and am trying to help them code an arm. If anyone can help me, and by that metric the kids I am helping out, that would be greatly appreciated. Thanks!

Alright, so it’s been a good while since I’ve even looked at robotC, but the idea behind it should be pretty consistent. An easy way to do this is to make the difference between your current position and your desired position and use it as your input. Tell your motor to just rotate (the difference should tell your motors which direction, pos = forward, neg = backward) and write a “waitUntil” block in your code. That will tell the robot to wait until your arm has rotated to/past the desired position, then put a stop at the end.

You’ll have to look up the syntax of how to do it because this is how you do it in vexcode v5, and I’m not sure if taking the difference even works on robotC because of what’s available in it. It is a pretty old-ish/outdated language in the vex ecosystem.

Edit: I realize that I might have been a bit vague with my explanation, so please ask any questions if it’s still unclear.


Here’s some pseudocode for additional clarification:

function definition:
   difference = desiredRotation - currentRotation

   if difference > 0:
      rotate forward
   waitUntil desiredRotation > currentRotation
      stop motor

   else if difference < 0:
      rotate backward

   waitUntil desiredRotation < currentRotation
      stop motor


Old post, but this may help.