-
Notifications
You must be signed in to change notification settings - Fork 0
Drivetrain
The drivetrain package contains the two main categories of drivetrains(Autonomous and HumanControlled) and the controller packages which defines the basic behaviour of drivetrains and some already-written behaviours.
This type of drivetrain is used during the Autonomous period, giving the user the possibility of moving the robot either using a specific number of ticks or by setting a general speed for the robot.
- Moving using ticks
To tell the drivetrain where to move the robot to, use:
// this tells the robot to move 1000 ticks to the north with 0.5 power
drivetrain.move(Controller.Direction.N, 1000, 0.5);
If you want a bit more control, the move method returns a Checkable - an object that can be checked for it's status, value, failure etc. In this case, it tells us whether all the motors have arrived at the desired position. It looks like this:
Checkable checkable = drivetrain.move(Controller.Direction.N, 1000, 0.5);
// we can then check if the drivetrain finishes
while (!checkable.check()) {
// we use the ! operator because the Checkable returned by the drivetrain.move() method
// returns false if the drivetrain hasn't finished moving
}
For more safety, you should check if the opmode is still active, and immediately return if it is not.
Checkable checkable = drivetrain.move(Controller.Direction.N, 1000, 0.5);
while (!checkable.check() && opModeIsActive()) {
idle(); // idle() helps clear out lag during opmode operation
}
// immediately return if the opmode is active, skipping any execution that
// might crash the Robot Controller app
if (!opModeIsActive()) {
return;
}
- Moving using speed
To move using speed only, use:
// this moves the drivetrain forward with 0.5 speed
drivetrain.move(Controller.Direction.N, 0.5);
This type of drivetrain is used during the TeleOp period and is controlled using a gamepad.
- Initialization
super.drivetrain = new HumanControlledDrivetrain(WheelBase.MECANUM);
- Control
super.drivetrain.drive(gamepad1);