Class Pieces

java.lang.Object
com.crossbotics.ftchelper.robot.Module<Pieces>
com.crossbotics.ftchelper.robot.Pieces
All Implemented Interfaces:
Subsystem

public final class Pieces extends Module<Pieces>
Counts the game pieces the robot holds and knows the kind of the NEXT one to fire. A PieceSensor at the intake counts each piece coming in (and its kind), and each piece pushed back out through the intake; every feed of an Indexer counts one going out once it really went (the ready sensor sees it leave, or the feed ended without a jam); an optional sensor at the "ready to fire" slot says what is next for sure.

 public Pieces pieces;                                                   // Robot.java
 pieces = add(Pieces.kinds("POLLEN", "RED_NECTAR", "BLUE_NECTAR")
         .comingIn(PieceSensor.color("intake_color"))
         .readyToFire(PieceSensor.color("ready_color"))                 // optional
         .max(4)                                                         // the game's limit
         .startsWith(4, "POLLEN"));                                      // the preload

 robot.pieces.count();      // 3
 robot.pieces.next();       // "POLLEN", Pieces.UNKNOWN or Pieces.NONE
 robot.pieces.isFull();     // true at max
 

Hooks for other parts: nextKind() (a Supplier<String>, e.g. to pick the shot table), whenFull(), whenEmpty(), whenNextIs(String) (BooleanSuppliers, e.g. for LEDs or Intake.stopsWhen). No Tunables of its own (its sensors have theirs). Suggested button: hold operator left-stick button 1 s = count 0 (the count went wrong).

The count is a helper, not a guarantee: a miscount happens (two touching pieces, a piece that bounced out). The drivers, not the count, are responsible for the game's limit (BIOBUZZ G407) until the robot has a hardware stop. Docs: docs/modules/robot.md (section "Pieces and PieceSensor")

  • Field Details

  • Method Details

    • kinds

      public static Pieces kinds(String... names)
      The kinds of piece this season, as names: letters, digits and _ only (they are also the Tunables fields of the sensors), e.g. Pieces.kinds("POLLEN", "RED_NECTAR", "BLUE_NECTAR").
    • comingIn

      public Pieces comingIn(PieceSensor sensor)
      The sensor that sees each piece come in (at or just past the intake). Each new piece there counts one.
    • readyToFire

      public Pieces readyToFire(PieceSensor sensor)
      The sensor at the "ready to fire" slot: it says for sure what fires next. Optional.
    • max

      public Pieces max(int pieces)
      The most pieces the robot may hold (BIOBUZZ G407: 4). isFull() is true at this count.
      Parameters:
      pieces - at least 1
    • startsWith

      public Pieces startsWith(int count, String kind)
      The pieces in the robot at INIT (a preload), e.g. startsWith(4, "POLLEN").
      Parameters:
      count - how many
      kind - their kind (one of the kinds, or UNKNOWN)
    • update

      public void update()
      Description copied from interface: Subsystem
      Called once every loop. Do the hardware work here. Must be quick: no sleep, no waiting. While update() waits, the whole robot is frozen (no driving, no limits, no STOP).
    • count

      public int count()
      How many pieces the robot holds now (a piece being fed counts until it has gone).
    • count

      public int count(String kind)
      How many of this kind it holds.
    • next

      public String next()
      The kind of the next piece to fire: a kind, UNKNOWN, or NONE when empty. While a feed is sending one out, the one after it.
    • nextIs

      public boolean nextIs(String kind)
      True if the next piece to fire is this kind.
    • isFull

      public boolean isFull()
      True when it holds max pieces (or more). False with no max.
    • isEmpty

      public boolean isEmpty()
      True when it holds none.
    • held

      public List<String> held()
      The pieces held, next to fire first (a copy).
    • atIntake

      public String atIntake()
      What the intake sensor sees now (NONE without one).
    • atReady

      public String atReady()
      What the ready sensor sees now (NONE without one).
    • comingInSensor

      public PieceSensor comingInSensor()
      The sensor given with comingIn(PieceSensor), or null.
    • readyToFireSensor

      public PieceSensor readyToFireSensor()
      The sensor given with readyToFire(PieceSensor), or null.
    • maxPieces

      public int maxPieces()
      The limit from max(int) (0 = none).
    • nextKind

      public Supplier<String> nextKind()
      next() as a Supplier<String>, for a part that asks every loop (a shot table chooser).
    • whenFull

      public BooleanSupplier whenFull()
      isFull() as a condition (for LEDs, Intake.stopsWhen, an action's wait).
    • whenEmpty

      public BooleanSupplier whenEmpty()
      isEmpty() as a condition.
    • whenNextIs

      public BooleanSupplier whenNextIs(String kind)
      "The next piece is this kind" as a condition, e.g. whenNextIs("POLLEN") for a yellow LED.
    • pieceIn

      public void pieceIn(String kind)
      One more piece of this kind came in (the intake sensor calls this; a claw can too).
    • pieceOut

      public void pieceOut()
      One piece went out, the next to fire (for a part that sends pieces out itself). Nothing if it holds none.
    • clear

      public void clear()
      Empties the count (e.g. a button after the robot was emptied by hand; its suggested button).
    • set

      public void set(String... kinds)
      Sets what it holds, next to fire first, e.g. set("POLLEN", "POLLEN").
    • stop

      public void stop()
      Description copied from interface: Subsystem
      Stops all motion. Called at the end of every OpMode.
    • addTelemetry

      public void addTelemetry(RobotTelemetry t)
      Description copied from class: Module
      The part's telemetry line; each module adds its own.
      Specified by:
      addTelemetry in interface Subsystem
      Overrides:
      addTelemetry in class Module<Pieces>