Skip to content

Commit

Permalink
Right steal right
Browse files Browse the repository at this point in the history
  • Loading branch information
alexDickhans committed Dec 11, 2021
1 parent fc5e4b6 commit 6166bbb
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 87 deletions.
28 changes: 26 additions & 2 deletions include/auton/autonSelector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace Pronounce {
std::vector<Auton> autons;
Auton defaultAuton;

Auton preAuton;
Auton postAuton;

Pronounce::Controller* controller;

int autonIndex = 0;
Expand All @@ -27,13 +30,18 @@ namespace Pronounce {
}

int run() {
preAuton.run();
int result = 0;
if (autonIndex >= autons.size()) {
return defaultAuton.run();
result = defaultAuton.run();
}
return autons[autonIndex].run();
result = autons[autonIndex].run();
postAuton.run();
return result;
}

Auton getAuton(int index) {
int result = 0;
if (index < 0 || index >= autons.size()) {
return defaultAuton;
}
Expand All @@ -56,6 +64,22 @@ namespace Pronounce {
this->defaultAuton = defaultAuton;
}

Auton getPreAuton() {
return preAuton;
}

void setPreAuton(Auton preAuton) {
this->preAuton = preAuton;
}

Auton getPostAuton() {
return postAuton;
}

void setPostAuton(Auton postAuton) {
this->postAuton = postAuton;
}

void setController(Pronounce::Controller* controller) {
this->controller = controller;
}
Expand Down
10 changes: 9 additions & 1 deletion include/driver/button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Pronounce {
pros::controller_digital_e_t positiveButton, negativeButton;

bool singleToggle = false;
bool retainOnNeutral = true;
bool retainOnNeutral = false;

public:
Button(pros::Controller* cotroller);
Expand Down Expand Up @@ -62,6 +62,14 @@ namespace Pronounce {
this->retainOnNeutral = retainOnNeutral;
}

bool getAutonomous() {
return this->autonomous;
}

void setAutonomous(bool autonomous) {
this->autonomous = autonomous;
}

~Button();
};
} // namespace Pronounce
20 changes: 20 additions & 0 deletions include/driver/motorButton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ namespace Pronounce {
private:
bool goToImmediately = false;

bool autonomousButton = false;

int positiveAuthority = 0;
int neutralAuthority = 0;
int negativeAuthority = 0;

int autonomousAuthority = 0;

int min = 0;
int max = 0;
pros::Motor* motor;
Expand All @@ -39,6 +43,22 @@ namespace Pronounce {
this->goToImmediately = goToImmediately;
}

int getAutonomousAuthority() {
return this->autonomousAuthority;
}

void setAutonomousAuthority(int autonomousAuthority) {
this->autonomousAuthority = autonomousAuthority;
}

bool getAutonomousButton() {
return this->autonomousButton;
}

void setAutonomousButton(bool autonomousButton) {
this->autonomousButton = autonomousButton;
}

~MotorButton();
};

Expand Down
14 changes: 12 additions & 2 deletions src/auton/autonSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Pronounce {
AutonSelector::AutonSelector() {
controller = new Pronounce::Controller(pros::E_CONTROLLER_MASTER);
preAuton = Auton();
postAuton = Auton();
defaultAuton = Auton();
}

AutonSelector::AutonSelector(std::vector<Auton> autons, Auton defaultAuton) : AutonSelector() {
Expand All @@ -21,7 +24,11 @@ namespace Pronounce {

controller->setIsRendering(false);

printf("Auton selector\n");

while (!done) {
controller->clear();

if (controller->get_digital(pros::E_CONTROLLER_DIGITAL_A)) {
done = true;
}
Expand All @@ -40,11 +47,14 @@ namespace Pronounce {
}
}

pros::lcd::print(0, "Auton: %s", autons[autonIndex].getName().c_str());
controller->set_text(0, 0, autons[autonIndex].getName());

pros::Task::delay(50);

pros::Task::delay(20);
}

printf("Auton selected: %s", autons[autonIndex].getName().c_str());

controller->setIsRendering(true);
}

Expand Down
6 changes: 6 additions & 0 deletions src/driver/motorButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ namespace Pronounce {
return;
}

if (this->getAutonomous() && !this->autonomousButton) {
this->motor->move_absolute(this->autonomousAuthority, abs(this->positiveAuthority));
printf("MotorButton: autonomous authority: %d\n", this->autonomousAuthority);
return;
}

switch (this->getButtonStatus()) {
case NEGATIVE:
if (goToImmediately) {
Expand Down
Loading

0 comments on commit 6166bbb

Please sign in to comment.