Class FieldMap

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

public final class FieldMap extends Object
The places on the field the robot must not drive through, and how to get around them: your own "keep-out" boxes, in Robot.java. The library knows no game, so the numbers are yours.

 fieldMap(FieldMap.margin(13)
         .keepOut("Left post", -30, 10, -20, 20)    // two opposite corners, inches
         .keepOut("Right post", 20, 10, 30, 20)
         .safePoint(0, -40));                       // optional: a good place to pass through
 

The numbers are like driveTo's: written for BLUE, seen from your drivers' wall, x inches right of the center line, y inches from the center toward the far wall.

How a route is found: first the straight line. If it crosses a box, the robot goes around the boxes' corners and your safe points, by the shortest way of straight lines. It uses only where the odometry says the robot is. It cannot see anything: another robot is not on this map, and a wrong pose means a wrong route.

The margin: how far the robot's CENTER must stay from a box. Half the robot's longest corner to corner size, plus some for odometry drift. An 18 x 18 in robot: 13 in. A spot you choose inside a margin is allowed (a place right next to a box): the robot drives to just outside the margin, then straight in. A spot on the box itself is not. Docs: docs/modules/odometry.md, "Keep-out boxes and routes"

  • Method Summary

    Modifier and Type
    Method
    Description
    int
    How many boxes the map has.
    fieldSize(double inches)
    The field's size.
    keepOut(String name, double x1, double y1, double x2, double y2)
    Adds a box the robot must not drive through.
    boolean
    lineIsClear(double fromX, double fromY, double toX, double toY)
    True if the robot's center may drive straight from one place to another: the line misses every box with its margin.
    static FieldMap
    margin(double inches)
    Starts a map.
    double
    How far the robot's center stays from every box, inches.
    List<double[]>
    route(double fromX, double fromY, double toX, double toY)
    Finds the shortest route of straight lines that misses every box.
    safePoint(double x, double y)
    Adds a place a route may pass through (optional: the boxes' corners are used without this).
    whyBadSpot(double x, double y)
    Why a route cannot end at this spot: on a box, boxed in, or off the field.

    Methods inherited from class java.lang.Object

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

    • margin

      public static FieldMap margin(double inches)
      Starts a map.
      Parameters:
      inches - how far the robot's center stays from every box, 0 or more (half its longest corner to corner size, plus some for drift)
    • keepOut

      public FieldMap keepOut(String name, double x1, double y1, double x2, double y2)
      Adds a box the robot must not drive through.
      Parameters:
      name - a name for messages, e.g. "Left post"
      x1 - one corner: inches right of the center line
      y1 - one corner: inches from the center toward the far wall
      x2 - the opposite corner: inches right
      y2 - the opposite corner: inches toward the far wall
    • safePoint

      public FieldMap safePoint(double x, double y)
      Adds a place a route may pass through (optional: the boxes' corners are used without this). Use one to make routes go your way, e.g. through a gap you trust. A gap less than 2.5 in wide (after the margins) needs one at each end, because the boxes' corners do not fit in it. It must be at least 0.5 in outside every margin, and inside the walls by the margin.
      Parameters:
      x - inches right of the center line
      y - inches from the center toward the far wall
    • fieldSize

      public FieldMap fieldSize(double inches)
      The field's size. Default 144 in, an FTC field.
      Parameters:
      inches - one side of the square field
    • marginIn

      public double marginIn()
      How far the robot's center stays from every box, inches.
    • boxCount

      public int boxCount()
      How many boxes the map has.
    • whyBadSpot

      public String whyBadSpot(double x, double y)
      Why a route cannot end at this spot: on a box, boxed in, or off the field. A spot inside a margin is fine if the robot can get to it from outside.
      Parameters:
      x - inches right of the center line
      y - inches from the center toward the far wall
      Returns:
      the reason, or "" if the spot is good
    • route

      public List<double[]> route(double fromX, double fromY, double toX, double toY)
      Finds the shortest route of straight lines that misses every box. Quick: it is safe to call in the loop once, when the robot sets off. If the robot stands within a box's margin (or inside it, from a wrong pose), the route's first point takes it out by the nearest side. A spot inside a margin is reached the same way backwards: the last line goes straight in from just outside.
      Parameters:
      fromX - where the robot is: inches right
      fromY - where the robot is: inches toward the far wall
      toX - where to go: inches right
      toY - where to go: inches toward the far wall
      Returns:
      the points to drive to, in order, the last one being (toX, toY); each is {x, y}. Empty if there is no route, so the robot must not set off.
    • lineIsClear

      public boolean lineIsClear(double fromX, double fromY, double toX, double toY)
      True if the robot's center may drive straight from one place to another: the line misses every box with its margin. A box whose margin holds the END is checked without its margin, because a route's last line goes straight in to a spot next to a box. RouteDriver.checkLines(com.crossbotics.ftchelper.drive.RouteDriver.LineCheck) uses this.
      Parameters:
      fromX - from: inches right of the center line
      fromY - from: inches toward the far wall
      toX - to: inches right
      toY - to: inches toward the far wall