diff --git a/include/EZ-Template/api.hpp b/include/EZ-Template/api.hpp index 18648270..fa856d1b 100644 --- a/include/EZ-Template/api.hpp +++ b/include/EZ-Template/api.hpp @@ -11,5 +11,4 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. #include "EZ-Template/auton_selector.hpp" #include "EZ-Template/drive/drive.hpp" #include "EZ-Template/sdcard.hpp" -#include "EZ-Template/util.hpp" -#include "EZ-Template/pre_auto_selector.hpp" +#include "EZ-Template/util.hpp" \ No newline at end of file diff --git a/include/EZ-Template/pre_auto_selector.hpp b/include/EZ-Template/pre_auto_selector.hpp deleted file mode 100644 index f55e017d..00000000 --- a/include/EZ-Template/pre_auto_selector.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "main.h" - -namespace ez -{ -extern pros::ADIDigitalIn* left_limit_switch; -extern pros::ADIDigitalIn* right_limit_switch; -/** -* Initialize two limitswithces to change pages on the lcd -* -* @param left_limit_port -* port for the left limit switch -* @param right_limit_port -* port for the right limit switch -*/ -void limit_switch_lcd_initialize(int left_limit_port, int right_limit_port); - -/** -* pre_auto_task -*/ -extern pros::Task limit_switch_task; -} diff --git a/include/EZ-Template/sdcard.hpp b/include/EZ-Template/sdcard.hpp index d7bc8fb5..c04cf399 100644 --- a/include/EZ-Template/sdcard.hpp +++ b/include/EZ-Template/sdcard.hpp @@ -7,6 +7,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. #pragma once #include "EZ-Template/auton_selector.hpp" +#include "api.h" namespace ez { namespace as { @@ -15,25 +16,47 @@ extern AutonSelector auton_selector; * Sets sd card to current page. */ void init_auton_selector(); + /** * Sets the sd card to current page. */ void update_auto_sd(); + /** * Increases the page by 1. */ void page_up(); + /** * Decreases the page by 1. */ void page_down(); + /** * Initializes LLEMU and sets up callbacks for auton selector. */ void initialize(); + /** * Wrapper for pros::lcd::shutdown. */ void shutdown(); + +extern pros::ADIDigitalIn* left_limit_switch; +extern pros::ADIDigitalIn* right_limit_switch; +/** + * Initialize two limitswithces to change pages on the lcd + * + * @param left_limit_port + * port for the left limit switch + * @param right_limit_port + * port for the right limit switch + */ +void limit_switch_lcd_initialize(pros::ADIDigitalIn* right_limit, pros::ADIDigitalIn* left_limit = nullptr); + +/** + * pre_auto_task + */ +void limitSwitchTask(); } // namespace as } // namespace ez diff --git a/src/EZ-Template/PID.cpp b/src/EZ-Template/PID.cpp index e809c80b..664ee9cf 100644 --- a/src/EZ-Template/PID.cpp +++ b/src/EZ-Template/PID.cpp @@ -150,14 +150,14 @@ exit_output PID::exit_condition(std::vector sensor, bool print) { // If the motors are pulling too many mA, the code will timeout and set interfered to true. if (exit.mA_timeout != 0) { // Check if this condition is enabled for (auto i : sensor) { - // Check if the motor isn't drawing too many mA. If 1 of the motors isn't, break. - if (!i.is_over_current()) { - is_mA = false; + // Check if 1 motor is pulling too many mA + if (i.is_over_current()) { + is_mA = true; break; } - // If all of the motors are drawing too many mA, keep the bool true + // If all of the motors aren't drawing too many mA, keep bool false else { - is_mA = true; + is_mA = false; } } if (is_mA) { diff --git a/src/EZ-Template/drive/drive.cpp b/src/EZ-Template/drive/drive.cpp index 7d94a716..1f6dfad2 100644 --- a/src/EZ-Template/drive/drive.cpp +++ b/src/EZ-Template/drive/drive.cpp @@ -168,6 +168,9 @@ void Drive::set_defaults() { // Enable auto printing and drive motors moving toggle_auto_drive(true); toggle_auto_print(true); + + // Disables limit switch for auto selector + as::limit_switch_lcd_initialize(nullptr, nullptr); } double Drive::get_tick_per_inch() { diff --git a/src/EZ-Template/pre_auto_selector.cpp b/src/EZ-Template/pre_auto_selector.cpp deleted file mode 100644 index 22292db2..00000000 --- a/src/EZ-Template/pre_auto_selector.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "pre_auto_selector.hpp" - -namespace ez -{ - pros::ADIDigitalIn* left_limit_switch = nullptr; - pros::ADIDigitalIn* right_limit_switch = nullptr; - void limit_switch_lcd_initialize(int left_limit_port, int right_limit_port) - { - if(left_limit_port == -1 || right_limit_port == -1) - { - limit_switch_task.suspend(); - return; - } - left_limit_switch = new pros::ADIDigitalIn(left_limit_port); - right_limit_switch = new pros::ADIDigitalIn(right_limit_port); - limit_switch_task.resume(); - } - - void limitSwitchTask() - { - while(true) - { - if(left_limit_switch || right_limit_switch) - { - if(left_limit_switch->get_new_press()) - { - ez::as::page_down(); - } - else if(right_limit_switch->get_new_press()) - { - ez::as::page_up(); - } - } - pros::delay(20); - } - } - pros::Task limit_switch_task(limitSwitchTask, nullptr); -} diff --git a/src/EZ-Template/sdcard.cpp b/src/EZ-Template/sdcard.cpp index 67387a02..d69453a8 100644 --- a/src/EZ-Template/sdcard.cpp +++ b/src/EZ-Template/sdcard.cpp @@ -5,10 +5,11 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include + #include "main.h" -namespace ez { -namespace as { + +namespace ez::as { AutonSelector auton_selector{}; void update_auto_sd() { @@ -33,10 +34,10 @@ void init_auton_selector() { fread(l_buf, 1, 5, as_usd_file_read); ez::as::auton_selector.current_auton_page = std::stof(l_buf); fclose(as_usd_file_read); - } + } // If file doesn't exist, create file else { - update_auto_sd(); // Writing to a file that doesn't exist creates the file + update_auto_sd(); // Writing to a file that doesn't exist creates the file printf("Created auto.txt\n"); } @@ -78,5 +79,31 @@ void initialize() { void shutdown() { pros::lcd::shutdown(); } -} // namespace as -} // namespace ez + +// Using a button to control the lcd +pros::ADIDigitalIn* left_limit_switch = nullptr; +pros::ADIDigitalIn* right_limit_switch = nullptr; +pros::Task limit_switch_task(limitSwitchTask); +void limit_switch_lcd_initialize(pros::ADIDigitalIn* right_limit, pros::ADIDigitalIn* left_limit) { + if (!left_limit && !right_limit) { + delete left_limit_switch; + delete right_limit_switch; + return; + } + + right_limit_switch = right_limit; + left_limit_switch = left_limit; + limit_switch_task.resume(); +} + +void limitSwitchTask() { + while (true) { + if (right_limit_switch && right_limit_switch->get_new_press()) + page_up(); + else if (left_limit_switch && left_limit_switch->get_new_press()) + page_down(); + + pros::delay(50); + } +} +} // namespace ez::as diff --git a/src/main.cpp b/src/main.cpp index 0d5913dd..c6799d48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,7 +57,7 @@ void initialize() { // Print our branding over your terminal :D ez::print_ez_template(); pros::delay(500); // Stop the user from doing anything while legacy ports configure. - ez::limit_switch_lcd_initialize(-1, -1); //limit switch for lcd + // Configure your chassis controls chassis.toggle_modify_curve_with_controller(true); // Enables modifying the controller curve with buttons on the joysticks chassis.set_active_brake(0); // Sets the active brake kP. We recommend 0.1. @@ -68,7 +68,7 @@ void initialize() { // chassis.set_left_curve_buttons (pros::E_CONTROLLER_DIGITAL_LEFT, pros::E_CONTROLLER_DIGITAL_RIGHT); // chassis.set_right_curve_buttons(pros::E_CONTROLLER_DIGITAL_Y, pros::E_CONTROLLER_DIGITAL_A); - // Autonomous Selector using LLEMMU + // Autonomous Selector using LLEMU ez::as::auton_selector.add_autons({ Auton("Example Drive\n\nDrive forward and come back.", drive_example), Auton("Example Turn\n\nTurn 3 times.", turn_example),