Class SpinMotor

java.lang.Object
com.crossbotics.ftchelper.mechanism.SpinMotor
All Implemented Interfaces:
Subsystem

public class SpinMotor extends Object implements 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
    Modifier and Type
    Class
    Description
    static enum 
    What it is doing.
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    void
    Shows the state; a warning while it backs out of a jam; speed and jam count in debug mode.
    static SpinMotor
    create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
    Gets the motor (coast, plain power) and wraps it.
    int
    How many jams were cleared since the OpMode started.
    com.qualcomm.robotcore.hardware.DcMotorEx
    The FTC motor inside, for anything this helper does not do.
    What it is doing now.
    void
    in()
    Spin IN.
    A step: start spinning IN and go straight on.
    boolean
    True 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.
    The name shown in telemetry and in the hardware check.
    void
    out()
    Spin OUT.
    outForStep(double seconds)
    A step: run OUT for some seconds, then stop (e.g.
    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).
    Positive power spins the other way.
    void
    setPower(double power)
    Any power you like, -1 to 1 (e.g.
    void
    Stop.
    A step: stop.
    void
    IN if it was not running IN, else STOPPED.
    void
    OUT if it was not running OUT, else STOPPED.
    void
    Once per loop: sends the power for the current state and, while IN, watches for jams.

    Methods inherited from class java.lang.Object

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

    • SpinMotor

      public SpinMotor(String name, com.qualcomm.robotcore.hardware.DcMotorEx motor)
      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

      public SpinMotor reversed()
      Positive power spins the other way.
    • powers

      public SpinMotor powers(double in, double out)
      Powers for IN and OUT, -1 to 1 (OUT is usually negative and a bit gentler).
    • jamDetection

      public SpinMotor jamDetection(double minSpeed, double jamSec, double unjamSec)
      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 second
      jamSec - 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

      public SpinMotor jamCurrent(double amps)
      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 write if (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().
      Specified by:
      stop in interface Subsystem
    • 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.
      Specified by:
      update in interface Subsystem
    • inStep

      public AutoStep inStep()
      A step: start spinning IN and go straight on.
    • outStep

      public AutoStep outStep()
      A step: start spinning OUT and go straight on.
    • stopStep

      public AutoStep stopStep()
      A step: stop.
    • outForStep

      public AutoStep outForStep(double seconds)
      A step: run OUT for some seconds, then stop (e.g. to drop a game piece).
    • getState

      public SpinMotor.State 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

      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; a warning while it backs out of a jam; speed and jam count in debug mode.
      Specified by:
      addTelemetry in interface Subsystem