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.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.voidstop()All wheels to 0.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.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. -
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".
-