public class Drivetrain extends Mechanism
init()
before being used.
This class also contains autonomous actions involving the drivetrain. encoderInit()
must be called before an autonomous action can be called.
This class describes a slidedrive drivetrain (Two motor for both sides of robot + One motor for center wheels).Modifier and Type | Field and Description |
---|---|
(package private) double |
globalAngle |
private com.qualcomm.hardware.bosch.BNO055IMU |
imu |
(package private) org.firstinspires.ftc.robotcore.external.navigation.Orientation |
lastAngles |
(package private) double |
left |
private com.qualcomm.robotcore.hardware.DcMotor |
leftFront |
(package private) double |
max |
(package private) PIDController |
pidDrive |
(package private) PIDController |
pidRotate |
(package private) double |
power |
(package private) double |
right |
private com.qualcomm.robotcore.hardware.DcMotor |
rightFront |
(package private) SingleIMU |
singleImu |
private com.qualcomm.robotcore.hardware.DcMotor |
slideDrive |
Constructor and Description |
---|
Drivetrain()
Default constructor for Drivetrain.
|
Drivetrain(com.qualcomm.robotcore.eventloop.opmode.LinearOpMode opMode)
Overloaded constructor for Drivetrain.
|
Modifier and Type | Method and Description |
---|---|
void |
drive(double y_value,
double x_value)
Set drivetrain motor power based on input.
|
void |
driveSlide(double y_value,
double x_value,
double slide,
boolean brake)
Set drivetrain motor power based on input.
|
void |
driveSlideScaled(double y_value,
double x_value,
double slide,
boolean brake)
Set drivetrain motor power based on a scaled input.
|
void |
driveStraightPID(double speed)
Drive accurately using a PID loop.
|
void |
driveToPos(double speed,
double leftInches,
double rightInches,
double timeoutS)
Drive to a relative position using encoders and an IMU.
|
void |
encoderInit()
Initializes motors for encoder driving.
|
private double |
getAngle()
Get current cumulative angle rotation from last reset.
|
private double |
getError(double targetAngle) |
double |
getHeading() |
double[] |
getPositions() |
void |
init(com.qualcomm.robotcore.hardware.HardwareMap hwMap)
Initializes drivetrain hardware.
|
void |
resetAngle() |
private void |
rotate(int degrees,
double power)
Rotate left or right the number of degrees.
|
(package private) double |
scaleInput(double joystickValue) |
void |
setDriveZeroPowers(com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior behavior) |
void |
strafe(double power)
Set center motor power for strafing.
|
void |
strafeToPos(double speed,
double inches,
double timeoutS) |
void |
turn(double speed,
double angle,
double timeoutS)
Turn to a specified angle using an IMU.
|
void |
turnPID(int angle)
Turn to a specified angle accurately using a PID loop.
|
private com.qualcomm.robotcore.hardware.DcMotor leftFront
private com.qualcomm.robotcore.hardware.DcMotor rightFront
private com.qualcomm.robotcore.hardware.DcMotor slideDrive
private com.qualcomm.hardware.bosch.BNO055IMU imu
double left
double right
double max
org.firstinspires.ftc.robotcore.external.navigation.Orientation lastAngles
double globalAngle
double power
PIDController pidRotate
PIDController pidDrive
SingleIMU singleImu
public Drivetrain()
public Drivetrain(com.qualcomm.robotcore.eventloop.opmode.LinearOpMode opMode)
opMode
- the LinearOpMode that is currently runningpublic void init(com.qualcomm.robotcore.hardware.HardwareMap hwMap)
public void encoderInit()
double scaleInput(double joystickValue)
public void drive(double y_value, double x_value)
y_value
- power for vertical direction of drivetrain (-1 to 1)x_value
- power for turning of drivetrain (-1 to 1)public void driveSlide(double y_value, double x_value, double slide, boolean brake)
y_value
- power for vertical direction of drivetrain (-1 to 1)x_value
- power for turning of drivetrain (-1 to 1)slide
- power for sliding of drivetrain (-1 to 1)public void driveSlideScaled(double y_value, double x_value, double slide, boolean brake)
y_value
- power for vertical direction of drivetrain (-1 to 1)x_value
- power for turning of drivetrain (-1 to 1)slide
- power for sliding of drivetrain (-1 to 1)public void driveToPos(double speed, double leftInches, double rightInches, double timeoutS)
speed
- maximum power of drivetrain motors when drivingleftInches
- number of inches to move on the left siderightInches
- number of inches to move on the right sidetimeoutS
- amount of time before the move should stoppublic void driveStraightPID(double speed)
speed
- speed at which the motor shall turnpublic void turnPID(int angle)
angle
- number of degrees to turnpublic void turn(double speed, double angle, double timeoutS)
speed
- maximum power of drivetrain motors when drivingangle
- number of degrees to turntimeoutS
- amount of time before the move should stoppublic void strafe(double power)
power
- power for horizontal direction of drivetrain (-1 to 1)public void strafeToPos(double speed, double inches, double timeoutS)
public double getHeading()
public double[] getPositions()
private double getError(double targetAngle)
public void resetAngle()
private double getAngle()
private void rotate(int degrees, double power)
degrees
- Degrees to turn, + is left - is rightpublic void setDriveZeroPowers(com.qualcomm.robotcore.hardware.DcMotor.ZeroPowerBehavior behavior)