Class SmartMotorControllerConfig<T extends SmartMotorControllerConfig<T>>
java.lang.Object
yams.core.motorcontrollers.SmartMotorControllerConfig<T>
- Type Parameters:
T- Concrete config type, so chainedwithcalls keep the subclass type.
- Direct Known Subclasses:
SmartMotorControllerConfig, SmartMotorControllerConfig
public abstract class SmartMotorControllerConfig<T extends SmartMotorControllerConfig<T>>
extends Object
Smart motor controller config.
Example
SmartMotorControllerConfig config = new SmartMotorControllerConfig()
.withMotorInverted(false)
.withStatorCurrentLimit(Amps.of(40))
.withSupplyCurrentLimit(Amps.of(60))
.withFeedforward(new SimpleMotorFeedforward(0.001, 0.002))
.withMechanismUpperLimit(Degrees.of(90))
.withMechanismLowerLimit(Degrees.of(-90))
.withGearing(new GearBox(12.0, 60.0));
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAll possible options that must be checked and applied during motor config application. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstruct theSmartMotorControllerConfig.protectedDuplicate the SmartMotorControllerConfig. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidattachController(SmartMotorController controller) Attach theSmartMotorControllerthis config was applied to, so command-layer helpers (e.g.voidClear the follower motors so they are not reappliedabstract Tclone()org.wpilib.units.measure.DistanceconvertFromMechanism(org.wpilib.units.measure.Angle rotations) ConvertAngletoDistanceusingmechanismCircumferenceorg.wpilib.units.measure.LinearAccelerationconvertFromMechanism(org.wpilib.units.measure.AngularAcceleration acceleration) ConvertAngletoLinearAccelerationusingmechanismCircumferenceorg.wpilib.units.measure.LinearVelocityconvertFromMechanism(org.wpilib.units.measure.AngularVelocity velocity) ConvertAngletoLinearVelocityusingmechanismCircumferenceorg.wpilib.units.measure.Velocity<org.wpilib.units.LinearAccelerationUnit> convertFromMechanism(org.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> jerk) Convertorg.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit>toorg.wpilib.units.measure.Velocity<org.wpilib.units.LinearAccelerationUnit>using themechanismCircumferenceorg.wpilib.units.measure.CurrentconvertToCurrent(org.wpilib.math.system.DCMotor motor, org.wpilib.units.measure.Force feedforwardForce) Convert a feedforwardForceapplied at the mechanism into the equivalent motor feedforwardCurrent, usinggearingandmechanismCircumference.org.wpilib.units.measure.AngleconvertToMechanism(org.wpilib.units.measure.Distance distance) ConvertDistancetoAngleusingmechanismCircumferenceorg.wpilib.units.measure.AngularAccelerationconvertToMechanism(org.wpilib.units.measure.LinearAcceleration acceleration) ConvertLinearAccelerationtoAngularAccelerationusing themechanismCircumferenceorg.wpilib.units.measure.AngularVelocityconvertToMechanism(org.wpilib.units.measure.LinearVelocity velocity) ConvertLinearVelocitytoAngularVelocityusing themechanismCircumferenceorg.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> convertToMechanism(org.wpilib.units.measure.Velocity<org.wpilib.units.LinearAccelerationUnit> jerk) Convertorg.wpilib.units.measure.Velocity<org.wpilib.units.LinearAccelerationUnit>toorg.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit>using themechanismCircumferenceorg.wpilib.units.measure.VoltageconvertToVoltage(org.wpilib.math.system.DCMotor motor, org.wpilib.units.measure.Force feedforwardForce) Convert a feedforwardForceapplied at the mechanism into the equivalent motor feedforwardVoltage, usinggearingandmechanismCircumference.Optional<org.wpilib.math.controller.ArmFeedforward> Get theArmFeedforwardif it is set.protected Optional<SmartMotorController> Get theSmartMotorControllerthis config was attached to viaattachController(SmartMotorController), if any.Optional<org.wpilib.units.measure.Voltage> Get the closed loop maximum voltage.Optional<org.wpilib.units.measure.Time> Get the period of theSmartMotorControllerclosed loop period.Optional<org.wpilib.units.measure.Time> Get the closed loop ramp rate.Optional<org.wpilib.units.measure.Angle> Get theSmartMotorControllerclosed loop controller tolerance.Optional<org.wpilib.units.measure.Angle> Get the continuous wrapping point for theSmartMotorControllerencoder.Optional<org.wpilib.units.measure.Angle> Get the continuous wrapping point for theSmartMotorControllerencoder.org.wpilib.units.measure.AnglegetContinuousWrappingSetpoint(org.wpilib.units.measure.Angle setpoint, org.wpilib.units.measure.Angle current) Get the position setpoint to command with continuous wrapping: the angle equivalent tosetpoint, a whole number of wrapping ranges away, that is nearestcurrent.Optional<org.wpilib.math.controller.ElevatorFeedforward> Get theElevatorFeedforwardOptionalGet the encoder inversion stateOptional<org.wpilib.math.trajectory.ExponentialProfile.Constraints> Get the exponential profile for the closed loop controller onSmartMotorController.Get the external encoder.Optional<org.wpilib.units.measure.Angle> Get the external encoder discontinuity point.Get the external encoder gearing, default is 1:1 on a MAXPlanetary.Get whether or not the external encoder is inverted.Optional<org.wpilib.units.measure.Angle> Get the zero offset for theSmartMotorControllerOptional<org.wpilib.units.measure.Angle> Get the feedback synchronization threshold.Get the follower motors to theSmartMotorControllerConfigGet the gearing to convert rotor rotations to mechanisms rotations connected to theSmartMotorControllerbooleanIf the closed loop controller is linear orDistancebased.Get the loosely coupled follower motors.Get the controller for theSmartMotorController, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), the outputs are in Volts.Optional<org.wpilib.units.measure.Distance> Get the mechanism to distance ratio for theSmartMotorControllerOptional<org.wpilib.units.measure.Angle> Lower limit of the mechanism.Optional<org.wpilib.units.measure.Angle> Upper limit of the mechanism.doublegetMOI()Get the Moment of Inertia of theSmartMotorController's mechanism for theDCMotorSim.Get the motor controller mode to use.Get the motor inversion stateOptional<org.wpilib.units.measure.Time> Get the open loop ramp rate.Optional<org.wpilib.math.controller.PIDController> Get the simple closed loop controller without motion profiling.booleanReset the old config?Optional<org.wpilib.math.controller.SimpleMotorFeedforward> Get theSimpleMotorFeedforwardOptional.org.wpilib.units.measure.TimeGet the simulation loop period the rate at whichSmartMotorController.simIterate()steps the simulated physics forward.Get the telemetry configurationOptional<org.wpilib.units.measure.Angle> Get the starting mechanism position of theSmartMotorControllerGet the stator stall current limit.Get the supply stall current limit.Telemetry name.Optional<org.wpilib.units.measure.Temperature> Get the temperature cut off for theSmartMotorControllerOptional<org.wpilib.math.trajectory.TrapezoidProfile.Constraints> Get the trapezoidal motion profile for theSmartMotorController.booleanUse the external feedback sensor.booleanVelocity trapezoidal profile configured.Get the vendor specific configuration object to mutate withSmartMotorControllerConfigoptions.Get the vendor specific control request.Get Telemetry verbosity.Optional<org.wpilib.units.measure.Voltage> Get the voltage compensation for theSmartMotorControllerGet the zero power mode for theSmartMotorControllervoidReset the validation checks for all required options to be applied toSmartMotorControllerfromSmartMotorController.applyConfig(SmartMotorControllerConfig).protected abstract Tself()Get this config as its concrete type, so chainedwithcalls keep the subclass type.voidSetup live tuning for theSmartMotorControllervoidValidate all required options are at least fetched and handled in eachSmartMotorControllerwrapper.voidValidate external encoder config options for the config.withCascadingElevatorStages(int stages) Change theSmartMotorControllerConfiggear ratio to be divided by the number of stages given, will reapply it if already done manually.withClosedLoopController(double kP, double kI, double kD) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if linear closed loop controller is configured), the outputs are in Volts.withClosedLoopController(double kP, double kI, double kD, SmartMotorController.ClosedLoopControllerSlot slot) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if linear closed loop controller is configured), the outputs are in Volts.withClosedLoopController(org.wpilib.math.controller.PIDController controller) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if linear closed loop controller is configured), the outputs are in Volts.withClosedLoopController(org.wpilib.math.controller.PIDController controller, SmartMotorController.ClosedLoopControllerSlot slot) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if linear closed loop controller is configured), the outputs are in Volts.withClosedLoopController(LQRController controller) Set the closed loop controller for theSmartMotorControllerwith an exponential profile, the units passed in are in Rotations (or Meters if linear closed loop controller configured), outputs are in Volts.withClosedLoopControllerMaximumVoltage(org.wpilib.units.measure.Voltage volts) Set the closed loop maximum voltage output.withClosedLoopControlPeriod(org.wpilib.units.measure.Frequency time) Modify the period of the PID controller for the motor controller.withClosedLoopControlPeriod(org.wpilib.units.measure.Time time) Modify the period of the PID controller for the motor controller.withClosedLoopRampRate(org.wpilib.units.measure.Time rate) Set the closed loop ramp rate.withClosedLoopTolerance(org.wpilib.units.measure.Angle tolerance) Set the closed loop tolerance of the mechanism controller.withClosedLoopTolerance(org.wpilib.units.measure.Distance tolerance) Set theSmartMotorControllerclosed loop controller tolerance via distance.withContinuousWrapping(org.wpilib.units.measure.Angle bottom, org.wpilib.units.measure.Angle top) Set continuous wrapping for theSmartMotorControllerwithControlMode(ControlMode controlMode) Set the control mode for theSmartMotorControllerwithDrumRadius(org.wpilib.units.measure.Distance radius) Set theElevatordrum radiuswithDrumRadius(org.wpilib.units.measure.Distance chainPitch, int teeth) Set theElevatordrum radius via the chain pitch (.25in or .35in) and teeth count.withEncoderInverted(boolean inverted) Set the encoder inversion state.withExponentialProfile(org.wpilib.math.trajectory.ExponentialProfile.Constraints constraints) Set the exponential profile for theSmartMotorController.withExponentialProfile(org.wpilib.units.measure.Voltage maxVolts, org.wpilib.math.system.DCMotor motor, org.wpilib.units.measure.Mass mass, org.wpilib.units.measure.Distance drumRadius) Get theExponentialProfile.Constraintsfor an elevator.withExponentialProfile(org.wpilib.units.measure.Voltage maxVolts, org.wpilib.math.system.DCMotor motor, org.wpilib.units.measure.MomentOfInertia moi) Get theExponentialProfile.Constraintsfor an arm or flywheel.withExponentialProfile(org.wpilib.units.measure.Voltage maxVolts, org.wpilib.units.measure.AngularVelocity maxVelocity, org.wpilib.units.measure.AngularAcceleration maxAcceleration) Create a generic constraints object.withExternalEncoder(Object externalEncoder) Set the external encoder which is attached to the motor type sent used bySmartMotorControllerwithExternalEncoderDiscontinuityPoint(org.wpilib.units.measure.Angle discontinuityPoint) Set the external encoder absolute position to wrap around a defined discontinuity point.withExternalEncoderGearing(double reductionRatio) Set the external encoder gearing.withExternalEncoderGearing(MechanismGearing externalEncoderGearing) Set the external encoder gearing.withExternalEncoderInverted(boolean externalEncoderInverted) Set the external encoder inversion state.withExternalEncoderZeroOffset(org.wpilib.units.measure.Angle angle) Set the zero offset of theSmartMotorController's external Encoder.withExternalEncoderZeroOffset(org.wpilib.units.measure.Distance distance) Set the zero offset of theSmartMotorController's external Encoder.withFeedbackSynchronizationThreshold(org.wpilib.units.measure.Angle angle) Set the feedback synchronization threshold so the relative encoder synchronizes with the absolute encoder at this point.withFeedforward(org.wpilib.math.controller.ArmFeedforward armFeedforward) Configure theArmFeedforwardfor theSmartMotorController, units are in Rotations: kS and kG in volts, kV in volts per rotation per second and kA in volts per rotation per second squared.withFeedforward(org.wpilib.math.controller.ArmFeedforward armFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) Configure theArmFeedforwardfor theSmartMotorController, units are in Rotations: kS and kG in volts, kV in volts per rotation per second and kA in volts per rotation per second squared.withFeedforward(org.wpilib.math.controller.ElevatorFeedforward elevatorFeedforward) ConfigureElevatorFeedforwardfor theSmartMotorControllerwithFeedforward(org.wpilib.math.controller.ElevatorFeedforward elevatorFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) ConfigureElevatorFeedforwardfor theSmartMotorControllerwithFeedforward(org.wpilib.math.controller.SimpleMotorFeedforward simpleFeedforward) Set theSimpleMotorFeedforwardforSmartMotorController, units are in RotationswithFeedforward(org.wpilib.math.controller.SimpleMotorFeedforward simpleFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) Set theSimpleMotorFeedforwardforSmartMotorController, units are in Rotationsfinal TwithFollowers(org.wpilib.util.Pair<Object, Boolean>... followers) Set the follower motors of theSmartMotorControllerwithGearing(double reductionRatio) Set theMechanismGearingfor theSmartMotorController.withGearing(MechanismGearing gear) Set theMechanismGearingfor theSmartMotorController.withInputCurrentLimit(org.wpilib.units.measure.Current supplyCurrent) Set the stall supply current limit for theSmartMotorControllerwithLinearClosedLoopController(boolean linearClosedLoopController) Set the closed loop controller to be Linear orDistancebased.final TwithLooselyCoupledFollowers(SmartMotorController... followers) Applies loosely coupled follower motors to theSmartMotorController.withMechanismCircumference(org.wpilib.units.measure.Distance circumference) Set the mechanism circumference to allow distance calculations on theSmartMotorController.withMomentOfInertia(org.wpilib.units.measure.Distance length, org.wpilib.units.measure.Mass weight) Add the mechanism moment of inertia to theSmartMotorControllers simulation when not run under a formal mechanism.withMomentOfInertia(org.wpilib.units.measure.MomentOfInertia MOI) Add the mechanism moment of inertia to theSmartMotorControllers simulation when not run under a formal mechanism.withMotorInverted(boolean motorInverted) Set the motor inversion state.withOpenLoopRampRate(org.wpilib.units.measure.Time rate) Set the open loop ramp rate.withOutputCurrentLimit(org.wpilib.units.measure.Current stallCurrent) Set the stall stator current limit for theSmartMotorControllerwithProfile(org.wpilib.math.trajectory.ExponentialProfile.Constraints profile) Set the exponential profilewithProfile(org.wpilib.math.trajectory.TrapezoidProfile.Constraints profile) Set the trapezoidal motion profile for theSmartMotorController.withResetPreviousConfig(boolean resetPreviousConfig) Set theSmartMotorControllerto reset the old configurations and only apply what is given toSmartMotorControllerConfigwithSimClosedLoopController(double kP, double kI, double kD) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured).withSimClosedLoopController(double kP, double kI, double kD, SmartMotorController.ClosedLoopControllerSlot slot) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured).withSimClosedLoopController(org.wpilib.math.controller.PIDController controller) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured).withSimClosedLoopController(org.wpilib.math.controller.PIDController controller, SmartMotorController.ClosedLoopControllerSlot slot) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured).withSimClosedLoopController(LQRController controller) Set the closed loop controller for theSmartMotorController.withSimFeedforward(org.wpilib.math.controller.ArmFeedforward armFeedforward) Configure theArmFeedforwardfor theSmartMotorController, units are in Rotations: kS and kG in volts, kV in volts per rotation per second and kA in volts per rotation per second squared.withSimFeedforward(org.wpilib.math.controller.ArmFeedforward armFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) Configure theArmFeedforwardfor theSmartMotorController, units are in Rotations: kS and kG in volts, kV in volts per rotation per second and kA in volts per rotation per second squared.withSimFeedforward(org.wpilib.math.controller.ElevatorFeedforward elevatorFeedforward) ConfigureElevatorFeedforwardfor theSmartMotorControllerwithSimFeedforward(org.wpilib.math.controller.ElevatorFeedforward elevatorFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) ConfigureElevatorFeedforwardfor theSmartMotorControllerwithSimFeedforward(org.wpilib.math.controller.SimpleMotorFeedforward simpleFeedforward) Set theSimpleMotorFeedforwardforSmartMotorController, units are in Rotations.withSimFeedforward(org.wpilib.math.controller.SimpleMotorFeedforward simpleFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) Set theSimpleMotorFeedforwardforSmartMotorController, units are in Rotations.withSimStartingPosition(org.wpilib.units.measure.Angle simStartingAngle) Set the starting angle of theSmartMotorControllerto be used only in simulationwithSimStartingPosition(org.wpilib.units.measure.Distance simStartingAngle) Set the starting angle of theSmartMotorControllerto be used only in simulationwithSimulationPeriod(org.wpilib.units.measure.Time time) Set the simulation loop period the rate at whichSmartMotorController.simIterate()steps the simulated physics forward.withSoftLimits(org.wpilib.units.measure.Angle low, org.wpilib.units.measure.Angle high) Set the angle soft limits.withSoftLimits(org.wpilib.units.measure.Distance low, org.wpilib.units.measure.Distance high) Set the distance soft limits.withStartingPosition(org.wpilib.units.measure.Angle startingAngle) Set the starting angle of theSmartMotorControllerwithStartingPosition(org.wpilib.units.measure.Distance startingAngle) Set the starting angle of theSmartMotorControllerwithStatorCurrentLimit(org.wpilib.units.measure.Current stallCurrent) Set the stall stator current limit for theSmartMotorControllerwithSupplyCurrentLimit(org.wpilib.units.measure.Current supplyCurrent) Set the stall supply current limit for theSmartMotorControllerwithTelemetry(String telemetryName, TelemetryVerbosity verbosity) Set the telemetry for theSmartMotorControllerwithTelemetry(String telemetryName, SmartMotorControllerTelemetryConfig telemetryConfig) Set the telemetry for theSmartMotorControllerwith aSmartMotorControllerTelemetryConfigwithTelemetry(TelemetryVerbosity verbosity) Set the telemetry for theSmartMotorControllerwithTemperatureCutoff(org.wpilib.units.measure.Temperature cutoff) Set theTemperaturecut off for theSmartMotorController/withTrapezoidalProfile(org.wpilib.units.measure.AngularAcceleration maxAccel, org.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> maxJerk) Set the angular velocity trapezoidal profile for theSmartMotorController.withTrapezoidalProfile(org.wpilib.units.measure.AngularVelocity maxVel, org.wpilib.units.measure.AngularAcceleration maxAccel) Set the angular trapezoidal motion profile for theSmartMotorController.withTrapezoidalProfile(org.wpilib.units.measure.LinearAcceleration maxAccel, org.wpilib.units.measure.Velocity<org.wpilib.units.LinearAccelerationUnit> maxJerk) Set the linear velocity trapezoidal profile for theSmartMotorController.withTrapezoidalProfile(org.wpilib.units.measure.LinearVelocity maxVel, org.wpilib.units.measure.LinearAcceleration maxAccel) Set the linear trapezoidal motion profile for theSmartMotorController.withTrapezoidalProfileConstraints(org.wpilib.math.trajectory.TrapezoidProfile.Constraints constraints) Replace the trapezoidal profile's constraints, keeping how the profile is used (position or velocity, rotational or linear).withUseExternalFeedbackEncoder(boolean useExternalEncoder) Set the external encoder to be the primary feedback device for the PID controller.withVelocityTrapezoidalProfile(boolean velocityTrapezoidalProfile) Set the trapezoidal profile to be read explicitly as a velocity profile.withVendorConfig(Object vendorConfig) Set the vendor specific config for theSmartMotorControllerwhich will be used as a base.withVendorControlRequest(Object vendorControlRequest) Set the vendor specific control request for theSmartMotorControllerwhich will be used in place of default or calculated ones.withVoltageCompensation(org.wpilib.units.measure.Voltage voltageCompensation) Set the voltage compensation for theSmartMotorControllerwithWheelDiameter(org.wpilib.units.measure.Distance diameter) Set the wheel diameter for the mechanism.withWheelRadius(org.wpilib.units.measure.Distance radius) Set the wheel radius for the mechanism.withZeroPower(MotorMode zeroPower) Set theSmartMotorControllerto brake or coast mode.
-
Constructor Details
-
SmartMotorControllerConfig
protected SmartMotorControllerConfig()Construct theSmartMotorControllerConfig.- Implementation Note:
- Protected so only
SmartMotorControllerConfigcan construct this.
-
SmartMotorControllerConfig
Duplicate the SmartMotorControllerConfig.- Parameters:
cfg- Config to duplicate.
-
-
Method Details
-
self
Get this config as its concrete type, so chainedwithcalls keep the subclass type.- Returns:
- this
SmartMotorControllerConfig.
-
clone
-
withVendorConfig
Set the vendor specific config for theSmartMotorControllerwhich will be used as a base. Vendor configs will be overridden by theSmartMotorControllerConfigoptions.- Parameters:
vendorConfig- Vendor specific config object. Must be of the correct type for theSmartMotorController. Only the root configuration class is accepted.- Returns:
SmartMotorControllerConfigfor chaining.- Implementation Requirements:
SmartMotorControllerConfigoptions will always take precedence and overwrite the vendor config. Apply any changes after theSmartMotorControlleris created to ensure accuracy.
-
attachController
Attach theSmartMotorControllerthis config was applied to, so command-layer helpers (e.g. live tuning) can reach back into it without core depending on any command framework types.- Parameters:
controller-SmartMotorControllerthis config configured.
-
getAttachedController
Get theSmartMotorControllerthis config was attached to viaattachController(SmartMotorController), if any.- Returns:
Optionalof the attachedSmartMotorController.
-
withExternalEncoderInverted
Set the external encoder inversion state.- Parameters:
externalEncoderInverted- External encoder inversion state.- Returns:
SmartMotorControllerConfigfor chaining.- Implementation Note:
- This may mean the zero offset you gather should be negated.
-
withControlMode
Set the control mode for theSmartMotorController- Parameters:
controlMode-ControlModeto apply.- Returns:
SmartMotorControllerConfigfor chaining.
-
withFeedbackSynchronizationThreshold
Set the feedback synchronization threshold so the relative encoder synchronizes with the absolute encoder at this point.- Parameters:
angle-Angleto exceed.- Returns:
SmartMotorControllerConfigfor chaining.- Throws:
SmartMotorControllerConfigurationException- if a mechanism circumference is configured, since auto-synchronization is unavailable for distance based mechanisms.
-
withClosedLoopControllerMaximumVoltage
Set the closed loop maximum voltage output.- Parameters:
volts- Maximum voltage.- Returns:
SmartMotorControllerConfigfor chaining.
-
withStartingPosition
Set the starting angle of theSmartMotorController- Parameters:
startingAngle- Starting Mechanism Angle.- Returns:
SmartMotorControllerConfigfor chaining.
-
withStartingPosition
Set the starting angle of theSmartMotorController- Parameters:
startingAngle- Starting Mechanism Distance.- Returns:
SmartMotorControllerConfigfor chaining.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
withSimStartingPosition
Set the starting angle of theSmartMotorControllerto be used only in simulation- Parameters:
simStartingAngle- Starting Mechanism Angle.- Returns:
SmartMotorControllerConfigfor chaining.
-
withSimStartingPosition
Set the starting angle of theSmartMotorControllerto be used only in simulation- Parameters:
simStartingAngle- Starting Mechanism Distance.- Returns:
SmartMotorControllerConfigfor chaining.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
withUseExternalFeedbackEncoder
Set the external encoder to be the primary feedback device for the PID controller.- Parameters:
useExternalEncoder- External encoder as primary feedback device for the PID controller.- Returns:
SmartMotorControllerConfigfor chaining
-
withEncoderInverted
Set the encoder inversion state.- Parameters:
inverted- Encoder inversion state.- Returns:
SmartMotorControllerConfigfor chaining.
-
withMotorInverted
Set the motor inversion state.- Parameters:
motorInverted- Motor inversion state.- Returns:
SmartMotorControllerConfigfor chaining.
-
withResetPreviousConfig
Set theSmartMotorControllerto reset the old configurations and only apply what is given toSmartMotorControllerConfig- Parameters:
resetPreviousConfig- Reset the old config?- Returns:
SmartMotorControllerConfigfor chaining.
-
withTemperatureCutoff
Set theTemperaturecut off for theSmartMotorController/- Parameters:
cutoff- maximumTemperature- Returns:
SmartMotorControllerConfigfor chaining.
-
withExternalEncoderZeroOffset
Set the zero offset of theSmartMotorController's external Encoder.- Parameters:
distance- Zero offset in distance.- Returns:
SmartMotorControllerConfigfor chaining.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
withExternalEncoderDiscontinuityPoint
Set the external encoder absolute position to wrap around a defined discontinuity point.- Parameters:
discontinuityPoint- Discontinuity point of the external encoder, when provided 0.5rot the external encoder will read between [-0.5, 0.5]; when provided 1rot the external encoder will read between [0, 1].- Returns:
SmartMotorControllerConfigfor chaining.- Throws:
SmartMotorControllerConfigurationException- if the discontinuity point is not equivalent to 0.5 or 1 rotations.- Implementation Note:
- Only works for External Absolute Encoders.
-
withExternalEncoderZeroOffset
Set the zero offset of theSmartMotorController's external Encoder.- Parameters:
angle-Angleto 0.- Returns:
SmartMotorControllerConfigfor chaining.
-
withContinuousWrapping
public T withContinuousWrapping(org.wpilib.units.measure.Angle bottom, org.wpilib.units.measure.Angle top) Set continuous wrapping for theSmartMotorController- Parameters:
bottom- Bottom value to wrap to.top- Top value to wrap to.- Returns:
SmartMotorControllerConfigfor chaining.- Throws:
SmartMotorControllerConfigurationException- if soft limits are already configured.SmartMotorControllerConfigurationException- if a linear (distance based) closed loop controller is in use.SmartMotorControllerConfigurationException- if no closed loop controller is configured.
-
withClosedLoopTolerance
Set the closed loop tolerance of the mechanism controller.- Parameters:
tolerance- Closed loop controller tolerance- Returns:
SmartMotorControllerConfigfor chaining.- Throws:
SmartMotorControllerConfigurationException- if the tolerance is not null and no closed loop controller is configured.
-
withClosedLoopTolerance
Set theSmartMotorControllerclosed loop controller tolerance via distance.- Parameters:
tolerance-Distancetolerance.- Returns:
SmartMotorControllerConfigfor chaining.- Throws:
SmartMotorControllerConfigurationException- if a linear closed loop controller is not in use.SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.SmartMotorControllerConfigurationException- if the tolerance is not null and no closed loop controller is configured.
-
getClosedLoopTolerance
Get theSmartMotorControllerclosed loop controller tolerance.- Returns:
Angletolerance.
-
withTelemetry
Set the telemetry for theSmartMotorController- Parameters:
telemetryName- Name for theSmartMotorControllerverbosity- Verbosity of the Telemetry for theSmartMotorController- Returns:
SmartMotorControllerConfigfor chaining.
-
withTelemetry
Set the telemetry for theSmartMotorController- Parameters:
verbosity- Verbosity of the Telemetry for theSmartMotorController- Returns:
SmartMotorControllerConfigfor chaining.
-
withTelemetry
Set the telemetry for theSmartMotorControllerwith aSmartMotorControllerTelemetryConfig- Parameters:
telemetryName- Name for theSmartMotorControllertelemetryConfig- Config that specifies what to log.- Returns:
SmartMotorControllerConfigfor chaining.
-
getSmartControllerTelemetryConfig
Get the telemetry configuration- Returns:
- Telemetry configuration.
-
getStatorStallCurrentLimit
Get the stator stall current limit.- Returns:
- Stator current limit.
-
withSoftLimits
public T withSoftLimits(org.wpilib.units.measure.Distance low, org.wpilib.units.measure.Distance high) Set the distance soft limits.- Parameters:
low- Low distance soft limit.high- High distance soft limit.- Returns:
SmartMotorControllerConfigfor chaining.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.SmartMotorControllerConfigurationException- if the converted lower limit is greater than or equal to the upper limit.
-
withMomentOfInertia
public T withMomentOfInertia(org.wpilib.units.measure.Distance length, org.wpilib.units.measure.Mass weight) Add the mechanism moment of inertia to theSmartMotorControllers simulation when not run under a formal mechanism.- Parameters:
length- Length of the mechanism for MOI.weight- Weight of the mechanism for MOI.- Returns:
SmartMotorControllerConfigfor chaining- Throws:
SmartMotorControllerConfigurationException- if the length or weight is null.
-
withMomentOfInertia
Add the mechanism moment of inertia to theSmartMotorControllers simulation when not run under a formal mechanism.- Parameters:
MOI- Known moment of inertia.- Returns:
SmartMotorControllerConfigfor chaining
-
withSoftLimits
Set the angle soft limits.- Parameters:
low- Low angle soft limit.high- High angle soft limit.- Returns:
SmartMotorControllerConfigfor chaining.- Throws:
SmartMotorControllerConfigurationException- if both limits are non-null and the lower limit is greater than or equal to the upper limit.
-
getSupplyStallCurrentLimit
Get the supply stall current limit.- Returns:
- Supply stall current limit.
-
getVoltageCompensation
Get the voltage compensation for theSmartMotorController- Returns:
- Ideal voltage
-
getZeroPower
Get the zero power mode for theSmartMotorController- Returns:
MotorMode
-
getMOI
public double getMOI()Get the Moment of Inertia of theSmartMotorController's mechanism for theDCMotorSim.- Returns:
- Moment of Inertia in JKgMetersSquared.
-
getMechanismLowerLimit
Lower limit of the mechanism.- Returns:
- Lower angle soft limit.
-
getMechanismUpperLimit
Upper limit of the mechanism.- Returns:
- Higher angle soft limit.
-
withZeroPower
Set theSmartMotorControllerto brake or coast mode.- Parameters:
zeroPower-MotorModezero power mode- Returns:
SmartMotorControllerConfigfor chaining.
-
withVoltageCompensation
Set the voltage compensation for theSmartMotorController- Parameters:
voltageCompensation- Ideal voltage value.- Returns:
SmartMotorControllerConfigfor chaining.
-
withFollowers
Set the follower motors of theSmartMotorController- Parameters:
followers- Base motor types (NOTSmartMotorController!) to configure as followers, must be same brand as theSmartMotorControllerwith inversion from the base motor.- Returns:
SmartMotorControllerConfigfor chaining
-
withLooselyCoupledFollowers
Applies loosely coupled follower motors to theSmartMotorController.- Parameters:
followers-SmartMotorControllers to configure as followers.- Returns:
SmartMotorControllerConfigfor chaining- Implementation Requirements:
- Configurations are not transferred!
- Implementation Note:
- ONLY the position and velocity requests will be forwarded.
-
clearFollowers
public void clearFollowers()Clear the follower motors so they are not reapplied -
withStatorCurrentLimit
Set the stall stator current limit for theSmartMotorController- Parameters:
stallCurrent- Stall stator current limit for theSmartMotorController.- Returns:
SmartMotorControllerConfigfor chaining.
-
withOutputCurrentLimit
Set the stall stator current limit for theSmartMotorController- Parameters:
stallCurrent- Stall stator current limit for theSmartMotorController.- Returns:
SmartMotorControllerConfigfor chaining.
-
withSupplyCurrentLimit
Set the stall supply current limit for theSmartMotorController- Parameters:
supplyCurrent- Supply current limit.- Returns:
SmartMotorControllerConfigfor chaining.
-
withInputCurrentLimit
Set the stall supply current limit for theSmartMotorController- Parameters:
supplyCurrent- Supply current limit.- Returns:
SmartMotorControllerConfigfor chaining.
-
withClosedLoopRampRate
Set the closed loop ramp rate. The ramp rate is the minimum time it should take to go from 0 power to full power in the motor controller while using PID.- Parameters:
rate- time to go from 0 to full throttle.- Returns:
SmartMotorControllerConfigfor chaining.
-
withOpenLoopRampRate
Set the open loop ramp rate. The ramp rate is the minimum time it should take to go from 0 power to full power in the motor controller while not using PID.- Parameters:
rate- time to go from 0 to full throttle.- Returns:
SmartMotorControllerConfigfor chaining.
-
withExternalEncoder
Set the external encoder which is attached to the motor type sent used bySmartMotorControllerSupported external encoders:
- SPARK MAX and SPARK Flex: the SPARK's absolute encoder, the SPARK MAX's alternate encoder or
the SPARK Flex's external encoder (quadrature, whose counts per revolution come from the
vendor config), or an encoder the SPARK reads over CAN (a REVLib
DetachedEncoder). - TalonFX and TalonFXS: a CANcoder, or a CANdi whose PWM input is selected by the feedback sensor source of the vendor config.
- Parameters:
externalEncoder- External encoder attached to theSmartMotorController- Returns:
SmartMotorControllerConfigfor chaining.
- SPARK MAX and SPARK Flex: the SPARK's absolute encoder, the SPARK MAX's alternate encoder or
the SPARK Flex's external encoder (quadrature, whose counts per revolution come from the
vendor config), or an encoder the SPARK reads over CAN (a REVLib
-
getFollowers
Get the follower motors to theSmartMotorControllerConfig- Returns:
- Follower motor list.
-
withGearing
Set theMechanismGearingfor theSmartMotorController.- Parameters:
gear-MechanismGearingrepresenting the gearbox and sprockets to the final axis.- Returns:
SmartMotorControllerConfigfor chaining.
-
withGearing
Set theMechanismGearingfor theSmartMotorController.- Parameters:
reductionRatio- Reduction ratio, for example, a ratio of "3:1" is 3; a ratio of "1:2" is 0.5.- Returns:
SmartMotorControllerConfigfor chaining.
-
withMechanismCircumference
Set the mechanism circumference to allow distance calculations on theSmartMotorController.- Parameters:
circumference- Circumference of the actuating spool or sprocket+chain attached the mechanism actuator.- Returns:
SmartMotorControllerConfigfor chaining.
-
withWheelRadius
Set the wheel radius for the mechanism.- Parameters:
radius- Radius of the wheels asDistance- Returns:
SmartMotorControllerConfigfor chaining.
-
withDrumRadius
Set theElevatordrum radius- Parameters:
radius- Drum radius of elevator spool.- Returns:
SmartMotorControllerConfigfor chaining- Implementation Note:
- Overload for
withWheelRadius(Distance)
-
withDrumRadius
Set theElevatordrum radius via the chain pitch (.25in or .35in) and teeth count.- Parameters:
chainPitch- Chain pitch.teeth- Sprocket teeth count.- Returns:
SmartMotorControllerConfigfor chaining.- Implementation Note:
- Overload for
withWheelRadius(Distance)
-
withCascadingElevatorStages
Change theSmartMotorControllerConfiggear ratio to be divided by the number of stages given, will reapply it if already done manually.- Parameters:
stages- Stages given- Returns:
SmartMotorControllerConfigfor chaining.- Implementation Note:
- Alias for
withGearing(MechanismGearing)whereMechanismGearing.div(double)is applied via the stages.
-
withWheelDiameter
Set the wheel diameter for the mechanism.- Parameters:
diameter- Diameter of the wheels asDistance- Returns:
SmartMotorControllerConfigfor chaining.
-
getMechanismCircumference
Get the mechanism to distance ratio for theSmartMotorController- Returns:
- Rotations/Distance ratio to convert mechanism rotations to distance.
-
getLinearClosedLoopControllerUse
public boolean getLinearClosedLoopControllerUse()If the closed loop controller is linear orDistancebased.- Returns:
- Linear closed loop controller.
-
withClosedLoopControlPeriod
Modify the period of the PID controller for the motor controller.- Parameters:
time- Period of the motor controller PID.- Returns:
SmartMotorControllerConfigfor chaining.
-
withClosedLoopControlPeriod
Modify the period of the PID controller for the motor controller.- Parameters:
time- Period of the motor controller PID.- Returns:
SmartMotorControllerConfigfor chaining.
-
withSimulationPeriod
Set the simulation loop period the rate at whichSmartMotorController.simIterate()steps the simulated physics forward. Independent ofwithClosedLoopControlPeriod(Time); a robot can run its periodic loop at 20ms while stepping simulation physics at 5ms, for example. Defaults to 20ms if not set.- Parameters:
time- Simulation loop period.- Returns:
SmartMotorControllerConfigfor chaining.
-
getSimulationPeriod
public org.wpilib.units.measure.Time getSimulationPeriod()Get the simulation loop period the rate at whichSmartMotorController.simIterate()steps the simulated physics forward. Defaults to 20ms if not set viawithSimulationPeriod(Time).- Returns:
- Simulation loop period.
-
getArmFeedforward
public Optional<org.wpilib.math.controller.ArmFeedforward> getArmFeedforward(SmartMotorController.ClosedLoopControllerSlot slot) Get theArmFeedforwardif it is set.- Parameters:
slot-SmartMotorController.ClosedLoopControllerSlotfor theArmFeedforward.- Returns:
Optionalof theArmFeedforward.
-
withSimFeedforward
public T withSimFeedforward(org.wpilib.math.controller.ArmFeedforward armFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) Configure theArmFeedforwardfor theSmartMotorController, units are in Rotations: kS and kG in volts, kV in volts per rotation per second and kA in volts per rotation per second squared.- Parameters:
armFeedforward- Arm feedforward for theSmartMotorControllerslot-SmartMotorController.ClosedLoopControllerSlotfor theArmFeedforward.- Returns:
SmartMotorControllerConfigfor chaining.
-
withSimFeedforward
Configure theArmFeedforwardfor theSmartMotorController, units are in Rotations: kS and kG in volts, kV in volts per rotation per second and kA in volts per rotation per second squared.- Parameters:
armFeedforward- Arm feedforward for theSmartMotorController- Returns:
SmartMotorControllerConfigfor chaining.
-
withFeedforward
public T withFeedforward(org.wpilib.math.controller.ArmFeedforward armFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) Configure theArmFeedforwardfor theSmartMotorController, units are in Rotations: kS and kG in volts, kV in volts per rotation per second and kA in volts per rotation per second squared.- Parameters:
armFeedforward- Arm feedforward for theSmartMotorControllerslot-SmartMotorController.ClosedLoopControllerSlotfor theArmFeedforward.- Returns:
SmartMotorControllerConfigfor chaining.
-
withFeedforward
Configure theArmFeedforwardfor theSmartMotorController, units are in Rotations: kS and kG in volts, kV in volts per rotation per second and kA in volts per rotation per second squared.- Parameters:
armFeedforward- Arm feedforward for theSmartMotorController- Returns:
SmartMotorControllerConfigfor chaining.
-
getElevatorFeedforward
public Optional<org.wpilib.math.controller.ElevatorFeedforward> getElevatorFeedforward(SmartMotorController.ClosedLoopControllerSlot slot) Get theElevatorFeedforwardOptional- Parameters:
slot-SmartMotorController.ClosedLoopControllerSlotfor theElevatorFeedforward.- Returns:
ElevatorFeedforwardOptional
-
withSimFeedforward
public T withSimFeedforward(org.wpilib.math.controller.ElevatorFeedforward elevatorFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) ConfigureElevatorFeedforwardfor theSmartMotorController- Parameters:
elevatorFeedforward-ElevatorFeedforwardto set.slot-SmartMotorController.ClosedLoopControllerSlotfor theElevatorFeedforward.- Returns:
SmartMotorControllerConfigfor chaining.
-
withSimFeedforward
ConfigureElevatorFeedforwardfor theSmartMotorController- Parameters:
elevatorFeedforward-ElevatorFeedforwardto set.- Returns:
SmartMotorControllerConfigfor chaining.
-
withFeedforward
public T withFeedforward(org.wpilib.math.controller.ElevatorFeedforward elevatorFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) ConfigureElevatorFeedforwardfor theSmartMotorController- Parameters:
elevatorFeedforward-ElevatorFeedforwardto set.slot-SmartMotorController.ClosedLoopControllerSlotfor theElevatorFeedforward.- Returns:
SmartMotorControllerConfigfor chaining.
-
withFeedforward
ConfigureElevatorFeedforwardfor theSmartMotorController- Parameters:
elevatorFeedforward-ElevatorFeedforwardto set.- Returns:
SmartMotorControllerConfigfor chaining.
-
getSimpleFeedforward
public Optional<org.wpilib.math.controller.SimpleMotorFeedforward> getSimpleFeedforward(SmartMotorController.ClosedLoopControllerSlot slot) Get theSimpleMotorFeedforwardOptional.- Parameters:
slot-SmartMotorController.ClosedLoopControllerSlotfor theSimpleMotorFeedforward.- Returns:
SimpleMotorFeedforwardOptional
-
withSimClosedLoopController
Set the closed loop controller for theSmartMotorController. The units passed in are in Rotations (or Meters if Mechanism Circumference is configured), and outputs are in Volts.- Parameters:
controller-LQRControllerto use, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), and output is Voltage.- Returns:
SmartMotorControllerConfigfor chaining.
-
withSimClosedLoopController
public T withSimClosedLoopController(double kP, double kI, double kD, SmartMotorController.ClosedLoopControllerSlot slot) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured).- Parameters:
kP- KP scalar for the PID Controller.kI- KI scalar for the PID Controller.kD- KD scalar for the PID Controller.slot- Closed loop controller slot.- Returns:
SmartMotorControllerConfigfor chaining.
-
withSimClosedLoopController
Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured).- Parameters:
kP- KP scalar for the PID Controller.kI- KI scalar for the PID Controller.kD- KD scalar for the PID Controller.- Returns:
SmartMotorControllerConfigfor chaining.
-
withSimClosedLoopController
public T withSimClosedLoopController(org.wpilib.math.controller.PIDController controller, SmartMotorController.ClosedLoopControllerSlot slot) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured).- Parameters:
controller-PIDControllerto use.slot- Closed loop controller slot.- Returns:
SmartMotorControllerConfigfor chaining.
-
withSimClosedLoopController
Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured).- Parameters:
controller-PIDControllerto use.- Returns:
SmartMotorControllerConfigfor chaining.
-
withProfile
Set the trapezoidal motion profile for theSmartMotorController.- Parameters:
profile-TrapezoidProfile; if linear use meters/s, meters/s^2; if rotational use rotations/s, rotations/s^2.- Returns:
SmartMotorControllerConfigfor chaining.
-
withTrapezoidalProfile
public T withTrapezoidalProfile(org.wpilib.units.measure.LinearVelocity maxVel, org.wpilib.units.measure.LinearAcceleration maxAccel) Set the linear trapezoidal motion profile for theSmartMotorController.- Parameters:
maxVel- Max velocity for the profile.maxAccel- Max acceleration for the profile.- Returns:
SmartMotorControllerConfigfor chaining.
-
withTrapezoidalProfile
public T withTrapezoidalProfile(org.wpilib.units.measure.AngularVelocity maxVel, org.wpilib.units.measure.AngularAcceleration maxAccel) Set the angular trapezoidal motion profile for theSmartMotorController.- Parameters:
maxVel- Max velocity for the profile.maxAccel- Max acceleration for the profile.- Returns:
SmartMotorControllerConfigfor chaining.
-
withTrapezoidalProfile
public T withTrapezoidalProfile(org.wpilib.units.measure.AngularAcceleration maxAccel, org.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> maxJerk) Set the angular velocity trapezoidal profile for theSmartMotorController.- Parameters:
maxAccel- Max acceleration for the profile.maxJerk- Max velocity for the profile.- Returns:
SmartMotorControllerConfigfor chaining.
-
withTrapezoidalProfile
public T withTrapezoidalProfile(org.wpilib.units.measure.LinearAcceleration maxAccel, org.wpilib.units.measure.Velocity<org.wpilib.units.LinearAccelerationUnit> maxJerk) Set the linear velocity trapezoidal profile for theSmartMotorController.- Parameters:
maxAccel- Max acceleration for the profile.maxJerk- Max velocity for the profile.- Returns:
SmartMotorControllerConfigfor chaining.
-
withProfile
Set the exponential profile- Parameters:
profile- Exponential profile; meters/s, meters/s^2 for linear controllers; rotations/s, and rotations/s^2 for rotational controllers..- Returns:
SmartMotorControllerConfigfor chaining.
-
withExponentialProfile
public T withExponentialProfile(org.wpilib.units.measure.Voltage maxVolts, org.wpilib.math.system.DCMotor motor, org.wpilib.units.measure.MomentOfInertia moi) Get theExponentialProfile.Constraintsfor an arm or flywheel.- Parameters:
maxVolts- Maximum input voltage for profile generation.motor-DCMotorof the arm.moi-MomentOfInertiaof the arm.- Returns:
SmartMotorControllerConfigfor chaining.
-
withExponentialProfile
public T withExponentialProfile(org.wpilib.units.measure.Voltage maxVolts, org.wpilib.math.system.DCMotor motor, org.wpilib.units.measure.Mass mass, org.wpilib.units.measure.Distance drumRadius) Get theExponentialProfile.Constraintsfor an elevator.- Parameters:
maxVolts- Maximum input voltage for profile generation.motor-DCMotorof the elevator.mass-Massof the elevator carriage.drumRadius-Distanceof the elevator drum radius.- Returns:
SmartMotorControllerConfigfor chaining.
-
withExponentialProfile
public T withExponentialProfile(org.wpilib.units.measure.Voltage maxVolts, org.wpilib.units.measure.AngularVelocity maxVelocity, org.wpilib.units.measure.AngularAcceleration maxAcceleration) Create a generic constraints object.- Parameters:
maxVolts- Maximum input voltage for profile generation.maxVelocity- Maximum velocity.maxAcceleration- Maximum acceleration.- Returns:
SmartMotorControllerConfigfor chaining.
-
withTrapezoidalProfileConstraints
public T withTrapezoidalProfileConstraints(org.wpilib.math.trajectory.TrapezoidProfile.Constraints constraints) Replace the trapezoidal profile's constraints, keeping how the profile is used (position or velocity, rotational or linear). Used by live tuning, so that tuning one constraint keeps the others that were tuned before.- Parameters:
constraints- Constraints in the profile's units: rotations or meters, per second, or per second squared for a velocity profile.- Returns:
SmartMotorControllerConfigfor chaining.
-
withExponentialProfile
public T withExponentialProfile(org.wpilib.math.trajectory.ExponentialProfile.Constraints constraints) Set the exponential profile for theSmartMotorController.- Parameters:
constraints-ExponentialProfile.Constraintsfor the profile.- Returns:
SmartMotorControllerConfigfor chaining.
-
withClosedLoopController
Set the closed loop controller for theSmartMotorControllerwith an exponential profile, the units passed in are in Rotations (or Meters if linear closed loop controller configured), outputs are in Volts.- Parameters:
controller-LQRControllerto use, the units passed in are in Rotations and output is Voltage.- Returns:
SmartMotorControllerConfigfor chaining.- Implementation Note:
- This clears all PIDs.
-
withClosedLoopController
public T withClosedLoopController(double kP, double kI, double kD, SmartMotorController.ClosedLoopControllerSlot slot) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if linear closed loop controller is configured), the outputs are in Volts.- Parameters:
kP- KP scalar for the PID Controller, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), the outputs are in Volts.kI- KI scalar for the PID Controller, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), the outputs are in Volts.kD- KD scalar for the PID Controller, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), the outputs are in Volts.slot- Closed loop controller slot.- Returns:
SmartMotorControllerConfigfor chaining.
-
withClosedLoopController
Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if linear closed loop controller is configured), the outputs are in Volts.- Parameters:
kP- KP scalar for the PID Controller, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), the outputs are in Volts.kI- KI scalar for the PID Controller, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), the outputs are in Volts.kD- KD scalar for the PID Controller, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), the outputs are in Volts.- Returns:
SmartMotorControllerConfigfor chaining.
-
withClosedLoopController
public T withClosedLoopController(org.wpilib.math.controller.PIDController controller, SmartMotorController.ClosedLoopControllerSlot slot) Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if linear closed loop controller is configured), the outputs are in Volts.- Parameters:
controller-PIDControllerto use, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), the outputs are in Volts.slot- Closed loop controller slot.- Returns:
SmartMotorControllerConfigfor chaining.
-
withClosedLoopController
Set the closed loop controller for theSmartMotorController, the units passed in are in Rotations (or Meters if linear closed loop controller is configured), the outputs are in Volts.- Parameters:
controller-PIDControllerto use, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), the outputs are in Volts.- Returns:
SmartMotorControllerConfigfor chaining.
-
getLQRClosedLoopController
Get the controller for theSmartMotorController, the units passed in are in Rotations (or Meters if Mechanism Circumference is configured), the outputs are in Volts.- Returns:
LQRController
-
getPID
public Optional<org.wpilib.math.controller.PIDController> getPID(SmartMotorController.ClosedLoopControllerSlot slot) Get the simple closed loop controller without motion profiling.- Parameters:
slot- Closed loop controller slot.- Returns:
PIDControllerif it exists.
-
getExponentialProfile
Get the exponential profile for the closed loop controller onSmartMotorController.- Returns:
ExponentialProfileif it exists.
-
getTrapezoidProfile
Get the trapezoidal motion profile for theSmartMotorController.- Returns:
TrapezoidProfileif it exists.
-
withSimFeedforward
public T withSimFeedforward(org.wpilib.math.controller.SimpleMotorFeedforward simpleFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) Set theSimpleMotorFeedforwardforSmartMotorController, units are in Rotations.- Parameters:
simpleFeedforward-SimpleMotorFeedforwardslot- Closed loop controller slot.- Returns:
SmartMotorControllerConfigfor chaining.
-
withSimFeedforward
Set theSimpleMotorFeedforwardforSmartMotorController, units are in Rotations.- Parameters:
simpleFeedforward-SimpleMotorFeedforward- Returns:
SmartMotorControllerConfigfor chaining.
-
withLinearClosedLoopController
Set the closed loop controller to be Linear orDistancebased.- Parameters:
linearClosedLoopController- Closed loop controller is distance based when true, angle based when false.- Returns:
SmartMotorControllerConfigfor chaining.
-
withVelocityTrapezoidalProfile
Set the trapezoidal profile to be read explicitly as a velocity profile.- Parameters:
velocityTrapezoidalProfile- The trapezoidal profile is read explicitly as a velocity profile.- Returns:
SmartMotorControllerConfigfor chaining.
-
withFeedforward
public T withFeedforward(org.wpilib.math.controller.SimpleMotorFeedforward simpleFeedforward, SmartMotorController.ClosedLoopControllerSlot slot) Set theSimpleMotorFeedforwardforSmartMotorController, units are in Rotations- Parameters:
simpleFeedforward-SimpleMotorFeedforwardslot- Closed loop controller slot.- Returns:
SmartMotorControllerConfigfor chaining.
-
withFeedforward
Set theSimpleMotorFeedforwardforSmartMotorController, units are in Rotations- Parameters:
simpleFeedforward-SimpleMotorFeedforward- Returns:
SmartMotorControllerConfigfor chaining.
-
getClosedLoopControlPeriod
Get the period of theSmartMotorControllerclosed loop period.- Returns:
SmartMotorControllerclosed loop controller period.
-
getGearing
Get the gearing to convert rotor rotations to mechanisms rotations connected to theSmartMotorController- Returns:
MechanismGearingrepresenting the gearbox and sprockets attached to theSmartMotorController.
-
getExternalEncoder
-
getOpenLoopRampRate
Get the open loop ramp rate.- Returns:
- Open loop ramp rate.
-
getClosedLoopRampRate
Get the closed loop ramp rate.- Returns:
- Closed loop ramp.
-
getVerbosity
Get Telemetry verbosity.- Returns:
- Verbosity for telemetry.
-
getTelemetryName
-
convertToMechanism
public org.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> convertToMechanism(org.wpilib.units.measure.Velocity<org.wpilib.units.LinearAccelerationUnit> jerk) Convertorg.wpilib.units.measure.Velocity<org.wpilib.units.LinearAccelerationUnit>toorg.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit>using themechanismCircumference- Parameters:
jerk- Linear jerk to convert.- Returns:
- Equivalent angular jerk.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
convertFromMechanism
public org.wpilib.units.measure.Velocity<org.wpilib.units.LinearAccelerationUnit> convertFromMechanism(org.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> jerk) Convertorg.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit>toorg.wpilib.units.measure.Velocity<org.wpilib.units.LinearAccelerationUnit>using themechanismCircumference- Parameters:
jerk- Angular jerk to convert.- Returns:
- Equivalent angular jerk.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
convertToMechanism
public org.wpilib.units.measure.AngularVelocity convertToMechanism(org.wpilib.units.measure.LinearVelocity velocity) ConvertLinearVelocitytoAngularVelocityusing themechanismCircumference- Parameters:
velocity- Linear velocity to convert.- Returns:
- Equivalent angular velocity.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
convertToMechanism
public org.wpilib.units.measure.AngularAcceleration convertToMechanism(org.wpilib.units.measure.LinearAcceleration acceleration) ConvertLinearAccelerationtoAngularAccelerationusing themechanismCircumference- Parameters:
acceleration- Linear acceleration to convert.- Returns:
- Equivalent angular acceleration.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
convertToMechanism
public org.wpilib.units.measure.Angle convertToMechanism(org.wpilib.units.measure.Distance distance) ConvertDistancetoAngleusingmechanismCircumference- Parameters:
distance-Distanceto convert toAngle- Returns:
Angleof distance.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
convertFromMechanism
public org.wpilib.units.measure.Distance convertFromMechanism(org.wpilib.units.measure.Angle rotations) ConvertAngletoDistanceusingmechanismCircumference- Parameters:
rotations- Rotations to convert.- Returns:
- Distance of the mechanism.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
convertFromMechanism
public org.wpilib.units.measure.LinearVelocity convertFromMechanism(org.wpilib.units.measure.AngularVelocity velocity) ConvertAngletoLinearVelocityusingmechanismCircumference- Parameters:
velocity- Velocity to convert.- Returns:
- Velocity of the mechanism.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
convertFromMechanism
public org.wpilib.units.measure.LinearAcceleration convertFromMechanism(org.wpilib.units.measure.AngularAcceleration acceleration) ConvertAngletoLinearAccelerationusingmechanismCircumference- Parameters:
acceleration- Rotations to convert.- Returns:
- Acceleration of the mechanism.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
convertToVoltage
public org.wpilib.units.measure.Voltage convertToVoltage(org.wpilib.math.system.DCMotor motor, org.wpilib.units.measure.Force feedforwardForce) Convert a feedforwardForceapplied at the mechanism into the equivalent motor feedforwardVoltage, usinggearingandmechanismCircumference. This is only the voltage that produces the force (the resistive drop of the matching current), not the back-EMF of the commanded speed, since it is added on top of a velocity feedforward that already covers that.- Parameters:
motor-DCMotorof the mechanism.feedforwardForce- FeedforwardForceapplied to the mechanism.- Returns:
- Equivalent feedforward
Voltageat the motor. - Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
convertToCurrent
public org.wpilib.units.measure.Current convertToCurrent(org.wpilib.math.system.DCMotor motor, org.wpilib.units.measure.Force feedforwardForce) Convert a feedforwardForceapplied at the mechanism into the equivalent motor feedforwardCurrent, usinggearingandmechanismCircumference. This is the feedforward to use for torque-current based closed-loop control (e.g. TorqueCurrentFOC).- Parameters:
motor-DCMotorof the mechanism.feedforwardForce- FeedforwardForceapplied to the mechanism.- Returns:
- Equivalent feedforward
Currentat the motor. - Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
getExternalEncoderZeroOffset
Get the zero offset for theSmartMotorController- Returns:
Angleoffset.
-
getTemperatureCutoff
Get the temperature cut off for theSmartMotorController- Returns:
- Maximum
Temperature
-
getEncoderInverted
-
getMotorInverted
-
getUseExternalFeedback
public boolean getUseExternalFeedback()Use the external feedback sensor.- Returns:
- Use the attached absolute encoder.
-
getStartingPosition
Get the starting mechanism position of theSmartMotorController- Returns:
- Starting Mechanism position.
-
getClosedLoopControllerMaximumVoltage
Get the closed loop maximum voltage.- Returns:
- Maximum voltage in Volts.
-
getFeedbackSynchronizationThreshold
Get the feedback synchronization threshold.- Returns:
- Feedback synchronization threshold.
-
getMotorControllerMode
Get the motor controller mode to use.- Returns:
ControlModeto use.
-
getExternalEncoderGearing
Get the external encoder gearing, default is 1:1 on a MAXPlanetary.- Returns:
- External encoder gearing.
-
withExternalEncoderGearing
Set the external encoder gearing.- Parameters:
externalEncoderGearing- External encoder gearing.- Returns:
SmartMotorControllerConfigfor chaining.
-
withExternalEncoderGearing
Set the external encoder gearing.- Parameters:
reductionRatio- External encoder gearing. For example, a ratio of "3:1" is 3; "1:2" is 0.5- Returns:
SmartMotorControllerConfigfor chaining.
-
getContinuousWrapping
Get the continuous wrapping point for theSmartMotorControllerencoder.- Returns:
Anglewhere the encoder wraps around.- Throws:
SmartMotorControllerConfigurationException- if continuous wrapping is configured with bounds that do not span exactly one rotation (minimum is not maximum minus 1 rotation).
-
getContinuousWrappingMin
Get the continuous wrapping point for theSmartMotorControllerencoder.- Returns:
Anglewhere the encoder wraps around.- Throws:
SmartMotorControllerConfigurationException- if continuous wrapping is configured with bounds that do not span exactly one rotation (minimum is not maximum minus 1 rotation).
-
getContinuousWrappingSetpoint
public org.wpilib.units.measure.Angle getContinuousWrappingSetpoint(org.wpilib.units.measure.Angle setpoint, org.wpilib.units.measure.Angle current) Get the position setpoint to command with continuous wrapping: the angle equivalent tosetpoint, a whole number of wrapping ranges away, that is nearestcurrent. For motor controllers whose onboard wrapping cannot be given the mechanism's wrapping range.- Parameters:
setpoint- Mechanism angle to go to.current- Current mechanism angle.- Returns:
- The equivalent setpoint nearest
current, orsetpointunchanged when continuous wrapping is not configured. - Throws:
SmartMotorControllerConfigurationException- if continuous wrapping is configured with bounds that do not span exactly one rotation (minimum is not maximum minus 1 rotation).
-
getLooselyCoupledFollowers
Get the loosely coupled follower motors.- Returns:
SmartMotorControllerlist of loosely coupled followers.
-
getVelocityTrapezoidalProfileInUse
public boolean getVelocityTrapezoidalProfileInUse()Velocity trapezoidal profile configured.- Returns:
- true, if trapezoidal profile is configured as a velocity profile. false otherwise.
-
getVendorConfig
Get the vendor specific configuration object to mutate withSmartMotorControllerConfigoptions.- Returns:
SmartMotorControllervendor-specific configuration object.
-
withVendorControlRequest
Set the vendor specific control request for theSmartMotorControllerwhich will be used in place of default or calculated ones.- Parameters:
vendorControlRequest- Vendor specific control request for velocity or position.- Returns:
SmartMotorControllerConfigfor chaining
-
getResetPreviousConfig
public boolean getResetPreviousConfig()Reset the old config?- Returns:
- Should reset old config
-
resetValidationCheck
public void resetValidationCheck()Reset the validation checks for all required options to be applied toSmartMotorControllerfromSmartMotorController.applyConfig(SmartMotorControllerConfig). -
validateBasicOptions
public void validateBasicOptions()Validate all required options are at least fetched and handled in eachSmartMotorControllerwrapper.- Throws:
SmartMotorControllerConfigurationException- if any required basic option was not fetched (applied) by the SmartMotorController wrapper.
-
validateExternalEncoderOptions
public void validateExternalEncoderOptions()Validate external encoder config options for the config.- Throws:
SmartMotorControllerConfigurationException- if any external encoder option was not fetched (applied) by the SmartMotorController wrapper.
-
getExternalEncoderInverted
-
getVendorControlRequest
-
getExternalEncoderDiscontinuityPoint
Get the external encoder discontinuity point.- Returns:
- External encoder discontinuity point.
-
setupLiveTuning
public void setupLiveTuning()Setup live tuning for theSmartMotorController
-