Class Flywheel

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

public class Flywheel extends Object implements Subsystem
A flywheel (shooter wheel) that holds a speed in RPM, says when it is ready, and notices shots. (Last season's Launcher, made general.)

 Flywheel flywheel = Flywheel.create(hardwareMap, "flywheel")
         .countsPerRev(28)            // encoder counts per FLYWHEEL turn (see below)
         .pidf(10, 3, 0, 12)          // the hub's speed control (start here, then tune)
         .tolerance(75)               // within 75 RPM...
         .settleTime(0.15);           // ...for 0.15 s = ready
 flywheel.setRpm(3200);
 // every loop:
 flywheel.update();
 if (flywheel.isReady()) { ...feed a ball... }
 

countsPerRev = encoder counts for ONE turn of the flywheel. Motor encoder on a 1:1 flywheel: 28 (goBILDA/REV bare motor). With gears between motor and flywheel, multiply by (motor turns per flywheel turn). An encoder on the flywheel shaft plugged into this motor's encoder port: that encoder's counts per turn (REV Through Bore: 8192). Check that the hub reads your top speed correctly (the speed on telemetry must match a tachometer or a slow-motion video).

Speed control runs on the hub (RUN_USING_ENCODER), so it is fast and smooth. A dropping battery still changes the result a little: tune the F gain with a charged battery.

RPM = revolutions (turns) per minute. The hub works in encoder counts per second, so this class converts between the two. Tutorial 17 builds a shooter step by step. Docs: docs/modules/launcher.md

  • Constructor Summary

    Constructors
    Constructor
    Description
    Flywheel(String name, com.qualcomm.robotcore.hardware.DcMotorEx motor)
    Wraps a motor you already set up (RUN_USING_ENCODER).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Shows measured / target RPM and READY; shots seen in debug mode; a warning for a fault.
    countsPerRev(double counts)
    Encoder counts per ONE flywheel turn.
    static Flywheel
    create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
    Gets the motor: coast (a flywheel must spin down freely), speed control on.
    follower(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String followerName, boolean reversed)
    A second motor on the same flywheel.
    "" or a problem, e.g.
    double
    The highest speed it may be asked for (see maxRpm).
    com.qualcomm.robotcore.hardware.DcMotorEx
    The FTC motor inside, for anything this helper does not do.
    double
    The measured speed (RPM).
    int
    How many shots were noticed (speed drops) since the OpMode started.
    double
    The target speed (RPM).
    boolean
    True when at speed and steady.
    maxRpm(double max)
    The highest speed it may be asked for, in RPM.
    The name shown in telemetry and in the hardware check.
    pidf(double p, double i, double d, double f)
    The hub's speed-control gains (P, I, D, F).
    Spins the other way for positive speeds.
    void
    setRpm(double newRpm)
    Spins to this speed in RPM (0 = coast to a stop).
    settleTime(double seconds)
    ...for at least this long, in seconds.
    shotDrop(double rpmDrop)
    A drop of more than this many RPM after being ready counts as a shot.
    spinUpStep(double targetRpmValue, double timeoutSec)
    A step (autonomous): spin up and wait until ready (or timeoutSec).
    void
    Coasts to a stop (no braking: a fast flywheel must spin down freely).
    tolerance(double rpmTolerance)
    Ready when within this many RPM of the target.
    void
    Once per loop: sends the speed, reads the real speed, works out "ready", and counts shots.

    Methods inherited from class java.lang.Object

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

    • Flywheel

      public Flywheel(String name, com.qualcomm.robotcore.hardware.DcMotorEx motor)
      Wraps a motor you already set up (RUN_USING_ENCODER).
  • Method Details

    • create

      public static Flywheel create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
      Gets the motor: coast (a flywheel must spin down freely), speed control on.
    • reversed

      public Flywheel reversed()
      Spins the other way for positive speeds.
    • follower

      public Flywheel follower(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String followerName, boolean reversed)
      A second motor on the same flywheel. It gets the same speed command, so it needs its own encoder cable (the hub's speed control reads it). If its encoder reads nothing while the wheel spins, the follower is switched off and a warning shows (without an encoder, its speed control would drive it to full power and fight the first motor). It gets the same pidf(double, double, double, double) gains, whether you call pidf before or after this.
    • countsPerRev

      public Flywheel countsPerRev(double counts)
      Encoder counts per ONE flywheel turn. Default 28.
    • pidf

      public Flywheel pidf(double p, double i, double d, double f)
      The hub's speed-control gains (P, I, D, F). Applied to the follower too (in any order). F is the main one: the steady power for a given speed.
    • tolerance

      public Flywheel tolerance(double rpmTolerance)
      Ready when within this many RPM of the target. Default 75.
    • settleTime

      public Flywheel settleTime(double seconds)
      ...for at least this long, in seconds. Stops one lucky reading from counting. Default 0.15.
    • maxRpm

      public Flywheel maxRpm(double max)
      The highest speed it may be asked for, in RPM. Default 6000.
    • shotDrop

      public Flywheel shotDrop(double rpmDrop)
      A drop of more than this many RPM after being ready counts as a shot. Default 150.
    • setRpm

      public void setRpm(double newRpm)
      Spins to this speed in RPM (0 = coast to a stop). Changing the target restarts the "ready" timer. Safe to call every loop with the same (or almost the same) speed.
    • stop

      public void stop()
      Coasts to a stop (no braking: a fast flywheel must spin down freely).
      Specified by:
      stop in interface Subsystem
    • getFault

      public String getFault()
      "" or a problem, e.g. the follower's encoder not reading.
    • update

      public void update()
      Once per loop: sends the speed, reads the real speed, works out "ready", and counts shots.
      Specified by:
      update in interface Subsystem
    • isReady

      public boolean isReady()
      True when at speed and steady.
    • getMaxRpm

      public double getMaxRpm()
      The highest speed it may be asked for (see maxRpm).
    • getRpm

      public double getRpm()
      The measured speed (RPM).
    • getTargetRpm

      public double getTargetRpm()
      The target speed (RPM).
    • getShotCount

      public int getShotCount()
      How many shots were noticed (speed drops) since the OpMode started.
    • spinUpStep

      public AutoStep spinUpStep(double targetRpmValue, double timeoutSec)
      A step (autonomous): spin up and wait until ready (or timeoutSec).
    • getMotor

      public com.qualcomm.robotcore.hardware.DcMotorEx getMotor()
      The FTC motor inside, for anything this helper does not do.
    • 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 measured / target RPM and READY; shots seen in debug mode; a warning for a fault.
      Specified by:
      addTelemetry in interface Subsystem