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

  • 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)
      Set the PID values for the motor controller directly, without using the property system. 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 the property system. 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 the property system.
      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

      public abstract void setPidDirectly(XCANMotorControllerPIDProperties pidProperties, int slot)
      Set the PID values for the motor controller directly, without using the property system.
      Parameters:
      pidProperties - The PID properties to set.
      slot - The PID slot to set the values for.
    • 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.
    • setVelocityTargetWithFeedForward

      public void setVelocityTargetWithFeedForward(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(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(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(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(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(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(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)