Class JamDetector

java.lang.Object
com.crossbotics.ftchelper.safety.JamDetector

public final class JamDetector extends Object
Tells when a motor is jammed: it is asked to spin but barely turns (or draws too much current) for a while. No hardware here; SpinMotor and MotorFeeder use it.

Why it matters: a jammed motor gets hot, drains the battery and can strip gears or burn out. Noticing the jam lets your code back the game piece out instead.


 JamDetector jam = new JamDetector(50, 0.3);   // slower than 50 ticks/s for 0.3 s = jammed
 // every loop:
 if (jam.update(power, motor.getVelocity(), getRuntime())) { ...back it out... }
 
Docs: docs/modules/safety.md (section "JamDetector")
  • Constructor Summary

    Constructors
    Constructor
    Description
    JamDetector(double minSpeed, double timeSec)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Starts over (after clearing a jam).
    setMaxCurrent(double amps)
    Also counts as jammed when the current is above this many amps (for the same time).
    setMinPower(double power)
    Below this power the motor is not really trying, so it is never "jammed".
    boolean
    update(double power, double speed, double nowSec)
    Checks speed only.
    boolean
    update(double power, double speed, double amps, double nowSec)
    Checks speed and current.

    Methods inherited from class java.lang.Object

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

    • JamDetector

      public JamDetector(double minSpeed, double timeSec)
      Parameters:
      minSpeed - slowest normal speed while powered (ticks per second, any sign)
      timeSec - how long it must be too slow before it counts as jammed
  • Method Details

    • setMinPower

      public JamDetector setMinPower(double power)
      Below this power the motor is not really trying, so it is never "jammed". Default 0.15.
    • setMaxCurrent

      public JamDetector setMaxCurrent(double amps)
      Also counts as jammed when the current is above this many amps (for the same time).
    • update

      public boolean update(double power, double speed, double nowSec)
      Checks speed only. Call every loop.
      Parameters:
      power - the power you are sending
      speed - the measured speed (ticks per second)
      nowSec - the time now, in seconds
      Returns:
      true while jammed
    • update

      public boolean update(double power, double speed, double amps, double nowSec)
      Checks speed and current. Call every loop.
      Parameters:
      power - the power you are sending
      speed - the measured speed (ticks per second)
      amps - the measured current (0 if you do not measure it)
      nowSec - the time now, in seconds
      Returns:
      true while jammed
    • reset

      public void reset()
      Starts over (after clearing a jam).