Skip to content

Commit

Permalink
Cleaned user_input.cpp #31
Browse files Browse the repository at this point in the history
  • Loading branch information
ssejrog committed Dec 29, 2021
1 parent fcf3aed commit 8c373b5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
1 change: 1 addition & 0 deletions include/EZ-Template/drive/drive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ class Drive {

private: // !Auton
void reset_drive_sensors_opcontrol();
void joy_thresh_opcontrol(int l_stick, int r_stick);

// Heading toggle
bool heading_on = true;
Expand Down
45 changes: 18 additions & 27 deletions src/EZ-Template/drive/user_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ void Drive::reset_drive_sensors_opcontrol() {
}
}

void Drive::joy_thresh_opcontrol(int l_stick, int r_stick) {
// Threshold if joysticks don't come back to perfect 0
if (abs(l_stick) > JOYSTICK_THRESHOLD || abs(r_stick) > JOYSTICK_THRESHOLD) {
set_tank(l_stick, r_stick);
if (active_brake_kp != 0) reset_drive_sensor();
}
// When joys are released, run active brake (P) on drive
else {
set_tank((0 - left_sensor()) * active_brake_kp, (0 - right_sensor()) * active_brake_kp);
}
}

// Tank control
void Drive::tank() {
mode = DISABLE;
Expand All @@ -202,15 +214,8 @@ void Drive::tank() {
int l_stick = left_curve_function(master.get_analog(ANALOG_LEFT_Y));
int r_stick = left_curve_function(master.get_analog(ANALOG_RIGHT_Y));

// Threshold if joysticks don't come back to perfect 0
if (abs(l_stick) > JOYSTICK_THRESHOLD || abs(r_stick) > JOYSTICK_THRESHOLD) {
set_tank(l_stick, r_stick);
reset_drive_sensor();
}
// When joys are released, run active brake (P) on drive
else {
set_tank((0 - left_sensor()) * active_brake_kp, (0 - right_sensor()) * active_brake_kp);
}
// Set robot to l_stick and r_stick, check joystick threshold, set active brake
joy_thresh_opcontrol(l_stick, r_stick);
}

// Arcade standard
Expand All @@ -234,15 +239,8 @@ void Drive::arcade_standard(e_type stick_type) {
r_stick = right_curve_function(master.get_analog(ANALOG_LEFT_X));
}

// Threshold if joysticks don't come back to perfect 0
if (abs(l_stick) > JOYSTICK_THRESHOLD || abs(r_stick) > JOYSTICK_THRESHOLD) {
set_tank(l_stick + r_stick, l_stick - r_stick);
reset_drive_sensor();
}
// When joys are released, run active brake (P) on drive
else {
set_tank((0 - left_sensor()) * active_brake_kp, (0 - right_sensor()) * active_brake_kp);
}
// Set robot to l_stick and r_stick, check joystick threshold, set active brake
joy_thresh_opcontrol(l_stick, r_stick);
}

// Arcade control flipped
Expand All @@ -266,13 +264,6 @@ void Drive::arcade_flipped(e_type stick_type) {
l_stick = left_curve_function(master.get_analog(ANALOG_RIGHT_X));
}

// Threshold if joysticks don't come back to perfect 0
if (abs(l_stick) > JOYSTICK_THRESHOLD || abs(r_stick) > JOYSTICK_THRESHOLD) {
set_tank(r_stick + l_stick, r_stick - l_stick);
reset_drive_sensor();
}
// When joys are released, run active brake (P) on drive
else {
set_tank((0 - left_sensor()) * active_brake_kp, (0 - right_sensor()) * active_brake_kp);
}
// Set robot to l_stick and r_stick, check joystick threshold, set active brake
joy_thresh_opcontrol(l_stick, r_stick);
}
9 changes: 5 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "main.h"

/*

// Chassis constructor
Drive chassis (
// Left Chassis Ports (negative port will reverse it!)
Expand All @@ -27,7 +27,7 @@ Drive chassis (
// eg. if your drive is 84:36 where the 36t is powered, your RATIO would be 2.333.
// eg. if your drive is 36:60 where the 60t is powered, your RATIO would be 0.6.
,2
*/


// Uncomment if using tracking wheels
/*
Expand All @@ -41,8 +41,8 @@ Drive chassis (
// Uncomment if tracking wheels are plugged into a 3 wire expander
// 3 Wire Port Expander Smart Port
// ,1
//);

);
/*
// Chassis constructor with rotation sensor
Drive chassis (
// Left Chassis Ports (negative port will reverse it!)
Expand Down Expand Up @@ -72,6 +72,7 @@ Drive chassis (
// Left Rotation Port (negative port will reverse it!)
,7
);
*/



Expand Down

0 comments on commit 8c373b5

Please sign in to comment.