Package xbot.common.controls.actuators
Class XCANMotorController
java.lang.Object
xbot.common.controls.actuators.XCANMotorController
- All Implemented Interfaces:
DataFrameRefreshable
- Direct Known Subclasses:
CANSparkMaxWpiAdapter
,CANTalonFxWpiAdapter
,CANVictorSPXWpiAdapter
,MockCANMotorController
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
The PID mode to use when setting a target position or velocity.static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
final CANBusId
final int
protected boolean
protected xbot.common.controls.io_inputs.XCANMotorControllerInputsAutoLogged
protected DoubleProperty
protected DoubleProperty
protected DoubleProperty
protected DoubleProperty
protected DoubleProperty
protected DoubleProperty
protected DoubleProperty
static final Voltage
The maximum voltage that the motor controller can accept.final PropertyFactory
protected BooleanSupplier
protected BooleanSupplier
protected boolean
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
XCANMotorController
(CANMotorControllerInfo info, String owningSystemPrefix, PropertyFactory propertyFactory, DevicePolice police, String pidPropertyPrefix, XCANMotorControllerPIDProperties defaultPIDProperties) -
Method Summary
Modifier and TypeMethodDescriptionprotected Angle
convertDistanceToRawAngle
(Distance distance) protected Distance
convertRawAngleToDistance
(Angle rawAngle) protected Angle
convertRawAngleToScaledAngle
(Angle rawAngle) protected AngularVelocity
convertRawVelocityToScaledVelocity
(AngularVelocity rawVelocity) protected Angle
convertScaledAngleToRawAngle
(Angle scaledAngle) protected AngularVelocity
convertScaledVelocityToRawVelocity
(AngularVelocity scaledVelocity) abstract DeviceHealth
Get the position reported by the motor controller.Get the position reported by the motor controller.abstract double
getPower()
Get the position reported by the motor controller.Get the velocity reported by the motor controller.Get the velocity reported by the motor controller.abstract boolean
protected boolean
isValidPowerRequest
(double power) protected boolean
isValidVoltageRequest
(Voltage voltage) void
periodic()
void
Consumes and processes inputs from the device or subsystem.void
setAngleScaleFactor
(Measure<? extends PerUnit<AngleUnit, AngleUnit>> angleScaleFactor) Set the angle scaling factor for the motor controller.abstract void
setClosedLoopRampRates
(Time dutyCyclePeriod, Time voltagePeriod) abstract void
setConfiguration
(CANMotorControllerOutputConfig outputConfig) void
setDistancePerMotorRotationsScaleFactor
(Measure<? extends PerUnit<DistanceUnit, AngleUnit>> distancePerAngle) Set the distance per motor rotation scaling factor for the motor controller.abstract void
setOpenLoopRampRates
(Time dutyCyclePeriod, Time voltagePeriod) void
setPidDirectly
(double p, double i, double d) void
setPidDirectly
(double p, double i, double d, double velocityFF, double gravityFF) abstract void
setPidDirectly
(double p, double i, double d, double velocityFF, double gravityFF, int slot) void
setPosition
(Angle position) Override the position of the motor controller.abstract void
setPositionAndVelocityUpdateFrequency
(Frequency frequency) void
setPositionTarget
(Angle position) Set the target position for the motor controller.void
setPositionTarget
(Angle position, XCANMotorController.MotorPidMode mode) Set the target position for the motor controller.void
setPositionTarget
(Angle position, XCANMotorController.MotorPidMode mode, int slot) Set the target position for the motor controller.abstract void
setPower
(double power) abstract void
setPowerRange
(double minPower, double maxPower) abstract void
setRawPosition
(Angle position) Override the position of the motor controller.void
setRawPositionTarget
(Angle rawPosition) Set the target position for the motor controller.void
setRawPositionTarget
(Angle rawPosition, XCANMotorController.MotorPidMode mode) Set the target position for the motor controller.abstract void
setRawPositionTarget
(Angle rawPosition, XCANMotorController.MotorPidMode mode, int slot) Set the target position for the motor controller.void
setRawVelocityTarget
(AngularVelocity rawVelocity) Set the target velocity for the motor controller.void
setRawVelocityTarget
(AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode) Set the target velocity for the motor controller.abstract void
setRawVelocityTarget
(AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode, int slot) Set the target velocity for the motor controller.void
setSoftwareForwardLimit
(BooleanSupplier softwareForwardLimit) Set the software forward limit for the motor controller.void
setSoftwareReverseLimit
(BooleanSupplier softwareReverseLimit) Set the software reverse limit for the motor controller.abstract void
setTrapezoidalProfileAcceleration
(AngularAcceleration acceleration) abstract void
abstract void
void
setVelocityTarget
(AngularVelocity velocity) Set the target velocity for the motor controller.void
setVelocityTarget
(AngularVelocity velocity, XCANMotorController.MotorPidMode mode) Set the target velocity for the motor controller.void
setVelocityTarget
(AngularVelocity velocity, XCANMotorController.MotorPidMode mode, int slot) Set the target velocity for the motor controller.abstract void
setVoltage
(Voltage voltage) abstract void
setVoltageRange
(Voltage minVoltage, Voltage maxVoltage) protected abstract void
-
Field Details
-
MAX_VOLTAGE
The 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 -
propertyFactory
-
inputs
protected xbot.common.controls.io_inputs.XCANMotorControllerInputsAutoLogged inputs -
akitName
-
usesPropertySystem
protected boolean usesPropertySystem -
firstPeriodicCall
protected boolean firstPeriodicCall -
kPProp
-
kIProp
-
kDProp
-
kVelocityFFProp
-
kGravityFFProp
-
kMaxOutputProp
-
kMinOutputProp
-
softwareReverseLimit
-
softwareForwardLimit
-
-
Constructor Details
-
XCANMotorController
protected XCANMotorController(CANMotorControllerInfo info, String owningSystemPrefix, PropertyFactory propertyFactory, DevicePolice police, String pidPropertyPrefix, XCANMotorControllerPIDProperties defaultPIDProperties)
-
-
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) -
setPidDirectly
public void setPidDirectly(double p, double i, double d, double velocityFF, double gravityFF) -
setPidDirectly
public abstract void setPidDirectly(double p, double i, double d, double velocityFF, double gravityFF, int slot) -
getHealth
-
periodic
public void periodic() -
setOpenLoopRampRates
-
setClosedLoopRampRates
-
setTrapezoidalProfileAcceleration
-
setTrapezoidalProfileJerk
-
setTrapezoidalProfileMaxVelocity
-
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(Measure<? extends PerUnit<DistanceUnit, 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
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
Get the position reported by the motor controller.- Returns:
- The position reported by the motor controller.
-
getPositionAsDistance
Get the position reported by the motor controller.- Returns:
- The position reported by the motor controller.
-
getPosition
Get the position reported by the motor controller.- Returns:
- The position reported by the motor controller.
-
setPosition
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
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
Set the target position for the motor controller.- Parameters:
position
- The target position to set.
-
setPositionTarget
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
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
Set the target position for the motor controller.- Parameters:
rawPosition
- The target position to set.
-
setRawPositionTarget
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(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
Get the velocity reported by the motor controller.- Returns:
- The velocity reported by the motor controller.
-
getRawVelocity
Get the velocity reported by the motor controller.- Returns:
- The velocity reported by the motor controller.
-
setVelocityTarget
Set the target velocity for the motor controller.- Parameters:
velocity
- The target velocity to set.
-
setVelocityTarget
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(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
Set the target velocity for the motor controller.- Parameters:
rawVelocity
- The target velocity to set.
-
setRawVelocityTarget
public void setRawVelocityTarget(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(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.
-
setVoltage
-
getVoltage
-
setVoltageRange
-
getCurrent
-
isInverted
public abstract boolean isInverted() -
updateInputs
-
refreshDataFrame
public void refreshDataFrame()Description copied from interface:DataFrameRefreshable
Consumes and processes inputs from the device or subsystem.- Specified by:
refreshDataFrame
in interfaceDataFrameRefreshable
-
isValidVoltageRequest
-
isValidPowerRequest
protected boolean isValidPowerRequest(double power) -
convertRawAngleToScaledAngle
-
convertRawAngleToDistance
-
convertDistanceToRawAngle
-
convertScaledAngleToRawAngle
-
convertRawVelocityToScaledVelocity
-
convertScaledVelocityToRawVelocity
-
setPositionAndVelocityUpdateFrequency
-