Package com.crossbotics.ftchelper.drive
Class RouteDriver
java.lang.Object
com.crossbotics.ftchelper.drive.RouteDriver
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"
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceSays if a straight line on the field is clear.static enumHow a route ended. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleA point on the way (not the last one) counts as reached within this many inches. -
Constructor Summary
ConstructorsConstructorDescriptionRouteDriver(AutoDriveConfig cfg, double powerLimit, Supplier<FieldPose> pose, BooleanSupplier ready, LongSupplier clockNanos) -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Ends the route now.checkLines(RouteDriver.LineCheck check) Gives it the map's line check (optional, but routes fromFieldMap.route(double, double, double, double)should have it).booleanTrue while it drives.result()How the last route ended, or null if it is still running or none has run.booleanStarts a route.double[]update()One loop of the route.
-
Field Details
-
PASS_POINT_IN
public static final double PASS_POINT_INA 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 nowready- false while the odometry cannot be trustedclockNanos- the clock, in nanoseconds (tests pass their own)
-
-
Method Details
-
checkLines
Gives it the map's line check (optional, but routes fromFieldMap.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
Starts a route. A route with no points does not start (seeFieldMap.route(double, double, double, double)).- Parameters:
route- the points, each {x, y}, inches; the last one is where it endsheadingDeg- the heading to turn to on the way (counterclockwise +; 0 = facing away)maxPower- 0.1 to 1toleranceIn- close enough at the last point, inches (1 is usual)- Returns:
- true if it started
-
isRunning
public boolean isRunning()True while it drives. -
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
-