Package trclib.drivebase
Class TrcSwerveModule
java.lang.Object
trclib.drivebase.TrcSwerveModule
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTrcSwerveModule
(String instanceName, TrcMotor driveMotor, TrcMotor steerMotor) Constructor: Create an instance of the object.TrcSwerveModule
(String instanceName, TrcMotor driveMotor, TrcServo steerServo) Constructor: Create an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method disables the steer limits.double
The current angle of the turn motor.void
setPower
(double power) This method sets the motor power.void
setSteerAngle
(double angle) This method sets the steer angle.void
setSteerAngle
(double angle, boolean optimize) This method sets the steer angle.void
setSteerAngle
(double angle, boolean optimize, boolean hold) This method sets the steer angle.void
setSteeringLimits
(double steerLowLimit, double steerHighLimit) This method sets the hard steer limits, used for noncontinuous swerve modules.toString()
This method returns the instance name.void
This method performs a zero calibration on the steering motor.
-
Field Details
-
tracer
-
driveMotor
-
steerMotor
-
steerServo
-
-
Constructor Details
-
TrcSwerveModule
Constructor: Create an instance of the object.- Parameters:
instanceName
- specifies the instance name.driveMotor
- specifies the drive motor.steerMotor
- specifies the steering motor.
-
TrcSwerveModule
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
This method returns the 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. -
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.
-