com.qualcomm.robotcore.hardware

## Interface Servo

- All Superinterfaces:
    HardwareDevice
  All Known Implementing Classes:
    ServoImpl, ServoImplEx

      public interface Servo
      extends HardwareDevice

  Instances of Servo interface provide access to servo hardware devices.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static class` | `Servo.Direction` Servos can be configured to internally reverse the values to which their positioning power is set.

    - ### Nested classes/interfaces inherited from interface com.qualcomm.robotcore.hardware.HardwareDevice

      `HardwareDevice.Manufacturer`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static double` | `MAX_POSITION` The maximum allowable position to which a servo can be moved
    `static double` | `MIN_POSITION` The minimum allowable position to which a servo can be moved

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `ServoController` | `getController()` Returns the underlying servo controller on which this servo is situated.
    `Servo.Direction` | `getDirection()` Returns the current logical direction in which this servo is set as operating.
    `int` | `getPortNumber()` Returns the port number on the underlying servo controller on which this motor is situated.
    `double` | `getPosition()` Returns the position to which the servo was last commanded to move.
    `void` | `scaleRange(double min, double max)` Scales the available movement range of the servo to be a subset of its maximum range.
    `void` | `setDirection(Servo.Direction direction)` Sets the logical direction in which this servo operates.
    `void` | `setPosition(double position)` Sets the current position of the servo, expressed as a fraction of its available range.

    - ### Methods inherited from interface com.qualcomm.robotcore.hardware.HardwareDevice

      `close, getConnectionInfo, getDeviceName, getManufacturer, getVersion, resetDeviceConfigurationForOpMode`

- - ### Field Detail

    - #### MIN_POSITION

          static final double MIN_POSITION

      The minimum allowable position to which a servo can be moved
      See Also:
        `setPosition(double)`, Constant Field Values

    - #### MAX_POSITION

          static final double MAX_POSITION

      The maximum allowable position to which a servo can be moved
      See Also:
        `setPosition(double)`, Constant Field Values

  - ### Method Detail

    - #### getController

          ServoController getController()

      Returns the underlying servo controller on which this servo is situated.
      Returns:
        the underlying servo controller on which this servo is situated.
      See Also:
        `getPortNumber()`

    - #### getPortNumber

          int getPortNumber()

      Returns the port number on the underlying servo controller on which this motor is situated.
      Returns:
        the port number on the underlying servo controller on which this motor is situated.
      See Also:
        `getController()`

    - #### setDirection

          void setDirection(Servo.Direction direction)

      Sets the logical direction in which this servo operates.
      Parameters:
        `direction` - the direction to set for this servo
      See Also:
        `getDirection()`, `Servo.Direction`

    - #### getDirection

          Servo.Direction getDirection()

      Returns the current logical direction in which this servo is set as operating.
      Returns:
        the current logical direction in which this servo is set as operating.
      See Also:
        `setDirection(Direction)`

    - #### setPosition

          void setPosition(double position)

      Sets the current position of the servo, expressed as a fraction of its available range. If PWM power is enabled for the servo, the servo will attempt to move to the indicated position.
      Parameters:
        `position` - the position to which the servo should move, a value in the range [0.0, 1.0]
      See Also:
        `ServoController.pwmEnable()`, `getPosition()`

    - #### getPosition

          double getPosition()

      Returns the position to which the servo was last commanded to move. Note that this method does NOT read a position from the servo through any electrical means, as no such electrical mechanism is, generally, available.
      Returns:
        the position to which the servo was last commanded to move, or Double.NaN if no such position is known
      See Also:
        `setPosition(double)`, `Double.NaN`, `Double.isNaN()`

    - #### scaleRange

          void scaleRange(double min,
                          double max)

      Scales the available movement range of the servo to be a subset of its maximum range. Subsequent positioning calls will operate within that subset range. This is useful if your servo has only a limited useful range of movement due to the physical hardware that it is manipulating (as is often the case) but you don't want to have to manually scale and adjust the input to `setPosition()` each time.

      For example, if scaleRange(0.2, 0.8) is set; then servo positions will be scaled to fit in that range:
      setPosition(0.0) scales to 0.2
      setPosition(1.0) scales to 0.8
      setPosition(0.5) scales to 0.5
      setPosition(0.25) scales to 0.35
      setPosition(0.75) scales to 0.65

      Note the parameters passed here are relative to the underlying full range of motion of the servo, not its currently scaled range, if any. Thus, scaleRange(0.0, 1.0) will reset the servo to its full range of movement.

      Parameters:
        `min` - the lower limit of the servo movement range, a value in the interval [0.0, 1.0]
        `max` - the upper limit of the servo movement range, a value in the interval [0.0, 1.0]
      See Also:
        `setPosition(double)`