HI all,
I’m trying to use two motors to power a catapult. In the past when using RobotC I’ve been able to run two motors at the same time with one button press; transitioning to VCS/V5 and I can’t figure it out. With the code below “CatapultMotor” completes it’s 200 degrees before “Catapult2Motor” begins to run, which is a problem with both motors attached to the same shaft. Any suggestions for running them at the same time?
Thanks!
//Catapult Control
if(Controller1.ButtonLeft.pressing()) { //If button up is pressed…
//…Spin the arm motor forward.
CatapultMotor.rotateFor(200,rotationUnits::deg,75,velocityUnits::pct);
Catapult2Motor.rotateFor(200,rotationUnits::deg,75,velocityUnits::pct);
}
The method is to only us rotateFor() on the last motor and us startRotateFor() on the others.
like:
//Catapult Control
if(Controller1.ButtonLeft.pressing()) { //If button up is pressed…
//…Spin the arm motor forward.
CatapultMotor.startRotateFor(200,rotationUnits::deg,75,velocityUnits::pct);
Catapult2Motor.rotateFor(200,rotationUnits::deg,75,velocityUnits::pct);
}
Actually, what you’ve got there is not a great solution. Once you press that button, you can’t do anything until the motor has rotated 200 degrees. So no changing your mind, no driving around, etc.
Meanwhile, yes, you can use rotateFor for the first motor. You just need to include the optional boolean at the end to tell it not to wait for completion.
Of course, you don’t want to loop around and rotate for 200 degrees multiple times accidentally, which could be prevented with a boolean to track if it’s in progress. I would do the following, though (no guarantees of no typos):
// option 1, earlier in the code
void moveCatapult(int rotateTarget) {
CatapultMotor.rotateFor(rotateTarget,rotationUnits::deg,75,velocityUnits::pct,false);
Catapult2Motor.rotateFor(rotateTarget,rotationUnits::deg,75,velocityUnits::pct,false);
}
// option 2, earlier in the code
void moveCatapult(int rotateTarget) {
CatapultMotor.startRotateFor(rotateTarget,rotationUnits::deg,75,velocityUnits::pct);
Catapult2Motor.startRotateFor(rotateTarget,rotationUnits::deg,75,velocityUnits::pct);
}
// inside main()
Controller1.ButtonLeft.pressed(moveCatapult(200));