Class RouteDriver

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

public final class RouteDriver extends Object
Drives a route of field points, one loop at a time. It never waits: each loop, call update() and send what it returns to the wheels. It works out powers like AutoDrive.driveTo(java.util.function.Supplier<com.crossbotics.ftchelper.util.FieldPose>, double, double, double, double, double). In autonomous, AutoDrive.followRoute(java.util.function.Supplier<com.crossbotics.ftchelper.util.FieldPose>, java.util.function.BooleanSupplier, java.util.List<double[]>, com.crossbotics.ftchelper.drive.RouteDriver.LineCheck, double, double, double) runs it for you and blocks.

 RouteDriver route = new RouteDriver(autoConfig, 1.0, robot::pose, odometry::isReady, System::nanoTime)
         .checkLines(map::lineIsClear);
 route.start(map.route(pose.x, pose.y, -56, -36), 0, 0.7, 2.0);
 // every loop:
 if (route.isRunning()) {
     double[] p = route.update();
     driving.drive(p[0], p[1], p[2], 1);
 }
 

Controls.java's route(...) uses this for you. It ends by itself: at the last point, when stuck, when the odometry stops working, or after actionTimeoutSec on one line of the route. Docs: docs/modules/drive.md, "RouteDriver"

  • Field Details

    • PASS_POINT_IN

      public static final double PASS_POINT_IN
      A point on the way (not the last one) counts as reached within this many inches.
      See Also:
  • Constructor Details

    • RouteDriver

      public RouteDriver(AutoDriveConfig cfg, double powerLimit, Supplier<FieldPose> pose, BooleanSupplier ready, LongSupplier clockNanos)
      Parameters:
      cfg - the autonomous numbers (turn gains, stuck rule, time limit)
      powerLimit - the drive's power limit, 0 to 1 (the slowest powers are raised to make up for it)
      pose - where the robot is now
      ready - false while the odometry cannot be trusted
      clockNanos - the clock, in nanoseconds (tests pass their own)
  • Method Details

    • checkLines

      public RouteDriver checkLines(RouteDriver.LineCheck check)
      Gives it the map's line check (optional, but routes from FieldMap.route(double, double, double, double) should have it). A point on the way then counts as reached early (within 2 in, or slid past it) only if the line from where the robot is to the next point is clear. Without it, a robot that left a safe point early, or slid past a corner at an angle, could cut through a box's margin.
      
       route.checkLines(map::lineIsClear);
       
      Parameters:
      check - the check, or null for none
      Returns:
      this, to chain
    • start

      public boolean start(List<double[]> route, double headingDeg, double maxPower, double toleranceIn)
      Starts a route. A route with no points does not start (see FieldMap.route(double, double, double, double)).
      Parameters:
      route - the points, each {x, y}, inches; the last one is where it ends
      headingDeg - the heading to turn to on the way (counterclockwise +; 0 = facing away)
      maxPower - 0.1 to 1
      toleranceIn - close enough at the last point, inches (1 is usual)
      Returns:
      true if it started
    • isRunning

      public boolean isRunning()
      True while it drives.
    • result

      public RouteDriver.Result result()
      How the last route ended, or null if it is still running or none has run.
    • cancel

      public void cancel()
      Ends the route now. Send 0 to the wheels (or the driver's sticks) after this.
    • update

      public double[] update()
      One loop of the route. Never waits.
      Returns:
      {forward, strafe right, turn clockwise}, each -1 to 1; all 0 once it has ended