Class TrcSwerveModule

java.lang.Object
trclib.drivebase.TrcSwerveModule

public class TrcSwerveModule extends Object
This class implements a platform independent Swerve Drive module. A Swerve Drive module consists of a drive motor and a steer motor. The steer motor can be a PID controlled motor with a zero calibration limit switch that allows an absolute steering angle to be set and held. It can also be a servo motor which has a limited range of motion.
  • Field Details

    • tracer

      public final TrcDbgTrace tracer
    • instanceName

      private final String instanceName
    • driveMotor

      public final TrcMotor driveMotor
    • steerMotor

      public final TrcMotor steerMotor
    • steerServo

      public final TrcServo steerServo
    • warpSpace

      private final TrcWarpSpace warpSpace
    • steerLimitsEnabled

      private boolean steerLimitsEnabled
    • steerLowLimit

      private double steerLowLimit
    • steerHighLimit

      private double steerHighLimit
    • optimizedWheelDir

      private double optimizedWheelDir
  • Constructor Details

    • TrcSwerveModule

      private TrcSwerveModule(String instanceName, TrcMotor driveMotor, TrcMotor steerMotor, TrcServo steerServo)
      Constructor: Create an instance of the object. Note: steerMotor and steerServo are exclusive. You can either have a steerMotor or a steerServo but not both.
      Parameters:
      instanceName - specifies the instance name.
      driveMotor - specifies the drive motor.
      steerMotor - specifies the steering motor.
      steerServo - specifies the steering servo.
    • TrcSwerveModule

      public TrcSwerveModule(String instanceName, TrcMotor driveMotor, TrcMotor steerMotor)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      driveMotor - specifies the drive motor.
      steerMotor - specifies the steering motor.
    • TrcSwerveModule

      public TrcSwerveModule(String instanceName, TrcMotor driveMotor, TrcServo steerServo)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
      driveMotor - specifies the drive motor.
      steerServo - specifies the steering servo.
  • Method Details

    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • setSteeringLimits

      public void setSteeringLimits(double steerLowLimit, double steerHighLimit)
      This method sets the hard steer limits, used for noncontinuous swerve modules. The angles must be in range (-180,180]. The limits must also be at least 180 degrees apart.
      Parameters:
      steerLowLimit - The low steer limit.
      steerHighLimit - The high steer limit.
    • disableSteeringLimits

      public void disableSteeringLimits()
      This method disables the steer limits.
    • zeroCalibrateSteering

      public void zeroCalibrateSteering()
      This method performs a zero calibration on the steering motor. This is not applicable for servo steering.
    • doneZeroCalibrate

      private void doneZeroCalibrate(Object context)
      This method is called when zero calibration is done.
      Parameters:
      context - not used.
    • setSteerAngle

      public void setSteerAngle(double angle, boolean optimize, boolean hold)
      This method sets the steer angle.
      Parameters:
      angle - specifies the angle in degrees to set the steer motor to. Not necessarily within [0,360).
      optimize - specifies true to optimize steering angle to be no greater than 90 degrees, false otherwise.
      hold - specifies true to hold the angle, false otherwise.
    • setSteerAngle

      public void setSteerAngle(double angle, boolean optimize)
      This method sets the steer angle.
      Parameters:
      angle - specifies the angle in degrees to set the steer motor to, in the range [0,360).
      optimize - specifies true to optimize steering angle to be no greater than 90 degrees, false otherwise.
    • setSteerAngle

      public void setSteerAngle(double angle)
      This method sets the steer angle.
      Parameters:
      angle - specifies the angle in degrees to set the steer motor to, in the range [0,360).
    • getSteerAngle

      public double getSteerAngle()
      The current angle of the turn motor. This is not necessarily the target angle.
      Returns:
      The angle of the turn motor, in degrees, in the range [0,360).
    • setPower

      public void setPower(double power)
      This method sets the motor power.
      Parameters:
      power - specifies the percentage power (range -1.0 to 1.0) to be set.