1516b Over Under 2.0
Codebase for 1516b over under season
Loading...
Searching...
No Matches
drivetrain.cpp
Go to the documentation of this file.
1#include "robot/drivetrain.h"
2#include "api.h"
3#include "globals.h"
4
5using namespace Robot;
6using namespace Robot::Globals;
7
8int Drivetrain::CheckDeadzone(int ControllerInput) {
9 if(std::abs(ControllerInput) < Drivetrain::deadzone) {
10 return 0;
11 }
12 else {
13 return ControllerInput;
14 }
15}
16
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}
37
40}
41
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}
62
63// Set the deadzone for the drivetrain
64
65
66// Run the drivetrain depending on the control mode
67void Drivetrain::run() {
68 if (Drivetrain::driveMode == 0) {
70 }
71 if (Drivetrain::driveMode == 1) {
73 }
74}
75
76
77// Switch the drivetrain control mode between arcade and tank drive with the down button(between 1 and 2)
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}
Represents the drivetrain of the robot.
Definition drivetrain.h:23
void run()
Runs the drivetrain.
int driveMode
The current drive train mode, between arcade (0) and tank (1).
Definition drivetrain.h:72
void SwitchDrive()
Switches the DriveTrain mode between arcade and tank drive.
void ArcadeDrive()
Drives the robot using arcade drive.
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
Drivetrain()
Initializes the Drivetrain object.
void TankDrive()
Drives the robot using tank drive.
Contains global variables and type definitions for the Robot namespace.
Definition globals.cpp:18
pros::Controller controller
pros::Motor_Group drive_right
pros::Motor_Group drive_left
Contains all objects generated by the 1516B team - Contains all of the subsystems,...
Definition globals.cpp:17