Accurate turn with autonomous

I use text and didn’t want to type Drivetrain.driveFor(forward, 12, inches); for basically every command, so I made my own functions for most of the drive commands. It’s not that important, but if I didn’t tell you, you’d get confused. This is the definition of fd() for my program:

void fd(double input) {
  Drivetrain.driveFor(forward, input, inches);
}

So then instead of Drivetrain.driveFor(forward, 12, inches);, I say, fd(12); and it find the definition of fd() and executes all those commands. Just so you know. The example I gave is basically the same as all my other ones,

which I'll put here in case you're curious.
void fd(double in) {
  Drivetrain.driveFor(forward, in, inches);
}

void bk(double in) {
  Drivetrain.driveFor(reverse, in, inches);
}

void rt(double deg) { //deg short for degrees
  Drivetrain.turnFor(right, deg, degrees);
}

void lt(double deg) {
  Drivetrain.turnFor(left, deg, degrees);
}

I do have a couple of special ones, though. If I want to back into something, instead of saying, drive backward 3 inches, I say drive backward for 0.5 seconds. You’ll find there’s no block for this, which is why I made my own:

void fds(double sec) {
  Drivetrain.drive(forward); 
  wait(sec, seconds);
  Drivetrain.stop();
}

void bks(double sec) {
  Drivetrain.drive(reverse);
  wait(sec, seconds);
  Drivetrain.stop();
}

This way the robot just blindly drives backward for sec seconds and then stops. It’s worked wonderfully for me. You can do much the same thing in blocks. They show you how at the beginning of the Caution Tape videos. You’ll only need one input, though.

2 Likes