-
Notifications
You must be signed in to change notification settings - Fork 5
DrivetrainDriveCommand
Ivan Wei edited this page Apr 21, 2019
·
3 revisions
Here is some simplified code for the drivetrain:
public class DrivetrainDriveCommand extends Command {
protected double speed = 0;
protected double turn = 0;
protected boolean quickTurn = true;
public DrivetrainDriveCommand() {
requires(Robot.drivetrain);
}
@Override
protected void execute() {
setSpeed();
setTurn();
setQuickturn();
updateDrivetrain();
}
protected void setSpeed() {
speed = 0;
speed += Math.pow(Robot.oi.driverGamepad.getRawRightTriggerAxis(), 2);
speed -= Math.pow(Robot.oi.driverGamepad.getRawLeftTriggerAxis(), 2);
}
protected void setTurn() {
turn = Robot.oi.driverGamepad.getLeftX();
}
protected void setQuickTurn() {
quickTurn = Math.abs(speed) < RobotMap.QUICKTURN_THRESHOLD;
if (quickTurn) {
turn /= RobotMap.QUICKTURN_SPEED;
}
}
protected void updateDrivetrain() {
Robot.drivetrain.curvatureDrive(speed, turn, quickTurn);
}
@Override
protected boolean isFinished() {
return false;
}
}Notice: There is actually more code than this, but that code either plays a role in enabling and disabling the LEDs on the limelight or squaring the inputs of the controller. They were omitted for simplicity.
This code breaks down the drivetrain into its simple parts. The reason for this is so that any part can be overriden when implementing the limelight. Our actual code is DrivetrainDriveCommand.java, which contains some extra unrelated features.
-
- This determines the speed at which the drivetrain will switch into quickturn. Curvature drive changes the path of the robot so that it turns similarly to the wheels of a car, which allows for easier driving. The downside to this is that the robot is not able to turn in place, which quickturn remedies. Therefore, if the speed of the robot is below this threshold, the robot will use quick turn.
- Recommended Value: 0.05 to 0.02
-
- This determines the speed at which the robot will turn when the robot switches into quickturn. Quickturn is more startling than curvature drive because it can often turn too fast. You may want to slow this down.
- Recommended Value: 1 to 0.2
Team694 - Alfred 2019