Class Flywheel
- All Implemented Interfaces:
Subsystem
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidShows 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 FlywheelGets 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.getFault()"" or a problem, e.g.doubleThe highest speed it may be asked for (seemaxRpm).com.qualcomm.robotcore.hardware.DcMotorExgetMotor()The FTC motor inside, for anything this helper does not do.doublegetRpm()The measured speed (RPM).intHow many shots were noticed (speed drops) since the OpMode started.doubleThe target speed (RPM).booleanisReady()True when at speed and steady.maxRpm(double max) The highest speed it may be asked for, in RPM.name()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).reversed()Spins the other way for positive speeds.voidsetRpm(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 (ortimeoutSec).voidstop()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.voidupdate()Once per loop: sends the speed, reads the real speed, works out "ready", and counts shots.
-
Constructor Details
-
Flywheel
Wraps a motor you already set up (RUN_USING_ENCODER).
-
-
Method Details
-
create
Gets the motor: coast (a flywheel must spin down freely), speed control on. -
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 samepidf(double, double, double, double)gains, whether you call pidf before or after this. -
countsPerRev
Encoder counts per ONE flywheel turn. Default 28. -
pidf
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
Ready when within this many RPM of the target. Default 75. -
settleTime
...for at least this long, in seconds. Stops one lucky reading from counting. Default 0.15. -
maxRpm
The highest speed it may be asked for, in RPM. Default 6000. -
shotDrop
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). -
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. -
isReady
public boolean isReady()True when at speed and steady. -
getMaxRpm
public double getMaxRpm()The highest speed it may be asked for (seemaxRpm). -
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
A step (autonomous): spin up and wait until ready (ortimeoutSec). -
getMotor
public com.qualcomm.robotcore.hardware.DcMotorEx getMotor()The FTC motor inside, for anything this helper does not do. -
name
Description copied from interface:SubsystemThe name shown in telemetry and in the hardware check. -
addTelemetry
Shows measured / target RPM and READY; shots seen in debug mode; a warning for a fault.- Specified by:
addTelemetryin interfaceSubsystem
-