[C++] Programming Catapult w/ Potentiometer

We are using C++ programming on V5 and we want to use a potentiometer to have the catapult shoot and return the original degree. We have the potentiometer on the same axle as the actual catapult gear itself. We aren’t sure how to program the potentiometer to allow the motors to return to the original position. We have two motors on our catapult and currently don’t have an automatic reload. We would like to do this by clicking on button on the controller which lets it shoot and reload all in one motion because it is a slip gear with a ratchet. Some programming help would be greatly appreciated as for we are very confused.

I would create a PID control loop with set positions for the catapult and use a task/thread to perform the automatic functions. There’s plenty of guides for PID on Google. You can start with this guide

This post can probably help you with multitasking in vex c++.

PID is not necessary, just say if arm is not far enough, go dawn, else, go up, and then fine-tune it to stay in the right position

I just use the internal motor encoder and it works fine.

How did you Program the internal Motor encoder. We tried but couldn’t get it to work on Robot Mesh Studio.

that might not be as accurate

I don’t know because I use vcs.

it’s not nearly as accurate, I just did it that way because i don’t know how to use a pot with vcs and i was in a rush when i was programming.

Do you happen to have an example of programming for a potentiometer? And do you necessarily need to us a PID?

what if the slip gear turns too much and catches again b4 the arm soots?

I guess that makes sense to use a potentiometer instead because it’s more accurate. How would I program it without a PID?

i’ll try to send a snapshot of my code soon

Do you use robot mesh studio? If so, a snapshot would be really helpful.

no, robotc for cortex

How different is RobotC to C++ for Robot Mesh Studio?


will give you the raw value of the pot from 0-4095 ticks. You can also use rotationUnits::deg or rotationUnits::rev to get the degrees or revolutions output.

I would definitely recommend using PID for your actions due to its accuracy, but if you would like to not use PID, you can set your motor to stop when the potentiometer hits its desired value and tell the motor to hold.

i wouldn’t know, i’ve only ever used robotc, but im saying the basic code structure should be the same despite syntax

almost the same. You’ll be having to learn new api’s and stuff, but they’re very similar in the way that you construct them.

E: api like the commands to spin motors.

MOTOR.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct); for C++ vs
motor[MOTOR] = 100;

what’s api?

why the empty post?