Class Elevator
java.lang.Object
yams.core.mechanisms.SmartMechanism
yams.core.mechanisms.positional.SmartPositionalMechanism
yams.core.mechanisms.positional.Elevator
yams.commands2.mechanisms.Elevator
- All Implemented Interfaces:
CommandMechanism
Command-based extension of
Elevator that adds the
Subsystem binding and Command/Trigger factories.
Usage Example
SmartMotorController motor = new TalonFXWrapper(
new TalonFX(4), DCMotor.getKrakenX60(1),
new SmartMotorControllerConfig(this).withClosedLoopController(0.5,0,0).withFeedforward(new
ElevatorFeedforward(0.4,0,0)); Elevator elevator = new Elevator( new
ElevatorConfig(motor).withDrumRadius(Inches.of(1.0)));
// Move to heights
Command toHigh = elevator.setHeight(Meters.of(1.2));
Command toLow = elevator.runTo(Meters.of(0.05), Meters.of(0.01));
// Trigger bindings
elevator.near(Meters.of(1.2), Meters.of(0.02)).onTrue(shooter.shoot());
elevator.max().onTrue(Commands.print("Elevator at max"));
// In periodic():
elevator.simIterate();
elevator.updateTelemetry();
-
Field Summary
Fields inherited from class SmartPositionalMechanism
m_mechanismLigament, m_mechanismRootFields inherited from class SmartMechanism
m_mechanismWindow, m_smc, m_telemetry -
Constructor Summary
ConstructorsConstructorDescriptionElevator(ElevatorConfig config, SmartMotorController smc) Construct theElevatorclass for easy manipulation of an elevator. -
Method Summary
Modifier and TypeMethodDescriptionorg.wpilib.command2.button.Triggerbetween(org.wpilib.units.measure.Distance start, org.wpilib.units.measure.Distance end) Between two heights.org.wpilib.command2.SubsystemSubsystem the mechanism's commands should require.org.wpilib.command2.button.Triggergte(org.wpilib.units.measure.Distance height) Greater than or equal to height.org.wpilib.command2.button.Triggerlte(org.wpilib.units.measure.Distance height) Less than or equal to heightorg.wpilib.command2.button.Triggermax()Elevatoris at max, defined by the soft limit or hard limit on the elevator.org.wpilib.command2.button.Triggermin()Minimum height of the elevator given by the soft limit or hard limit of the elevator.org.wpilib.command2.button.Triggernear(org.wpilib.units.measure.Distance height, org.wpilib.units.measure.Distance within) Elevator is near a height.org.wpilib.command2.CommandSet the height of the elevator.org.wpilib.command2.Commandrun(org.wpilib.units.measure.Distance height) Set the height of the elevator.org.wpilib.command2.CommandrunTo(Supplier<org.wpilib.units.measure.Distance> height, org.wpilib.units.measure.Distance tolerance) Run the elevator to the desired height with a tolerance, then move on.org.wpilib.command2.CommandrunTo(org.wpilib.units.measure.Distance height, org.wpilib.units.measure.Distance tolerance) Run the elevator to the desired height with a tolerance, then move on.org.wpilib.command2.CommandSet the height of the elevator.org.wpilib.command2.CommandsetHeight(org.wpilib.units.measure.Distance height) Set the height of the elevator.Methods inherited from class Elevator
getCascadePose3d, getConfig, getContinuousPose3d, getHeight, getName, getPose3d, getVelocity, isAtMax, isAtMin, isBetween, isGte, isLte, isNear, simIterate, updateTelemetry, visualizationUpdateMethods inherited from class SmartPositionalMechanism
getMechanismLigament, getMechanismRoot, getMotorMethods inherited from class SmartMechanism
getMeasurementSetpoint, getMechanismSetpoint, getMechanismWindow, getMotorController, publishMechanismWindow, setDutyCycleSetpoint, setMeasurementPositionSetpoint, setMeasurementVelocitySetpoint, setMechanismPositionSetpoint, setMechanismVelocitySetpoint, setVoltageSetpointMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface CommandMechanism
getMotorController, set, set, setVoltage, setVoltage
-
Constructor Details
-
Elevator
Construct theElevatorclass for easy manipulation of an elevator.- Parameters:
config-ElevatorConfigto set.smc-SmartMotorControllerto use for the Elevator- Throws:
ElevatorConfigurationException- if running in simulation and the carriage mass is not configured.ElevatorConfigurationException- if running in simulation and the minimum or maximum height is not configured.SmartMotorControllerConfigurationException- ifsmc's config does not have aSubsystemset viawithSubsystem(Subsystem).SmartMotorControllerConfigurationException- if running in simulation and the starting position is not configured.SmartMotorControllerConfigurationException- if running in simulation and the mechanism circumference is not configured.SmartMotorControllerConfigurationException- if running in simulation and the starting height is outside the hard limits.- Implementation Note:
smc's config must be aSmartMotorControllerConfigwith aSubsystemset viawithSubsystem(Subsystem).
-
-
Method Details
-
getSubsystem
public org.wpilib.command2.Subsystem getSubsystem()Description copied from interface:CommandMechanismSubsystem the mechanism's commands should require.- Specified by:
getSubsystemin interfaceCommandMechanism- Returns:
Subsystemfor the mechanism.
-
setHeight
public org.wpilib.command2.Command setHeight(org.wpilib.units.measure.Distance height) Set the height of the elevator.- Parameters:
height- Height of the elevator to reach.- Returns:
Commandthat sets the elevator height, stops immediately.
-
setHeight
Set the height of the elevator.- Parameters:
height- Height of the elevator to reach.- Returns:
Commandthat sets the elevator height, stops immediately.
-
run
public org.wpilib.command2.Command run(org.wpilib.units.measure.Distance height) Set the height of the elevator.- Parameters:
height- Height of the elevator to reach.- Returns:
Commandthat sets the elevator height, does not stop.
-
run
Set the height of the elevator.- Parameters:
height- Height of the elevator to reach.- Returns:
Commandthat sets the elevator height, stops immediately.
-
runTo
public org.wpilib.command2.Command runTo(org.wpilib.units.measure.Distance height, org.wpilib.units.measure.Distance tolerance) Run the elevator to the desired height with a tolerance, then move on.- Parameters:
height- Height to reach.tolerance- The acceptable tolerance- Returns:
Commandwhich will run the elevator to the desired height with a tolerance, then move on.- Implementation Note:
- This should NOT be used with a default command, the mechanism will not stop running after this to allow for easy chaining.
-
runTo
public org.wpilib.command2.Command runTo(Supplier<org.wpilib.units.measure.Distance> height, org.wpilib.units.measure.Distance tolerance) Run the elevator to the desired height with a tolerance, then move on.- Parameters:
height- Height to reach.tolerance- The acceptable tolerance- Returns:
Commandwhich will run the elevator to the desired height with a tolerance, then move on.- Implementation Note:
- This should NOT be used with a default command, the mechanism will not stop running after this to allow for easy chaining.
-
near
public org.wpilib.command2.button.Trigger near(org.wpilib.units.measure.Distance height, org.wpilib.units.measure.Distance within) Elevator is near a height.- Parameters:
height-Distanceto be near.within-Distancewithin.- Returns:
- Trigger on when the elevator is near another height.
-
max
public org.wpilib.command2.button.Trigger max()Elevatoris at max, defined by the soft limit or hard limit on the elevator.- Returns:
Triggeron maximum of the elevator.- Throws:
ElevatorConfigurationException- when the returned trigger is evaluated, if neither a motor controller upper soft limit nor an elevator maximum height is configured.
-
min
public org.wpilib.command2.button.Trigger min()Minimum height of the elevator given by the soft limit or hard limit of the elevator.- Returns:
Triggeron minimum of the elevator.- Throws:
ElevatorConfigurationException- when the returned trigger is evaluated, if neither a motor controller lower soft limit nor an elevator minimum height is configured.
-
between
public org.wpilib.command2.button.Trigger between(org.wpilib.units.measure.Distance start, org.wpilib.units.measure.Distance end) Between two heights.- Parameters:
start- Start height.end- End height.- Returns:
Trigger
-
lte
public org.wpilib.command2.button.Trigger lte(org.wpilib.units.measure.Distance height) Less than or equal to height- Parameters:
height-Distanceto check against- Returns:
Trigger
-
gte
public org.wpilib.command2.button.Trigger gte(org.wpilib.units.measure.Distance height) Greater than or equal to height.- Parameters:
height- Height to check against.- Returns:
Triggerfor elevator.
-