Skip to content

Commit

Permalink
Merge pull request #76 from ad101-lab/ad-left-awp-left
Browse files Browse the repository at this point in the history
Left AWP Left
  • Loading branch information
alexDickhans authored Dec 11, 2021
2 parents 7f7c799 + 9861eda commit 445da18
Show file tree
Hide file tree
Showing 13 changed files with 408 additions and 299 deletions.
42 changes: 42 additions & 0 deletions include/auton/auton.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <string>


namespace Pronounce {

typedef int (*AutonFunction)();

int nullAutonFunc();

class Auton {
private:
std::string name;
AutonFunction func;
public:
Auton();
Auton(std::string name, AutonFunction func);

int run();

std::string getName() {
return name;
}

void setName(std::string name) {
this->name = name;
}

AutonFunction getFunc() {
return func;
}

void setFunc(AutonFunction func) {
this->func = func;
}

~Auton();
};
} // namespace Pronounce


99 changes: 99 additions & 0 deletions include/auton/autonSelector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#pragma once

#include "api.h"
#include "auton.hpp"
#include "driver/controller.hpp"
#include <vector>

namespace Pronounce {
class AutonSelector {
private:
std::vector<Auton> autons;
Auton defaultAuton;

Auton preAuton;
Auton postAuton;

Pronounce::Controller* controller;

int autonIndex = 0;
public:
AutonSelector();
AutonSelector(std::vector<Auton> autons, Auton defaultAuton);
AutonSelector(std::vector<Auton> autons, Auton defaultAuton, Pronounce::Controller* controller);

void choose();

int addAuton(Auton auton) {
autons.push_back(auton);
return autons.size() - 1;
}

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

Auton getAuton(int index) {
int result = 0;
if (index < 0 || index >= autons.size()) {
return defaultAuton;
}
return autons[index];
}

std::vector<Auton> getAutons() {
return autons;
}

void setAutons(std::vector<Auton> autons) {
this->autons = autons;
}

Auton getDefaultAuton() {
return defaultAuton;
}

void setDefaultAuton(Auton defaultAuton) {
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;
}

int getAutonIndex() {
return autonIndex;
}

void setAutonIndex(int autonIndex) {
this->autonIndex = autonIndex;
}

~AutonSelector();
};
}


136 changes: 0 additions & 136 deletions include/autonSelector.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion include/defines.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#define AUTON_SELECTOR_COUNT 3
#define AUTON_SELECTOR_COUNT 2

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
5 changes: 4 additions & 1 deletion include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
*/

#include "defines.h"
#include "autonSelector.hpp"

// Auton
#include "auton/auton.hpp"
#include "auton/autonSelector.hpp"

// Chassis
#include "chassis/drivetrain.hpp"
Expand Down
24 changes: 24 additions & 0 deletions src/auton/auton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "auton.hpp"

namespace Pronounce {
int nullAutonFunc() {
return 0;
}

Auton::Auton(/* args */) {
this->name = "";
this->func = nullAutonFunc;
}

Auton::Auton(std::string name, AutonFunction func) {
this->name = name;
this->func = func;
}

int Auton::run() {
return func();
}

Auton::~Auton() {
}
} // namespace Pronounce
Loading

0 comments on commit 445da18

Please sign in to comment.