Class SmartPositionalMechanism
- Direct Known Subclasses:
Arm, DifferentialMechanism, DoubleJointedArm, Elevator, Pivot
SmartPositionalMechanism sits between SmartMechanism and the
concrete positional mechanism implementations such as
Arm,
Elevator, Pivot,
and
DifferentialMechanism. It provides the shared
infrastructure required for closed-loop position control:
- Setpoint management via
SmartMechanism.setMechanismPositionSetpoint(Angle)andSmartMechanism.setMeasurementPositionSetpoint(Distance) - Position-based
Triggerfactories (near(),gte(),lte(),between(),max(),min()) defined by each concrete subclass - Command factories such as
setAngle()andsetHeight()defined by each concrete subclass, which internally callSmartMechanism.setMechanismPositionSetpoint(Angle)orSmartMechanism.setMeasurementPositionSetpoint(Distance) - A 2D visualization model via
MechanismRoot2dandMechanismLigament2dfields that subclasses populate and update
Concrete mechanisms extend this class and supply the physics-specific details: how to read the current position, how to drive the simulation model, and how to update visualization and telemetry. The setpoint infrastructure and WPILib subsystem integration live here so that all positional mechanisms share a consistent, command-based API without code duplication.
Conceptual subclass pattern: A concrete positional mechanism extends
SmartPositionalMechanism, provides a typed command factory, and calls into the
base-class setpoint methods:
// A concrete mechanism delegates setpoint management to this base class:
public Command setAngle(Angle target) {
return Commands.startRun(
() -> setMechanismPositionSetpoint(target),
() -> {},
m_subsystem
).withName(getName() + " SetAngle");
}
For Subclass Authors
Every concrete subclass of SmartPositionalMechanism must implement the following
abstract methods inherited from SmartMechanism:
SmartMechanism.getPose3d()returns the mechanism's pose relative to the robot, for an AdvantageScope robot modelSmartMechanism.visualizationUpdate()updatesm_mechanismLigament(and any setpoint ligament) to reflect the current stateSmartMechanism.getName()returns a human-readable mechanism name used for telemetry and command namesSmartMechanism.simIterate()advances the physics simulation model and writes back simulated encoder values each robot loopSmartMechanism.updateTelemetry()publishes mechanism state to NetworkTables or an equivalent telemetry sinkisAtMax()true when the mechanism reaches its configured maximum limitisAtMin()true when the mechanism reaches its configured minimum limit
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.wpilib.smartdashboard.MechanismLigament2dThe ligament that is being moved.protected org.wpilib.smartdashboard.MechanismRoot2dThe root point of the Mechanism.Fields inherited from class SmartMechanism
m_mechanismWindow, m_smc, m_telemetry -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate the positional mechanism, subclasses set up the motor and telemetry. -
Method Summary
Modifier and TypeMethodDescriptionorg.wpilib.smartdashboard.MechanismLigament2dGet the ligament of the 2D mechanism model.org.wpilib.smartdashboard.MechanismRoot2dThe root of the 2D mechanism model.getMotor()Get the motor controller which is moving the mechanism.abstract booleanisAtMax()SmartPositionalMechanismis at max, defined by the soft limit or hard limit on theSmartPositionalMechanism.abstract booleanisAtMin()Minimum angle of theSmartPositionalMechanismgiven by the soft limit or hard limit of theSmartPositionalMechanism.Methods inherited from class SmartMechanism
getMeasurementSetpoint, getMechanismSetpoint, getMechanismWindow, getMotorController, getName, getPose3d, publishMechanismWindow, setDutyCycleSetpoint, setMeasurementPositionSetpoint, setMeasurementVelocitySetpoint, setMechanismPositionSetpoint, setMechanismVelocitySetpoint, setVoltageSetpoint, simIterate, updateTelemetry, visualizationUpdate
-
Field Details
-
m_mechanismRoot
protected org.wpilib.smartdashboard.MechanismRoot2d m_mechanismRootThe root point of the Mechanism. -
m_mechanismLigament
protected org.wpilib.smartdashboard.MechanismLigament2d m_mechanismLigamentThe ligament that is being moved.
-
-
Constructor Details
-
SmartPositionalMechanism
protected SmartPositionalMechanism()Create the positional mechanism, subclasses set up the motor and telemetry.
-
-
Method Details
-
isAtMax
public abstract boolean isAtMax()SmartPositionalMechanismis at max, defined by the soft limit or hard limit on theSmartPositionalMechanism.- Returns:
- True if the mechanism is at its configured maximum.
-
isAtMin
public abstract boolean isAtMin()Minimum angle of theSmartPositionalMechanismgiven by the soft limit or hard limit of theSmartPositionalMechanism.- Returns:
- True if the mechanism is at its configured minimum.
-
getMechanismLigament
public org.wpilib.smartdashboard.MechanismLigament2d getMechanismLigament()Get the ligament of the 2D mechanism model. Used to change the position of the mechanism model in the SmartDashboard.- Returns:
- Ligament of the 2D mechanism model.
-
getMechanismRoot
public org.wpilib.smartdashboard.MechanismRoot2d getMechanismRoot()The root of the 2D mechanism model.- Returns:
- Root of the 2D mechanism model.
-
getMotor
Get the motor controller which is moving the mechanism.- Returns:
- Motor controller which is moving the mechanism.
-