Package lib.subsystems.motor
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
FieldsModifier and TypeFieldDescriptionprotected static final doubleprotected booleanprotected doubleprotected static final doubleprotected static final doubleprotected final edu.wpi.first.wpilibj.Servo[] -
Constructor Summary
ConstructorsConstructorDescriptionServoSubsystem(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 TypeMethodDescriptionprotected static doubleangleToPosition(double degrees) Convert a degree to a servo set value.doublegetAngle()Get the servo angle.booleanGet whether this entire servo is inverted.doubleGet the servo position.protected static doubleinvertAngle(double degrees) protected static doubleinvertPosition(double position) Invert the given value (0 becomes 1, 1 becomes 0)protected static doublepositionToAngle(double position) Convert a servo set value to degrees.voidsetAngle(double degrees) Set the servo angle.voidsetInverted(boolean inverted) Set whether this entire servo is inverted.voidsetPosition(double position) Set the servo position.Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 bygetPosition()andgetAngle()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) - Parameters:
degrees- The degree to invert- Returns:
- the inverted degree
-