Class ServoSubsystem

java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
lib.subsystems.motor.ServoSubsystem
All Implemented Interfaces:
edu.wpi.first.util.sendable.Sendable, edu.wpi.first.wpilibj2.command.Subsystem

public class ServoSubsystem extends edu.wpi.first.wpilibj2.command.SubsystemBase
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final double
     
    protected boolean
     
    protected double
     
    protected static final double
     
    protected static final double
     
    protected final edu.wpi.first.wpilibj.Servo[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ServoSubsystem(boolean inverted, edu.wpi.first.wpilibj.Servo... servos)
    A class that wraps around a variable number of Servo objects to give them Subsystem functionality.
    ServoSubsystem(edu.wpi.first.wpilibj.Servo... servos)
    A class that wraps around a variable number of Servo objects to give them Subsystem functionality.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static double
    angleToPosition(double degrees)
    Convert a degree to a servo set value.
    double
    Get the servo angle.
    boolean
    Get whether this entire servo is inverted.
    double
    Get the servo position.
    protected static double
    invertAngle(double degrees)
    Invert the given degree (MIN_ANGLE becomes MAX_ANGLE, MAX_ANGLE becomes MIN_ANGLE)
    protected static double
    invertPosition(double position)
    Invert the given value (0 becomes 1, 1 becomes 0)
    protected static double
    positionToAngle(double position)
    Convert a servo set value to degrees.
    void
    setAngle(double degrees)
    Set the servo angle.
    void
    setInverted(boolean inverted)
    Set whether this entire servo is inverted.
    void
    setPosition(double position)
    Set the servo position.

    Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase

    addChild, getName, getSubsystem, initSendable, setName, setSubsystem

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem

    defer, getCurrentCommand, getDefaultCommand, idle, periodic, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
  • Field Details

    • servos

      protected final edu.wpi.first.wpilibj.Servo[] servos
    • inverted

      protected boolean inverted
    • lastPosition

      protected double lastPosition
    • MIN_ANGLE

      protected static final double MIN_ANGLE
      See Also:
    • MAX_ANGLE

      protected static final double MAX_ANGLE
      See Also:
    • ANGLE_RANGE

      protected static final double ANGLE_RANGE
      See Also:
  • Constructor Details

    • ServoSubsystem

      public ServoSubsystem(boolean inverted, edu.wpi.first.wpilibj.Servo... servos)
      A class that wraps around a variable number of Servo objects to give them Subsystem functionality.
      Parameters:
      inverted - Inverts the direction of all of the Servos. This does not override the individual inversions of the servos.
      servos - The Servos in this subsystem. Can be a single Servo or multiple.
    • ServoSubsystem

      public ServoSubsystem(edu.wpi.first.wpilibj.Servo... servos)
      A class that wraps around a variable number of Servo objects to give them Subsystem functionality.
      Parameters:
      servos - The Servos in this subsystem. Can be a single Servo or multiple.
  • Method Details

    • getPosition

      public double getPosition()
      Get the servo position. Servo positions range from 0.0 to 1.0 corresponding to the range of full left to full right.
      Returns:
      Position from 0.0 to 1.0.
    • getAngle

      public double getAngle()
      Get the servo angle.
      Returns:
      The angle in degrees to which the servo is set.
    • setPosition

      public void setPosition(double position)
      Set the servo position. Servo positions range from 0.0 to 1.0 corresponding to the range of full left to full right.
      Parameters:
      position - Position from 0.0 to 1.0.
    • setAngle

      public void setAngle(double degrees)
      Set the servo angle.
    • getInverted

      public boolean getInverted()
      Get whether this entire servo is inverted.
      Returns:
      isInverted The state of inversion, true is inverted.
    • setInverted

      public void setInverted(boolean inverted)
      Set whether this entire servo is inverted. Note that this will also convert the values returned by getPosition() and getAngle() to the new coordinate system, so anything continuously reading these methods will see a discontinuity.
      Parameters:
      inverted - The desired state of inversion, true is inverted.
    • positionToAngle

      protected static double positionToAngle(double position)
      Convert a servo set value to degrees.
      Parameters:
      position - servo set value to convert to degrees. Should be in the range [0, 1].
      Returns:
      the value converted to degrees
    • angleToPosition

      protected static double angleToPosition(double degrees)
      Convert a degree to a servo set value.
      Parameters:
      degrees - the servo degree to convert to a servo set
      Returns:
      a servo set value in the range [0, 1] (as long as the input degree was in the servo's range)
    • invertPosition

      protected static double invertPosition(double position)
      Invert the given value (0 becomes 1, 1 becomes 0)
      Parameters:
      position - The value to invert. Should be in the range [0, 1]
      Returns:
      the inverted value
    • invertAngle

      protected static double invertAngle(double degrees)
      Invert the given degree (MIN_ANGLE becomes MAX_ANGLE, MAX_ANGLE becomes MIN_ANGLE)
      Parameters:
      degrees - The degree to invert
      Returns:
      the inverted degree