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 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 DoublePropertyprotected DoublePropertyprotected DoublePropertyprotected DoublePropertyprotected DoublePropertyprotected DoublePropertyprotected DoublePropertystatic final VoltageThe maximum voltage that the motor controller can accept.final PropertyFactoryprotected BooleanSupplierprotected BooleanSupplierprotected boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedXCANMotorController(CANMotorControllerInfo info, String owningSystemPrefix, PropertyFactory propertyFactory, DevicePolice police, String pidPropertyPrefix, XCANMotorControllerPIDProperties defaultPIDProperties) -
Method Summary
Modifier and TypeMethodDescriptionprotected AngleconvertDistanceToRawAngle(Distance distance) protected DistanceconvertRawAngleToDistance(Angle rawAngle) protected AngleconvertRawAngleToScaledAngle(Angle rawAngle) protected AngularVelocityconvertRawVelocityToScaledVelocity(AngularVelocity rawVelocity) protected AngleconvertScaledAngleToRawAngle(Angle scaledAngle) protected AngularVelocityconvertScaledVelocityToRawVelocity(AngularVelocity scaledVelocity) abstract DeviceHealthGet the position reported by the motor controller.Get the position reported by the motor controller.abstract doublegetPower()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 booleanprotected booleanisValidPowerRequest(double power) protected booleanisValidVoltageRequest(Voltage voltage) voidperiodic()voidConsumes and processes inputs from the device or subsystem.voidsetAngleScaleFactor(Measure<? extends PerUnit<AngleUnit, AngleUnit>> angleScaleFactor) Set the angle scaling factor for the motor controller.abstract voidsetClosedLoopRampRates(Time dutyCyclePeriod, Time voltagePeriod) abstract voidsetConfiguration(CANMotorControllerOutputConfig outputConfig) voidsetDistancePerMotorRotationsScaleFactor(Measure<? extends PerUnit<DistanceUnit, AngleUnit>> distancePerAngle) Set the distance per motor rotation scaling factor for the motor controller.abstract voidsetOpenLoopRampRates(Time dutyCyclePeriod, Time voltagePeriod) voidsetPidDirectly(double p, double i, double d) voidsetPidDirectly(double p, double i, double d, double velocityFF, double gravityFF) abstract voidsetPidDirectly(double p, double i, double d, double velocityFF, double gravityFF, int slot) voidsetPosition(Angle position) Override the position of the motor controller.abstract voidsetPositionAndVelocityUpdateFrequency(Frequency frequency) voidsetPositionTarget(Angle position) Set the target position for the motor controller.voidsetPositionTarget(Angle position, XCANMotorController.MotorPidMode mode) Set the target position for the motor controller.voidsetPositionTarget(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(Angle position) Override the position of the motor controller.voidsetRawPositionTarget(Angle rawPosition) Set the target position for the motor controller.voidsetRawPositionTarget(Angle rawPosition, XCANMotorController.MotorPidMode mode) Set the target position for the motor controller.abstract voidsetRawPositionTarget(Angle rawPosition, XCANMotorController.MotorPidMode mode, int slot) Set the target position for the motor controller.voidsetRawVelocityTarget(AngularVelocity rawVelocity) Set the target velocity for the motor controller.voidsetRawVelocityTarget(AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode) Set the target velocity for the motor controller.abstract voidsetRawVelocityTarget(AngularVelocity rawVelocity, XCANMotorController.MotorPidMode mode, 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(AngularAcceleration acceleration) abstract voidabstract voidvoidsetVelocityTarget(AngularVelocity velocity) Set the target velocity for the motor controller.voidsetVelocityTarget(AngularVelocity velocity, XCANMotorController.MotorPidMode mode) Set the target velocity for the motor controller.voidsetVelocityTarget(AngularVelocity velocity, XCANMotorController.MotorPidMode mode, int slot) Set the target velocity for the motor controller.abstract voidsetVoltage(Voltage voltage) abstract voidsetVoltageRange(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:DataFrameRefreshableConsumes and processes inputs from the device or subsystem.- Specified by:
refreshDataFramein interfaceDataFrameRefreshable
-
isValidVoltageRequest
-
isValidPowerRequest
protected boolean isValidPowerRequest(double power) -
convertRawAngleToScaledAngle
-
convertRawAngleToDistance
-
convertDistanceToRawAngle
-
convertScaledAngleToRawAngle
-
convertRawVelocityToScaledVelocity
-
convertScaledVelocityToRawVelocity
-
setPositionAndVelocityUpdateFrequency
-