Skip to content

Commit

Permalink
Updated names for util.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 2d7de7f commit 248d3d5
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 101 deletions.
2 changes: 1 addition & 1 deletion docs/Docs/auton_selector.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void initialize() {


## add_autons();
Adds autonomous routines to the autonomous selector. Uses `ez::print_to_screen()` to display to the brain.
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);
Expand Down
12 changes: 6 additions & 6 deletions docs/Docs/pid.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ void opcontrol() {
# Exit Conditions

## No Motor
Outputs one of the `exit_output` states. This exit condition checks `small_error`, `big_error` and `velocity` if they are enabled.
Outputs one of the `e_exit_output` states. This exit condition checks `small_error`, `big_error` and `velocity` if they are enabled.
**Prototype**
```cpp
ez::exit_output exit_condition(bool print = false);
ez::e_exit_output exit_condition(bool print = false);
```
**Example**
Expand Down Expand Up @@ -229,10 +229,10 @@ void autonomous() {


## One Motor
Outputs one of the `exit_output` states. This exit condition checks `small_error`, `big_error`, `velocity` and `mA` if they are enabled.
Outputs one of the `e_exit_output` states. This exit condition checks `small_error`, `big_error`, `velocity` and `mA` if they are enabled.
**Prototype**
```cpp
ez::exit_output exit_condition(pros::Motor sensor, bool print = false);
ez::e_exit_output exit_condition(pros::Motor sensor, bool print = false);
```
**Example**
Expand Down Expand Up @@ -265,10 +265,10 @@ void autonomous() {


## Multiple Motors
Outputs one of the `exit_output` states. This exit condition checks `small_error`, `big_error`, `velocity` and `mA` if they are enabled. When any of the motors trip `mA`, it returns `mA_EXIT`.
Outputs one of the `e_exit_output` states. This exit condition checks `small_error`, `big_error`, `velocity` and `mA` if they are enabled. When any of the motors trip `mA`, it returns `mA_EXIT`.
**Prototype**
```cpp
ez::exit_output exit_condition(std::vector<pros::Motor> sensor, bool print = false);
ez::e_exit_output exit_condition(std::vector<pros::Motor> sensor, bool print = false);
```
**Example**
Expand Down
28 changes: 14 additions & 14 deletions docs/Docs/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ void opcontrol() {
---


## print_to_screen()
## screen_print()
Prints to the LLEMU. This function handles text that's too long for a line by finding the last word and starting it on a new line, and takes `\n` to set a new line.
`text` input string.
`line` starting line.
**Prototype**
```cpp
void print_to_screen(, std::string text, int line)
void screen_print(, std::string text, int line)
```
**Example 1**
Expand All @@ -59,7 +59,7 @@ hello, this is line 0
this is line 1
```cpp
void initialize() {
ez::print_to_screen("hello, this is line 0\nthis is line 1");
ez::screen_print("hello, this is line 0\nthis is line 1");
}
```

Expand All @@ -70,44 +70,44 @@ hello
```cpp
void initialize() {
std::string 32char = 01234567890123456789012345678901;
ez::print_to_screen(32char + "hello");
ez::screen_print(32char + "hello");
}
```


---


## print_ez_template()
## ez_template_print()
Prints our branding on your terimnal :D.
**Prototype**
```cpp
void print_ez_template();
void ez_template_print();
```

**Example**
```cpp
void initialize() {
print_ez_template();
ez_template_print();
}
```


---


## sgn()
Returns the sgn of the input. Returns 1 if positive, -1 if negative, and 0 if 0.
## sign()
Returns the sign of the input. Returns 1 if positive, -1 if negative, and 0 if 0.
**Prototype**
```cpp
double sgn(double input);
double sign(double input);
```
**Example**
```cpp
void opcontrol() {
while (true) {
printf("Sgn of Controller: %i \n", sgn(master.get_analog(ANALOG_LEFT_Y)));
printf("Sign of Controller: %i \n", sign(master.get_analog(ANALOG_LEFT_Y)));
pros::delay(ez::util::DELAY_TIME);
}
Expand All @@ -118,11 +118,11 @@ void opcontrol() {
---


## clip_num()
## clamp_number()
Checks if `input` is within range of `max` and `min`. If it's out, this returns `max` or `min` respectively.
**Prototype**
```cpp
double clip_num(double input, double max, double min);
double clamp_number(double input, double max, double min);
```
**Example**
Expand All @@ -133,7 +133,7 @@ void opcontrol() {
// When the joystick is between 100 and 127
// (or -100 and -127) this will print 100 (or -100).
printf("Clipped Controller: %i \n", clip_num(joy, 100, -100));
printf("Clipped Controller: %i \n", clamp_number(joy, 100, -100));
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/Tutorials/pid.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ PID liftPID{0.45, 0, 0, 0, "Lift"};

void lift_auto(double target) {
liftPID.set_target(target);
ez::exit_output exit = ez::RUNNING;
ez::e_exit_output exit = ez::RUNNING;
while (liftPID.exit_condition({l_lift, r_lift}, true) == ez::RUNNING) {
double output = liftPID.compute(l_lift.get_position());
set_lift(output);
Expand Down
16 changes: 8 additions & 8 deletions include/EZ-Template/PID.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class PID {
* kD
* \param p_start_i
* error value that i starts within
* \param name
* std::string of name that prints
* \param name
* std::string of name that prints
*/
PID(double p, double i = 0, double d = 0, double start_i = 0, std::string name = "");

Expand Down Expand Up @@ -131,7 +131,7 @@ class PID {
* \param print = false
* if true, prints when complete.
*/
ez::exit_output exit_condition(bool print = false);
ez::e_exit_output exit_condition(bool print = false);

/**
* Iterative exit condition for PID.
Expand All @@ -141,7 +141,7 @@ class PID {
* \param print = false
* if true, prints when complete.
*/
ez::exit_output exit_condition(pros::Motor sensor, bool print = false);
ez::e_exit_output exit_condition(pros::Motor sensor, bool print = false);

/**
* Iterative exit condition for PID.
Expand All @@ -151,18 +151,18 @@ class PID {
* \param print = false
* if true, prints when complete.
*/
ez::exit_output exit_condition(std::vector<pros::Motor> sensor, bool print = false);
ez::e_exit_output exit_condition(std::vector<pros::Motor> sensor, bool print = false);

/**
* Sets the name of the PID that prints during exit conditions.
* Sets the name of the PID that prints during exit conditions.
*
* \param name
* a string that is the name you want to print
*/
void set_name(std::string name);

/**
* PID variables.
* PID variables.
*/
double output;
double cur;
Expand All @@ -180,5 +180,5 @@ class PID {
void reset_timers();
std::string name;
bool is_name = false;
void print_exit(ez::exit_output exit_type);
void print_exit(ez::e_exit_output exit_type);
};
24 changes: 12 additions & 12 deletions include/EZ-Template/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace ez {
/**
* Prints our branding all over your pros terminal
*/
void print_ez_template();
void ez_template_print();

/**
* Prints to the brain screen in one string. Splits input between lines with
Expand All @@ -33,7 +33,7 @@ void print_ez_template();
* @param line
* Starting line to print on, defaults to 0
*/
void print_to_screen(std::string text, int line = 0);
void screen_print(std::string text, int line = 0);

/////
//
Expand All @@ -56,12 +56,12 @@ enum e_swing { LEFT_SWING = 0,
/**
* Enum for PID::exit_condition outputs.
*/
enum exit_output { RUNNING = 1,
SMALL_EXIT = 2,
BIG_EXIT = 3,
VELOCITY_EXIT = 4,
mA_EXIT = 5,
ERROR_NO_CONSTANTS = 6 };
enum e_exit_output { RUNNING = 1,
SMALL_EXIT = 2,
BIG_EXIT = 3,
VELOCITY_EXIT = 4,
mA_EXIT = 5,
ERROR_NO_CONSTANTS = 6 };

/**
* Enum for split and single stick arcade.
Expand All @@ -74,25 +74,25 @@ enum e_mode { DISABLE = 0,
/**
* Outputs string for exit_condition enum.
*/
std::string exit_to_string(exit_output input);
std::string exit_to_string(e_exit_output input);

namespace util {
extern bool AUTON_RAN;

/**
* Returns 1 if input is positive and -1 if input is negative
*/
int sgn(double input);
int sign(double input);

/**
* Returns true if the input is < 0
*/
bool is_reversed(double input);
bool reversed_active(double input);

/**
* Returns input restricted to min-max threshold
*/
double clip_num(double input, double max, double min);
double clamp_number(double input, double max, double min);

/**
* Is the SD card plugged in?
Expand Down
10 changes: 5 additions & 5 deletions src/EZ-Template/PID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ double PID::compute(double current) {
if (fabs(error) < constants.start_i)
integral += error;

if (util::sgn(error) != util::sgn(prev_error))
if (util::sign(error) != util::sign(prev_error))
integral = 0;
}

Expand All @@ -86,15 +86,15 @@ void PID::set_name(std::string p_name) {
is_name = name == "" ? false : true;
}

void PID::print_exit(ez::exit_output exit_type) {
void PID::print_exit(ez::e_exit_output exit_type) {
std::cout << " ";
if (is_name)
std::cout << name << " PID " << exit_to_string(exit_type) << " Exit.\n";
else
std::cout << exit_to_string(exit_type) << " Exit.\n";
}

exit_output PID::exit_condition(bool print) {
e_exit_output PID::exit_condition(bool print) {
// If this function is called while all exit constants are 0, print an error
if (!(exit.small_error && exit.small_exit_time && exit.big_error && exit.big_exit_time && exit.velocity_exit_time && exit.mA_timeout)) {
print_exit(ERROR_NO_CONSTANTS);
Expand Down Expand Up @@ -148,7 +148,7 @@ exit_output PID::exit_condition(bool print) {
return RUNNING;
}

exit_output PID::exit_condition(pros::Motor sensor, bool print) {
e_exit_output PID::exit_condition(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
if (sensor.is_over_current()) {
Expand All @@ -166,7 +166,7 @@ exit_output PID::exit_condition(pros::Motor sensor, bool print) {
return exit_condition(print);
}

exit_output PID::exit_condition(std::vector<pros::Motor> sensor, bool print) {
e_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) {
Expand Down
2 changes: 1 addition & 1 deletion src/EZ-Template/auton_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void AutonSelector::print_selected_auton() {
if (auton_count == 0) return;
for (int i = 0; i < 8; i++)
pros::lcd::clear_line(i);
ez::print_to_screen("Page " + std::to_string(current_auton_page + 1) + "\n" + Autons[current_auton_page].Name);
ez::screen_print("Page " + std::to_string(current_auton_page + 1) + "\n" + Autons[current_auton_page].Name);
}

void AutonSelector::call_selected_auton() {
Expand Down
Loading

0 comments on commit 248d3d5

Please sign in to comment.