1516b Over Under 2.0
Codebase for 1516b over under season
Loading...
Searching...
No Matches
Robot::Drivetrain Class Reference

Represents the drivetrain of the robot. More...

#include <drivetrain.h>

Public Member Functions

void run ()
 Runs the drivetrain.
 
void setdeadzone (int newDeadZone)
 Sets the joystick deadzone.
 
int getdeadzone ()
 Returns the current deadzone value.
 
void SwitchDrive ()
 Switches the DriveTrain mode between arcade and tank drive.
 
 Drivetrain ()
 Initializes the Drivetrain object.
 

Public Attributes

int driveMode
 The current drive train mode, between arcade (0) and tank (1).
 

Private Member Functions

void ArcadeDrive ()
 Drives the robot using arcade drive.
 
void TankDrive ()
 Drives the robot using tank drive.
 
int CheckDeadzone (int entry)
 Checks if the controller input is inside the deadzone range.
 

Private Attributes

int deadzone
 The deadzone value for the joystick.
 

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 deadzone value for the joystick. The deadzone is a range around the joystick's resting position where no movement is registered. By adjusting the deadzone value, the sensitivity of the joystick inputs can be fine-tuned.

Definition at line 23 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 38 of file drivetrain.cpp.

38 {
40}
int driveMode
The current drive train mode, between arcade (0) and tank (1).
Definition drivetrain.h:72

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

17 {
18
20 // Arcade Measurements
21 int left = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
22 int right = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_X);
23
24
25 // std::abs takes the absolute value of whatever it is called on.
26 // Thus, any values in range (-5,5) are discarded as 0.
27 left = CheckDeadzone(left);
28 right = CheckDeadzone(right);
29
30 // Arcade movement
31 // Move the left side of the robot
32 drive_left.move(left + right);
33
34 // Move the right side of the robot
35 drive_right.move(left - right);
36}
int CheckDeadzone(int entry)
Checks if the controller input is inside the deadzone range.
Definition drivetrain.cpp:8
int deadzone
The deadzone value for the joystick.
Definition drivetrain.h:104
pros::Controller controller
pros::Motor_Group drive_right
pros::Motor_Group drive_left

References CheckDeadzone(), Robot::Globals::controller, deadzone, Robot::Globals::drive_left, and Robot::Globals::drive_right.

Referenced by run().

◆ CheckDeadzone()

int Drivetrain::CheckDeadzone ( int entry)
private

Checks if the controller input is inside the deadzone range.

Parameters
entryThe controller input to check.
Returns
The input value if it is outside the deadzone range, otherwise 0.

Definition at line 8 of file drivetrain.cpp.

8 {
9 if(std::abs(ControllerInput) < Drivetrain::deadzone) {
10 return 0;
11 }
12 else {
13 return ControllerInput;
14 }
15}

References deadzone.

Referenced by ArcadeDrive(), and TankDrive().

◆ getdeadzone()

int Robot::Drivetrain::getdeadzone ( )

Returns the current deadzone value.

Returns
The deadzone value.

The deadzone is a range around the joystick's resting position where no movement is registered. This function returns the current deadzone value that is being used by the drivetrain.

The deadzone value can be used to fine-tune the drivetrain's responsiveness to joystick inputs. By retrieving the current deadzone value, you can adjust other parts of your code to take it into account.

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

67 {
68 if (Drivetrain::driveMode == 0) {
70 }
71 if (Drivetrain::driveMode == 1) {
73 }
74}
void ArcadeDrive()
Drives the robot using arcade drive.
void TankDrive()
Drives the robot using tank drive.

References ArcadeDrive(), driveMode, and TankDrive().

Referenced by opcontrol().

◆ setdeadzone()

void Robot::Drivetrain::setdeadzone ( int newDeadZone)

Sets the joystick deadzone.

Parameters
newDeadZoneThe new deadzone value.

The deadzone is a range around the joystick's resting position where no movement is registered. This function allows you to set the deadzone value to filter out small joystick movements.

The deadzone value determines the sensitivity of the joystick inputs. A higher deadzone value will require larger joystick movements to register any movement in the drivetrain. Conversely, a lower deadzone value will make the drivetrain more responsive to small joystick movements.

◆ SwitchDrive()

void Drivetrain::SwitchDrive ( )

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

78 {
79 if(controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_DOWN)) {
81 if (Drivetrain::driveMode == 2) {
83 }
84
85 if (Drivetrain::driveMode == 0) {
86 controller.print(0, 0, "Drive: Arcade");
87 }
88 if (Drivetrain::driveMode == 1) {
89 controller.print(0, 0, "Drive: Tank");
90 }
91 }
92}

References Robot::Globals::controller, and driveMode.

Referenced by Robot::Utility::toggleSubsystemOptions().

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

42 {
43
45
46 int left = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
47 int right = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);
48
49
50 // std::abs takes the absolute value of whatever it is called on.
51 // Thus, any values in range (-5,5) are discarded as 0.
52 left = CheckDeadzone(left);
53 right = CheckDeadzone(right);
54
55 // Arcade movement
56 // Move the left side of the robot
57 drive_left.move(left);
58
59 // Move the right side of the robot
60 drive_right.move(right);
61}

References CheckDeadzone(), Robot::Globals::controller, deadzone, Robot::Globals::drive_left, and Robot::Globals::drive_right.

Referenced by run().

Member Data Documentation

◆ deadzone

int Robot::Drivetrain::deadzone
private

The deadzone value for the joystick.

Definition at line 104 of file drivetrain.h.

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

◆ driveMode

int Robot::Drivetrain::driveMode

The current drive train mode, between arcade (0) and tank (1).

Definition at line 72 of file drivetrain.h.

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


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