Puncher Ratchet Code

Hello fellow forum goers! My team has been experimenting with a ratchet on our puncher and I wanted to see examples of ratchet code. My original idea was to have a button that could be pressed after a shot that would use the rotatefor command in VCS to use the encoder to rotate near the firing point. However, while the puncher is pulling back, it stops all other functions and drive controls. It also seems like some teams pull their ratchet back automatically after the shot. If anyone had any ratchet code they wouldn’t mind sharing that’d be great for me to better understand the right way to go about this.

Thanks,
Andres

The command you want is motor.startRotateFor. motor.rotatefor is a blocking function, which will pause everything in the loop until it finishes. Hope this helped!

3 Likes

when you us controller.button.pressed(callback) and the call your call back, you can run motor.rotateFor and it launches a separate thread form the button pressed function, so you should be able to fire your puncher while maintaining control in your drive function. Or you could also (as stated above) use startRotateFor

Thanks for the help!

you can use motor.rotatefor(degrees, vex::rotationunits::deg, false); the false as the third parameter makes it a non-blocking function which allows other things to run at the same time and keeps the motor accurate.

Thanks for all the help. I tried both startRotatefor and adding false to the end and something odd is happening. When I keep it locking until done it pulls back normally at full speed. However, if I add the false or change it to startRotatefor the puncher all of a sudden slowly starts creeping instead. Does anyone know why this happens or how I can fix it?

a non-blocking function will immediately go to the next line after setting the motor. Make sure you are not setting the motor back to something else right after.

for example,

motor.startRotateFor(100, vex::rotationUnits::deg);
motor.spin(vex::directionType::fwd, 10, vex::velocityUnits::pct);

will skip the startRotateFor and start it creeping at a slow velocity of 10.

@mattjiang

the ratcheststart function is just Shoot.rotateFor(310,rotationUnits::deg,100,velocityUnits::pct, false);

what could be stopping it?

would it be possible to post what your shoot and brakeshoot functions are?

void shoot()
{
Shoot.spin(directionType::fwd,100,velocityUnits::pct);
}

void brakeshoot()
{
Shoot.stop(brakeType::hold);
}

it seems like what is happening is that when the shoot function is called, shot is set to true. Therefore what will happen is that the motor is set to spin at full speed, then the program recognizes that shot is set to true. it is immediately set to rotate for the distance, and then if the button is still being pressed, it is immediately set back to spin at full speed. I think the problem lies within the logic of the program. Try using a thread to handle the shoot commands, you would not have a problem with blocking.