Class DifferentialMechanismConfig
java.lang.Object
yams.core.mechanisms.config.DifferentialMechanismConfig
Configuration for a
DifferentialMechanism driven by two coordinated motors working
differentially. In a differential mechanism the sum and difference of the two motor outputs
independently control two separate degrees of freedom commonly referred to as tilt
(the average of both motors) and twist (half the difference between the two motors).
This class is a builder that collects every setting needed before the mechanism is
constructed. All with*() methods return this so calls can be chained.
Builder Example
// leftSMC / rightSMC are SmartMotorController instances already configured
// with gearing from the motor to the differential bevel gears.
DifferentialMechanismConfig config = new DifferentialMechanismConfig(leftSMC, rightSMC)
.withStartingPosition(Degrees.of(45), Degrees.of(0)) // tilt=45°, twist=0°
.withLength(Inches.of(18))
.withMOI(Inches.of(18), Pounds.of(3))
.withTelemetry("DifferentialWrist", TelemetryVerbosity.HIGH)
.withSimColor(new Color8Bit(Color.ORANGE));
DifferentialMechanism wrist = new DifferentialMechanism(config);
-
Constructor Summary
ConstructorsConstructorDescriptionDifferential Mechanism configuration class.Differential Mechanism configuration class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanApply config changes from this class to theSmartMotorControllerclone()org.wpilib.units.measure.AnglegetLeftMechanismPosition(org.wpilib.units.measure.Angle tilt, org.wpilib.units.measure.Angle twist) The leftSmartMotorControllermechanism position.Get the leftSmartMotorControllerof theDifferentialMechanismOptional<org.wpilib.units.measure.Distance> Get the length of theDifferentialMechanismGet theMechanismPositionConfigassociated with thisDifferentialMechanismConfig.doublegetMOI()Get the moment of inertia for theDifferentialMechanismsimulation.org.wpilib.units.measure.AnglegetRightMechanismPosition(org.wpilib.units.measure.Angle tilt, org.wpilib.units.measure.Angle twist) The rightSmartMotorControllermechanism position.Get the rightSmartMotorControllerof theDifferentialMechanismorg.wpilib.util.Color8BitSim color valueOptional<org.wpilib.units.measure.Angle> Get starting tiltAngle.Optional<org.wpilib.units.measure.Angle> Get starting twistAngle.Network Tables name for thePivotGet the telemetry verbosity of thePivotorg.wpilib.units.measure.AnglegetTiltAngle(org.wpilib.units.measure.Angle leftMechPos, org.wpilib.units.measure.Angle rightMechPos) Get the tilt angle of theDifferentialMechanism.Get the angle supplier for the attached absolute encoder, if it exists.Optional<org.wpilib.units.measure.Angle> Get the starting angle of theDifferentialMechanismtilt.org.wpilib.units.measure.AnglegetTwistAngle(org.wpilib.units.measure.Angle leftMechPos, org.wpilib.units.measure.Angle rightMechPos) Get the twist angle of theDifferentialMechanismwith any additional twist gearing.Get the angle supplier for the attached absolute encoder, if it exists.The gearing for the twist in theDifferentialMechanismOptional<org.wpilib.units.measure.Angle> Get the starting angle of theDifferentialMechanismtwist.withAngleSuppliers(Supplier<org.wpilib.units.measure.Angle> twistSupplier, Supplier<org.wpilib.units.measure.Angle> tiltSupplier) Setup suppliers for absolute encoders on theDifferentialMechanismwithGearing(MechanismGearing gearing) Set the gearing for the differential mechanism if it isn't 1:1.withLength(org.wpilib.units.measure.Distance length) Set the length of theDifferentialMechanism.withMechanismPositionConfig(MechanismPositionConfig mechanismPositionConfig) Set the differential mechanism position configuration.withMOI(org.wpilib.units.measure.Distance length, org.wpilib.units.measure.Mass weight) Configure the MOI directly instead of estimating it with the length and mass of theDifferentialMechanismfor simulation.withMOI(org.wpilib.units.measure.MomentOfInertia MOI) Configure the MOI directly instead of estimating it with the length and mass of theDifferentialMechanismfor simulation.withSimColor(org.wpilib.util.Color8Bit simColor) Publish the color in sim as this.Add the smart motor controllers to the configuration.withStartingPosition(org.wpilib.units.measure.Angle tilt, org.wpilib.units.measure.Angle twist) Set theDifferentialMechanismstarting positions.withTelemetry(String telemetryName, TelemetryVerbosity telemetryVerbosity) Configure telemetry for thePivotmechanism.withTiltStartingPosition(org.wpilib.units.measure.Angle startingPosition) Set theDifferentialMechanismtilt starting position.withTwistStartingPosition(org.wpilib.units.measure.Angle startingPosition) Set theDifferentialMechanismtwist starting position.
-
Constructor Details
-
DifferentialMechanismConfig
Differential Mechanism configuration class.- Parameters:
left- LeftSmartMotorControllerconfigured with the gearing up to the tilt movement if synchronized.right- RightSmartMotorControllerconfigured with the gearing up to the tilt movement if synchronized.
-
DifferentialMechanismConfig
public DifferentialMechanismConfig()Differential Mechanism configuration class. Required call towithSmartMotorControllers(SmartMotorController, SmartMotorController)before usage.
-
-
Method Details
-
clone
-
withSmartMotorControllers
public DifferentialMechanismConfig withSmartMotorControllers(SmartMotorController left, SmartMotorController right) Add the smart motor controllers to the configuration.- Parameters:
left- LeftSmartMotorControllerright- RightSmartMotorController- Returns:
DifferentialMechanismConfigfor chaining.- Throws:
DifferentialMechanismConfigurationException- if the left or rightSmartMotorControlleris already defined, e.g. through the constructor.
-
getTwistAngle
public org.wpilib.units.measure.Angle getTwistAngle(org.wpilib.units.measure.Angle leftMechPos, org.wpilib.units.measure.Angle rightMechPos) Get the twist angle of theDifferentialMechanismwith any additional twist gearing.- Parameters:
leftMechPos- LeftSmartMotorControllerMechanism PositionrightMechPos- RightSmartMotorControllerMechanism Position- Returns:
- Twist
Angle
-
getTiltAngle
public org.wpilib.units.measure.Angle getTiltAngle(org.wpilib.units.measure.Angle leftMechPos, org.wpilib.units.measure.Angle rightMechPos) Get the tilt angle of theDifferentialMechanism.- Parameters:
leftMechPos- LeftSmartMotorControllerMechanism PositionrightMechPos- RightSmartMotorControllerMechanism Position- Returns:
- Tilt
Angle
-
getLeftMechanismPosition
public org.wpilib.units.measure.Angle getLeftMechanismPosition(org.wpilib.units.measure.Angle tilt, org.wpilib.units.measure.Angle twist) The leftSmartMotorControllermechanism position.- Parameters:
tilt-Angleof the Tilt.twist-Angleof the twist.- Returns:
- Left mechanism position
Angle
-
getRightMechanismPosition
public org.wpilib.units.measure.Angle getRightMechanismPosition(org.wpilib.units.measure.Angle tilt, org.wpilib.units.measure.Angle twist) The rightSmartMotorControllermechanism position.- Parameters:
tilt-Angleof the Tilt.twist-Angleof the Twist.- Returns:
- Right mechanism position
Angle
-
withSimColor
Publish the color in sim as this.- Parameters:
simColor-Color8Bitto show.- Returns:
DifferentialMechanismConfigfor chaining.
-
withMOI
Configure the MOI directly instead of estimating it with the length and mass of theDifferentialMechanismfor simulation.- Parameters:
MOI- Moment of Inertia of theDifferentialMechanism- Returns:
DifferentialMechanismConfigfor chaining.
-
withLength
Set the length of theDifferentialMechanism.- Parameters:
length- Length of theDifferentialMechanism- Returns:
DifferentialMechanismConfigfor chaining.
-
withMOI
public DifferentialMechanismConfig withMOI(org.wpilib.units.measure.Distance length, org.wpilib.units.measure.Mass weight) Configure the MOI directly instead of estimating it with the length and mass of theDifferentialMechanismfor simulation.- Parameters:
length- Length of theDifferentialMechanism.weight- Weight of theDifferentialMechanism- Returns:
DifferentialMechanismConfigfor chaining.
-
withTelemetry
public DifferentialMechanismConfig withTelemetry(String telemetryName, TelemetryVerbosity telemetryVerbosity) Configure telemetry for thePivotmechanism.- Parameters:
telemetryName- Telemetry NetworkTable name to appear under "SmartDashboard/"telemetryVerbosity- Telemetry verbosity to apply.- Returns:
DifferentialMechanismConfigfor chaining.
-
withMechanismPositionConfig
public DifferentialMechanismConfig withMechanismPositionConfig(MechanismPositionConfig mechanismPositionConfig) Set the differential mechanism position configuration.- Parameters:
mechanismPositionConfig-MechanismPositionConfigfor theDifferentialMechanism- Returns:
DifferentialMechanismConfigfor chaining
-
withGearing
Set the gearing for the differential mechanism if it isn't 1:1. Separate from gearing to the bevel gears.- Parameters:
gearing- Gearing for the bevel gears.- Returns:
DifferentialMechanismConfigfor chaining
-
withTwistStartingPosition
public DifferentialMechanismConfig withTwistStartingPosition(org.wpilib.units.measure.Angle startingPosition) Set theDifferentialMechanismtwist starting position.- Parameters:
startingPosition- Starting position of theDifferentialMechanismtwist.- Returns:
DifferentialMechanismConfigfor chaining
-
withAngleSuppliers
public DifferentialMechanismConfig withAngleSuppliers(Supplier<org.wpilib.units.measure.Angle> twistSupplier, Supplier<org.wpilib.units.measure.Angle> tiltSupplier) Setup suppliers for absolute encoders on theDifferentialMechanism- Parameters:
twistSupplier-Supplier<org.wpilib.units.measure.Angle>for the twist.tiltSupplier-Supplier<org.wpilib.units.measure.Angle>for the tilt.- Returns:
DifferentialMechanismConfigfor chaining.
-
withStartingPosition
public DifferentialMechanismConfig withStartingPosition(org.wpilib.units.measure.Angle tilt, org.wpilib.units.measure.Angle twist) Set theDifferentialMechanismstarting positions.- Parameters:
tilt-Angleof the tilt.twist-Angleof the twist.- Returns:
DifferentialMechanismConfigfor chaining.
-
withTiltStartingPosition
public DifferentialMechanismConfig withTiltStartingPosition(org.wpilib.units.measure.Angle startingPosition) Set theDifferentialMechanismtilt starting position.- Parameters:
startingPosition- Starting position of theDifferentialMechanismtilt.- Returns:
DifferentialMechanismConfigfor chaining
-
applyConfig
public boolean applyConfig()Apply config changes from this class to theSmartMotorController- Returns:
SmartMotorController.applyConfig(SmartMotorControllerConfig)result.- Throws:
NoSuchElementException- if the left or rightSmartMotorControllerwas never set through the constructor orwithSmartMotorControllers(SmartMotorController, SmartMotorController).
-
getMOI
public double getMOI()Get the moment of inertia for theDifferentialMechanismsimulation.- Returns:
- Moment of Inertia.
- Throws:
DifferentialMechanismConfigurationException- if the MOI was not set withwithMOI(MomentOfInertia)orwithMOI(Distance, Mass).
-
getTelemetryVerbosity
Get the telemetry verbosity of thePivot- Returns:
TelemetryVerbosityof thePivot
-
getTelemetryName
-
getTiltStartingAngle
Get the starting angle of theDifferentialMechanismtilt.- Returns:
Angleof theDifferentialMechanismtilt.
-
getStartingTiltAngle
Get starting tiltAngle.- Returns:
- Tilt
Angle.
-
getStartingTwistAngle
Get starting twistAngle.- Returns:
- Twist
Angle.
-
getTwistStartingAngle
Get the starting angle of theDifferentialMechanismtwist.- Returns:
Angleof theDifferentialMechanismtwist.
-
getTwistAngleSupplier
-
getLength
Get the length of theDifferentialMechanism- Returns:
DistanceofDifferentialMechanism
-
getTwistGearing
The gearing for the twist in theDifferentialMechanism- Returns:
MechanismGearingof the twist.
-
getTiltAngleSupplier
-
getLeftMotorController
Get the leftSmartMotorControllerof theDifferentialMechanism- Returns:
- left
SmartMotorController - Throws:
NoSuchElementException- if the leftSmartMotorControllerwas never set through the constructor orwithSmartMotorControllers(SmartMotorController, SmartMotorController).
-
getRightMotorController
Get the rightSmartMotorControllerof theDifferentialMechanism- Returns:
- right
SmartMotorController - Throws:
NoSuchElementException- if the rightSmartMotorControllerwas never set through the constructor orwithSmartMotorControllers(SmartMotorController, SmartMotorController).
-
getSimColor
public org.wpilib.util.Color8Bit getSimColor()Sim color value- Returns:
- Sim color value
-
getMechanismPositionConfig
Get theMechanismPositionConfigassociated with thisDifferentialMechanismConfig.- Returns:
- An
Optionalcontaining theMechanismPositionConfigif present, otherwise an emptyOptional.
-