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);
}
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.
Turn task autonomous into a while loop and use timer to determine when to do a specific task
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);
}
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
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.