Package com.crossbotics.ftchelper.drive
Class DriverControls
java.lang.Object
com.crossbotics.ftchelper.drive.DriverControls
Standard TeleOp driving from one gamepad, for mecanum AND standard (tank) robots, in one line per
loop.
EasyTeleOp uses it for you; you can also use it in your own OpMode.
left stick drive (mecanum: any direction; tank: forward/back)
right stick X turn
left trigger slow: squeeze for fine moves (down to slowSpeed at full squeeze)
Mecanum robots can also drive field-centric ("stick up = away from the driver"), using a
DriverHeading. Robot-centric ("stick up = where the robot points") is the default.
DriverControls driving = DriverControls.create(hardwareMap, new RobotSettings().drive(), heading);
// every loop:
driving.update(gamepad1);
// at the end (in finally):
driving.stop();
Docs: docs/modules/drive.md (section "DriverControls")-
Method Summary
Modifier and TypeMethodDescriptionbooleanTrue if this robot can drive field-centric: mecanum wheels and a heading.static DriverControlscreate(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, DriveConfig config, DriverHeading heading) voiddrive(double forward, double strafeRight, double turnClockwise, double speed) Drives with numbers you worked out yourself (robot-centric), for your own controls.voidhold()Holds the wheels still this loop (e.g.booleanTrue while driving field-centric.booleanisSlow()True while the slow trigger is pulled.moveScale(DoubleSupplier scale) Multiplies forward and strafe by this every loop, 0 to 1 (1 = unchanged, the default).reverseWhen(BooleanSupplier when) Reverse drive whilewhenis true: forward and strafe are flipped, so the back of the robot acts as the front (turning is not flipped).voidsetFieldCentric(boolean on) Field-centric on or off.slowSpeed(double speed) Speed at a full squeeze of the left trigger, 0 to 1.status()One short line for telemetry, e.g.sticks(double deadband, double exponent) How the sticks feel.booleanTrue whenswapSticks(boolean)is on.voidstop()All wheels to 0.swapSticks(boolean swap) True: drive (and strafe) with the RIGHT stick and turn with the LEFT stick's X, for drivers who like it that way round.voidtank(double left, double right, double speed) Two-stick "tank style": one value per side, -1 to 1.booleanSwitches field-centric on/off; returns the new state.turnAssist(DoubleUnaryOperator assist) A helper that may change the turn, e.g.voidupdate(com.qualcomm.robotcore.hardware.Gamepad gamepad) Drives from the gamepad's sticks.voidupdate(com.qualcomm.robotcore.hardware.Gamepad gamepad, boolean slow) Drives from the gamepad's sticks, with slow mode switched by your own code instead of the left trigger (for example a one-driver layout where the trigger has another job).voidupdate(com.qualcomm.robotcore.hardware.Gamepad gamepad, double speed) Drives from the gamepad's sticks at a speed your own code works out (0 to 1, e.g.
-
Method Details
-
create
public static DriverControls create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, DriveConfig config, DriverHeading heading) - Parameters:
hardwareMap- the OpMode's hardwareMapconfig- your drive settings (e.g.robotConfig.drive())heading- for field-centric driving; null if the robot has no IMU (robot-centric only)
-
slowSpeed
Speed at a full squeeze of the left trigger, 0 to 1. Default 0.3 (30%). -
sticks
How the sticks feel. Deadband: stick values smaller than this count as 0, so a resting stick does not creep (default 0.05). Exponent: 2 (default) gives fine control near the middle, 1 = straight line. SeeStickShaping. -
swapSticks
True: drive (and strafe) with the RIGHT stick and turn with the LEFT stick's X, for drivers who like it that way round. False (default): the left stick drives, the right stick X turns. -
sticksSwapped
public boolean sticksSwapped()True whenswapSticks(boolean)is on. -
reverseWhen
Reverse drive whilewhenis true: forward and strafe are flipped, so the back of the robot acts as the front (turning is not flipped). Robot-centric only: field-centric driving ignores it (the field does not turn round). The robot in five files:g1.x.toggle(robot.reverseDriveMode()). -
turnAssist
A helper that may change the turn, e.g. aiming at a goal while the driver drives: every loop it gets the driver's turn (after the stick shaping, clockwise +) and gives back the turn to use. Forward and sideways stay the driver's. Null = none (the default). The five-files TeleOp uses it forrobot.aimMode().driving.turnAssist(turn -> aimOn && turn == 0 ? aim.turnPower(camera.target("RED SCORING")) : turn); -
moveScale
Multiplies forward and strafe by this every loop, 0 to 1 (1 = unchanged, the default). The turn is not changed: a turn assist (aim) keeps its full power. The five-files TeleOp uses it to drive slower whilerobot.aimMode()is on (Tunables.Aim.aimDriveSpeed), so the aim keeps up.driving.moveScale(() -> aimOn ? 0.5 : 1);- Parameters:
scale- gives the share of forward and strafe to use, 0 to 1; null = always 1
-
update
public void update(com.qualcomm.robotcore.hardware.Gamepad gamepad) Drives from the gamepad's sticks. Call once every loop. Never waits. -
update
public void update(com.qualcomm.robotcore.hardware.Gamepad gamepad, boolean slow) Drives from the gamepad's sticks, with slow mode switched by your own code instead of the left trigger (for example a one-driver layout where the trigger has another job). Call every loop.- Parameters:
gamepad- the driver's gamepadslow- true = drive at the slow speed
-
update
public void update(com.qualcomm.robotcore.hardware.Gamepad gamepad, double speed) Drives from the gamepad's sticks at a speed your own code works out (0 to 1, e.g. from a slow trigger that is not the left one). Call every loop. -
drive
public void drive(double forward, double strafeRight, double turnClockwise, double speed) Drives with numbers you worked out yourself (robot-centric), for your own controls. Each value -1 to 1; a tank robot ignores strafeRight. -
tank
public void tank(double left, double right, double speed) Two-stick "tank style": one value per side, -1 to 1. Works on tank AND mecanum robots. Example:driving.tank(-gamepad1.left_stick_y, -gamepad1.right_stick_y, 1). -
hold
public void hold()Holds the wheels still this loop (e.g. while a menu uses the gamepad). -
stop
public void stop()All wheels to 0. Call at the end of the OpMode (infinally). -
setFieldCentric
public void setFieldCentric(boolean on) Field-centric on or off. Ignored (stays off) on a tank robot or without a heading. -
toggleFieldCentric
public boolean toggleFieldCentric()Switches field-centric on/off; returns the new state. -
isFieldCentric
public boolean isFieldCentric()True while driving field-centric. -
canFieldCentric
public boolean canFieldCentric()True if this robot can drive field-centric: mecanum wheels and a heading. -
isSlow
public boolean isSlow()True while the slow trigger is pulled. -
status
One short line for telemetry, e.g. "field SLOW".
-