Skip to content

Commit

Permalink
Fixed arcade control (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssejrog committed Jan 19, 2022
1 parent 4ddea1d commit f992549
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
Binary file renamed [email protected][email protected]
Binary file not shown.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ EXCLUDE_COLD_LIBRARIES:=
IS_LIBRARY:=1
# TODO: CHANGE THIS!
LIBNAME:=EZ-Template
VERSION:=2.1.0
VERSION:=2.1.1
# EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c
# this line excludes opcontrol.c and similar files
EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/autons $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext)))
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permalink: /
Simple plug-and-play PROS template that handles drive base functions for VEX robots.


[EZ-Template Version](https://github.com/EZ-Robotics/EZ-Template): 2.1.0
[EZ-Template Version](https://github.com/EZ-Robotics/EZ-Template): 2.1.1

[Autonomous routines that used EZ-Template](https://photos.app.goo.gl/yRwuvmq7hDoM4f6EA)

Expand All @@ -26,9 +26,9 @@ Simple plug-and-play PROS template that handles drive base functions for VEX rob
## Upgrading
*Note: this only works for 2.0.0 and beyond. You cannot upgrade from 1.X.X to 2.X.X.*
1) Download the most recent EZ-Template [here](https://github.com/EZ-Robotics/EZ-Template/releases/latest).
2) In your terminal, `cd` into the directory you downloaded the file.
3) Run this command from terminal `prosv5 c fetch [email protected]`.
4) `cd` into your pros project directory in your terminal.
2) Move the file to your project.
3) Open terminal or command prompt, and `cd` into your projects directory.
4) Run this command from terminal `prosv5 c fetch [email protected]`.
5) Apply the library to the project `prosv5 c apply EZ-Template`.
6) Put `#include "EZ-Template/api.hpp"` in your `include/main.h`.

Expand Down
44 changes: 22 additions & 22 deletions src/EZ-Template/drive/user_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ void Drive::init_curve_sd() {
fread(l_buf, 1, 5, l_usd_file_read);
left_curve_scale = std::stof(l_buf);
fclose(l_usd_file_read);
}
}
// If file doesn't exist, create file
else {
save_l_curve_sd(); // Writing to a file that doesn't exist creates the file
save_l_curve_sd(); // Writing to a file that doesn't exist creates the file
printf("Created left_curve.txt\n");
}

Expand All @@ -41,10 +41,10 @@ void Drive::init_curve_sd() {
fread(l_buf, 1, 5, r_usd_file_read);
right_curve_scale = std::stof(l_buf);
fclose(r_usd_file_read);
}
}
// If file doesn't exist, create file
else {
save_r_curve_sd(); // Writing to a file that doesn't exist creates the file
save_r_curve_sd(); // Writing to a file that doesn't exist creates the file
printf("Created right_curve.txt\n");
}
}
Expand Down Expand Up @@ -157,21 +157,21 @@ void Drive::modify_curve_with_controller() {
// Left curve function
double Drive::left_curve_function(double x) {
if (left_curve_scale != 0) {
//if (CURVE_TYPE)
// if (CURVE_TYPE)
return (powf(2.718, -(left_curve_scale / 10)) + powf(2.718, (fabs(x) - 127) / 10) * (1 - powf(2.718, -(left_curve_scale / 10)))) * x;
//else
//return powf(2.718, ((abs(x)-127)*RIGHT_CURVE_SCALE)/100)*x;
// else
// return powf(2.718, ((abs(x)-127)*RIGHT_CURVE_SCALE)/100)*x;
}
return x;
}

// Right curve fnuction
double Drive::right_curve_function(double x) {
if (right_curve_scale != 0) {
//if (CURVE_TYPE)
// if (CURVE_TYPE)
return (powf(2.718, -(right_curve_scale / 10)) + powf(2.718, (fabs(x) - 127) / 10) * (1 - powf(2.718, -(right_curve_scale / 10)))) * x;
//else
//return powf(2.718, ((abs(x)-127)*RIGHT_CURVE_SCALE)/100)*x;
// else
// return powf(2.718, ((abs(x)-127)*RIGHT_CURVE_SCALE)/100)*x;
}
return x;
}
Expand Down Expand Up @@ -225,20 +225,20 @@ void Drive::arcade_standard(e_type stick_type) {
// Toggle for controller curve
modify_curve_with_controller();

int l_stick, r_stick;
int fwd_stick, turn_stick;
// Check arcade type (split vs single, normal vs flipped)
if (stick_type == SPLIT) {
// Put the joysticks through the curve function
l_stick = left_curve_function(master.get_analog(ANALOG_LEFT_Y));
r_stick = right_curve_function(master.get_analog(ANALOG_RIGHT_X));
fwd_stick = left_curve_function(master.get_analog(ANALOG_LEFT_Y));
turn_stick = right_curve_function(master.get_analog(ANALOG_RIGHT_X));
} else if (stick_type == SINGLE) {
// Put the joysticks through the curve function
l_stick = left_curve_function(master.get_analog(ANALOG_LEFT_Y));
r_stick = right_curve_function(master.get_analog(ANALOG_LEFT_X));
fwd_stick = left_curve_function(master.get_analog(ANALOG_LEFT_Y));
turn_stick = right_curve_function(master.get_analog(ANALOG_LEFT_X));
}

// Set robot to l_stick and r_stick, check joystick threshold, set active brake
joy_thresh_opcontrol(l_stick, r_stick);
joy_thresh_opcontrol(fwd_stick + turn_stick, fwd_stick - turn_stick);
}

// Arcade control flipped
Expand All @@ -249,18 +249,18 @@ void Drive::arcade_flipped(e_type stick_type) {
// Toggle for controller curve
modify_curve_with_controller();

int l_stick, r_stick;
int turn_stick, fwd_stick;
// Check arcade type (split vs single, normal vs flipped)
if (stick_type == SPLIT) {
// Put the joysticks through the curve function
r_stick = right_curve_function(master.get_analog(ANALOG_RIGHT_Y));
l_stick = left_curve_function(master.get_analog(ANALOG_LEFT_X));
fwd_stick = right_curve_function(master.get_analog(ANALOG_RIGHT_Y));
turn_stick = left_curve_function(master.get_analog(ANALOG_LEFT_X));
} else if (stick_type == SINGLE) {
// Put the joysticks through the curve function
r_stick = right_curve_function(master.get_analog(ANALOG_RIGHT_Y));
l_stick = left_curve_function(master.get_analog(ANALOG_RIGHT_X));
fwd_stick = right_curve_function(master.get_analog(ANALOG_RIGHT_Y));
turn_stick = left_curve_function(master.get_analog(ANALOG_RIGHT_X));
}

// Set robot to l_stick and r_stick, check joystick threshold, set active brake
joy_thresh_opcontrol(l_stick, r_stick);
joy_thresh_opcontrol(fwd_stick + turn_stick, fwd_stick - turn_stick);
}
2 changes: 1 addition & 1 deletion src/EZ-Template/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void print_ez_template() {
|_|
)" << '\n';

printf("Version: 2.1.0\n");
printf("Version: 2.1.1\n");
}
std::string get_last_word(std::string text) {
std::string word = "";
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.1.1

0 comments on commit f992549

Please sign in to comment.