Class SpinMotor
java.lang.Object
com.crossbotics.ftchelper.mechanism.SpinMotor
- All Implemented Interfaces:
Subsystem
A motor that spins: an intake, a roller, a conveyor, a spinner. IN, OUT or STOPPED, with
optional jam detection that backs it out by itself.
SpinMotor intake = SpinMotor.create(hardwareMap, "intake")
.powers(1.0, -0.6) // in, out
.jamDetection(80, 0.3, 0.4); // < 80 ticks/s for 0.3 s = jammed; back out for 0.4 s
controls.bindToggle(Pad.G2, Btn.A, intake::in, intake::stop)
.bindHold(Pad.G2, Btn.B, intake::out)
.bindRelease(Pad.G2, Btn.B, intake::stop);
routine.step("Intake on", intake.inStep());
Buttons only change what it is doing (its "state"); update(), once per loop, sends the
power and watches for jams. Jam detection needs the motor's encoder cable (the encoder is the sensor
that measures how fast the shaft turns). Docs: docs/modules/mechanism.md; the jam check itself is
JamDetector (docs/modules/safety.md).
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidShows the state; a warning while it backs out of a jam; speed and jam count in debug mode.static SpinMotorGets the motor (coast, plain power) and wraps it.intHow many jams were cleared since the OpMode started.com.qualcomm.robotcore.hardware.DcMotorExgetMotor()The FTC motor inside, for anything this helper does not do.getState()What it is doing now.voidin()Spin IN.inStep()A step: start spinning IN and go straight on.booleanTrue unless STOPPED.jamCurrent(double amps) Also counts a jam when the current is above this (amps).jamDetection(double minSpeed, double jamSec, double unjamSec) Turns on jam detection while IN.name()The name shown in telemetry and in the hardware check.voidout()Spin OUT.outForStep(double seconds) A step: run OUT for some seconds, then stop (e.g.outStep()A step: start spinning OUT and go straight on.powers(double in, double out) Powers for IN and OUT, -1 to 1 (OUT is usually negative and a bit gentler).reversed()Positive power spins the other way.voidsetPower(double power) Any power you like, -1 to 1 (e.g.voidstop()Stop.stopStep()A step: stop.voidtoggleIn()IN if it was not running IN, else STOPPED.voidOUT if it was not running OUT, else STOPPED.voidupdate()Once per loop: sends the power for the current state and, while IN, watches for jams.
-
Constructor Details
-
SpinMotor
Wraps a motor you already set up.
-
-
Method Details
-
create
public static SpinMotor create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name) Gets the motor (coast, plain power) and wraps it. -
reversed
Positive power spins the other way. -
powers
Powers for IN and OUT, -1 to 1 (OUT is usually negative and a bit gentler). -
jamDetection
Turns on jam detection while IN. A jam = it is given power but barely turns, for a while. When that happens it runs OUT for a moment to spit out what is stuck, then goes back to IN.- Parameters:
minSpeed- slowest normal speed while running, ticks per secondjamSec- how long too slow before it counts as a jam (long enough for the motor to spin up)unjamSec- how long to run OUT to clear it, then IN again
-
jamCurrent
Also counts a jam when the current is above this (amps). Reading current costs a little loop time. -
in
public void in()Spin IN. Safe to call every loop: if it is already in (or clearing a jam), nothing changes. So you can writeif (reverse) out(); else if (on) in(); else stop();each loop. -
out
public void out()Spin OUT. Safe to call every loop. -
stop
public void stop()Stop. Safe to call every loop. The 0 power is sent right away, not in the next update(). -
toggleIn
public void toggleIn()IN if it was not running IN, else STOPPED. -
toggleOut
public void toggleOut()OUT if it was not running OUT, else STOPPED. -
setPower
public void setPower(double power) Any power you like, -1 to 1 (e.g. from a trigger). 0 = stop. No jam detection in this mode. -
update
public void update()Once per loop: sends the power for the current state and, while IN, watches for jams. Never waits. -
inStep
A step: start spinning IN and go straight on. -
outStep
A step: start spinning OUT and go straight on. -
stopStep
A step: stop. -
outForStep
A step: run OUT for some seconds, then stop (e.g. to drop a game piece). -
getState
What it is doing now. -
getJamCount
public int getJamCount()How many jams were cleared since the OpMode started. -
isRunning
public boolean isRunning()True unless STOPPED. -
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 the state; a warning while it backs out of a jam; speed and jam count in debug mode.- Specified by:
addTelemetryin interfaceSubsystem
-