Class XCANMotorController

java.lang.Object
xbot.common.controls.actuators.XCANMotorController
All Implemented Interfaces:
DataFrameRefreshable
Direct Known Subclasses:
CANSparkMaxWpiAdapter, CANTalonFxWpiAdapter, CANVictorSPXWpiAdapter, MockCANMotorController

public abstract class XCANMotorController extends Object implements DataFrameRefreshable
  • Field Details

    • MAX_VOLTAGE

      public static final Voltage 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

      public final CANBusId busId
    • deviceId

      public final int deviceId
    • propertyFactory

      public final PropertyFactory propertyFactory
    • inputs

      protected xbot.common.controls.io_inputs.XCANMotorControllerInputsAutoLogged inputs
    • akitName

      protected String akitName
    • usesPropertySystem

      protected boolean usesPropertySystem
    • firstPeriodicCall

      protected boolean firstPeriodicCall
    • kPProp

      protected DoubleProperty kPProp
    • kIProp

      protected DoubleProperty kIProp
    • kDProp

      protected DoubleProperty kDProp
    • kVelocityFFProp

      protected DoubleProperty kVelocityFFProp
    • kGravityFFProp

      protected DoubleProperty kGravityFFProp
    • kMaxOutputProp

      protected DoubleProperty kMaxOutputProp
    • kMinOutputProp

      protected DoubleProperty kMinOutputProp
    • softwareReverseLimit

      protected BooleanSupplier softwareReverseLimit
    • softwareForwardLimit

      protected BooleanSupplier softwareForwardLimit
  • Constructor Details

  • Method Details

    • setConfiguration

      public abstract void setConfiguration(CANMotorControllerOutputConfig outputConfig)
    • setSoftwareForwardLimit

      public void setSoftwareForwardLimit(BooleanSupplier softwareForwardLimit)
      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

      public void setSoftwareReverseLimit(BooleanSupplier softwareReverseLimit)
      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

      public abstract DeviceHealth getHealth()
    • periodic

      public void periodic()
    • setOpenLoopRampRates

      public abstract void setOpenLoopRampRates(Time dutyCyclePeriod, Time voltagePeriod)
    • setClosedLoopRampRates

      public abstract void setClosedLoopRampRates(Time dutyCyclePeriod, Time voltagePeriod)
    • setTrapezoidalProfileAcceleration

      public abstract void setTrapezoidalProfileAcceleration(AngularAcceleration acceleration)
    • setTrapezoidalProfileJerk

      public abstract void setTrapezoidalProfileJerk(Velocity<AngularAccelerationUnit> jerk)
    • setTrapezoidalProfileMaxVelocity

      public abstract void setTrapezoidalProfileMaxVelocity(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(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

      public void setAngleScaleFactor(Measure<? extends PerUnit<AngleUnit,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 Angle getRawPosition()
      Get the position reported by the motor controller.
      Returns:
      The position reported by the motor controller.
    • getPositionAsDistance

      public Distance getPositionAsDistance()
      Get the position reported by the motor controller.
      Returns:
      The position reported by the motor controller.
    • getPosition

      public Angle getPosition()
      Get the position reported by the motor controller.
      Returns:
      The position reported by the motor controller.
    • setPosition

      public void setPosition(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(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(Angle position)
      Set the target position for the motor controller.
      Parameters:
      position - The target position to set.
    • setPositionTarget

      public void setPositionTarget(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(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(Angle rawPosition)
      Set the target position for the motor controller.
      Parameters:
      rawPosition - The target position to set.
    • setRawPositionTarget

      public void setRawPositionTarget(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(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 AngularVelocity getVelocity()
      Get the velocity reported by the motor controller.
      Returns:
      The velocity reported by the motor controller.
    • getRawVelocity

      public AngularVelocity getRawVelocity()
      Get the velocity reported by the motor controller.
      Returns:
      The velocity reported by the motor controller.
    • setVelocityTarget

      public void setVelocityTarget(AngularVelocity velocity)
      Set the target velocity for the motor controller.
      Parameters:
      velocity - The target velocity to set.
    • setVelocityTarget

      public void setVelocityTarget(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(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(AngularVelocity rawVelocity)
      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

      public abstract void setVoltage(Voltage voltage)
    • getVoltage

      public Voltage getVoltage()
    • setVoltageRange

      public abstract void setVoltageRange(Voltage minVoltage, Voltage maxVoltage)
    • getCurrent

      public Current getCurrent()
    • isInverted

      public abstract boolean isInverted()
    • updateInputs

      protected abstract void updateInputs(XCANMotorControllerInputs inputs)
    • refreshDataFrame

      public void refreshDataFrame()
      Description copied from interface: DataFrameRefreshable
      Consumes and processes inputs from the device or subsystem.
      Specified by:
      refreshDataFrame in interface DataFrameRefreshable
    • isValidVoltageRequest

      protected boolean isValidVoltageRequest(Voltage voltage)
    • isValidPowerRequest

      protected boolean isValidPowerRequest(double power)
    • convertRawAngleToScaledAngle

      protected Angle convertRawAngleToScaledAngle(Angle rawAngle)
    • convertRawAngleToDistance

      protected Distance convertRawAngleToDistance(Angle rawAngle)
    • convertDistanceToRawAngle

      protected Angle convertDistanceToRawAngle(Distance distance)
    • convertScaledAngleToRawAngle

      protected Angle convertScaledAngleToRawAngle(Angle scaledAngle)
    • convertRawVelocityToScaledVelocity

      protected AngularVelocity convertRawVelocityToScaledVelocity(AngularVelocity rawVelocity)
    • convertScaledVelocityToRawVelocity

      protected AngularVelocity convertScaledVelocityToRawVelocity(AngularVelocity scaledVelocity)
    • setPositionAndVelocityUpdateFrequency

      public abstract void setPositionAndVelocityUpdateFrequency(Frequency frequency)