[C++] Programming Catapult w/ Potentiometer


#1

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.


#2

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++.


#3

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


#4

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


#5

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


#6

that might not be as accurate


#7

I don’t know because I use vcs.


#8

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.


#9

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


#10

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


#11

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


#12

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


#13

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


#14

no, robotc for cortex


#15

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


#16

"PotentiometerName".value(rotationUnits::raw);

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.


#17

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


#18

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;


#19

what’s api?


#20

why the empty post?