Class SparkWrapper
java.lang.Object
yams.core.motorcontrollers.SmartMotorController
yams.core.motorcontrollers.local.SparkWrapper
Spark wrapper for REV Spark Motor controllers.
External encoder discontinuity point support (SparkAbsoluteEncoder):
0.5rotations sensor range is [-0.5, 0.5),rangeOffset(0)1.0rotations sensor range is [0, 1),rangeOffset(0.5)
zeroCentered is deprecated for removal in 2027, so the SPARK's absolute encoder
is given a range offset. An absolute encoder read over CAN has no range offset, and is still given
dutyCycleZeroCentered.
A discontinuity point must be configured via SmartMotorControllerConfig.withExternalEncoderDiscontinuityPoint(Angle)
whenever a SparkAbsoluteEncoder is used as the external encoder.
Example
// Configure and create a SPARK MAX (NEO motor) on CAN ID 3
SmartMotorControllerConfig config = new SmartMotorControllerConfig()
.withMotorInverted(false)
.withStatorCurrentLimit(Amps.of(40))
.withClosedLoopController(0.2,0,0)
.withExternalEncoderDiscontinuityPoint(Rotations.of(0.5)); // required for
SparkAbsoluteEncoder SmartMotorController motor = new SparkWrapper( new SparkMax(3,
MotorType.kBrushless), DCMotor.getNEO(1), config); Arm arm = new Arm(new
ArmConfig(motor).withLength(Meters.of(0.6)));
-
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
ConstructorsConstructorDescriptionSparkWrapper(SparkBase controller, org.wpilib.math.system.DCMotor motor, SmartMotorControllerConfig<?> config) -
Method Summary
Modifier and TypeMethodDescriptionbooleanapplyConfig(SmartMotorControllerConfig<?> config) Apply theSmartMotorControllerConfigto theSmartMotorController.voidclose()Close the SMC for unit testing.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> Deprecated.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.voidSetup 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.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
-
SparkWrapper
public SparkWrapper(SparkBase controller, org.wpilib.math.system.DCMotor motor, SmartMotorControllerConfig<?> config) - Parameters:
controller-SparkMaxorSparkFlexmotor-DCMotorcontroller by theSparkFlexorSparkMax. Must be a brushless motor.config-SmartMotorControllerConfigto apply.- Throws:
SmartMotorControllerConfigurationException- if the vendor config does not match the controller type (a SparkMaxConfig is required for a SparkMax and a SparkFlexConfig for a SparkFlex).SmartMotorControllerConfigurationException- if the motor is a NEO 550 with no stator current limit.SmartMotorControllerConfigurationException- if the motor is a NEO 550 with a stator current limit above 40A.SmartMotorControllerConfigurationException- ifapplyConfig(SmartMotorControllerConfig)rejects the config.IllegalArgumentException- if the controller is neither a SparkMax nor a SparkFlex.IllegalArgumentException- ifapplyConfig(SmartMotorControllerConfig)rejects the config.
-
-
Method Details
-
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()Description copied from class:SmartMotorControllerCheck if the relative encoder is out of sync with absolute encoder within defined tolerances.- Specified by:
synchronizeRelativeEncoderin classSmartMotorController
-
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.LinearVelocity velocity) Set the encoder velocity.- Specified by:
setEncoderVelocityin classSmartMotorController- Parameters:
velocity- MeasurementLinearVelocity- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.UnsupportedOperationException- if called outside of simulation, since REV Sparks do not support setting encoder velocity.
-
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.
-
setEncoderVelocity
public void setEncoderVelocity(org.wpilib.units.measure.AngularVelocity velocity) Set the encoder velocity- Specified by:
setEncoderVelocityin classSmartMotorController- Parameters:
velocity-AngularVelocityof the Mechanism.- Throws:
UnsupportedOperationException- if called outside of simulation, since REV Sparks do not support setting encoder velocity.
-
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) Description copied from class:SmartMotorControllerSet the MechanismAngleusing the PID and feedforward fromSmartMotorControllerConfig.- Specified by:
setPositionin classSmartMotorController- Parameters:
angle- Mechanism angle to set.
-
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.
-
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.
-
setVelocity
public void setVelocity(org.wpilib.units.measure.AngularVelocity angularVelocity) Description copied from class:SmartMotorControllerSet the MechanismAngularVelocityusing the PID and feedforward fromSmartMotorControllerConfig.- Specified by:
setVelocityin classSmartMotorController- Parameters:
angularVelocity- MechanismAngularVelocityto target.
-
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.
-
applyConfig
Apply theSmartMotorControllerConfigto theSmartMotorController.- Specified by:
applyConfigin classSmartMotorController- Parameters:
config-SmartMotorControllerConfigto use.- Returns:
- Successful Application of the configuration.
- Throws:
SmartMotorControllerConfigurationException- if a supply current limit is configured.SmartMotorControllerConfigurationException- if an external encoder discontinuity point is configured without an external encoder.SmartMotorControllerConfigurationException- if an external encoder zero offset is configured without an external encoder.SmartMotorControllerConfigurationException- if an external encoder inversion is configured without an external encoder.SmartMotorControllerConfigurationException- if an external encoder gearing is configured without an external encoder.SmartMotorControllerConfigurationException- if a closed loop control period is configured without an exponential profile or LQR controller.SmartMotorControllerConfigurationException- if a closed loop controller maximum voltage is configured without an exponential profile or LQR controller.SmartMotorControllerConfigurationException- if a feedback synchronization threshold is configured without an exponential profile or LQR controller.SmartMotorControllerConfigurationException- if a temperature cutoff is configured without an exponential or trapezoidal profile.SmartMotorControllerConfigurationException- if a vendor control request is configured.SmartMotorControllerConfigurationException- if the continuous wrapping bounds do not span exactly one rotation.SmartMotorControllerConfigurationException- if a linear closed loop controller is in use without a mechanism circumference.SmartMotorControllerConfigurationException- if a required config option is left unhandled during validation.IllegalArgumentException- if a closed loop control period is configured with an exponential profile or LQR controller while not in closed loop mode.IllegalArgumentException- if a closed loop tolerance is configured with an LQR controller.IllegalArgumentException- if the external encoder is not a SparkAbsoluteEncoder.IllegalArgumentException- if a follower is not a SparkMax or SparkFlex.IllegalArgumentException- if relative encoder inversion is configured.
-
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.Read from the SPARK's encoder settings when the config is applied. The SPARK's closed loop uses the velocity as soon as it is filtered. A closed loop run on the SystemCore reads it from its status frame instead, which on average is half the frame's period older.
- Overrides:
getVelocityMeasurementDelayin classSmartMotorController- Returns:
- The delay, or empty if it is not known for this motor controller.
-
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]
-
getSupplyCurrent
Deprecated.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
-
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.
-
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.
-
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) Set 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.- Throws:
SmartMotorControllerConfigurationException- if an exponential profile is configured with a linear closed loop controller and the mechanism circumference is not configured.
-
setKp
public void setKp(double kP) Description copied from class:SmartMotorControllerSet kP for the feedback controller PID.- Specified by:
setKpin classSmartMotorController- Parameters:
kP- kP
-
setKi
public void setKi(double kI) Description copied from class:SmartMotorControllerSet kI for the feedback controller PID.- Specified by:
setKiin classSmartMotorController- Parameters:
kI- kI.
-
setKd
public void setKd(double kD) Description copied from class:SmartMotorControllerSet kD for the feedback controller PID.- Specified by:
setKdin classSmartMotorController- Parameters:
kD- kD for the feedback controller PID.
-
setFeedback
public void setFeedback(double kP, double kI, double kD) Description copied from class:SmartMotorControllerSet the closed loop feedback controller PID.- Specified by:
setFeedbackin classSmartMotorController- Parameters:
kP- kP; Proportional scalar.kI- kI; Integral scalar.kD- kD; derivative scalar.
-
setKs
public void setKs(double kS) Description copied from class:SmartMotorControllerStatic feedforward element.- Specified by:
setKsin classSmartMotorController- Parameters:
kS- kS; Static feedforward.
-
setKv
public void setKv(double kV) Description copied from class:SmartMotorControllerVelocity feedforward element.- Specified by:
setKvin classSmartMotorController- Parameters:
kV- kV; Velocity feedforward.
-
setKa
public void setKa(double kA) Description copied from class:SmartMotorControllerAcceleration feedforward element.- Specified by:
setKain classSmartMotorController- Parameters:
kA- kA; Acceleration feedforward.
-
setKg
public void setKg(double kG) Description copied from class:SmartMotorControllerkSin feedforward element.- Specified by:
setKgin classSmartMotorController- Parameters:
kG- kG; Gravity feedforward.
-
setFeedforward
public void setFeedforward(double kS, double kV, double kA, double kG) Description copied from class:SmartMotorControllerSet the feedforward controller.- Specified by:
setFeedforwardin classSmartMotorController- Parameters:
kS- kS; Static feedforward.kV- kV; Velocity feedforward.kA- kA; Acceleration feedforward.kG- kG; Gravity feedforward.
-
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 a lower limit is configured and it is greater than or equal to the new upper limit.
-
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 an upper limit is configured and the new lower limit is greater than or equal to it.
-
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 the new upper limit.
-
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 the new lower limit 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 both limits are non-null and the lower limit is greater than or equal to the upper limit.
-
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
Description copied from class:SmartMotorControllerSet the closed loop controller slot to use.- Specified by:
setClosedLoopSlotin classSmartMotorController- Parameters:
slot- Slot to use.
-
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
-