Class XCANMotorController
java.lang.Object
xbot.common.controls.actuators.XCANMotorController
- All Implemented Interfaces:
DataFrameRefreshable
- Direct Known Subclasses:
CANSparkMaxWpiAdapter, CANTalonFxWpiAdapter, MockCANMotorController
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe PID mode to use when setting a target position or velocity.static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringfinal CANBusIdfinal intprotected booleanprotected xbot.common.controls.io_inputs.XCANMotorControllerInputsAutoLoggedprotected org.wpilib.tunable.TunableDoubleprotected org.wpilib.tunable.TunableDoublestatic final org.wpilib.units.measure.VoltageThe maximum voltage that the motor controller can accept.protected Map<Integer, XCANMotorControllerPIDProperties> protected BooleanSupplierprotected BooleanSupplierfinal TunableFactoryprotected boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedXCANMotorController(CANMotorControllerInfo info, String owningSystemPrefix, TunableFactory tunableFactory, DevicePolice police, String pidTunablePrefix, XCANMotorControllerPIDProperties defaultPIDProperties, DataFrameRegistry dataFrameRegistry, PowerDistributionProperties pdProperties) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.wpilib.units.measure.AngleconvertDistanceToRawAngle(org.wpilib.units.measure.Distance distance) protected org.wpilib.units.measure.DistanceconvertRawAngleToDistance(org.wpilib.units.measure.Angle rawAngle) protected org.wpilib.units.measure.AngleconvertRawAngleToScaledAngle(org.wpilib.units.measure.Angle rawAngle) protected org.wpilib.units.measure.AngularVelocityconvertRawVelocityToScaledVelocity(org.wpilib.units.measure.AngularVelocity rawVelocity) protected org.wpilib.units.measure.AngleconvertScaledAngleToRawAngle(org.wpilib.units.measure.Angle scaledAngle) protected org.wpilib.units.measure.AngularVelocityconvertScaledVelocityToRawVelocity(org.wpilib.units.measure.AngularVelocity scaledVelocity) org.wpilib.units.measure.Currentabstract DeviceHealthorg.wpilib.units.measure.AngleGet the position reported by the motor controller.org.wpilib.units.measure.DistanceGet the position reported by the motor controller.abstract doublegetPower()org.wpilib.units.measure.AngleGet the position reported by the motor controller.org.wpilib.units.measure.AngularVelocityGet the velocity reported by the motor controller.org.wpilib.units.measure.AngularVelocityGet the velocity reported by the motor controller.org.wpilib.units.measure.Voltageabstract booleanprotected booleanisValidPowerRequest(double power) protected booleanisValidVoltageRequest(org.wpilib.units.measure.Voltage voltage) voidperiodic()voidConsumes and processes inputs from the device or subsystem.voidsetAngleScaleFactor(org.wpilib.units.Measure<? extends org.wpilib.units.PerUnit<org.wpilib.units.AngleUnit, org.wpilib.units.AngleUnit>> angleScaleFactor) Set the angle scaling factor for the motor controller.abstract voidsetClosedLoopRampRates(org.wpilib.units.measure.Time dutyCyclePeriod, org.wpilib.units.measure.Time voltagePeriod) abstract voidsetConfiguration(CANMotorControllerOutputConfig outputConfig) voidsetDistancePerMotorRotationsScaleFactor(org.wpilib.units.Measure<? extends org.wpilib.units.PerUnit<org.wpilib.units.DistanceUnit, org.wpilib.units.AngleUnit>> distancePerAngle) Set the distance per motor rotation scaling factor for the motor controller.abstract voidsetOpenLoopRampRates(org.wpilib.units.measure.Time dutyCyclePeriod, org.wpilib.units.measure.Time voltagePeriod) voidsetPidDirectly(double p, double i, double d) Set the PID values for the motor controller directly, without using tunables.voidsetPidDirectly(double p, double i, double d, double velocityFF, double gravityFF) Set the PID values for the motor controller directly, without using tunables.voidsetPidDirectly(double p, double i, double d, double staticFF, double velocityFF, double gravityFF, int slot) Set the PID values for the motor controller directly, without using tunables.abstract voidsetPidDirectly(XCANMotorControllerPIDProperties pidProperties, int slot) Set the PID values for the motor controller directly, without using tunables.voidsetPosition(org.wpilib.units.measure.Angle position) Override the position of the motor controller.abstract voidsetPositionAndVelocityUpdateFrequency(org.wpilib.units.measure.Frequency frequency) voidsetPositionTarget(org.wpilib.units.measure.Angle position) Set the target position for the motor controller.voidsetPositionTarget(org.wpilib.units.measure.Angle position, XCANMotorController.MotorPidMode mode) Set the target position for the motor controller.voidsetPositionTarget(org.wpilib.units.measure.Angle position, XCANMotorController.MotorPidMode mode, int slot) Set the target position for the motor controller.abstract voidsetPower(double power) abstract voidsetPowerRange(double minPower, double maxPower) abstract voidsetRawPosition(org.wpilib.units.measure.Angle position) Override the position of the motor controller.voidsetRawPositionTarget(org.wpilib.units.measure.Angle rawPosition) Set the target position for the motor controller.voidsetRawPositionTarget(org.wpilib.units.measure.Angle rawPosition, XCANMotorController.MotorPidMode mode) Set the target position for the motor controller.abstract voidsetRawPositionTarget(org.wpilib.units.measure.Angle rawPosition, XCANMotorController.MotorPidMode mode, int slot) Set the target position for the motor controller.voidsetRawVelocityTarget(org.wpilib.units.measure.AngularVelocity rawVelocity) Set the target velocity for the motor controller.voidsetRawVelocityTarget(org.wpilib.units.measure.AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode) Set the target velocity for the motor controller.abstract voidsetRawVelocityTarget(org.wpilib.units.measure.AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode, int slot) Set the target velocity for the motor controller.voidsetRawVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity rawVelocity, double feedForward) Set the target velocity for the motor controller.voidsetRawVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode, double feedForward) Set the target velocity for the motor controller.abstract voidsetRawVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode, double feedForward, int slot) Set the target velocity for the motor controller.voidsetSoftwareForwardLimit(BooleanSupplier softwareForwardLimit) Set the software forward limit for the motor controller.voidsetSoftwareReverseLimit(BooleanSupplier softwareReverseLimit) Set the software reverse limit for the motor controller.abstract voidsetTrapezoidalProfileAcceleration(org.wpilib.units.measure.AngularAcceleration acceleration) abstract voidsetTrapezoidalProfileJerk(org.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> jerk) abstract voidsetTrapezoidalProfileMaxVelocity(org.wpilib.units.measure.AngularVelocity velocity) voidsetVelocityTarget(org.wpilib.units.measure.AngularVelocity velocity) Set the target velocity for the motor controller.voidsetVelocityTarget(org.wpilib.units.measure.AngularVelocity velocity, XCANMotorController.MotorPidMode mode) Set the target velocity for the motor controller.voidsetVelocityTarget(org.wpilib.units.measure.AngularVelocity velocity, XCANMotorController.MotorPidMode mode, int slot) Set the target velocity for the motor controller.voidsetVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity velocity, double feedForward) Set the target velocity for the motor controller.voidsetVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity velocity, XCANMotorController.MotorPidMode mode, double feedForward) Set the target velocity for the motor controller.voidsetVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity velocity, XCANMotorController.MotorPidMode mode, double feedForward, int slot) Set the target velocity for the motor controller.abstract voidsetVoltage(org.wpilib.units.measure.Voltage voltage) abstract voidsetVoltageRange(org.wpilib.units.measure.Voltage minVoltage, org.wpilib.units.measure.Voltage maxVoltage) protected abstract void
-
Field Details
-
MAX_VOLTAGE
public static final org.wpilib.units.measure.Voltage MAX_VOLTAGEThe maximum voltage that the motor controller can accept. This is typically 12V, but at the start of a match the voltage could be a little higher.. -
busId
-
deviceId
public final int deviceId -
tunableFactory
-
pidProperties
-
inputs
protected xbot.common.controls.io_inputs.XCANMotorControllerInputsAutoLogged inputs -
akitName
-
usesTunables
protected boolean usesTunables -
firstPeriodicCall
protected boolean firstPeriodicCall -
kPTunables
-
kITunables
-
kDTunables
-
kStaticFFTunables
-
kVelocityFFTunables
-
kGravityFFTunables
-
kMaxOutputTunable
protected org.wpilib.tunable.TunableDouble kMaxOutputTunable -
kMinOutputTunable
protected org.wpilib.tunable.TunableDouble kMinOutputTunable -
softwareReverseLimit
-
softwareForwardLimit
-
-
Constructor Details
-
XCANMotorController
protected XCANMotorController(CANMotorControllerInfo info, String owningSystemPrefix, TunableFactory tunableFactory, DevicePolice police, String pidTunablePrefix, XCANMotorControllerPIDProperties defaultPIDProperties, DataFrameRegistry dataFrameRegistry, PowerDistributionProperties pdProperties)
-
-
Method Details
-
setConfiguration
-
setSoftwareForwardLimit
Set the software forward limit for the motor controller. If the limit is hit, the motor controller will stop. This is evaluated on every periodic call.- Parameters:
softwareForwardLimit- A supplier that returns true if the forward limit is hit.
-
setSoftwareReverseLimit
Set the software reverse limit for the motor controller. If the limit is hit, the motor controller will stop. This is evaluated on every periodic call.- Parameters:
softwareReverseLimit- A supplier that returns true if the reverse limit is hit.
-
setPidDirectly
public void setPidDirectly(double p, double i, double d) Set the PID values for the motor controller directly, without using tunables. This method sets the PID values on slot 0, and leaves feed forward values at 0.- Parameters:
p- The proportional gain to set.i- The integral gain to set.d- The derivative gain to set.
-
setPidDirectly
public void setPidDirectly(double p, double i, double d, double velocityFF, double gravityFF) Set the PID values for the motor controller directly, without using tunables. This method sets the PID values on slot 0.- Parameters:
p- The proportional gain to set.i- The integral gain to set.d- The derivative gain to set.velocityFF- The velocity feed forward to set.gravityFF- The gravity feed forward to set.
-
setPidDirectly
public void setPidDirectly(double p, double i, double d, double staticFF, double velocityFF, double gravityFF, int slot) Set the PID values for the motor controller directly, without using tunables.- Parameters:
p- The proportional gain to set.i- The integral gain to set.d- The derivative gain to set.staticFF- The static feed forward to set.velocityFF- The velocity feed forward to set.gravityFF- The gravity feed forward to set.slot- The PID slot to set the values for.
-
setPidDirectly
Set the PID values for the motor controller directly, without using tunables.- Parameters:
pidProperties- The PID properties to set.slot- The PID slot to set the values for.
-
getHealth
-
periodic
public void periodic() -
setOpenLoopRampRates
public abstract void setOpenLoopRampRates(org.wpilib.units.measure.Time dutyCyclePeriod, org.wpilib.units.measure.Time voltagePeriod) -
setClosedLoopRampRates
public abstract void setClosedLoopRampRates(org.wpilib.units.measure.Time dutyCyclePeriod, org.wpilib.units.measure.Time voltagePeriod) -
setTrapezoidalProfileAcceleration
public abstract void setTrapezoidalProfileAcceleration(org.wpilib.units.measure.AngularAcceleration acceleration) -
setTrapezoidalProfileJerk
public abstract void setTrapezoidalProfileJerk(org.wpilib.units.measure.Velocity<org.wpilib.units.AngularAccelerationUnit> jerk) -
setTrapezoidalProfileMaxVelocity
public abstract void setTrapezoidalProfileMaxVelocity(org.wpilib.units.measure.AngularVelocity velocity) -
setPower
public abstract void setPower(double power) -
getPower
public abstract double getPower() -
setPowerRange
public abstract void setPowerRange(double minPower, double maxPower) -
setDistancePerMotorRotationsScaleFactor
public void setDistancePerMotorRotationsScaleFactor(org.wpilib.units.Measure<? extends org.wpilib.units.PerUnit<org.wpilib.units.DistanceUnit, org.wpilib.units.AngleUnit>> distancePerAngle) Set the distance per motor rotation scaling factor for the motor controller. This is used to convert the motor controller's position to a distance.Example:
setDistancePerMotorRotationScaleFactor(Meters.per(Rotation).of(0.5))- Parameters:
distancePerAngle- The distance per angle scaling factor to set.
-
setAngleScaleFactor
public void setAngleScaleFactor(org.wpilib.units.Measure<? extends org.wpilib.units.PerUnit<org.wpilib.units.AngleUnit, org.wpilib.units.AngleUnit>> angleScaleFactor) Set the angle scaling factor for the motor controller. This is used to convert the motor controller's position to an angle.Example:
setAngleScaleFactor(Degrees.per(Rotation).of(488))- Parameters:
angleScaleFactor- The angle scaling factor to set.
-
getRawPosition
public org.wpilib.units.measure.Angle getRawPosition()Get the position reported by the motor controller.- Returns:
- The position reported by the motor controller.
-
getPositionAsDistance
public org.wpilib.units.measure.Distance getPositionAsDistance()Get the position reported by the motor controller.- Returns:
- The position reported by the motor controller.
-
getPosition
public org.wpilib.units.measure.Angle getPosition()Get the position reported by the motor controller.- Returns:
- The position reported by the motor controller.
-
setPosition
public void setPosition(org.wpilib.units.measure.Angle position) Override the position of the motor controller.Typically, this would be called to zero the reported position of the motor as part of a calibration routine.
- Parameters:
position- The new position to set.
-
setRawPosition
public abstract void setRawPosition(org.wpilib.units.measure.Angle position) Override the position of the motor controller.Typically, this would be called to zero the reported position of the motor as part of a calibration routine.
- Parameters:
position- The new position to set.
-
setPositionTarget
public void setPositionTarget(org.wpilib.units.measure.Angle position) Set the target position for the motor controller.- Parameters:
position- The target position to set.
-
setPositionTarget
public void setPositionTarget(org.wpilib.units.measure.Angle position, XCANMotorController.MotorPidMode mode) Set the target position for the motor controller.- Parameters:
position- The target position to set.mode- The PID mode to use when setting the target position.
-
setPositionTarget
public void setPositionTarget(org.wpilib.units.measure.Angle position, XCANMotorController.MotorPidMode mode, int slot) Set the target position for the motor controller.- Parameters:
position- The target position to set.mode- The PID mode to use when setting the target position.slot- The PID slot to use when setting the target position.
-
setRawPositionTarget
public void setRawPositionTarget(org.wpilib.units.measure.Angle rawPosition) Set the target position for the motor controller.- Parameters:
rawPosition- The target position to set.
-
setRawPositionTarget
public void setRawPositionTarget(org.wpilib.units.measure.Angle rawPosition, XCANMotorController.MotorPidMode mode) Set the target position for the motor controller.- Parameters:
rawPosition- The target position to set.mode- The PID mode to use when setting the target position.
-
setRawPositionTarget
public abstract void setRawPositionTarget(org.wpilib.units.measure.Angle rawPosition, XCANMotorController.MotorPidMode mode, int slot) Set the target position for the motor controller.- Parameters:
rawPosition- The target position to set.mode- The PID mode to use when setting the target position.slot- The PID slot to use when setting the target position.
-
getVelocity
public org.wpilib.units.measure.AngularVelocity getVelocity()Get the velocity reported by the motor controller.- Returns:
- The velocity reported by the motor controller.
-
getRawVelocity
public org.wpilib.units.measure.AngularVelocity getRawVelocity()Get the velocity reported by the motor controller.- Returns:
- The velocity reported by the motor controller.
-
setVelocityTarget
public void setVelocityTarget(org.wpilib.units.measure.AngularVelocity velocity) Set the target velocity for the motor controller.- Parameters:
velocity- The target velocity to set.
-
setVelocityTarget
public void setVelocityTarget(org.wpilib.units.measure.AngularVelocity velocity, XCANMotorController.MotorPidMode mode) Set the target velocity for the motor controller.- Parameters:
velocity- The target velocity to set.mode- The PID mode to use when setting the target velocity.
-
setVelocityTarget
public void setVelocityTarget(org.wpilib.units.measure.AngularVelocity velocity, XCANMotorController.MotorPidMode mode, int slot) Set the target velocity for the motor controller.- Parameters:
velocity- The target velocity to set.mode- The PID mode to use when setting the target velocity.slot- The PID slot to use when setting the target velocity.
-
setRawVelocityTarget
public void setRawVelocityTarget(org.wpilib.units.measure.AngularVelocity rawVelocity) Set the target velocity for the motor controller.- Parameters:
rawVelocity- The target velocity to set.
-
setRawVelocityTarget
public void setRawVelocityTarget(org.wpilib.units.measure.AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode) Set the target velocity for the motor controller.- Parameters:
rawVelocity- The target velocity to set.mode- The PID mode to use when setting the target velocity.
-
setRawVelocityTarget
public abstract void setRawVelocityTarget(org.wpilib.units.measure.AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode, int slot) Set the target velocity for the motor controller.- Parameters:
rawVelocity- The target velocity to set.mode- The PID mode to use when setting the target velocity.slot- The PID slot to use when setting the target velocity.
-
setVelocityTargetWithFeedForward
public void setVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity velocity, double feedForward) Set the target velocity for the motor controller.- Parameters:
velocity- The target velocity to set.feedForward- The additional feed forward to apply (-1..1 for duty-cycle PID mode).
-
setVelocityTargetWithFeedForward
public void setVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity velocity, XCANMotorController.MotorPidMode mode, double feedForward) Set the target velocity for the motor controller.- Parameters:
velocity- The target velocity to set.mode- The PID mode to use when setting the target velocity.feedForward- The additional feed forward to apply (in volts for voltage PID modes or -1..1 for duty-cycle PID modes).
-
setVelocityTargetWithFeedForward
public void setVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity velocity, XCANMotorController.MotorPidMode mode, double feedForward, int slot) Set the target velocity for the motor controller.- Parameters:
velocity- The target velocity to set.mode- The PID mode to use when setting the target velocity.feedForward- The additional feed forward to apply (in volts for voltage PID modes or -1..1 for duty-cycle PID modes).slot- The PID slot to use when setting the target velocity.
-
setRawVelocityTargetWithFeedForward
public void setRawVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity rawVelocity, double feedForward) Set the target velocity for the motor controller.- Parameters:
rawVelocity- The target velocity to set.feedForward- The additional feed forward to apply (-1..1 for duty-cycle PID mode).
-
setRawVelocityTargetWithFeedForward
public void setRawVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode, double feedForward) Set the target velocity for the motor controller.- Parameters:
rawVelocity- The target velocity to set.mode- The PID mode to use when setting the target velocity.feedForward- The additional feed forward to apply (in volts for voltage PID modes or -1..1 for duty-cycle PID modes).
-
setRawVelocityTargetWithFeedForward
public abstract void setRawVelocityTargetWithFeedForward(org.wpilib.units.measure.AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode, double feedForward, int slot) Set the target velocity for the motor controller.- Parameters:
rawVelocity- The target velocity to set.mode- The PID mode to use when setting the target velocity.feedForward- The additional feed forward to apply (in volts for voltage PID modes or -1..1 for duty-cycle PID modes).slot- The PID slot to use when setting the target velocity.
-
setVoltage
public abstract void setVoltage(org.wpilib.units.measure.Voltage voltage) -
getVoltage
public org.wpilib.units.measure.Voltage getVoltage() -
setVoltageRange
public abstract void setVoltageRange(org.wpilib.units.measure.Voltage minVoltage, org.wpilib.units.measure.Voltage maxVoltage) -
getCurrent
public org.wpilib.units.measure.Current getCurrent() -
isInverted
public abstract boolean isInverted() -
updateInputs
-
refreshDataFrame
public void refreshDataFrame()Description copied from interface:DataFrameRefreshableConsumes and processes inputs from the device or subsystem.- Specified by:
refreshDataFramein interfaceDataFrameRefreshable
-
isValidVoltageRequest
protected boolean isValidVoltageRequest(org.wpilib.units.measure.Voltage voltage) -
isValidPowerRequest
protected boolean isValidPowerRequest(double power) -
convertRawAngleToScaledAngle
protected org.wpilib.units.measure.Angle convertRawAngleToScaledAngle(org.wpilib.units.measure.Angle rawAngle) -
convertRawAngleToDistance
protected org.wpilib.units.measure.Distance convertRawAngleToDistance(org.wpilib.units.measure.Angle rawAngle) -
convertDistanceToRawAngle
protected org.wpilib.units.measure.Angle convertDistanceToRawAngle(org.wpilib.units.measure.Distance distance) -
convertScaledAngleToRawAngle
protected org.wpilib.units.measure.Angle convertScaledAngleToRawAngle(org.wpilib.units.measure.Angle scaledAngle) -
convertRawVelocityToScaledVelocity
protected org.wpilib.units.measure.AngularVelocity convertRawVelocityToScaledVelocity(org.wpilib.units.measure.AngularVelocity rawVelocity) -
convertScaledVelocityToRawVelocity
protected org.wpilib.units.measure.AngularVelocity convertScaledVelocityToRawVelocity(org.wpilib.units.measure.AngularVelocity scaledVelocity) -
setPositionAndVelocityUpdateFrequency
public abstract void setPositionAndVelocityUpdateFrequency(org.wpilib.units.measure.Frequency frequency)
-