so, we are a team that only has one year of experience under our belts and made a relatively simple robot last year that just got the job done. This year we are getting more serious and we have a double reverse 4 - 6 bar lift and I want to use a potentiometer to have the lift go to two set positions (one for low posts and one for high posts) with the push of two separate buttons (one for each height) so that we can easily flip the cap to our team’s color without having to take the time to align. The only problem is that I have no idea how to use a potentiometer coding-wise. So if anyone can help me with that it would be appreciated. Also I need it functioning by Sometime before Friday, the last day of November because our competition is on the 1st of December. Thanks!
Pots give values between 0 and 4095 (someone correct me if I’m wrong). The same number will ALWAYS correspond to the same position on the pot. For you guys, if you don’t have a lot of time, you can do something simple where you take an axle that goes all the way across the rd4b/6b and attach a pot onto that, or you can put one pot on each side of the lift (or even just on one side if you have decent build quality). Then all you need to do is figure out what value the pot has at the two heights (i’d say do a range of values, see which “band” of values will work), and then write those down. So maybe 100-200 and 2600-2800. Then, in your code you just have to run the motors until you’re in those bands, and keep the motor running to stay in that band. So for 2600-2800 going up, I’d run motors until I pass 2600, then I’d try to have my motors stay at 2700 (middle.) If it went between 2725-2750 I’d do some minor “down”. If it went from 2650-2675 I’d do a little bit of “up”. Past 2750 I’d apply more “down”, and below 2650, same thing - more “up”. Then if I’m really out of that band (so >2800 or <2600), I’d run the motor quite fast to try and get it back as quickly as I can. You can get fancier with control loops and whatever but - this will work just fine.
What I would actually do is write a Lift PID task using the potentiometer and have each button change the target value within the constantly running task.
It should look something like this:
float kP;
float kI;
float kD;
int targetvalue;
task LiftPID()
{
pid code
}
then to change targets have it like
if(vexRT[Btn6U] == 1)
{
targetvalue = 1000 for instance;
}