Skip to content

Commit

Permalink
Added Ability for user to reverse Drive in opcontrol (#80)
Browse files Browse the repository at this point in the history
* Update drive.hpp

weird changes

* Added Reversal to opcontrol driving

* mistake deleting active break logic, added back
  • Loading branch information
Mactar1233 authored Jan 24, 2024
1 parent 32ee530 commit 081f822
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
20 changes: 19 additions & 1 deletion include/EZ-Template/drive/drive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,18 @@ class Drive {
*/
bool opcontrol_joystick_practicemode_toggle_get();

/**
* Reversal for drivetrain in opcontrol that flips the left and right side and the direction of the drive
*
* @param toggle True if you want your drivetrain reversed and False if you do not.
*/
void opcontrol_drive_reverse_set(bool toggle);

/**
* Gets current state of the toggle. Reversal for drivetrain in opcontrol that flips the left and right side and the direction of the drive.
*/
bool opcontrol_drive_reverse_get();

/////
//
// Autonomous Functions
Expand All @@ -578,7 +590,7 @@ class Drive {
* \param slew_on
* ramp up from slew_min to speed over slew_distance. only use when you're going over about 14"
* \param toggle_heading
* toggle for heading correction
* toggle for heading correction
*/
void pid_drive_set(okapi::QLength p_target, int speed, bool slew_on = false, bool toggle_heading = true);

Expand Down Expand Up @@ -1086,4 +1098,10 @@ class Drive {
void l_increase();
void r_decrease();
void r_increase();

/**
* Boolean to flip which side is the front of the robot for driver control.
*/
bool is_reversed = false;

};
9 changes: 8 additions & 1 deletion src/EZ-Template/drive/user_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,19 @@ void Drive::opcontrol_drive_sensors_reset() {
void Drive::opcontrol_joystick_practicemode_toggle(bool toggle) { practice_mode_is_on = toggle; }
bool Drive::opcontrol_joystick_practicemode_toggle_get() { return practice_mode_is_on; }

void Drive::opcontrol_drive_reverse_set(bool toggle) { is_reversed = toggle; }
bool Drive::opcontrol_drive_reverse_get() { return is_reversed; }

void Drive::opcontrol_joystick_threshold_iterate(int l_stick, int r_stick) {
// Check the motors are being set to power
if (abs(l_stick) > 0 || abs(r_stick) > 0) {
if (practice_mode_is_on && (abs(l_stick) > 120 || abs(r_stick) > 120))
drive_set(0, 0);
else
drive_set(l_stick, r_stick);
if(is_reversed == true)
drive_set(-r_stick, -l_stick);
else
drive_set(l_stick, r_stick);
if (active_brake_kp != 0) drive_sensor_reset();
}
// When joys are released, run active brake (P) on drive
Expand All @@ -229,6 +235,7 @@ void Drive::opcontrol_joystick_threshold_iterate(int l_stick, int r_stick) {
}
}


// Clip joysticks based on joystick threshold
int Drive::clipped_joystick(int joystick) { return abs(joystick) < JOYSTICK_THRESHOLD ? 0 : joystick; }

Expand Down

0 comments on commit 081f822

Please sign in to comment.