Class Launcher

java.lang.Object
com.crossbotics.ftchelper.launcher.Launcher
All Implemented Interfaces:
Subsystem

public class Launcher extends Object implements Subsystem
Joins a flywheel, a feeder, and optionally a hood, a shot table and any "ready" checks into one shooter: spin up, wait until everything is ready, feed, repeat. It never stops the loop, so it works the same in TeleOp and in autonomous. (Last season's FiringController, made general.)

 Launcher launcher = new Launcher(flywheel, feeder)
         .hood(hood)                              // a PositionServo with degrees(...)
         .table(pollenTable)                      // distance -> rpm + hood
         .requireReady("Turret", turret::isAimed) // add any check you like
         .shotInterval(0.25);                     // at least 0.25 s between pieces

 launcher.setDistance(40);                        // or launcher.setRpm(3200)
 controls.bindPress(Pad.G2, Btn.RB, () -> launcher.shoot(1))
         .bindPress(Pad.G2, Btn.LB, () -> launcher.shoot(4))
         .bindPress(Pad.G2, Btn.B, launcher::stopShooting);
 routine.step("Shoot 3", launcher.shootStep(3));
 // every loop: launcher.update();   (it updates the flywheel, feeder and hood for you)
 

If it is not ready within readyTimeout(double), it gives up the remaining shots and whyNotReady() says what was missing. That is your first debug clue.

How it works: shoot(int) only adds to a count of "shots still to fire". Each loop, update() feeds ONE piece if everything is ready, and otherwise just checks again next loop. No waiting anywhere (see docs/guides/non-blocking.md). Tutorial 17 builds a shooter step by step. Docs: docs/modules/launcher.md

  • Field Details

    • SPRAY_MIN_SHARE

      public static final double SPRAY_MIN_SHARE
      SPRAY feeds only when the wheel turns at least this share of its target speed (0.5).
      See Also:
    • PROBLEM_SHOW_SEC

      public static final double PROBLEM_SHOW_SEC
      How long a problem ("gave up: turret aimed") stays as a warning on the Driver Station, seconds.
      See Also:
  • Constructor Details

    • Launcher

      public Launcher(Flywheel flywheel, Feeder feeder)
      Makes a launcher from a flywheel and a feeder you already made. It starts OFF. Put only the launcher in your loop (or Subsystems group): it updates both for you.
  • Method Details

    • hood

      public Launcher hood(AngleDevice hoodServo)
      A hood: a PositionServo with degrees(...) set, or any AngleDevice (the five-files Hood, a motor, your own). The table's hood angle goes to it (only from a table with hood angles, see ShotTable.hasHood()), and the launcher waits for it to arrive before feeding ("hood" in whyNotReady()).
    • table

      public Launcher table(ShotTable shotTable)
      A shot table, used by setDistance(double).
    • requireReady

      public Launcher requireReady(String checkName, BooleanSupplier check)
      Another condition that must be true before each piece is fed (aim, sensor, anything). checkName is shown by whyNotReady() while it is false. Example: requireReady("Turret", turret::isAimed): "turret::isAimed" hands over the question "is the turret aimed?" so the launcher can ask it every loop.
    • clearReadyChecks

      public Launcher clearReadyChecks()
      Removes every requireReady(java.lang.String, java.util.function.BooleanSupplier) check. The Shot Tuner does this for a robot in five files: there you aim by hand, so a "turret aimed" check must not stop each shot.
    • shotInterval

      public Launcher shotInterval(double seconds)
      Least time between two pieces, seconds. Default 0.25.
    • readyTimeout

      public Launcher readyTimeout(double seconds)
      Give up the remaining shots if not ready within this many seconds. Default 3.
    • hoodDeadband

      public Launcher hoodDeadband(double degrees)
      The hood moves only when the table's angle changes by more than this (degrees, default 0.25). A camera's distance jitters a little every picture; without this the hood would be sent a new angle every loop, and a servo that is always "moving" never lets the launcher feed.
      Parameters:
      degrees - 0 or more, in the hood's scale (a hood in servo positions: e.g. 0.005); 0 = send every change
    • shotMode

      public Launcher shotMode(Launcher.ShotMode shotMode)
      How strict it is before each feed (see Launcher.ShotMode). Default CAREFUL. Takes effect at the next piece.
    • getShotMode

      public Launcher.ShotMode getShotMode()
      The shot mode in use.
    • quickBand

      public Launcher quickBand(double rpm)
      QUICK: after the volley's first piece, feed when the wheel is within this many RPM of its speed. Default: 3 x the flywheel's ready band (its tolerance).
    • quickMaxWait

      public Launcher quickMaxWait(double seconds)
      QUICK: after the volley's first piece, feed after waiting this long at most, seconds. Default 0.3.
    • getShotInterval

      public double getShotInterval()
      The least time between two pieces, seconds (shotInterval(double)).
    • getQuickMaxWait

      public double getQuickMaxWait()
      The QUICK wait limit, seconds (quickMaxWait(double)).
    • getQuickBand

      public double getQuickBand()
      The QUICK band in use, RPM.
    • idleRpm

      public Launcher idleRpm(double rpm)
      Speed to keep when not shooting, in RPM (0 = stop). A low idle speed makes spin-up faster.
    • setRpm

      public void setRpm(double rpm)
      Sets the shot speed by hand, in RPM.
    • setDistance

      public void setDistance(double distance)
      Sets the shot from the table: the speed, and the hood angle (plus hoodOffset(double)) when there is a hood and the table has hood angles. Distance in the table's unit (inches in the examples). Safe to call every loop, e.g. with the camera's distance: the hood is only sent a new angle when it changes by more than hoodDeadband(double) (0.25 deg).
    • hoodOffset

      public void hoodOffset(double degrees)
      Degrees added to the table's hood angle by setDistance(double) (a hood trim: +1 = every shot 1 degree more). 0 = as the table says (the default). Takes effect at the next setDistance.
      Parameters:
      degrees - e.g. +1 or -0.5
    • getHoodOffset

      public double getHoodOffset()
      The degrees added to the table's hood angle (hoodOffset(double)); 0 = none.
    • getTable

      public ShotTable getTable()
      The shot table given with table, or null.
    • speedScale

      public void speedScale(double scale)
      Multiplies the shot speed (from setRpm(double) or the table) by this, e.g. 1.03 = 3% faster: a live trim for a match (a tired battery, a worn wheel), not a new table. Not the idle speed. 1 = as set (the default). The robot in five files' speed trim uses it.
      Parameters:
      scale - 0.5 to 1.5 (kept to that); 1.03 = +3%
    • getShotRpm

      public double getShotRpm()
      The shot speed before speedScale: from setRpm(double) or the table (RPM; 0 = none yet).
    • getSpeedScale

      public double getSpeedScale()
      The shot speed's multiplier (speedScale): 1 = as set.
    • spinUp

      public void spinUp()
      Spins the flywheel up to the shot speed and keeps it there.
    • idle

      public void idle()
      Goes back to the idle speed (cancels any shots). Use stop() for fully off.
    • shoot

      public void shoot(int count)
      Shoots count pieces (spins up first if needed). Adds to any shots still waiting.
    • stopShooting

      public void stopShooting()
      Cancels the shots still waiting (keeps spinning).
    • stop

      public void stop()
      Fully off: no shots, no idle speed. Stays off until spinUp(), shoot() or idle().
      Specified by:
      stop in interface Subsystem
    • update

      public void update()
      Once per loop: sets the flywheel speed, updates the flywheel, feeder and hood, then feeds one piece if shots are waiting and everything is ready. Gives up (with a reason) if not ready in time.
      Specified by:
      update in interface Subsystem
    • getShotStats

      public ShotStats getShotStats()
      What each fed piece did to the wheel: for tuning the shot modes (debug lines).
    • isReady

      public boolean isReady()
      True when the flywheel is at speed, the hood has arrived, and every check passes.
    • whyNotReady

      public String whyNotReady()
      What is not ready yet, e.g. "flywheel, Turret" ("" when ready).
    • getState

      public Launcher.State getState()
      What it is doing now (see Launcher.State).
    • isShooting

      public boolean isShooting()
      True while shots are waiting or a piece is being fed.
    • getShotsLeft

      public int getShotsLeft()
      Shots still waiting to be fired.
    • getShotsFired

      public int getShotsFired()
      Pieces fed since the OpMode started.
    • getLastProblem

      public String getLastProblem()
      The last problem (e.g. why it gave up), or "".
    • getFlywheel

      public Flywheel getFlywheel()
      The flywheel inside.
    • getHood

      public AngleDevice getHood()
      The hood, or null if there is none.
    • hasTable

      public boolean hasTable()
      True if a shot table was given (setDistance(double) works).
    • spinUpStep

      public AutoStep spinUpStep()
      A step: spin up and wait until ready (or the ready timeout).
    • shootStep

      public AutoStep shootStep(int count)
      A step: shoot count pieces and wait until done (or it gives up).
    • name

      public String name()
      Description copied from interface: Subsystem
      The name shown in telemetry and in the hardware check.
      Specified by:
      name in interface Subsystem
    • addTelemetry

      public void addTelemetry(RobotTelemetry t)
      Shows the state, shots left and READY; problems as warnings; then the flywheel, feeder and hood.
      Specified by:
      addTelemetry in interface Subsystem