Vexcode Rotation vs. Time

Hello, recently I have been working on autonomous but when I code two motors ( two drive motors ) the go one at a time instead of both at a single time. So temporaily I used time something like this


void autonomous(void) {

drivemotora.spin(directionType::fwd, 50, velocityUnits::pct);
drivemotorb.spin(directionType::fwd, 50, velocityUnits::pct);

task::sleep(1500);

drivemotora.stop();
drivemotorb.stop();

}

So this would be driving forward for 1.5 seconds
But I want to try to be using rotations as it is usually more accurate.
Whenever I try using rotation it would fire consecutively.


void autonomous(void) {

drivemotora.rotateFor( 4, rotationUnits::rev);
drivemotorb.rotateFor( 4, rotationUnits::rev);

}

This is just an example of what I had.
If anyone understands the problem then please help me.
Thanks, Eclipse 7157A

Add a false argument to the end of the first rotate for statement. Rotate to and For can take an extra argument that bypasses the blocking characteristic of rotate to.

BackLeft.rotateFor( 4, rotationUnits::rev, false);
BackRight.rotateFor( 4, rotationUnits::rev);

This will tell the code to move on to the next line and not wait for the completion of the first line but be blocked by the second line. The code will only move on upon completion of the second line or a set motor timeout is reached. hope this helps.

2 Likes

Ill test that out tmr, thanks for your help!

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.