I am trying to test the integrated encoders to make more auton more precise. I wrote a basic code to make it drive forward but none of the wheels work. I changed it from false to true and then the code ran but they ran independently.
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
LeftFront.setVelocity(75, percent);
LeftBack.setVelocity(75, percent);
RightFront.setVelocity(75, percent);
RightBack.setVelocity(75, percent);
while(true){
LeftFront.rotateFor(28.66242, deg, false);
LeftBack.rotateFor(28.66242, deg, false);
RightFront.rotateFor(28.66242, deg, false);
RightBack.rotateFor(28.66242, deg, false);
waitUntil(LeftFront.isDone());
//stop all motors when done
LeftFront.stop(brake);
LeftBack.stop(brake);
RightFront.stop(brake);
RightBack.stop(brake);
When you post code you can use ``` to format it correctly. If I remember correctly rotateFor is relative to the current position of the motor, so you should call it once then wait for the motion to complete.
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
LeftFront.setVelocity(75, percent);
LeftBack.setVelocity(75, percent);
RightFront.setVelocity(75, percent);
RightBack.setVelocity(75, percent);
LeftFront.rotateFor(28.66242, deg, false);
LeftBack.rotateFor(28.66242, deg, false);
RightFront.rotateFor(28.66242, deg, false);
RightBack.rotateFor(28.66242, deg, false);
waitUntil(LeftFront.isDone());
//stop all motors when done
LeftFront.stop(brake);
LeftBack.stop(brake);
RightFront.stop(brake);
RightBack.stop(brake);
}
Your old code would go to forward 28 degrees then stop and do it again so it would effectively be the same as spinning forward forever. This should spin each of the motors to 28 degrees
Before I was using spinFor instead of rotateFor and wasn’t able to test it because my builder is working on other things. The code I’m asking about is spinFor not rotateFor.
My solution to this problem was to change the last of rotateFor from false to true and then it will wait for that motor to stop and they should all be close to done if the motors are all on the same drivetrain.