Class ServoSetup

java.lang.Object
com.crossbotics.ftchelper.hardware.ServoSetup

public final class ServoSetup extends Object
Sets up a servo in one readable chain.

A servo is a small motor that turns to a position you choose (0 to 1) and holds it there.


 Servo claw = ServoSetup.get(hardwareMap, "claw")
         .reversed()
         .range(0.20, 0.75)   // 0 now means 0.20 and 1 means 0.75
         .done();
 

This does NOT move the servo. A servo moves the first time you set a position.

How far 0 to 1 turns it. The hub tells a servo where to go with a pulse: 600 microseconds (us) for position 0 and 2400 us for 1 (the FTC SDK's normal range). Most FTC servos can take 500 to 2500 us, so the normal range leaves a little of their turn unused: a goBILDA 2000 servo (300 degrees over 500-2500 us) turns 270 degrees over 0 to 1. fullRange() widens the pulse to 500-2500 us, so 0 to 1 turns it all 300 degrees. Docs: docs/modules/hardware.md#full-range.

Each step hands back the same ServoSetup (return this) so the next step can follow. Tutorial 02 (docs/tutorials/02-motors-and-servos.md) shows servos in a full program. Docs: docs/modules/hardware.md

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    The pulse for position 1 with fullRange().
    static final double
    The pulse for position 0 with fullRange(): what goBILDA, REV and Axon servos accept.
    static final double
    The FTC SDK's normal pulse for position 1, microseconds (PwmControl.PwmRange.usPulseUpperDefault).
    static final double
    The FTC SDK's normal pulse for position 0, microseconds (PwmControl.PwmRange.usPulseLowerDefault).
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    checkPulse(double lowUs, double highUs)
    Checks a pulse range: 100 to 3000 microseconds, low below high.
    com.qualcomm.robotcore.hardware.Servo
    Gives you the servo.
    Uses the servo's whole turn: positions 0 to 1 send 500 to 2500 microseconds instead of the SDK's normal 600 to 2400.
    static ServoSetup
    get(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
    Starts the setup for a servo in the configuration.
    static ServoSetup
    of(com.qualcomm.robotcore.hardware.Servo servo)
    Starts the setup for a servo you already have.
    pulseRange(double lowUs, double highUs)
    Sets the pulse the hub sends for positions 0 and 1 (see fullRange() for the usual one).
    range(double min, double max)
    Limits the servo to part of its travel.
    Position 0 and 1 swap ends.
    static boolean
    setPulseRange(com.qualcomm.robotcore.hardware.Servo servo, double lowUs, double highUs)
    Sets a servo's pulse range if it can (a servo on a REV Control or Expansion Hub, or a Servo Hub, can: it is a PwmControl).

    Methods inherited from class java.lang.Object

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

    • SDK_PULSE_LOW_US

      public static final double SDK_PULSE_LOW_US
      The FTC SDK's normal pulse for position 0, microseconds (PwmControl.PwmRange.usPulseLowerDefault).
      See Also:
    • SDK_PULSE_HIGH_US

      public static final double SDK_PULSE_HIGH_US
      The FTC SDK's normal pulse for position 1, microseconds (PwmControl.PwmRange.usPulseUpperDefault).
      See Also:
    • FULL_PULSE_LOW_US

      public static final double FULL_PULSE_LOW_US
      The pulse for position 0 with fullRange(): what goBILDA, REV and Axon servos accept.
      See Also:
    • FULL_PULSE_HIGH_US

      public static final double FULL_PULSE_HIGH_US
      The pulse for position 1 with fullRange().
      See Also:
  • Method Details

    • get

      public static ServoSetup get(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
      Starts the setup for a servo in the configuration.
      Parameters:
      hardwareMap - the OpMode's hardwareMap
      name - the servo's configuration name
      Returns:
      the start of the chain
      Throws:
      IllegalArgumentException - with the list of real servo names if the name is wrong
    • of

      public static ServoSetup of(com.qualcomm.robotcore.hardware.Servo servo)
      Starts the setup for a servo you already have.
      Parameters:
      servo - the servo to set up
      Returns:
      the start of the chain
    • reversed

      public ServoSetup reversed()
      Position 0 and 1 swap ends. Use when a servo is mounted mirrored.
    • range

      public ServoSetup range(double min, double max)
      Limits the servo to part of its travel. After this, position 0 means min and position 1 means max. Use it so code can never drive the servo into the frame.
      Parameters:
      min - 0 to 1, the real position used for 0
      max - 0 to 1, the real position used for 1 (must be bigger than min)
    • fullRange

      public ServoSetup fullRange()
      Uses the servo's whole turn: positions 0 to 1 send 500 to 2500 microseconds instead of the SDK's normal 600 to 2400. A goBILDA 2000 servo then turns 300 degrees over 0 to 1 instead of 270. Do it BEFORE you measure positions (the Servo Finder has the same switch): the same position number points somewhere else after the change. A servo that cannot change its pulse (not on a REV hub) keeps the normal range: check setPulseRange(com.qualcomm.robotcore.hardware.Servo, double, double)'s answer if you need to know.
      
       Servo wrist = ServoSetup.get(hardwareMap, "wrist").fullRange().done();
       
      Returns:
      this setup, for the next step
    • pulseRange

      public ServoSetup pulseRange(double lowUs, double highUs)
      Sets the pulse the hub sends for positions 0 and 1 (see fullRange() for the usual one).
      Parameters:
      lowUs - microseconds for position 0, e.g. 500 (100 to 3000)
      highUs - microseconds for position 1, e.g. 2500 (more than lowUs, at most 3000)
      Returns:
      this setup, for the next step
      Throws:
      IllegalArgumentException - for numbers outside those ranges
    • setPulseRange

      public static boolean setPulseRange(com.qualcomm.robotcore.hardware.Servo servo, double lowUs, double highUs)
      Sets a servo's pulse range if it can (a servo on a REV Control or Expansion Hub, or a Servo Hub, can: it is a PwmControl). Does not move it.
      Parameters:
      servo - the servo
      lowUs - microseconds for position 0 (100 to 3000)
      highUs - microseconds for position 1 (more than lowUs, at most 3000)
      Returns:
      true if it was set; false if this servo cannot change its pulse (it keeps its range)
      Throws:
      IllegalArgumentException - for numbers outside those ranges
    • checkPulse

      public static void checkPulse(double lowUs, double highUs)
      Checks a pulse range: 100 to 3000 microseconds, low below high.
      Parameters:
      lowUs - microseconds for position 0
      highUs - microseconds for position 1
      Throws:
      IllegalArgumentException - when they are not
    • done

      public com.qualcomm.robotcore.hardware.Servo done()
      Gives you the servo. Always end the chain with this.
      Returns:
      the servo, set up (it has not moved yet)