Skip to content

Commit

Permalink
Completed limit switch lcd control #34
Browse files Browse the repository at this point in the history
Fixed error in mA calculation #33

Authored with @HakopZ
  • Loading branch information
ssejrog committed Jan 8, 2022
1 parent 21da733 commit cb38df3
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 75 deletions.
3 changes: 1 addition & 2 deletions include/EZ-Template/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
22 changes: 0 additions & 22 deletions include/EZ-Template/pre_auto_selector.hpp

This file was deleted.

23 changes: 23 additions & 0 deletions include/EZ-Template/sdcard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
10 changes: 5 additions & 5 deletions src/EZ-Template/PID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ exit_output PID::exit_condition(std::vector<pros::Motor> 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) {
Expand Down
3 changes: 3 additions & 0 deletions src/EZ-Template/drive/drive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
38 changes: 0 additions & 38 deletions src/EZ-Template/pre_auto_selector.cpp

This file was deleted.

39 changes: 33 additions & 6 deletions src/EZ-Template/sdcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <filesystem>

#include "main.h"

namespace ez {
namespace as {

namespace ez::as {
AutonSelector auton_selector{};

void update_auto_sd() {
Expand All @@ -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");
}

Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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),
Expand Down

0 comments on commit cb38df3

Please sign in to comment.