Class DifferentialMechanism
java.lang.Object
yams.core.mechanisms.SmartMechanism
yams.core.mechanisms.positional.SmartPositionalMechanism
yams.core.mechanisms.positional.DifferentialMechanism
- Direct Known Subclasses:
DifferentialMechanism, DifferentialMechanism
A differential mechanism for FRC robots driven by two coordinated motors whose combined motion
produces two distinct and independent outputs.
In a differential drive mechanism the two motors do not independently move two separate joints. Instead, their outputs are mixed mathematically:
- Tilt: controlled by the sum of the left and right motor positions
(
(left + right) / 2). When both motors turn in the same direction the mechanism tilts up or down. - Twist: controlled by the difference of the left and right motor
positions (
(left - right) / 2). When the motors turn in opposite directions the mechanism rotates about its longitudinal axis.
A common FRC use-case is a differential wrist at the end of an arm where one motor controls pitch while the other controls roll, allowing the intake or end-effector to be positioned in two degrees of freedom with fewer motors than a traditional two-joint wrist.
This core class holds mechanism state, physics simulation, and measurement logic only.
Command factories live on DifferentialMechanism, which
extends this class and has a full usage example in its Javadoc.
-
Field Summary
Fields inherited from class SmartPositionalMechanism
m_mechanismLigament, m_mechanismRootFields inherited from class SmartMechanism
m_mechanismWindow, m_smc, m_telemetry -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDifferentialMechanism(DifferentialMechanismConfig diffConfig) Constructor for the Differential mechanism. -
Method Summary
Modifier and TypeMethodDescriptionGet theDifferentialMechanismConfigfor this mechanism.Get the leftSmartMotorControllerof the mechanism.getName()Get the name of the mechanism.org.wpilib.math.geometry.Pose3dGet the mechanism's pose, for publishing to AdvantageScope as a component of a robot model: where it is mounted, as set in itsMechanismPositionConfig, tilted about the axis normal to its movement plane, then twisted about its own length.Get the rightSmartMotorControllerof the mechanism.org.wpilib.units.measure.AngleGet the tiltAngleof the mechanism.org.wpilib.units.measure.AngleGet the twistAngleof the mechanism.booleanisAtMax()Not supported forDifferentialMechanism.booleanisAtMin()Not supported forDifferentialMechanism.voidIterate simvoidUpdate the mechanism's telemetry.voidUpdates the mechanism ligament with the current angle of the Differential Mechanism.Methods inherited from class SmartPositionalMechanism
getMechanismLigament, getMechanismRoot, getMotorMethods inherited from class SmartMechanism
getMeasurementSetpoint, getMechanismSetpoint, getMechanismWindow, getMotorController, publishMechanismWindow, setDutyCycleSetpoint, setMeasurementPositionSetpoint, setMeasurementVelocitySetpoint, setMechanismPositionSetpoint, setMechanismVelocitySetpoint, setVoltageSetpoint
-
Constructor Details
-
DifferentialMechanism
Constructor for the Differential mechanism.- Parameters:
diffConfig- LowerDifferentialMechanismConfigto use.- Throws:
NoSuchElementException- if the left or rightSmartMotorControllerwas not set on theDifferentialMechanismConfig.DifferentialMechanismConfigurationException- if the starting tilt or twist angle is not set.DifferentialMechanismConfigurationException- if the length is not set.DifferentialMechanismConfigurationException- if running in simulation and the MOI is not set.- Implementation Note:
- Protected so only
DifferentialMechanismcan construct this.
-
-
Method Details
-
getLeftMotorController
Get the leftSmartMotorControllerof the mechanism.- Returns:
- Left
SmartMotorController.
-
getRightMotorController
Get the rightSmartMotorControllerof the mechanism.- Returns:
- Right
SmartMotorController.
-
getTwistPosition
public org.wpilib.units.measure.Angle getTwistPosition()Get the twistAngleof the mechanism.- Returns:
- Twist
Angle.
-
getTiltPosition
public org.wpilib.units.measure.Angle getTiltPosition()Get the tiltAngleof the mechanism.- Returns:
- Tilt
Angle.
-
getDifferentialMechanismConfig
Get theDifferentialMechanismConfigfor this mechanism.- Returns:
DifferentialMechanismConfigfor this mechanism.
-
updateTelemetry
public void updateTelemetry()Description copied from class:SmartMechanismUpdate the mechanism's telemetry.- Specified by:
updateTelemetryin classSmartMechanism
-
simIterate
public void simIterate()Description copied from class:SmartMechanismIterate sim- Specified by:
simIteratein classSmartMechanism
-
visualizationUpdate
public void visualizationUpdate()Updates the mechanism ligament with the current angle of the Differential Mechanism.- Specified by:
visualizationUpdatein classSmartMechanism- See Also:
-
getPose3d
public org.wpilib.math.geometry.Pose3d getPose3d()Get the mechanism's pose, for publishing to AdvantageScope as a component of a robot model: where it is mounted, as set in itsMechanismPositionConfig, tilted about the axis normal to its movement plane, then twisted about its own length.- Specified by:
getPose3din classSmartMechanism- Returns:
- The mechanism's
Pose3d, relative to the robot.
-
getName
Description copied from class:SmartMechanismGet the name of the mechanism.- Specified by:
getNamein classSmartMechanism- Returns:
Stringname.
-
isAtMax
public boolean isAtMax()Not supported forDifferentialMechanism.- Specified by:
isAtMaxin classSmartPositionalMechanism- Returns:
- Never returns.
- Throws:
RuntimeException- always, since max limits are not supported for this mechanism.
-
isAtMin
public boolean isAtMin()Not supported forDifferentialMechanism.- Specified by:
isAtMinin classSmartPositionalMechanism- Returns:
- Never returns.
- Throws:
RuntimeException- always, since min limits are not supported for this mechanism.
-