public abstract class DriveSystem
extends java.lang.Object
DriveSystem
represents the motors used for driving the robot, their
arrangement, and in some cases, the type of wheels attached to the motor. Every subclass
of DriveSystem
must be able to accept two vectors, forward and clockwise, and
calculate the exact power that must be sent to the individual motors for the robot to
move with the given two vectors.Modifier and Type | Field and Description |
---|---|
private double |
encoderTicksPerDriveInch
Sets the amount of ticks that should be expected if the robot drives forward one inch.
|
private double |
encoderTicksPerRotationDegree
Sets the amount of ticks that should be expected if the robot rotates one degree.
|
private double |
encoderTicksPerSwingDegree
Sets the amount of ticks that should be expected if the robot swings one degree.
|
private MotorSet |
motors
The motors in this drive system.
|
Constructor and Description |
---|
DriveSystem(MotorSet wheels)
Constructs a new
DriveSystem with the given DriveMotorSet as a base. |
DriveSystem(java.lang.String[] motornames)
Constructs a new
DriveSystem that uses the motors with the given names. |
Modifier and Type | Method and Description |
---|---|
boolean |
drive(double power)
Drives the robot forward with the given power.
|
boolean |
driveInches(double power,
double inches)
Drives the robot forward with the given power and for the given distance,
then stops.
|
private double |
driveInchesToTicks(double inches)
Converts between drive inches and encoder ticks.
|
boolean |
driveSeconds(double power,
double seconds)
Drives the robot forward with the given power and for the given time, then stops.
|
boolean |
driveTicks(double power,
int ticks)
Drives the robot forward with the given power and for the given tick distance,
then stops.
|
double |
getDriveInches()
Gets the distance that the robot has driven forward since the last encoder reset.
|
abstract int |
getDriveTicks()
Gets the average value in raw ticks of the encoders for driving,
assuming the robot is traveling in a straight line.
|
MotorSet |
getMotorSet()
Gets a reference to the
MotorSet used by this drive system. |
abstract int |
getRotateTicks()
Gets the average value in raw ticks of the encoders for driving,
assuming the robot is rotating.
|
double |
getRotationDegrees()
Gets the degrees that the robot has rotated clockwise since the last encoder reset.
|
double |
getSwingDegrees(boolean clockwise)
Gets the degrees that the robot has swung in the given direction since the last encoder reset.
|
abstract int |
getSwingTicks(boolean clockwise)
Gets the average value in raw ticks of the encoders for driving,
assuming the robot is swinging.
|
boolean |
halt()
Stops the robot.
|
void |
resetEncoders()
Resets the encoder of each motor in the drive system.
|
boolean |
rotate(double power)
Spins the robot clockwise with the given power.
|
boolean |
rotateDegrees(double power,
double degrees)
Spins the robot clockwise with the given power and for the given amount of degrees,
then stops.
|
private double |
rotateDegreesToTicks(double degrees)
Converts between rotation degrees and encoder ticks.
|
boolean |
rotateSeconds(double power,
double seconds)
Spins the robot clockwise with the given power and for the given time, then stops.
|
boolean |
rotateTicks(double power,
int ticks)
Spins the robot clockwise with the given power and for the given tick distance,
then stops.
|
void |
setEncoderTicksPerDriveInch(double ticks)
Sets the amount of ticks that should be expected if the robot drives forward one inch.
|
void |
setEncoderTicksPerRotationDegree(double ticks)
Sets the amount of ticks that should be expected if the robot rotates one degree.
|
void |
setEncoderTicksPerSwingDegree(double ticks)
Sets the amount of ticks that should be expected if the robot swings one degree.
|
abstract boolean |
setMovement(double forward,
double clockwise)
Sets the power of the motors on the robot so that the robot moves as described by
the two vectors.
|
boolean |
swing(boolean clockwise,
double power)
Swings the robot with the given spin and forward power.
|
boolean |
swingDegrees(boolean clockwise,
double power,
double degrees)
Swings the robot with the given spin and forward power, and for the given amount of degrees,
then stops.
|
private double |
swingDegreesToTicks(double degrees)
Converts between swing degrees and encoder ticks.
|
boolean |
swingSeconds(boolean clockwise,
double power,
double seconds)
Swings the robot with the given spin and forward power, then stops after the given
amount of time.
|
boolean |
swingTicks(boolean clockwise,
double power,
int ticks)
Swings the robot with the given spin and forward power, and for the given tick distance,
then stops.
|
boolean |
waitAndStop(double seconds)
Waits the given amount of time, then stops the robot.
|
private double encoderTicksPerDriveInch
This number cannot have a default value because different types of encoders will be used, and each may have a different definition of a tick.
private double encoderTicksPerRotationDegree
This number cannot have a default value because different types of encoders will be used, and each may have a different definition of a tick.
private double encoderTicksPerSwingDegree
This number cannot have a default value because different types of encoders will be used, and each may have a different definition of a tick.
public DriveSystem(MotorSet wheels)
DriveSystem
with the given DriveMotorSet
as a base.wheels
- the DriveMotorSet
of this drive system.public DriveSystem(java.lang.String[] motornames)
DriveSystem
that uses the motors with the given names.motornames
- the names of the motors to use with this drive system.public MotorSet getMotorSet()
MotorSet
used by this drive system.MotorSet
for this drive system.motors
public abstract boolean setMovement(double forward, double clockwise)
forward
- the forward-driving vector; between -1 and 1.clockwise
- the clockwise-spinning vector; between -1 and 1.public abstract int getDriveTicks()
public abstract int getRotateTicks()
public abstract int getSwingTicks(boolean clockwise)
private double driveInchesToTicks(double inches)
inches
- inches to convert.private double rotateDegreesToTicks(double degrees)
degrees
- degrees to convert.private double swingDegreesToTicks(double degrees)
degrees
- degrees to convert.public double getDriveInches()
If other (non-drive) movement has occurred since the last encoder reset, this method will not return an accurate result.
public double getRotationDegrees()
If other (non-rotation) movement has occurred since the last encoder reset, this method will not return an accurate result.
public double getSwingDegrees(boolean clockwise)
If other (non-swing) movement has occurred since the last encoder reset, this method will not return an accurate result.
clockwise
- true
if the robot should swing clockwise, or false
if the robot should spin counter-clockwise.public void resetEncoders()
public void setEncoderTicksPerDriveInch(double ticks)
ticks
- the amount of encoder ticks in one drive-inch of this drive system.encoderTicksPerDriveInch
public void setEncoderTicksPerRotationDegree(double ticks)
ticks
- the amount of encoder ticks in one rotation degree of this drive system.encoderTicksPerRotationDegree
public void setEncoderTicksPerSwingDegree(double ticks)
ticks
- the amount of encoder ticks in one swing degree of this drive system.encoderTicksPerSwingDegree
public boolean halt()
public boolean drive(double power)
power
- the forward power; between -1 and 1.public boolean rotate(double power)
power
- the clockwise power; between -1 and 1.public boolean swing(boolean clockwise, double power)
clockwise
- true
if the robot should swing clockwise, or false
if the robot should spin counter-clockwise.power
- the forward power; between -1 and 1.public boolean driveSeconds(double power, double seconds)
power
- the forward power; between -1 and 1.seconds
- the time to move for.drive(double)
public boolean rotateSeconds(double power, double seconds)
power
- the clockwise power; between -1 and 1.seconds
- the time to move for.rotate(double)
public boolean swingSeconds(boolean clockwise, double power, double seconds)
clockwise
- true
if the robot should swing clockwise, or false
if the robot should spin counter-clockwise.power
- the forward power; between -1 and 1.seconds
- the time to move for.#swing(boolean, int)
public boolean waitAndStop(double seconds)
seconds
- the time to wait before stopping the robot.true
if no interrupt exception was thrown during the wait.public boolean driveTicks(double power, int ticks)
power
- the forward power; between -1 and 1.ticks
- the amount of encoder ticks to move for.drive(double)
public boolean rotateTicks(double power, int ticks)
power
- the clockwise power; between -1 and 1.ticks
- the amount of encoder ticks to move for.rotate(double)
public boolean swingTicks(boolean clockwise, double power, int ticks)
clockwise
- true
if the robot should swing clockwise, or false
if the robot should spin counter-clockwise.power
- the forward power; between -1 and 1.ticks
- the amount of encoder ticks to move for.swing(boolean, double)
public boolean driveInches(double power, double inches)
power
- the forward power; between -1 and 1.inches
- the distance to drive forward, in inches.public boolean rotateDegrees(double power, double degrees)
power
- the clockwise power; between -1 and 1.degrees
- the degrees to rotate the robot.rotate(double)
public boolean swingDegrees(boolean clockwise, double power, double degrees)
clockwise
- true
if the robot should swing clockwise, or false
if the robot should spin counter-clockwise.power
- the forward power; between -1 and 1.ticks
- the amount of encoder ticks to move for.swing(boolean, double)