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#include <cmath>
4#define DEFAULT_DELAY_LENGTH 15
5
6using namespace Robot;
7using namespace Robot::Globals;
8
10
11bool Drivetrain::isReversed = false;
12
14
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}
29
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}
45
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}
55
56// Run the drivetrain depending on the control mode
58 switch (Drivetrain::driveMode) {
59 case CURVATURE_DRIVE:
61 break;
62 case ARCADE_DRIVE:
64 break;
65 case TANK_DRIVE:
67 break;
68 }
69}
70
71// Cycle through each drivetrain control mode, overflows back to 0
73 int driveMode = (Drivetrain::driveMode + 1) % (TANK_DRIVE + 1);
74 return SwitchDrive(driveMode);
75}
76
79 // Sets each motor to its opposite direction - see globals.cpp for motor ports
80 return thrust * -1;
81 }
82 return thrust;
83}
84
85// Switch the drivetrain control mode between arcade and tank drive with the down button(between 1 and 2)
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}
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:4
Contains the declaration of the Drivetrain class.
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)
Definition auton.h:10