Class DriverControls

java.lang.Object
com.crossbotics.ftchelper.drive.DriverControls

public final class DriverControls extends Object
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 Type
    Method
    Description
    boolean
    True if this robot can drive field-centric: mecanum wheels and a heading.
    create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, DriveConfig config, DriverHeading heading)
    Makes the drive from your settings: a MecanumDrive or a TankDrive, picked by config.type.
    void
    drive(double forward, double strafeRight, double turnClockwise, double speed)
    Drives with numbers you worked out yourself (robot-centric), for your own controls.
    void
    Holds the wheels still this loop (e.g.
    boolean
    True while driving field-centric.
    boolean
    True while the slow trigger is pulled.
    void
    setFieldCentric(boolean on)
    Field-centric on or off.
    slowSpeed(double speed)
    Speed at a full squeeze of the left trigger, 0 to 1.
    One short line for telemetry, e.g.
    sticks(double deadband, double exponent)
    How the sticks feel.
    void
    All wheels to 0.
    void
    tank(double left, double right, double speed)
    Two-stick "tank style": one value per side, -1 to 1.
    boolean
    Switches field-centric on/off; returns the new state.
    void
    update(com.qualcomm.robotcore.hardware.Gamepad gamepad)
    Drives from the gamepad's sticks.
    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).
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static DriverControls create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, DriveConfig config, DriverHeading heading)
      Makes the drive from your settings: a MecanumDrive or a TankDrive, picked by config.type.
      Parameters:
      hardwareMap - the OpMode's hardwareMap
      config - your drive settings (e.g. robotConfig.drive())
      heading - for field-centric driving; null if the robot has no IMU (robot-centric only)
    • slowSpeed

      public DriverControls slowSpeed(double speed)
      Speed at a full squeeze of the left trigger, 0 to 1. Default 0.3 (30%).
    • sticks

      public DriverControls sticks(double deadband, double exponent)
      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. See StickShaping.
    • 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 gamepad
      slow - 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 (in finally).
    • 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

      public String status()
      One short line for telemetry, e.g. "field SLOW".