1516X High Stakes 2.0
Codebase for 1516X High Stakes season
Loading...
Searching...
No Matches
drivetrain.cpp
Go to the documentation of this file.
1#include "robot/drivetrain.h"
2#include "globals.h"
3#define DEFAULT_DELAY_LENGTH 15
4
5using namespace Robot;
6using namespace Robot::Globals;
7
9
10bool Drivetrain::isReversed = false;
11
13
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}
22
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}
32
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}
41
42// Run the drivetrain depending on the control mode
44 switch (Drivetrain::driveMode) {
45 case CURVATURE_DRIVE:
47 break;
48 case ARCADE_DRIVE:
50 break;
51 case TANK_DRIVE:
53 break;
54 }
55}
56
57// Cycle through each drivetrain control mode, overflows back to 0
59 int driveMode = (Drivetrain::driveMode + 1) % (TANK_DRIVE + 1);
60 return SwitchDrive(driveMode);
61}
62
65 // Sets each motor to its opposite direction - see globals.cpp for motor ports
66 return thrust * -1;
67 }
68 return thrust;
69}
70
71// Switch the drivetrain control mode between arcade and tank drive with the down button(between 1 and 2)
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}
static std::string toggleDrive()
Cycles through each drivetrain control mode.
void run()
Runs the drivetrain.
static std::string SwitchDrive(int driveMode)
Switches the DriveTrain mode between arcade and tank drive.
DRIVE_MODE
Drive control schemes.
Definition drivetrain.h:42
void ArcadeDrive()
Drives the robot using arcade drive.
static DRIVE_MODE driveMode
Active drive control scheme.
Definition drivetrain.h:47
Drivetrain()
Initializes the Drivetrain object.
void CurvatureDrive()
Drives the robot using curvature drive.
static int thrustHandler(int thrust)
Toggles the orientation of the drivetrain.
static bool isReversed
Definition drivetrain.h:82
void TankDrive()
Drives the robot using tank drive.
#define DEFAULT_DELAY_LENGTH
Definition drivetrain.cpp:3
Contains the declaration of the Drivetrain class.
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve)
pros::Controller controller(pros::E_CONTROLLER_MASTER)
Definition auton.h:8