Class Arm
java.lang.Object
yams.core.mechanisms.SmartMechanism
yams.core.mechanisms.positional.SmartPositionalMechanism
yams.core.mechanisms.positional.Arm
yams.commands2.mechanisms.Arm
- All Implemented Interfaces:
CommandMechanism
Command-based extension of
Arm that adds the
Subsystem binding and Command/Trigger factories.
Usage Example
// Build and construct
SmartMotorController motor = new SparkWrapper(
new SparkMax(1, MotorType.kBrushless), DCMotor.getNEO(1),
new
SmartMotorControllerConfig(this).withClosedLoopController(0.2,0,0).withStatorCurrentLimit(Amps.of(40)));
ArmConfig armConfig = new ArmConfig().withLength(Meters.of(0.5));
Arm arm = new Arm(armConfig, motor);
// Schedule a setpoint command
Command moveToScore = arm.setAngle(Degrees.of(80));
Command holdAtZero = arm.runTo(Degrees.of(0), Degrees.of(2));
// Bind triggers
arm.near(Degrees.of(80), Degrees.of(2)).onTrue(indexer.run());
arm.max().onTrue(Commands.print("Arm at max!"));
// Call in robotPeriodic() or a subsystem's periodic():
arm.simIterate();
arm.updateTelemetry();
-
Field Summary
Fields inherited from class SmartPositionalMechanism
m_mechanismLigament, m_mechanismRootFields inherited from class SmartMechanism
m_mechanismWindow, m_smc, m_telemetry -
Constructor Summary
ConstructorsConstructorDescriptionArm(ArmConfig config, SmartMotorController smc) Constructor for the Arm mechanism. -
Method Summary
Modifier and TypeMethodDescriptionorg.wpilib.command2.button.Triggerbetween(org.wpilib.units.measure.Angle start, org.wpilib.units.measure.Angle end) Between two angles.org.wpilib.command2.SubsystemSubsystem the mechanism's commands should require.org.wpilib.command2.button.Triggergte(org.wpilib.units.measure.Angle angle) Greater than or equal to angle.org.wpilib.command2.button.Triggerlte(org.wpilib.units.measure.Angle angle) Less than or equal to angleorg.wpilib.command2.button.Triggermax()Armis at max, defined by the soft limit or hard limit on the arm.org.wpilib.command2.button.Triggermin()Minimum angle of the arm given by the soft limit or hard limit of the arm.org.wpilib.command2.button.Triggernear(org.wpilib.units.measure.Angle angle, org.wpilib.units.measure.Angle within) Arm is near an angle.org.wpilib.command2.CommandSet the arm to the given angle via a supplier.org.wpilib.command2.Commandrun(org.wpilib.units.measure.Angle angle) Set the arm to the given angle.org.wpilib.command2.CommandSet the arm to the given angle then end the command.org.wpilib.command2.CommandrunTo(org.wpilib.units.measure.Angle angle, org.wpilib.units.measure.Angle tolerance) Set the arm to the given angle then end the command.org.wpilib.command2.CommandSet the arm to the given angle via a supplier.org.wpilib.command2.CommandsetAngle(org.wpilib.units.measure.Angle angle) Set the arm to the given angle.Methods inherited from class Arm
getAngle, getArmConfig, getName, getPose3d, 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
-
Arm
Constructor for the Arm mechanism.- Parameters:
config-ArmConfigto use.smc-SmartMotorControllerfor the Arm.- Throws:
ArmConfigurationException- if running in simulation and the arm length is not configured.ArmConfigurationException- if running in simulation and the lower or upper hard limit is not configured.ArmConfigurationException- if running in simulation and neither a starting position nor an external encoder zero offset is configured.ArmConfigurationException- if running in simulation and the starting position is outside the hard limits.SmartMotorControllerConfigurationException- ifsmc's config does not have aSubsystemset viawithSubsystem(Subsystem).- 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.
-
setAngle
public org.wpilib.command2.Command setAngle(org.wpilib.units.measure.Angle angle) Set the arm to the given angle.- Parameters:
angle- Arm angle to go to.- Returns:
Commandthat sets the arm to the desired angle.
-
setAngle
Set the arm to the given angle via a supplier.- Parameters:
angle- Supplier for the arm angle to go to.- Returns:
Commandthat sets the arm to the desired angle.
-
run
public org.wpilib.command2.Command run(org.wpilib.units.measure.Angle angle) Set the arm to the given angle.- Parameters:
angle- Arm angle to go to.- Returns:
Commandthat sets the arm to the desired angle.
-
run
Set the arm to the given angle via a supplier.- Parameters:
angle- Supplier for the arm angle to go to.- Returns:
Commandthat sets the arm to the desired angle.
-
runTo
public org.wpilib.command2.Command runTo(org.wpilib.units.measure.Angle angle, org.wpilib.units.measure.Angle tolerance) Set the arm to the given angle then end the command.- Parameters:
angle-Angleto go to.tolerance- ToleranceAngle- Returns:
Commandthat sets the arm to the desired angle.- Implementation Note:
- This command will not stop. It should NOT be used when there is a default command on the Subsystem.
-
runTo
public org.wpilib.command2.Command runTo(Supplier<org.wpilib.units.measure.Angle> angle, org.wpilib.units.measure.Angle tolerance) Set the arm to the given angle then end the command.- Parameters:
angle-Angleto go to.tolerance- ToleranceAngle- Returns:
Commandthat sets the arm to the desired angle.- Implementation Note:
- This command will stop, but the last control request to the motor controller will continue. It should NOT be used when there is a default command on the Subsystem.
-
near
public org.wpilib.command2.button.Trigger near(org.wpilib.units.measure.Angle angle, org.wpilib.units.measure.Angle within) Arm is near an angle.- Parameters:
angle-Angleto be near.within-Anglewithin.- Returns:
Triggeron when the arm is near another angle.
-
max
public org.wpilib.command2.button.Trigger max()Armis at max, defined by the soft limit or hard limit on the arm.- Returns:
Triggeron maximum of the arm.- Throws:
ArmConfigurationException- when the returned trigger is evaluated, if neither a motor controller upper soft limit nor an arm upper hard limit is configured.
-
min
public org.wpilib.command2.button.Trigger min()Minimum angle of the arm given by the soft limit or hard limit of the arm.- Returns:
Triggeron minimum of the arm.- Throws:
ArmConfigurationException- when the returned trigger is evaluated, if neither a motor controller lower soft limit nor an arm lower hard limit is configured.
-
between
public org.wpilib.command2.button.Trigger between(org.wpilib.units.measure.Angle start, org.wpilib.units.measure.Angle end) Between two angles.- Parameters:
start- Start angle.end- End angle- Returns:
Trigger
-
lte
public org.wpilib.command2.button.Trigger lte(org.wpilib.units.measure.Angle angle) Less than or equal to angle- Parameters:
angle-Angleto check against- Returns:
Trigger
-
gte
public org.wpilib.command2.button.Trigger gte(org.wpilib.units.measure.Angle angle) Greater than or equal to angle.- Parameters:
angle- Angle to check against.- Returns:
Triggerfor Arm.
-