Skip to content

Commit

Permalink
Updated names in auton_selector.hpp EZ-Robotics#65
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhlb committed Oct 24, 2022
1 parent 0ab1f66 commit 02a755a
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 115 deletions.
2 changes: 1 addition & 1 deletion docs/Docs/auton_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void autonomous() {
chassis.reset_drive_sensor(); // Reset drive sensors to 0
chassis.set_drive_brake(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency.

ez::as::auton_selector.call_selected_auton(); // Calls selected auton from autonomous selector.
ez::as::auton_selector.selected_auton_call(); // Calls selected auton from autonomous selector.
}
```

Expand Down
18 changes: 9 additions & 9 deletions docs/Docs/auton_selector.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ void initialize() {
---


## add_autons();
## autons_add();
Adds autonomous routines to the autonomous selector. Uses `ez::screen_print()` to display to the brain.
**Prototype**
```cpp
void add_autons(std::vector<Auton> autons);
void autons_add(std::vector<Auton> autons);
```
**Example**
Expand All @@ -103,7 +103,7 @@ void auto3() {
}
void initialize() {
ez::as::auton_selector.add_autons({
ez::as::auton_selector.autons_add({
Auton("Autonomous 1\nDoes Something", auto1),
Auton("Autonomous 2\nDoes Something Else", auto2),
Auton("Autonomous 3\nDoes Something More", auto3),
Expand All @@ -115,17 +115,17 @@ void initialize() {
---


## print_selected_auton();
## selected_auton_print();
Prints the current autonomous mode to the screen.
**Prototype**
```cpp
void print_selected_auton();
void selected_auton_print();
```

**Example**
```cpp
void initialize() {
ez::as::auton_selector.print_selected_auton();
ez::as::auton_selector.selected_auton_print();
}
```

Expand Down Expand Up @@ -172,11 +172,11 @@ void initialize() {
---


## call_selected_auton()
## selected_auton_call()
Runs the current autonomous that's selected.
**Prototype**
```cpp
void call_selected_auton();
void selected_auton_call();
```

**Example**
Expand All @@ -186,7 +186,7 @@ void autonomous() {
chassis.reset_drive_sensor();
chassis.set_drive_brake(MOTOR_BRAKE_HOLD);

ez::as::auton_selector.call_selected_auton();
ez::as::auton_selector.selected_auton_call();
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/Releases/2.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void autonomous() {
chassis.reset_drive_sensor(); // Reset drive sensors to 0
chassis.set_drive_brake(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency.

ez::as::auton_selector.call_selected_auton(); // Calls selected auton from autonomous selector.
ez::as::auton_selector.selected_auton_call(); // Calls selected auton from autonomous selector.
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorials/autons.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void initialize() {
. . .

// Autonomous Selector using LLEMMU
ez::as::auton_selector.add_autons({
ez::as::auton_selector.autons_add({
Auton("Solo AWP\n\nStarting Position: Plat Down", SoloAWP),
Auton("Score Rings on Amogo\n\nStarting Position: Plat Down", ScoreRingsPlatDown),
Auton("Neutral Steal\n\nStarting Position: Plat Down", NeutralStealPlatDown),
Expand Down
10 changes: 5 additions & 5 deletions include/EZ-Template/auton_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
using namespace std;
class AutonSelector {
public:
std::vector<Auton> Autons;
int current_auton_page;
std::vector<Auton> autons;
int auton_page_current;
int auton_count;
AutonSelector();
AutonSelector(std::vector<Auton> autons);
void call_selected_auton();
void print_selected_auton();
void add_autons(std::vector<Auton> autons);
void selected_auton_call();
void selected_auton_print();
void autons_add(std::vector<Auton> autons);
};
24 changes: 12 additions & 12 deletions src/EZ-Template/auton_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.

AutonSelector::AutonSelector() {
auton_count = 0;
current_auton_page = 0;
Autons = {};
auton_page_current = 0;
autons = {};
}

AutonSelector::AutonSelector(std::vector<Auton> autons) {
auton_count = autons.size();
current_auton_page = 0;
Autons = {};
Autons.assign(autons.begin(), autons.end());
auton_page_current = 0;
autons = {};
autons.assign(autons.begin(), autons.end());
}

void AutonSelector::print_selected_auton() {
void AutonSelector::selected_auton_print() {
if (auton_count == 0) return;
for (int i = 0; i < 8; i++)
pros::lcd::clear_line(i);
ez::screen_print("Page " + std::to_string(current_auton_page + 1) + "\n" + Autons[current_auton_page].name);
ez::screen_print("Page " + std::to_string(auton_page_current + 1) + "\n" + autons[auton_page_current].name);
}

void AutonSelector::call_selected_auton() {
void AutonSelector::selected_auton_call() {
if (auton_count == 0) return;
Autons[current_auton_page].auton_call();
autons[auton_page_current].auton_call();
}

void AutonSelector::add_autons(std::vector<Auton> autons) {
void AutonSelector::autons_add(std::vector<Auton> autons) {
auton_count += autons.size();
current_auton_page = 0;
Autons.assign(autons.begin(), autons.end());
auton_page_current = 0;
autons.assign(autons.begin(), autons.end());
}
26 changes: 13 additions & 13 deletions src/EZ-Template/sdcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void auton_sd_update() {
if (!ez::util::SD_CARD_ACTIVE) return;

FILE* usd_file_write = fopen("/usd/auto.txt", "w");
std::string cp_str = std::to_string(auton_selector.current_auton_page);
std::string cp_str = std::to_string(auton_selector.auton_page_current);
char const* cp_c = cp_str.c_str();
fputs(cp_c, usd_file_write);
fclose(usd_file_write);
Expand All @@ -31,7 +31,7 @@ void auton_selector_init() {
if ((as_usd_file_read = fopen("/usd/auto.txt", "r"))) {
char l_buf[5];
fread(l_buf, 1, 5, as_usd_file_read);
ez::as::auton_selector.current_auton_page = std::stof(l_buf);
ez::as::auton_selector.auton_page_current = std::stof(l_buf);
fclose(as_usd_file_read);
}
// If file doesn't exist, create file
Expand All @@ -40,28 +40,28 @@ void auton_selector_init() {
printf("Created auto.txt\n");
}

if (ez::as::auton_selector.current_auton_page > ez::as::auton_selector.auton_count - 1 || ez::as::auton_selector.current_auton_page < 0) {
ez::as::auton_selector.current_auton_page = 0;
if (ez::as::auton_selector.auton_page_current > ez::as::auton_selector.auton_count - 1 || ez::as::auton_selector.auton_page_current < 0) {
ez::as::auton_selector.auton_page_current = 0;
ez::as::auton_sd_update();
}
}

void page_up() {
if (auton_selector.current_auton_page == auton_selector.auton_count - 1)
auton_selector.current_auton_page = 0;
if (auton_selector.auton_page_current == auton_selector.auton_count - 1)
auton_selector.auton_page_current = 0;
else
auton_selector.current_auton_page++;
auton_selector.auton_page_current++;
auton_sd_update();
auton_selector.print_selected_auton();
auton_selector.selected_auton_print();
}

void page_down() {
if (auton_selector.current_auton_page == 0)
auton_selector.current_auton_page = auton_selector.auton_count - 1;
if (auton_selector.auton_page_current == 0)
auton_selector.auton_page_current = auton_selector.auton_count - 1;
else
auton_selector.current_auton_page--;
auton_selector.auton_page_current--;
auton_sd_update();
auton_selector.print_selected_auton();
auton_selector.selected_auton_print();
}

void initialize() {
Expand All @@ -70,7 +70,7 @@ void initialize() {
ez::as::auton_selector_init();

// Callbacks for auto selector
ez::as::auton_selector.print_selected_auton();
ez::as::auton_selector.selected_auton_print();
pros::lcd::register_btn0_cb(ez::as::page_down);
pros::lcd::register_btn2_cb(ez::as::page_up);
}
Expand Down
Loading

0 comments on commit 02a755a

Please sign in to comment.