1516X High Stakes 2.0
Codebase for 1516X High Stakes season
Loading...
Searching...
No Matches
Robot::Drivetrain Class Reference

Represents the drivetrain of the robot. More...

#include <drivetrain.h>

Public Types

enum  DRIVE_MODE { CURVATURE_DRIVE = 0 , ARCADE_DRIVE = 1 , TANK_DRIVE = 2 }
 Drive control schemes. More...
 

Public Member Functions

 Drivetrain ()
 Initializes the Drivetrain object.
 
void run ()
 Runs the drivetrain.
 

Static Public Member Functions

static std::string SwitchDrive (int driveMode)
 Switches the DriveTrain mode between arcade and tank drive.
 
static std::string toggleDrive ()
 Cycles through each drivetrain control mode.
 
static int thrustHandler (int thrust)
 Toggles the orientation of the drivetrain.
 

Static Public Attributes

static DRIVE_MODE driveMode = CURVATURE_DRIVE
 Active drive control scheme.
 
static bool isReversed = false
 

Private Member Functions

void ArcadeDrive ()
 Drives the robot using arcade drive.
 
void CurvatureDrive ()
 Drives the robot using curvature drive.
 
void TankDrive ()
 Drives the robot using tank drive.
 

Detailed Description

Represents the drivetrain of the robot.

The Drivetrain class is responsible for controlling the movement of the robot's drivetrain. It provides functions to interpret joystick inputs and convert them into appropriate drivetrain movements. The drivetrain can be controlled using different drive modes, such as tank drive or arcade drive.

The Drivetrain class also allows setting and retrieving the dead zone value for the joystick. The dead zone is a range around the joystick's resting position where no movement is registered. By adjusting the dead zone value, the sensitivity of the joystick inputs can be fine-tuned.

Definition at line 26 of file drivetrain.h.

Member Enumeration Documentation

◆ DRIVE_MODE

Drive control schemes.

Data type representing all possible driving control schemes that can be used on the robot. Multiple drive modes can be used during runtime without recompilation.

Enumerator
CURVATURE_DRIVE 
ARCADE_DRIVE 
TANK_DRIVE 

Definition at line 42 of file drivetrain.h.

Constructor & Destructor Documentation

◆ Drivetrain()

Drivetrain::Drivetrain ( )

Initializes the Drivetrain object.

This constructor is responsible for initializing the Drivetrain object and setting default values.

Definition at line 12 of file drivetrain.cpp.

static DRIVE_MODE driveMode
Active drive control scheme.
Definition drivetrain.h:47

References CURVATURE_DRIVE, and driveMode.

Member Function Documentation

◆ ArcadeDrive()

void Drivetrain::ArcadeDrive ( )
private

Drives the robot using arcade drive.

Arcade drive uses the left joystick for forward and backward movement, and the right joystick for left and right movement.

Definition at line 23 of file drivetrain.cpp.

23 {
24 // Arcade Measurements
25 int left = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
26 int right = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X);
27
28 chassis.arcade(thrustHandler(left), thrustHandler(right), false, 0.6);
29
30 pros::delay(DEFAULT_DELAY_LENGTH);
31}
static int thrustHandler(int thrust)
Toggles the orientation of the drivetrain.
#define DEFAULT_DELAY_LENGTH
Definition drivetrain.cpp:3
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
pros::Controller controller(pros::E_CONTROLLER_MASTER)

References Robot::Globals::chassis(), Robot::Globals::controller(), DEFAULT_DELAY_LENGTH, and thrustHandler().

Referenced by run().

◆ CurvatureDrive()

void Drivetrain::CurvatureDrive ( )
private

Drives the robot using curvature drive.

Curvature drive applies curvature to turns and a negative inertia accumulator.

Definition at line 14 of file drivetrain.cpp.

14 {
15 int left = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
16 int right = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X);
17
18 chassis.curvature(thrustHandler(left), thrustHandler(right));
19
20 pros::delay(DEFAULT_DELAY_LENGTH);
21}

References Robot::Globals::chassis(), Robot::Globals::controller(), DEFAULT_DELAY_LENGTH, and thrustHandler().

Referenced by run().

◆ run()

void Drivetrain::run ( )

Runs the drivetrain.

This function is responsible for controlling the movement of the robot's drivetrain. It executes the necessary actions to make the robot move according to the current drive mode.

The drivetrain can be controlled using different drive modes, such as tank drive or arcade drive. This function implements the logic to interpret the joystick inputs and convert them into appropriate drivetrain movements.

Definition at line 43 of file drivetrain.cpp.

43 {
44 switch (Drivetrain::driveMode) {
45 case CURVATURE_DRIVE:
47 break;
48 case ARCADE_DRIVE:
50 break;
51 case TANK_DRIVE:
53 break;
54 }
55}
void ArcadeDrive()
Drives the robot using arcade drive.
void CurvatureDrive()
Drives the robot using curvature drive.
void TankDrive()
Drives the robot using tank drive.

References ARCADE_DRIVE, ArcadeDrive(), CURVATURE_DRIVE, CurvatureDrive(), driveMode, TANK_DRIVE, and TankDrive().

◆ SwitchDrive()

std::string Drivetrain::SwitchDrive ( int driveMode)
static

Switches the DriveTrain mode between arcade and tank drive.

The drive mode determines how the drivetrain interprets the joystick inputs. Arcade drive uses the left joystick for forward and backward movement, and the right joystick for left and right movement. Tank drive uses the left and right joysticks for controlling the left and right sides of the robot.

Definition at line 72 of file drivetrain.cpp.

72 {
73 switch (driveMode) {
74 case 0:
76 std::cout << "Curvature Drive" << std::endl;
77 return "Curvature Drive";
78 case 1:
80 std::cout << "Arcade Drive" << std::endl;
81 return "Arcade Drive";
82 case 2:
84 std::cout << "Tank Drive" << std::endl;
85 return "Tank Drive";
86 default:
87 std::cout << "Not a valid drivetrain control mode!" << std::endl;
88 return "Not a valid driveMode!";
89 }
90}

References ARCADE_DRIVE, CURVATURE_DRIVE, driveMode, and TANK_DRIVE.

Referenced by toggleDrive().

◆ TankDrive()

void Drivetrain::TankDrive ( )
private

Drives the robot using tank drive.

Tank drive uses the left and right joysticks for controlling the left and right sides of the robot.

Definition at line 33 of file drivetrain.cpp.

33 {
34 int left = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
35 int right = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);
36
37 chassis.tank(thrustHandler(left), thrustHandler(right));
38
39 pros::delay(DEFAULT_DELAY_LENGTH);
40}

References Robot::Globals::chassis(), Robot::Globals::controller(), DEFAULT_DELAY_LENGTH, and thrustHandler().

Referenced by run().

◆ thrustHandler()

int Drivetrain::thrustHandler ( int thrust)
static

Toggles the orientation of the drivetrain.

Definition at line 63 of file drivetrain.cpp.

63 {
65 // Sets each motor to its opposite direction - see globals.cpp for motor ports
66 return thrust * -1;
67 }
68 return thrust;
69}
static bool isReversed
Definition drivetrain.h:82

References isReversed.

Referenced by ArcadeDrive(), CurvatureDrive(), and TankDrive().

◆ toggleDrive()

std::string Drivetrain::toggleDrive ( )
static

Cycles through each drivetrain control mode.

Definition at line 58 of file drivetrain.cpp.

58 {
59 int driveMode = (Drivetrain::driveMode + 1) % (TANK_DRIVE + 1);
60 return SwitchDrive(driveMode);
61}
static std::string SwitchDrive(int driveMode)
Switches the DriveTrain mode between arcade and tank drive.

References driveMode, SwitchDrive(), and TANK_DRIVE.

Member Data Documentation

◆ driveMode

Drivetrain::DRIVE_MODE Drivetrain::driveMode = CURVATURE_DRIVE
static

Active drive control scheme.

Definition at line 47 of file drivetrain.h.

Referenced by Drivetrain(), run(), SwitchDrive(), and toggleDrive().

◆ isReversed

bool Drivetrain::isReversed = false
static

Definition at line 82 of file drivetrain.h.

Referenced by opcontrol(), and thrustHandler().


The documentation for this class was generated from the following files: