Class PositionServo

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

public class PositionServo extends Object implements Subsystem
A normal (positional) servo with named positions: a claw, a wrist, a hood, a gate. Can also work in degrees, move slowly, and tell (by estimate) when it has arrived.

 PositionServo claw = PositionServo.create(hardwareMap, "claw")
         .position("OPEN", 0.20)
         .position("CLOSED", 0.75)
         .travelTime(0.3);                       // seconds for a full 0..1 move (measure it)

 controls.bindPress(Pad.G2, Btn.RB, () -> claw.toggle("OPEN", "CLOSED"));
 routine.step("Grab", claw.goToStep("CLOSED"));  // waits until it should be closed

 PositionServo hood = PositionServo.create(hardwareMap, "hood")
         .degrees(0.10, 0, 0.90, 25);            // servo 0.10 = 0 deg, 0.90 = 25 deg (measured)
 hood.setDegrees(18);
 

Positions are raw servo positions (0 to 1). A servo cannot report where it really is, so "arrived" is an estimate from travelTime(double). Docs: docs/modules/mechanism.md (docs/images/servo-range.svg shows the 0 to 1 range).

  • Constructor Details

    • PositionServo

      public PositionServo(String name, com.qualcomm.robotcore.hardware.Servo servo)
      Wraps a servo you already have.
  • Method Details

    • create

      public static PositionServo create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
      Gets the servo. Does not move it.
    • reversed

      public PositionServo reversed()
      Position 0 and 1 swap ends.
    • limits

      public PositionServo limits(double min, double max)
      Never goes below min or above max (raw positions). Keeps it off the frame.
    • position

      public PositionServo position(String positionName, double value)
      Adds a named raw position, 0 to 1.
    • degrees

      public PositionServo degrees(double posA, double degA, double posB, double degB)
      Lets you use degrees. Measure two points: raw position posA is degA degrees, raw posB is degB degrees. In between is a straight line.
    • travelTime

      public PositionServo travelTime(double seconds)
      Seconds the servo needs for a full 0..1 move. Used to guess when it has arrived. Default 0.5.
    • maxSpeed

      public PositionServo maxSpeed(double positionsPerSecond)
      Moves slowly: at most this many raw positions per second (e.g. 0.5). 0 = full speed.
    • tunable

      public PositionServo tunable(String prefix)
      Puts every named position in the tuning menu as "prefix/NAME" (steps of 0.01, kept 0 to 1). Call it LAST. See docs/modules/tuning.md.
    • goTo

      public void goTo(String positionName)
      Goes to a named position. An unknown name (a typo) does nothing and shows a warning.
    • getWarning

      public String getWarning()
      "" or the last command problem (unknown position name).
    • set

      public void set(double position)
      Goes to a raw position (0 to 1, kept inside the limits).
    • setDegrees

      public void setDegrees(double deg)
      Goes to an angle in degrees (needs degrees(double, double, double, double)).
    • toggle

      public void toggle(String a, String b)
      Goes to b if at (or going to) a, else to a.
    • next

      public void next()
      The next named position in the order you added them (wraps around).
    • previous

      public void previous()
      The previous named position (wraps around).
    • update

      public void update()
      Once per loop. At full speed there is nothing to do (the servo was already told where to go). For a slow move (maxSpeed), it sends a position a little closer to the target each loop.
      Specified by:
      update in interface Subsystem
    • stop

      public void stop()
      Description copied from interface: Subsystem
      Stops all motion. Called at the end of every OpMode.
      Specified by:
      stop in interface Subsystem
    • isDone

      public boolean isDone()
      True when the servo should have arrived (an estimate: a servo cannot tell us where it is). We guess from the time since the move started and travelTime(double).
    • goToStep

      public AutoStep goToStep(String positionName)
      A step (autonomous): go to a named position and wait until it should have arrived.
    • getPosition

      public double getPosition()
      The raw position sent last (NaN before the first move).
    • getDegrees

      public double getDegrees()
      The angle sent last, in degrees (needs degrees(double, double, double, double); without it the number means nothing).
    • getTargetDegrees

      public double getTargetDegrees()
      The angle it is GOING to, in degrees (after the limits), or NaN before the first command. Differs from getDegrees() only during a slow move (maxSpeed).
    • getTargetName

      public String getTargetName()
      The named position it is at or going to, or "-" .
    • getServo

      public com.qualcomm.robotcore.hardware.Servo getServo()
      The FTC servo 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 target name; in debug mode also the raw position (and degrees, if set up).
      Specified by:
      addTelemetry in interface Subsystem