Class TalonFXWrapper
java.lang.Object
yams.core.motorcontrollers.SmartMotorController
yams.core.motorcontrollers.remote.TalonFXWrapper
TalonFX wrapper for a CTRE TalonFX motor controller.
External encoder discontinuity point support (CANcoder):
0.5rotations maps toAbsoluteSensorDiscontinuityPoint = 0.5, sensor range is [-0.5, 0.5)1.0rotations maps toAbsoluteSensorDiscontinuityPoint = 1.0, sensor range is [0, 1)
SmartMotorControllerConfig.withExternalEncoderDiscontinuityPoint(Angle).
Example
// Configure and create a Kraken X60 TalonFX on CAN ID 5
SmartMotorControllerConfig config = new SmartMotorControllerConfig()
.withMotorInverted(false)
.withStatorCurrentLimit(Amps.of(60))
.withSupplyCurrentLimit(Amps.of(80))
.withClosedLoopController(0.3, 0.1, 0.12);
SmartMotorController motor = new TalonFXWrapper(
new TalonFX(5), DCMotor.getKrakenX60(1), config);
Elevator elevator = new Elevator(new ElevatorConfig(motor).withDrumRadius(Inches.of(1)));
-
Nested Class Summary
Nested classes/interfaces inherited from class SmartMotorController
SmartMotorController.ClosedLoopControllerSlot -
Field Summary
Fields inherited from class SmartMotorController
m_batterySimUUID, m_closedLoopControllerThread, m_closeHooks, m_config, m_expoProfile, m_expoState, m_lastClosedLoopMechanismPosition, m_looseFollowers, m_lqr, m_pid, m_simSupplier, m_slot, m_systemCoreClosedLoopAlert, m_trapezoidProfile, m_trapState, parentTable, setpointFeedforwardForce, setpointPosition, setpointVelocity, telemetry, telemetryConfig, telemetryTable, tuningTable -
Constructor Summary
ConstructorsConstructorDescriptionTalonFXWrapper(TalonFX controller, org.wpilib.math.system.DCMotor motor, SmartMotorControllerConfig<?> smartConfig) Create theTalonFXwrapper -
Method Summary
Modifier and TypeMethodDescriptionbooleanapplyConfig(SmartMotorControllerConfig<?> config) Apply theSmartMotorControllerConfigto theSmartMotorController.voidclose()Close the SMC for unit testing.Disable FOC control, ignored if the device isn't PRO licensed.Enable FOC control, ignored if the device isn't PRO licensed.Ensure setting is applied, retries every 10ms.forceConfigApply(SlotConfigs slot) Apply part of the Talon's config, such as only a slot's gains, which uses less of the CAN bus than applying all of it, retrying silently for up to 15 ms.Get theSmartMotorControllerConfigfor theSmartMotorControllerorg.wpilib.math.system.DCMotorGet theDCMotormodeling the motor controlled by the motor controller.doubleGet the duty cycle output of the motor controller.Optional<org.wpilib.units.measure.Angle> Get the mechanismAnglefrom the external (absolute) encoder, scaled by the configured external encoderMechanismGearing.Optional<org.wpilib.units.measure.AngularVelocity> Get the mechanismAngularVelocityfrom the external (absolute) encoder, scaled by the configured external encoderMechanismGearing.org.wpilib.units.measure.LinearAccelerationGet the usable measurement of the motor for mechanisms operating under distance units converted with theSmartMotorControllerConfigorg.wpilib.units.measure.DistanceGet the usable measurement of the motor for mechanisms operating under distance units converted with theSmartMotorControllerConfig.org.wpilib.units.measure.LinearVelocityGet the usable measurement of the motor for mechanisms operating under distance units converted with theSmartMotorControllerConfig.org.wpilib.units.measure.AngularAccelerationGet the MechanismAngularAcceleration, calculating it on the robot controller if necessary by taking the derivative of the velocity.org.wpilib.units.measure.Angleorg.wpilib.units.measure.AngularVelocityGet the MechanismAngularVelocitytaking the configuredMechanismGearinginto the measurement applied via theSmartMotorControllerConfig.Get the Motor Controller Object passed into theSmartMotorController.Get the motor controller object config generated bySmartMotorControllerbased off theSmartMotorControllerConfigorg.wpilib.units.measure.AngleGet the mechanismAnglefrom the relative encoder in the motor, scaled by the configuredMechanismGearing.org.wpilib.units.measure.AngularVelocityGet the mechanismAngularVelocityfrom the relative encoder in the motor, scaled by the configuredMechanismGearing.org.wpilib.units.measure.AngleGet the rotations of the motor with the relative encoder since the motor controller powered on scaled to the mechanism rotations.org.wpilib.units.measure.AngularVelocityGets the angular velocity of the motor.org.wpilib.units.measure.CurrentGet the stator current of the motor controller.Optional<org.wpilib.units.measure.Current> Get the supply current of the motor controller.org.wpilib.units.measure.TemperatureGet theSmartMotorControllertemperature.org.wpilib.util.Pair<Optional<List<SmartMotorControllerTelemetry.BooleanTelemetryField>>, Optional<List<SmartMotorControllerTelemetry.DoubleTelemetryField>>> Get a list of unsupported telemetry fields if any exist.Optional<org.wpilib.units.measure.Time> Get how far behind the mechanism the measured velocity is, from how the motor controller filters it, as WPILib's SysId works it out for its presets.org.wpilib.units.measure.VoltageGet the voltage output of the motor.voidSeed the relative encoder with the position from the absolute encoder.voidsetClosedLoopRampRate(org.wpilib.units.measure.Time rampRate) Set the closed loop ramp rate.voidSet the closed loop controller slot to use.voidsetDutyCycle(double dutyCycle) Set the dutycycle output of the motor controller.voidsetEncoderInverted(boolean inverted) Set the phase of the encoder attached to the brushless motor.voidsetEncoderPosition(org.wpilib.units.measure.Angle angle) Set the encoder positionvoidsetEncoderPosition(org.wpilib.units.measure.Distance distance) Set the encoder position.voidsetEncoderVelocity(org.wpilib.units.measure.AngularVelocity velocity) Set the encoder velocityvoidsetEncoderVelocity(org.wpilib.units.measure.LinearVelocity velocity) Set the encoder velocity.voidsetExponentialProfile(OptionalDouble kV, OptionalDouble kA, Optional<org.wpilib.units.measure.Voltage> maxInput) Set the exponential profile fields.voidsetFeedback(double kP, double kI, double kD) Set the closed loop feedback controller PID.voidsetFeedforward(double kS, double kV, double kA, double kG) Set the feedforward controller.voidsetKa(double kA) Acceleration feedforward element.voidsetKd(double kD) Set kD for the feedback controller PID.voidsetKg(double kG) kSin feedforward element.voidsetKi(double kI) Set kI for the feedback controller PID.voidsetKp(double kP) Set kP for the feedback controller PID.voidsetKs(double kS) Static feedforward element.voidsetKv(double kV) Velocity feedforward element.voidsetMeasurementLowerLimit(org.wpilib.units.measure.Distance lowerLimit) Set the measurement lower limit, only works if mechanism circumference is defined.voidsetMeasurementUpperLimit(org.wpilib.units.measure.Distance upperLimit) Set the measurement upper limit, only works if mechanism circumference is defined.voidsetMechanismCircumference(org.wpilib.units.measure.Distance circumference) Update the mechanism circumference used for linear position/velocity conversions.voidsetMechanismGearing(MechanismGearing gearing) Update the mechanism gearing used for position/velocity conversions.voidsetMechanismLimits(org.wpilib.units.measure.Angle lower, org.wpilib.units.measure.Angle upper) Set the Mechanism limits for the motor controller.voidsetMechanismLimitsEnabled(boolean enabled) Enable or disable the mechanism/measurement limits in the motor controller.voidsetMechanismLowerLimit(org.wpilib.units.measure.Angle lowerLimit) Set the mechanism lower limit.voidsetMechanismUpperLimit(org.wpilib.units.measure.Angle upperLimit) Set the mechanism upper limit.voidsetMotionProfileMaxAcceleration(org.wpilib.units.measure.AngularAcceleration maxAcceleration) Set the maximum acceleration for the trapezoidal profile for the feedback controller.voidsetMotionProfileMaxAcceleration(org.wpilib.units.measure.LinearAcceleration maxAcceleration) Set the maximum acceleration of the trapezoidal profile for the feedback controller.voidsetMotionProfileMaxJerk(org.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> maxJerk) Set the maximum jerk for the trapezoidal profile for the feedback controller.voidsetMotionProfileMaxVelocity(org.wpilib.units.measure.AngularVelocity maxVelocity) Set the maximum velocity for the trapezoidal profile for the feedback controller.voidsetMotionProfileMaxVelocity(org.wpilib.units.measure.LinearVelocity maxVelocity) Set the maximum velocity of the trapezoidal profile for the feedback controller.voidsetMotorInverted(boolean inverted) Set the inversion state of the motor.voidsetOpenLoopRampRate(org.wpilib.units.measure.Time rampRate) Set the open loop ramp rate.voidsetPosition(org.wpilib.units.measure.Angle angle) Set the MechanismAngleusing the PID and feedforward fromSmartMotorControllerConfig.voidsetPosition(org.wpilib.units.measure.Distance distance) Set the MechanismDistanceusing the PID and feedforward fromSmartMotorControllerConfig.voidsetStatorCurrentLimit(org.wpilib.units.measure.Current currentLimit) Set the stator current limit for the device.voidsetSupplyCurrentLimit(org.wpilib.units.measure.Current currentLimit) Deprecated.voidsetUpdateFrequency(org.wpilib.units.measure.Frequency freq) Set the update frequency of theStatusSignals used by thisSmartMotorControllervoidSetup the simulation for the wrapper.voidsetVelocity(org.wpilib.units.measure.AngularVelocity angularVelocity) Set the MechanismAngularVelocityusing the PID and feedforward fromSmartMotorControllerConfig.voidsetVelocity(org.wpilib.units.measure.AngularVelocity angularVelocity, org.wpilib.units.measure.Force feedforwardForce) Set the MechanismAngularVelocityusing the PID and feedforward fromSmartMotorControllerConfig, with an additional feedforwardForceapplied on top, e.g.voidsetVelocity(org.wpilib.units.measure.LinearVelocity velocity) Set the MechanismLinearVelocityusing the PID and feedforward fromSmartMotorControllerConfig.voidsetVoltage(org.wpilib.units.measure.Voltage voltage) Set the voltage output of the motor controller.voidsetZeroPower(MotorMode mode) Set the motor zero power mode from COAST or BRAKE.voidSimulation iteration.voidCheck if the relative encoder is out of sync with absolute encoder within defined tolerances.booleanCheck ifCANdiPWM1 is used as theExternalFeedbackConfigs.ExternalFeedbackSensorSourceinTalonFXConfiguration.Feedback.booleanCheck ifCANdiPWM2 is used as theExternalFeedbackConfigs.ExternalFeedbackSensorSourceinTalonFXConfiguration.Feedback.Methods inherited from class SmartMotorController
addCloseHook, applyTuningValues, buildAlertId, checkConfigSafety, create, getClosedLoopControllerPeriod, getClosedLoopControllerSlot, getExponentialProfileState, getLooselyCoupledFollowers, getMeasurementPositionSetpoint, getMechanismPositionSetpoint, getMechanismSetpointVelocity, getName, getSetpointFeedforwardForce, getSimSupplier, getTrapezoidalProfileState, isMotor, iterateClosedLoopController, setSimSupplier, setupLiveTuning, setupTelemetry, setupTelemetry, setVelocity, startClosedLoopController, stopClosedLoopController, stopLiveTuning, toString, tuningEnabled, updateTelemetry
-
Constructor Details
-
TalonFXWrapper
public TalonFXWrapper(TalonFX controller, org.wpilib.math.system.DCMotor motor, SmartMotorControllerConfig<?> smartConfig) Create theTalonFXwrapper- Parameters:
controller-TalonFXmotor-DCMotorsmartConfig-SmartMotorControllerConfig- Throws:
SmartMotorControllerConfigurationException- if the vendor config is not a TalonFXConfiguration.SmartMotorControllerConfigurationException- ifapplyConfig(SmartMotorControllerConfig)rejects the config.SmartMotorControllerConfigurationException- if the motor is a single NEO 550 without a stator current limit of at most 40A.IllegalArgumentException- ifapplyConfig(SmartMotorControllerConfig)rejects an unsupported option (see its documentation).
-
-
Method Details
-
enableFOC
Enable FOC control, ignored if the device isn't PRO licensed.- Returns:
TalonFXWrapperfor ease of use.- Throws:
SmartMotorControllerConfigurationException- if the position or velocity control request is a TorqueCurrentFOC request (set through withVendorControlRequest), which does not support toggling FOC.
-
disableFOC
Disable FOC control, ignored if the device isn't PRO licensed.- Returns:
TalonFXWrapperfor ease of use.- Throws:
SmartMotorControllerConfigurationException- if the position or velocity control request is a TorqueCurrentFOC request (set through withVendorControlRequest), which does not support toggling FOC.
-
setupSimulation
public void setupSimulation()Description copied from class:SmartMotorControllerSetup the simulation for the wrapper.- Specified by:
setupSimulationin classSmartMotorController
-
seedRelativeEncoder
public void seedRelativeEncoder()Description copied from class:SmartMotorControllerSeed the relative encoder with the position from the absolute encoder.- Specified by:
seedRelativeEncoderin classSmartMotorController
-
synchronizeRelativeEncoder
public void synchronizeRelativeEncoder()Check if the relative encoder is out of sync with absolute encoder within defined tolerances.- Specified by:
synchronizeRelativeEncoderin classSmartMotorController- Implementation Note:
- Does nothing, the TalonFX fuses its feedback sources on the device, so there is no relative encoder to resynchronize.
-
simIterate
public void simIterate()Description copied from class:SmartMotorControllerSimulation iteration.- Specified by:
simIteratein classSmartMotorController
-
setZeroPower
Description copied from class:SmartMotorControllerSet the motor zero power mode from COAST or BRAKE.- Specified by:
setZeroPowerin classSmartMotorController- Parameters:
mode-MotorModeselected.
-
setEncoderVelocity
public void setEncoderVelocity(org.wpilib.units.measure.AngularVelocity velocity) Description copied from class:SmartMotorControllerSet the encoder velocity- Specified by:
setEncoderVelocityin classSmartMotorController- Parameters:
velocity-AngularVelocityof the Mechanism.
-
useCANdiPWM1
public boolean useCANdiPWM1()Check ifCANdiPWM1 is used as theExternalFeedbackConfigs.ExternalFeedbackSensorSourceinTalonFXConfiguration.Feedback.- Returns:
- True if CANdi PWM1 is the feedback sensor source of the configuration being applied.
- Throws:
IllegalArgumentException- if the feedback sensor source is set to a CANdi PWM1 source but no CANdi is configured as the external encoder in the SmartMotorControllerConfig.
-
useCANdiPWM2
public boolean useCANdiPWM2()Check ifCANdiPWM2 is used as theExternalFeedbackConfigs.ExternalFeedbackSensorSourceinTalonFXConfiguration.Feedback.- Returns:
- True if CANdi PWM2 is the feedback sensor source of the configuration being applied.
- Throws:
IllegalArgumentException- if the feedback sensor source is set to a CANdi PWM2 source but no CANdi is configured as the external encoder in the SmartMotorControllerConfig.
-
setEncoderVelocity
public void setEncoderVelocity(org.wpilib.units.measure.LinearVelocity velocity) Set the encoder velocity.- Specified by:
setEncoderVelocityin classSmartMotorController- Parameters:
velocity- MeasurementLinearVelocity- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
setEncoderPosition
public void setEncoderPosition(org.wpilib.units.measure.Angle angle) Description copied from class:SmartMotorControllerSet the encoder position- Specified by:
setEncoderPositionin classSmartMotorController- Parameters:
angle- Current MechanismAngle.
-
setEncoderPosition
public void setEncoderPosition(org.wpilib.units.measure.Distance distance) Set the encoder position.- Specified by:
setEncoderPositionin classSmartMotorController- Parameters:
distance- Current MeasurementDistance.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
setPosition
public void setPosition(org.wpilib.units.measure.Angle angle) Set the MechanismAngleusing the PID and feedforward fromSmartMotorControllerConfig.- Specified by:
setPositionin classSmartMotorController- Parameters:
angle- Mechanism angle to set.- Throws:
SmartMotorControllerConfigurationException- if the configured position control request is not a supported Phoenix 6 position request.
-
setPosition
public void setPosition(org.wpilib.units.measure.Distance distance) Set the MechanismDistanceusing the PID and feedforward fromSmartMotorControllerConfig.- Specified by:
setPositionin classSmartMotorController- Parameters:
distance- MechanismDistanceto set.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.SmartMotorControllerConfigurationException- if the configured position control request is not a supported Phoenix 6 position request.
-
setVelocity
public void setVelocity(org.wpilib.units.measure.LinearVelocity velocity) Set the MechanismLinearVelocityusing the PID and feedforward fromSmartMotorControllerConfig.- Overrides:
setVelocityin classSmartMotorController- Parameters:
velocity- MechanismLinearVelocityto target.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.SmartMotorControllerConfigurationException- if the configured velocity control request is not a supported Phoenix 6 velocity request.
-
setVelocity
public void setVelocity(org.wpilib.units.measure.AngularVelocity angularVelocity) Set the MechanismAngularVelocityusing the PID and feedforward fromSmartMotorControllerConfig.- Specified by:
setVelocityin classSmartMotorController- Parameters:
angularVelocity- MechanismAngularVelocityto target.- Throws:
SmartMotorControllerConfigurationException- if the configured velocity control request is not a supported Phoenix 6 velocity request.
-
setVelocity
public void setVelocity(org.wpilib.units.measure.AngularVelocity angularVelocity, org.wpilib.units.measure.Force feedforwardForce) Set the MechanismAngularVelocityusing the PID and feedforward fromSmartMotorControllerConfig, with an additional feedforwardForceapplied on top, e.g. from a PathPlanner set-point generator. Applied whether the motor controller's native closed-loop velocity control or an LQR/software motion profile loop is driving the mechanism.- Specified by:
setVelocityin classSmartMotorController- Parameters:
angularVelocity- MechanismAngularVelocityto target.feedforwardForce- Additional feedforwardForceapplied to the mechanism, ornullfor none.- Throws:
SmartMotorControllerConfigurationException- if a feedforward force is given without an LQR controller and the mechanism circumference is not configured.SmartMotorControllerConfigurationException- if the configured velocity control request is not a supported Phoenix 6 velocity request.
-
getDutyCycle
public double getDutyCycle()Description copied from class:SmartMotorControllerGet the duty cycle output of the motor controller.- Specified by:
getDutyCyclein classSmartMotorController- Returns:
- DutyCycle of the motor controller.
-
setDutyCycle
public void setDutyCycle(double dutyCycle) Description copied from class:SmartMotorControllerSet the dutycycle output of the motor controller.- Specified by:
setDutyCyclein classSmartMotorController- Parameters:
dutyCycle- Value between [-1,1]
-
applyConfig
Apply theSmartMotorControllerConfigto theSmartMotorController.- Specified by:
applyConfigin classSmartMotorController- Parameters:
config-SmartMotorControllerConfigto use.- Returns:
- Successful Application of the configuration.
- Throws:
SmartMotorControllerConfigurationException- if a closed loop tolerance is configured without an LQR controller.SmartMotorControllerConfigurationException- if a feedforward is configured for SLOT_3.SmartMotorControllerConfigurationException- if an external encoder inversion or gearing is set while no external encoder is used.SmartMotorControllerConfigurationException- if an integrated encoder inversion is set.SmartMotorControllerConfigurationException- if the vendor control request is not a supported Phoenix 6 position or velocity request.SmartMotorControllerConfigurationException- if the continuous wrapping bounds are not exactly one rotation apart.SmartMotorControllerConfigurationException- if not every required config option was read during validation.IllegalArgumentException- if an LQR controller is configured together with a closed loop tolerance.IllegalArgumentException- if a follower is neither a TalonFX nor a TalonFXS.IllegalArgumentException- if a closed loop control period is configured.IllegalArgumentException- if a temperature cutoff is configured.IllegalArgumentException- if a feedback synchronization threshold is configured.IllegalArgumentException- if voltage compensation is configured.
-
setUpdateFrequency
public void setUpdateFrequency(org.wpilib.units.measure.Frequency freq) Set the update frequency of theStatusSignals used by thisSmartMotorController- Parameters:
freq-Frequencyto use.
-
getSupplyCurrent
Description copied from class:SmartMotorControllerGet the supply current of the motor controller.- Specified by:
getSupplyCurrentin classSmartMotorController- Returns:
- The supply current of the motor controller.
-
getStatorCurrent
public org.wpilib.units.measure.Current getStatorCurrent()Description copied from class:SmartMotorControllerGet the stator current of the motor controller.- Specified by:
getStatorCurrentin classSmartMotorController- Returns:
- Stator current
-
getVoltage
public org.wpilib.units.measure.Voltage getVoltage()Description copied from class:SmartMotorControllerGet the voltage output of the motor.- Specified by:
getVoltagein classSmartMotorController- Returns:
- Voltage output of the motor.
-
setVoltage
public void setVoltage(org.wpilib.units.measure.Voltage voltage) Description copied from class:SmartMotorControllerSet the voltage output of the motor controller. Useful for Sysid.- Specified by:
setVoltagein classSmartMotorController- Parameters:
voltage- Voltage to set the motor controller output to.
-
getDCMotor
public org.wpilib.math.system.DCMotor getDCMotor()Description copied from class:SmartMotorControllerGet theDCMotormodeling the motor controlled by the motor controller.- Specified by:
getDCMotorin classSmartMotorController- Returns:
DCMotorof the controlled motor.
-
getMeasurementVelocity
public org.wpilib.units.measure.LinearVelocity getMeasurementVelocity()Get the usable measurement of the motor for mechanisms operating under distance units converted with theSmartMotorControllerConfig.- Specified by:
getMeasurementVelocityin classSmartMotorController- Returns:
- Measurement velocity of the mechanism post-gearing.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
getMeasurementPosition
public org.wpilib.units.measure.Distance getMeasurementPosition()Get the usable measurement of the motor for mechanisms operating under distance units converted with theSmartMotorControllerConfig.- Specified by:
getMeasurementPositionin classSmartMotorController- Returns:
- Measurement velocity of the mechanism post-gearing.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
getMeasurementAcceleration
public org.wpilib.units.measure.LinearAcceleration getMeasurementAcceleration()Get the usable measurement of the motor for mechanisms operating under distance units converted with theSmartMotorControllerConfig- Specified by:
getMeasurementAccelerationin classSmartMotorController- Returns:
- Measurement acceleration of the mechanism post-gearing.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
getMechanismVelocity
public org.wpilib.units.measure.AngularVelocity getMechanismVelocity()Description copied from class:SmartMotorControllerGet the MechanismAngularVelocitytaking the configuredMechanismGearinginto the measurement applied via theSmartMotorControllerConfig. UsesSmartMotorController.getExternalEncoderMechanismVelocity()when the external (absolute) encoder is enabled withSmartMotorControllerConfig.withUseExternalFeedbackEncoder(boolean), otherwiseSmartMotorController.getRelativeMechanismVelocity().- Specified by:
getMechanismVelocityin classSmartMotorController- Returns:
- Mechanism
AngularVelocity
-
getMechanismAcceleration
public org.wpilib.units.measure.AngularAcceleration getMechanismAcceleration()Description copied from class:SmartMotorControllerGet the MechanismAngularAcceleration, calculating it on the robot controller if necessary by taking the derivative of the velocity.- Specified by:
getMechanismAccelerationin classSmartMotorController- Returns:
- Mechanism
AngularAcceleration
-
getMechanismPosition
public org.wpilib.units.measure.Angle getMechanismPosition()Description copied from class:SmartMotorControllerGet the mechanismAngletaking the configuredMechanismGearingfromSmartMotorControllerConfig. UsesSmartMotorController.getExternalEncoderMechanismPosition()when the external (absolute) encoder is enabled withSmartMotorControllerConfig.withUseExternalFeedbackEncoder(boolean), otherwiseSmartMotorController.getRelativeMechanismPosition().- Specified by:
getMechanismPositionin classSmartMotorController- Returns:
- Mechanism
Angle
-
getRotorVelocity
public org.wpilib.units.measure.AngularVelocity getRotorVelocity()Description copied from class:SmartMotorControllerGets the angular velocity of the motor.- Specified by:
getRotorVelocityin classSmartMotorController- Returns:
AngularVelocityof the relative motor encoder.
-
getRotorPosition
public org.wpilib.units.measure.Angle getRotorPosition()Description copied from class:SmartMotorControllerGet the rotations of the motor with the relative encoder since the motor controller powered on scaled to the mechanism rotations.- Specified by:
getRotorPositionin classSmartMotorController- Returns:
Angleof the relative encoder in the motor.
-
getRelativeMechanismVelocity
public org.wpilib.units.measure.AngularVelocity getRelativeMechanismVelocity()Description copied from class:SmartMotorControllerGet the mechanismAngularVelocityfrom the relative encoder in the motor, scaled by the configuredMechanismGearing. Never uses the external (absolute) encoder.- Specified by:
getRelativeMechanismVelocityin classSmartMotorController- Returns:
- Mechanism
AngularVelocityfrom the relative encoder.
-
getRelativeMechanismPosition
public org.wpilib.units.measure.Angle getRelativeMechanismPosition()Description copied from class:SmartMotorControllerGet the mechanismAnglefrom the relative encoder in the motor, scaled by the configuredMechanismGearing. Never uses the external (absolute) encoder.- Specified by:
getRelativeMechanismPositionin classSmartMotorController- Returns:
- Mechanism
Anglefrom the relative encoder.
-
getExternalEncoderMechanismPosition
Description copied from class:SmartMotorControllerGet the mechanismAnglefrom the external (absolute) encoder, scaled by the configured external encoderMechanismGearing. Available whether or not the external encoder is used for feedback.- Specified by:
getExternalEncoderMechanismPositionin classSmartMotorController- Returns:
- Mechanism
Anglefrom the external encoder, or empty if none is attached.
-
getExternalEncoderMechanismVelocity
Description copied from class:SmartMotorControllerGet the mechanismAngularVelocityfrom the external (absolute) encoder, scaled by the configured external encoderMechanismGearing. Available whether or not the external encoder is used for feedback.- Specified by:
getExternalEncoderMechanismVelocityin classSmartMotorController- Returns:
- Mechanism
AngularVelocityfrom the external encoder, or empty if none is attached.
-
setMotorInverted
public void setMotorInverted(boolean inverted) Description copied from class:SmartMotorControllerSet the inversion state of the motor.- Specified by:
setMotorInvertedin classSmartMotorController- Parameters:
inverted- Inverted motor.
-
setEncoderInverted
public void setEncoderInverted(boolean inverted) Description copied from class:SmartMotorControllerSet the phase of the encoder attached to the brushless motor.- Specified by:
setEncoderInvertedin classSmartMotorController- Parameters:
inverted- Phase of the encoder.
-
setMotionProfileMaxVelocity
public void setMotionProfileMaxVelocity(org.wpilib.units.measure.LinearVelocity maxVelocity) Set the maximum velocity of the trapezoidal profile for the feedback controller.- Specified by:
setMotionProfileMaxVelocityin classSmartMotorController- Parameters:
maxVelocity- Maximum velocity, will be translated to MetersPerSecond.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
setMotionProfileMaxAcceleration
public void setMotionProfileMaxAcceleration(org.wpilib.units.measure.LinearAcceleration maxAcceleration) Set the maximum acceleration of the trapezoidal profile for the feedback controller.- Specified by:
setMotionProfileMaxAccelerationin classSmartMotorController- Parameters:
maxAcceleration- Maximum acceleration, will be translated to MetersPerSecondPerSecond.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
setMotionProfileMaxVelocity
public void setMotionProfileMaxVelocity(org.wpilib.units.measure.AngularVelocity maxVelocity) Description copied from class:SmartMotorControllerSet the maximum velocity for the trapezoidal profile for the feedback controller.- Specified by:
setMotionProfileMaxVelocityin classSmartMotorController- Parameters:
maxVelocity- Maximum velocity, will be translated to RotationsPerSecond.
-
setMotionProfileMaxAcceleration
public void setMotionProfileMaxAcceleration(org.wpilib.units.measure.AngularAcceleration maxAcceleration) Description copied from class:SmartMotorControllerSet the maximum acceleration for the trapezoidal profile for the feedback controller.- Specified by:
setMotionProfileMaxAccelerationin classSmartMotorController- Parameters:
maxAcceleration- Maximum acceleration, will be translated to RotationsPerSecondPerSecond.
-
setMotionProfileMaxJerk
public void setMotionProfileMaxJerk(org.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> maxJerk) Description copied from class:SmartMotorControllerSet the maximum jerk for the trapezoidal profile for the feedback controller.- Specified by:
setMotionProfileMaxJerkin classSmartMotorController- Parameters:
maxJerk- Maximum jerk, will be translated to RotationsPerSecondPerSecondPerSecond.
-
setExponentialProfile
public void setExponentialProfile(OptionalDouble kV, OptionalDouble kA, Optional<org.wpilib.units.measure.Voltage> maxInput) Description copied from class:SmartMotorControllerSet the exponential profile fields.- Specified by:
setExponentialProfilein classSmartMotorController- Parameters:
kV- kV for the exponential profile.kA- kA for the exponential profile.maxInput- Maximum input for the exponential profile.
-
getVelocityMeasurementDelay
Get how far behind the mechanism the measured velocity is, from how the motor controller filters it, as WPILib's SysId works it out for its presets. Feedback gains worked out for the closed loop depend on it. In simulation, the simulation period, since the simulated sensor is updated once a period.Phoenix 6 filters velocity with a Kalman filter tuned for the least latency, about 1 ms, as WPILib's SysId takes it for its CTRE Phoenix 6 preset. A closed loop run on the SystemCore reads the velocity from its status signal instead, which on average is half the signal's update period older. Phoenix 6 simulates the Talon in its own thread with the same filtering, so the delay is the same in simulation.
- Overrides:
getVelocityMeasurementDelayin classSmartMotorController- Returns:
- The delay, or empty if it is not known for this motor controller.
-
forceConfigApply
Ensure setting is applied, retries every 10ms.- Returns:
StatusCodefrom the device.
-
forceConfigApply
Apply part of the Talon's config, such as only a slot's gains, which uses less of the CAN bus than applying all of it, retrying silently for up to 15 ms. The part must also be in the Talon's config, so it is kept when the whole config is applied.- Parameters:
slot- The slot's configs to apply.- Returns:
- The last status the Talon returned, OK once it took them.
-
setKp
public void setKp(double kP) Set kP for the feedback controller PID.- Specified by:
setKpin classSmartMotorController- Parameters:
kP- kP- Throws:
SmartMotorControllerConfigurationException- if the active closed loop slot is SLOT_3, which the TalonFX does not support.
-
setKi
public void setKi(double kI) Set kI for the feedback controller PID.- Specified by:
setKiin classSmartMotorController- Parameters:
kI- kI.- Throws:
SmartMotorControllerConfigurationException- if the active closed loop slot is SLOT_3, which the TalonFX does not support.
-
setKd
public void setKd(double kD) Set kD for the feedback controller PID.- Specified by:
setKdin classSmartMotorController- Parameters:
kD- kD for the feedback controller PID.- Throws:
SmartMotorControllerConfigurationException- if the active closed loop slot is SLOT_3, which the TalonFX does not support.
-
setFeedback
public void setFeedback(double kP, double kI, double kD) Set the closed loop feedback controller PID.- Specified by:
setFeedbackin classSmartMotorController- Parameters:
kP- kP; Proportional scalar.kI- kI; Integral scalar.kD- kD; derivative scalar.- Throws:
SmartMotorControllerConfigurationException- if the active closed loop slot is SLOT_3, which the TalonFX does not support.
-
setKs
public void setKs(double kS) Static feedforward element.- Specified by:
setKsin classSmartMotorController- Parameters:
kS- kS; Static feedforward.- Throws:
SmartMotorControllerConfigurationException- if the active closed loop slot is SLOT_3, which the TalonFX does not support.
-
setKv
public void setKv(double kV) Velocity feedforward element.- Specified by:
setKvin classSmartMotorController- Parameters:
kV- kV; Velocity feedforward.- Throws:
SmartMotorControllerConfigurationException- if the active closed loop slot is SLOT_3, which the TalonFX does not support.
-
setKa
public void setKa(double kA) Acceleration feedforward element.- Specified by:
setKain classSmartMotorController- Parameters:
kA- kA; Acceleration feedforward.- Throws:
SmartMotorControllerConfigurationException- if the active closed loop slot is SLOT_3, which the TalonFX does not support.
-
setKg
public void setKg(double kG) kSin feedforward element.- Specified by:
setKgin classSmartMotorController- Parameters:
kG- kG; Gravity feedforward.- Throws:
SmartMotorControllerConfigurationException- if the active closed loop slot is SLOT_3, which the TalonFX does not support.
-
setFeedforward
public void setFeedforward(double kS, double kV, double kA, double kG) Set the feedforward controller.- Specified by:
setFeedforwardin classSmartMotorController- Parameters:
kS- kS; Static feedforward.kV- kV; Velocity feedforward.kA- kA; Acceleration feedforward.kG- kG; Gravity feedforward.- Throws:
SmartMotorControllerConfigurationException- if the active closed loop slot is SLOT_3, which the TalonFX does not support.
-
setStatorCurrentLimit
public void setStatorCurrentLimit(org.wpilib.units.measure.Current currentLimit) Description copied from class:SmartMotorControllerSet the stator current limit for the device.- Specified by:
setStatorCurrentLimitin classSmartMotorController- Parameters:
currentLimit- Stator current limit.
-
setSupplyCurrentLimit
Deprecated.Description copied from class:SmartMotorControllerSet the supply current limit.- Specified by:
setSupplyCurrentLimitin classSmartMotorController- Parameters:
currentLimit- Supply current limit.
-
setClosedLoopRampRate
public void setClosedLoopRampRate(org.wpilib.units.measure.Time rampRate) Description copied from class:SmartMotorControllerSet the closed loop ramp rate. The ramp rate is how fast the motor can go from 0-100, measured in seconds.- Specified by:
setClosedLoopRampRatein classSmartMotorController- Parameters:
rampRate- Time from 0 to 100.
-
setOpenLoopRampRate
public void setOpenLoopRampRate(org.wpilib.units.measure.Time rampRate) Description copied from class:SmartMotorControllerSet the open loop ramp rate. The ramp rate is how fast the motor can go from 0 to 100, measured in Seconds.- Specified by:
setOpenLoopRampRatein classSmartMotorController- Parameters:
rampRate- Time it takes to go from 0 to 100.
-
setMeasurementUpperLimit
public void setMeasurementUpperLimit(org.wpilib.units.measure.Distance upperLimit) Set the measurement upper limit, only works if mechanism circumference is defined.- Specified by:
setMeasurementUpperLimitin classSmartMotorController- Parameters:
upperLimit- Upper limit, will be translated to meters.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference and lower limit are configured and the lower limit is greater than or equal to upperLimit.
-
setMeasurementLowerLimit
public void setMeasurementLowerLimit(org.wpilib.units.measure.Distance lowerLimit) Set the measurement lower limit, only works if mechanism circumference is defined.- Specified by:
setMeasurementLowerLimitin classSmartMotorController- Parameters:
lowerLimit- Lower limit, will be translated to meters.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference and upper limit are configured and lowerLimit is greater than or equal to the upper limit.
-
setMechanismUpperLimit
public void setMechanismUpperLimit(org.wpilib.units.measure.Angle upperLimit) Set the mechanism upper limit.- Specified by:
setMechanismUpperLimitin classSmartMotorController- Parameters:
upperLimit- Upper limit, will be translated to rotations.- Throws:
SmartMotorControllerConfigurationException- if a lower limit is configured and it is greater than or equal to upperLimit.
-
setMechanismLowerLimit
public void setMechanismLowerLimit(org.wpilib.units.measure.Angle lowerLimit) Set the mechanism lower limit.- Specified by:
setMechanismLowerLimitin classSmartMotorController- Parameters:
lowerLimit- Lower limit, will be translated to rotations.- Throws:
SmartMotorControllerConfigurationException- if an upper limit is configured and lowerLimit is greater than or equal to it.
-
setMechanismLimits
public void setMechanismLimits(org.wpilib.units.measure.Angle lower, org.wpilib.units.measure.Angle upper) Set the Mechanism limits for the motor controller.- Specified by:
setMechanismLimitsin classSmartMotorController- Parameters:
lower- Lower limit, will be translated to rotations.upper- Upper limit, will be translated to rotations.- Throws:
SmartMotorControllerConfigurationException- if lower is greater than or equal to upper.
-
setMechanismLimitsEnabled
public void setMechanismLimitsEnabled(boolean enabled) Description copied from class:SmartMotorControllerEnable or disable the mechanism/measurement limits in the motor controller.- Specified by:
setMechanismLimitsEnabledin classSmartMotorController- Parameters:
enabled- Application of the limits
-
setMechanismGearing
Description copied from class:SmartMotorControllerUpdate the mechanism gearing used for position/velocity conversions.- Specified by:
setMechanismGearingin classSmartMotorController- Parameters:
gearing- NewMechanismGearingto apply.
-
setMechanismCircumference
public void setMechanismCircumference(org.wpilib.units.measure.Distance circumference) Description copied from class:SmartMotorControllerUpdate the mechanism circumference used for linear position/velocity conversions.- Specified by:
setMechanismCircumferencein classSmartMotorController- Parameters:
circumference- New mechanism circumference.
-
setClosedLoopSlot
Set the closed loop controller slot to use.- Specified by:
setClosedLoopSlotin classSmartMotorController- Parameters:
slot- Slot to use.- Throws:
IllegalArgumentException- if slot is SLOT_3, since the TalonFX only supports slots 0 through 2.SmartMotorControllerConfigurationException- if the position or velocity control request is a TorqueCurrentFOC request (set through withVendorControlRequest), which this method does not handle.- Implementation Note:
- The TalonFX supports 3 slots, not 4!
-
getTemperature
public org.wpilib.units.measure.Temperature getTemperature()Description copied from class:SmartMotorControllerGet theSmartMotorControllertemperature.- Specified by:
getTemperaturein classSmartMotorController- Returns:
Temperature
-
getConfig
Description copied from class:SmartMotorControllerGet theSmartMotorControllerConfigfor theSmartMotorController- Specified by:
getConfigin classSmartMotorController- Returns:
SmartMotorControllerConfigused.
-
getMotorController
Description copied from class:SmartMotorControllerGet the Motor Controller Object passed into theSmartMotorController.- Specified by:
getMotorControllerin classSmartMotorController- Returns:
- Motor Controller object.
-
getMotorControllerConfig
Description copied from class:SmartMotorControllerGet the motor controller object config generated bySmartMotorControllerbased off theSmartMotorControllerConfig- Specified by:
getMotorControllerConfigin classSmartMotorController- Returns:
- Motor controller config.
-
getUnsupportedTelemetryFields
public org.wpilib.util.Pair<Optional<List<SmartMotorControllerTelemetry.BooleanTelemetryField>>, Optional<List<SmartMotorControllerTelemetry.DoubleTelemetryField>>> getUnsupportedTelemetryFields()Description copied from class:SmartMotorControllerGet a list of unsupported telemetry fields if any exist.- Specified by:
getUnsupportedTelemetryFieldsin classSmartMotorController- Returns:
- Optional list of unsupported telemetry fields.
-
close
public void close()Description copied from class:SmartMotorControllerClose the SMC for unit testing.- Overrides:
closein classSmartMotorController
-