Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Ability for user to reverse Drive in opcontrol #80

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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