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 13 of file drivetrain.cpp.

13{}

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 30 of file drivetrain.cpp.

30 {
31 // Arcade Measurements
32 int throttle = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
33 int turn = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X);
34
35 // Makes the turning of the robot even more controlled when the thrust is 0, as the robot's turning is proportional to
36 // the thrust of the robot has no thrust. Based on an exponential drive curve.
37 if (throttle <= 1) {
38 turn = std::round(arcade_turn_curve.curve(turn));
39 }
40
41 chassis.arcade(thrustHandler(throttle), thrustHandler(turn), false, 0.55);
42
43 pros::delay(DEFAULT_DELAY_LENGTH);
44}
static int thrustHandler(int thrust)
Toggles the orientation of the drivetrain.
#define DEFAULT_DELAY_LENGTH
Definition drivetrain.cpp:4
lemlib::ExpoDriveCurve arcade_turn_curve(1, 8, 1.016)
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
pros::Controller controller(pros::E_CONTROLLER_MASTER)

References Robot::Globals::arcade_turn_curve(), 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 15 of file drivetrain.cpp.

15 {
16 int throttle = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
17 int turn = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X);
18
19 // Makes the turning of the robot even more controlled when the thrust is 0, as the robot's turning is proportional to
20 // the thrust of the robot has no thrust. Based on an exponential drive curve.
21 if (throttle <= 1) {
22 turn = std::round(arcade_turn_curve.curve(turn));
23 }
24
25 chassis.curvature(thrustHandler(throttle), thrustHandler(turn));
26
27 pros::delay(DEFAULT_DELAY_LENGTH);
28}

References Robot::Globals::arcade_turn_curve(), 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 57 of file drivetrain.cpp.

57 {
58 switch (Drivetrain::driveMode) {
59 case CURVATURE_DRIVE:
61 break;
62 case ARCADE_DRIVE:
64 break;
65 case TANK_DRIVE:
67 break;
68 }
69}
void ArcadeDrive()
Drives the robot using arcade drive.
static DRIVE_MODE driveMode
Active drive control scheme.
Definition drivetrain.h:47
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 86 of file drivetrain.cpp.

86 {
87 switch (driveMode) {
88 case 0:
90 std::cout << "Curvature Drive" << std::endl;
91 return "Curvature Drive";
92 case 1:
94 std::cout << "Arcade Drive" << std::endl;
95 return "Arcade Drive";
96 case 2:
98 std::cout << "Tank Drive" << std::endl;
99 return "Tank Drive";
100 default:
101 std::cout << "Not a valid drivetrain control mode!" << std::endl;
102 return "Not a valid driveMode!";
103 }
104}

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 46 of file drivetrain.cpp.

46 {
47 int throttle = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
48 int turn = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);
49
50
51 chassis.tank(thrustHandler(throttle), thrustHandler(turn));
52
53 pros::delay(DEFAULT_DELAY_LENGTH);
54}

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 77 of file drivetrain.cpp.

77 {
79 // Sets each motor to its opposite direction - see globals.cpp for motor ports
80 return thrust * -1;
81 }
82 return thrust;
83}
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 72 of file drivetrain.cpp.

72 {
73 int driveMode = (Drivetrain::driveMode + 1) % (TANK_DRIVE + 1);
74 return SwitchDrive(driveMode);
75}
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 run(), SwitchDrive(), and toggleDrive().

◆ isReversed

bool Drivetrain::isReversed = false
static

Definition at line 82 of file drivetrain.h.

Referenced by thrustHandler().


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