Autonomous Potentiometer Catapult not Stopping

So I have been struggling to find out why this is not working but I cannot seem to find the issue, During Driver Control I have the same code running and it works perfectly but when I try to use it during Autonomous period the CatapultMotor does not stop spinning. Any help?
Code:
if(CatapultPotentiometer.value(analogUnits::range12bit) < 850) {
CatapultMotor.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
}
else {
CatapultMotor.stop(brakeType::hold);
}

The code is made in VCS using the C++ language.

You most likely didn’t put it in something that loops, so the code you presented only would run once during autonomous, while in driver control your code is in a while loop.

You have two options to make it work:

  1. Turn task autonomous into a while loop and use timer to determine when to do a specific task
  2. Create a second task and make autonomous turn on the task and manipulate values within the task.
    Number 2 is easy to do in VCS, but since I haven’t went in VCS for a while have a bit of mercy:
int catapultDown(){
while(true){
if(CatapultPotentiometer.value(analogUnits::range12bit) < 850) {
CatapultMotor.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
}
else {
CatapultMotor.stop(brakeType::hold);
}
}
}

void autonomous(){
// this is similar to startTask
    vex::thread t(catapultDown);
}
1 Like

Worked perfectly! Thank you my guy!

1 Like

Wait but what would I do to continue running CatapultMotor after it stops? Like if I was ready to shoot.

No problem!
On another note… I see catapult and hold in a single statement, which means it looks like you aren’t using any ratchets for your catty motor. You would save yourself a lot of battery life, keep your catapult motor safe by telling it to stop when it reaches its position, you will be able to practice longer periods of time, and you can have a faster gear ratio if you ratchet your catapult and tell the motor to coast when it reaches its position.
Hopefully this can be useful too :slight_smile:

1 Like

We tried to ratchet this catty like our old one was but the area around where the ratchet is currently being used, I will try to do it though because I have been having issues with overheating of the motor and it starting to fail-safe.

If the motor is ready to shoot, you can program it in multiple ways, but I would suggest creating an integer outside the task that the task uses, and modifying it in autonomous; or creating a second task to fire then disable the down positon task.

1 Like

Alrighty thanks for the help!

1 Like

No problem! If you need any help with ratchets, you can contact me on discord or create a second vexforum thread related to what you need help with :slight_smile: