Package com.crossbotics.ftchelper.robot
Class Pieces
- All Implemented Interfaces:
Subsystem
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidThe part's telemetry line; each module adds its own.atIntake()What the intake sensor sees now (NONE without one).atReady()What the ready sensor sees now (NONE without one).voidclear()Empties the count (e.g.comingIn(PieceSensor sensor) The sensor that sees each piece come in (at or just past the intake).The sensor given withcomingIn(PieceSensor), or null.intcount()How many pieces the robot holds now (a piece being fed counts until it has gone).intHow many of this kind it holds.held()The pieces held, next to fire first (a copy).booleanisEmpty()True when it holds none.booleanisFull()True when it holdsmaxpieces (or more).static PiecesThe kinds of piece this season, as names: letters, digits and _ only (they are also the Tunables fields of the sensors), e.g.max(int pieces) The most pieces the robot may hold (BIOBUZZ G407: 4).intThe limit frommax(int)(0 = none).next()booleanTrue if the next piece to fire is this kind.nextKind()next()as aSupplier<String>, for a part that asks every loop (a shot table chooser).voidOne more piece of this kind came in (the intake sensor calls this; a claw can too).voidpieceOut()One piece went out, the next to fire (for a part that sends pieces out itself).readyToFire(PieceSensor sensor) The sensor at the "ready to fire" slot: it says for sure what fires next.The sensor given withreadyToFire(PieceSensor), or null.voidSets what it holds, next to fire first, e.g.startsWith(int count, String kind) The pieces in the robot at INIT (a preload), e.g.voidstop()Stops all motion.voidupdate()Called once every loop.isEmpty()as a condition.whenFull()isFull()as a condition (for LEDs,Intake.stopsWhen, an action's wait).whenNextIs(String kind) "The next piece is this kind" as a condition, e.g.
-
Field Details
-
NONE
No piece.- See Also:
-
UNKNOWN
A piece the sensor could not tell (not one of the kinds, or not tuned yet).- See Also:
-
-
Method Details
-
kinds
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
The sensor that sees each piece come in (at or just past the intake). Each new piece there counts one. -
readyToFire
The sensor at the "ready to fire" slot: it says for sure what fires next. Optional. -
max
The most pieces the robot may hold (BIOBUZZ G407: 4).isFull()is true at this count.- Parameters:
pieces- at least 1
-
startsWith
The pieces in the robot at INIT (a preload), e.g.startsWith(4, "POLLEN").- Parameters:
count- how manykind- their kind (one of the kinds, or UNKNOWN)
-
update
public void update()Description copied from interface:SubsystemCalled 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
How many of this kind it holds. -
next
-
nextIs
True if the next piece to fire is this kind. -
isFull
public boolean isFull()True when it holdsmaxpieces (or more). False with no max. -
isEmpty
public boolean isEmpty()True when it holds none. -
held
The pieces held, next to fire first (a copy). -
atIntake
What the intake sensor sees now (NONE without one). -
atReady
What the ready sensor sees now (NONE without one). -
comingInSensor
The sensor given withcomingIn(PieceSensor), or null. -
readyToFireSensor
The sensor given withreadyToFire(PieceSensor), or null. -
maxPieces
public int maxPieces()The limit frommax(int)(0 = none). -
nextKind
next()as aSupplier<String>, for a part that asks every loop (a shot table chooser). -
whenFull
isFull()as a condition (for LEDs,Intake.stopsWhen, an action's wait). -
whenEmpty
isEmpty()as a condition. -
whenNextIs
"The next piece is this kind" as a condition, e.g.whenNextIs("POLLEN")for a yellow LED. -
pieceIn
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
Sets what it holds, next to fire first, e.g.set("POLLEN", "POLLEN"). -
stop
public void stop()Description copied from interface:SubsystemStops all motion. Called at the end of every OpMode. -
addTelemetry
Description copied from class:ModuleThe part's telemetry line; each module adds its own.- Specified by:
addTelemetryin interfaceSubsystem- Overrides:
addTelemetryin classModule<Pieces>
-