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 Public Attributes

static DRIVE_MODE driveMode = CURVATURE_DRIVE
 Active drive control scheme.
 

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 27 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 43 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 10 of file drivetrain.cpp.

11{
13}
static DRIVE_MODE driveMode
Active drive control scheme.
Definition drivetrain.h:48

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

26{
27 // Arcade Measurements
28 int left = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
29 int right = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X);
30
31 chassis.arcade(left, right, false, 0.6);
32
33 pros::delay(15);
34}
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
pros::Controller controller(pros::E_CONTROLLER_MASTER)

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

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.

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

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

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

49{
50 switch (Drivetrain::driveMode) {
51 case CURVATURE_DRIVE:
53 break;
54 case ARCADE_DRIVE:
56 break;
57 case TANK_DRIVE:
59 break;
60 }
61}
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().

Referenced by opcontrol().

◆ 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 71 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 36 of file drivetrain.cpp.

37{
38 int left = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
39 int right = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);
40
41 chassis.tank(left, right);
42
43 pros::delay(15);
44}

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

Referenced by run().

◆ toggleDrive()

std::string Drivetrain::toggleDrive ( )
static

Cycles through each drivetrain control mode.

Definition at line 64 of file drivetrain.cpp.

65{
66 int driveMode = (Drivetrain::driveMode + 1) % (TANK_DRIVE + 1);
67 return SwitchDrive(driveMode);
68}
static std::string SwitchDrive(int driveMode)
Switches the DriveTrain mode between arcade and tank drive.

References driveMode, SwitchDrive(), and TANK_DRIVE.

Referenced by opcontrol().

Member Data Documentation

◆ driveMode

Drivetrain::DRIVE_MODE Drivetrain::driveMode = CURVATURE_DRIVE
static

Active drive control scheme.

Definition at line 48 of file drivetrain.h.

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


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