Class DifferentialMechanism
java.lang.Object
yams.core.mechanisms.SmartMechanism
yams.core.mechanisms.positional.SmartPositionalMechanism
yams.core.mechanisms.positional.DifferentialMechanism
yams.commands2.mechanisms.DifferentialMechanism
- All Implemented Interfaces:
CommandMechanism
Command-based extension of
DifferentialMechanism that
adds the Subsystem binding and Command/Trigger factories.
Usage Example
DifferentialMechanismConfig config = new DifferentialMechanismConfig(leftSMC, rightSMC)
.withStartingPosition(Degrees.of(30), Degrees.of(0)) // tilt=30°, twist=0°
.withLength(Inches.of(14))
.withMOI(Inches.of(14), Pounds.of(2))
.withTelemetry("DifferentialWrist", TelemetryVerbosity.HIGH);
DifferentialMechanism wrist = new DifferentialMechanism(config);
// Command: tilt to 60° and twist to 45°.
Command scoreCommand = wrist.setPosition(Degrees.of(60), Degrees.of(45));
// Command: continuously follow a joystick (suppliers).
Command manualCommand = wrist.run(
() -> Degrees.of(driverController.getLeftY() * 90),
() -> Degrees.of(driverController.getRightX() * 90));
-
Field Summary
Fields inherited from class SmartPositionalMechanism
m_mechanismLigament, m_mechanismRootFields inherited from class SmartMechanism
m_mechanismWindow, m_smc, m_telemetry -
Constructor Summary
ConstructorsConstructorDescriptionDifferentialMechanism(DifferentialMechanismConfig diffConfig) Constructor for the Differential mechanism. -
Method Summary
Modifier and TypeMethodDescriptionorg.wpilib.command2.SubsystemSubsystem the mechanism's commands should require.org.wpilib.command2.CommandRun the differential mechanism to a position.org.wpilib.command2.Commandrun(org.wpilib.units.measure.Angle tilt, org.wpilib.units.measure.Angle twist) Set the position of the differential mechanism.org.wpilib.command2.Commandset(double tilt, double twist) Set the dutycycle of the differential mechanism.org.wpilib.command2.CommandsetPosition(Supplier<org.wpilib.units.measure.Angle> tilt, Supplier<org.wpilib.units.measure.Angle> twist) Set the position of the differential mechanism using suppliers.org.wpilib.command2.CommandsetPosition(org.wpilib.units.measure.Angle tilt, org.wpilib.units.measure.Angle twist) Set the position of the differential mechanism.Methods inherited from class DifferentialMechanism
getDifferentialMechanismConfig, getLeftMotorController, getName, getPose3d, getRightMotorController, getTiltPosition, getTwistPosition, isAtMax, isAtMin, 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
-
DifferentialMechanism
Constructor for the Differential mechanism.- Parameters:
diffConfig- LowerDifferentialMechanismConfigto use.- Throws:
DifferentialMechanismConfigurationException- if the starting tilt or twist angle is not configured.DifferentialMechanismConfigurationException- if the length is not configured.DifferentialMechanismConfigurationException- if running in simulation and the MOI is not configured.DifferentialMechanismConfigurationException- if the left and right motor controllers' configs do not share the sameSubsystem.NoSuchElementException- if the left or rightSmartMotorControllerwas never set ondiffConfig.SmartMotorControllerConfigurationException- if either motor controller's config does not have aSubsystemset viawithSubsystem(Subsystem).- Implementation Note:
- Both motor controllers' configs must be
SmartMotorControllerConfigs that share the sameSubsystemset 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.
-
setPosition
public org.wpilib.command2.Command setPosition(Supplier<org.wpilib.units.measure.Angle> tilt, Supplier<org.wpilib.units.measure.Angle> twist) Set the position of the differential mechanism using suppliers.- Parameters:
tilt- Tilt of the Differential Mechanism.twist- Twist of the Differential Mechanism.- Returns:
Commandto set the position.
-
set
public org.wpilib.command2.Command set(double tilt, double twist) Set the dutycycle of the differential mechanism.- Parameters:
tilt- Tilt dutycycle.twist- Twist dutycycle.- Returns:
Commandto set the differential mechanism duty cycle.
-
setPosition
public org.wpilib.command2.Command setPosition(org.wpilib.units.measure.Angle tilt, org.wpilib.units.measure.Angle twist) Set the position of the differential mechanism.- Parameters:
tilt- Tilt of the differential mechanism.twist- Twist of the differential mechanism.- Returns:
Commandto set the position.
-
run
public org.wpilib.command2.Command run(org.wpilib.units.measure.Angle tilt, org.wpilib.units.measure.Angle twist) Set the position of the differential mechanism.- Parameters:
tilt- Tilt of the differential mechanism.twist- Twist of the differential mechanism.- Returns:
Commandto set the position.
-
run
public org.wpilib.command2.Command run(Supplier<org.wpilib.units.measure.Angle> tilt, Supplier<org.wpilib.units.measure.Angle> twist) Run the differential mechanism to a position.- Parameters:
tilt- Supplier of the tilt angle.twist- Supplier of the twist angle.- Returns:
Commandto run the differential mechanism to the position.
-