Catapult Reload Code Not Working

Currently, I’m trying to implement a part in my program where with the click of a button, the catapult moves to the desired position so it is ready to shoot a tri-ball.

void cataReload(){
  double cataRotation = Rotation17.position(deg);
  double cataReloadValue = 98; //placeholder
 
cata.spin(fwd, 12, vex::voltageUnits::volt);
waitUntil(cataRotation >= cataReloadValue);
cata.stop(coast);
 
}

Above is the catapult reload part of the program.

void usercontrol(void){
master.ButtonR1.pressed(cataReload);


while(1){


 arcadeDrive();
 pneumaticsCode();


}

}

When I tested this, the motor for the catapult did not seem to move at all.
Can someone please help.

This could be because of the catapult already being in that desired position (e.g. cataRotation is already larger than cataReloadValue). I.e. the program thinks that the robot has just reloaded again after it completes the cataReload() function, when it has actually in reality just stayed in the same position because it was already loaded. An easy way to fix this is to have the cata reload for some time so that the cataRotation is larger than 0, and then run that waitUntil section, although i’m sure that there are better ways to fix it.

First of all, you need a wait statement in the while loop in usercontrol. I recommend 20 msec. Also, consider what would happen if you were already at that catapult position. Instead of shooting, it would just stop. You’re going to need a bit more logic to be able to shoot and then return to the value you want. Personally, I would wait for a bit after it starts spinning and only check for the position after, say, 0.3 seconds.

While other people have stated helpful things you should do, it is not the true issue with your program. The issue is with cataRotation. You get the value of the position from the cata but that is just a value and will not update with the movement of the catapult. Corrected code is shown below:

void cataReload(){
  double cataReloadValue = 98; //placeholder
 
cata.spin(fwd, 12, vex::voltageUnits::volt);
waitUntil(Rotation17.position(deg) >= cataReloadValue);
cata.stop(coast);
 
}

In addition I would like to share some psuedo code of what I use to control my catapult so it automatically reloads.
Inside the while(true) of driver control
If(button pressing or cata is not past setpoint)
spin cata
else
stop cata

1 Like