What's Wrong with this tank drive code?

do you guys know what’s wrong with this tank drive code?

void usercontrol( void ) {
// Tank Drive
while (3){
Leftdrive.spin(directionType::fwd,Axis3.value()velocityUnits::pct);
}
while (2) {
Rightdrive.spin(directionType::fwd,Axis4.value()velocityUnits::pct);
}

You have two while loops, the first runs but the second never gets to run. Both commands should be in the same while loop. Also it should just be while(true) or while (1), I’m not sure what while(2) or while (3) will do.

Also, you are missing the comma between joystick value and units

2 Likes

still doesn’t work. i keep getting this error code

10:21:37 – error – error: extraneous closing brace (‘}’)

could you possibly be kind enough to just code the tank drive and send it here. i know that is kind of asking for a lot but i have a competition tomorrow.

Then something is wrong with the rest of your code. Please send us the whole code.

Unfortunately we cannot code for you since this is for competition and is Against competition rules

Here’s pseudocode:

While(true){
    Leftmotor power = left joystick value;
    Rightmotor power = right joystick value;
}

@Jared_Stark you have the general idea down. You don’t anyone else to code it for you.
Here are some steps

  • Just put the drive code in 1 while loop.
  • There should be commas like @Deicer said between value() and velocityUnits
  • The error you are getting is that you have an extra curly brace. Every curly brace should be in a pair. The error is that you have an extraneous (extra) closing brace. So make sure every curly brace has its pair, and no more.
2 Likes

@Jared_Stark, from what I have seen here, you seem to not be fully understanding how the “while( )” statement functions. This statement will run the code between the braces as long as the comparison in the parentheses is true. For example…

int x = 1;
while(x <= 5){
   x = x + 1;
}

This code will run until the number x is six. After the loop finishes, the next lines of code can be run. For a driver control code you want the loop to never stop, so you can declare the loop to be always running by using…

while(true){
   "driver control code"
}

Your code you presented should not have two while loops as the first loop will run forever and never allow the second loop to execute.

1 Like