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 tank drivetrain.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 |
leftBack |
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 |
rightBack |
private com.qualcomm.robotcore.hardware.DcMotor |
rightFront |
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 |
driveArcade(double y_value,
double x_value)
Set drivetrain motor power Arcade style based on input.
|
void |
driveParametric(double v_y,
double v_x,
double v_rot) |
void |
driveStraightPID(double speed,
double correction)
Drive accurately using a PID loop.
|
void |
driveTank(double left,
double right)
Set drivetrain motor power Tank style based on input.
|
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.
|
void |
turn(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 leftBack
private com.qualcomm.robotcore.hardware.DcMotor rightFront
private com.qualcomm.robotcore.hardware.DcMotor rightBack
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
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()
public void driveArcade(double y_value, double x_value)
y_value
- power for left side of drivetrain (-1 to 1)x_value
- power for right side of drivetrain (-1 to 1)public void driveTank(double left, double right)
left
- power for left side of drivetrain (-1 to 1)right
- power for right side of drivetrain (-1 to 1)public void driveParametric(double v_y, double v_x, double v_rot)
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, double correction)
speed
- speed at which the motor shall turncorrection
- a placeholder value for PID output in case correction isnt given a new valuepublic void turnPID(int angle)
angle
- number of degrees to turnpublic void turn(double angle, double timeoutS)
angle
- number of degrees to turntimeoutS
- amount of time before the move should stoppublic double getHeading()
private double getError(double targetAngle)
public double[] getPositions()
public void resetAngle()
private double getAngle()
private void rotate(int degrees, double power)
degrees
- Degrees to turn, + is left - is right