Skip to content

Commit

Permalink
changed names for PID.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 02a755a commit 5771520
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 110 deletions.
10 changes: 5 additions & 5 deletions docs/Docs/auton_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void initialize() {
---


## set_exit_condition()
## exit_condition_set()
Sets the exit condition constants. This uses the exit conditions from the PID class. Below is the defaults.
`type` either `chassis.turn_exit`, `chassis.swing_exit`, or `chassis.drive_exit`
`p_small_exit_time` time, in ms, before exiting `p_small_error`
Expand All @@ -359,16 +359,16 @@ Sets the exit condition constants. This uses the exit conditions from the PID cl
`p_mA_timeout` time, in ms, for `is_over_current` to be true
**Prototype**
```cpp
void set_exit_condition(exit_condition_ &type, int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout);
void exit_condition_set(exit_condition_ &type, int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout);

```
**Example**
```cpp
void initialize() {
chassis.set_exit_condition(chassis.turn_exit, 100, 3, 500, 7, 500, 500);
chassis.set_exit_condition(chassis.swing_exit, 100, 3, 500, 7, 500, 500);
chassis.set_exit_condition(chassis.drive_exit, 80, 50, 300, 150, 500, 500);
chassis.exit_condition_set(chassis.turn_exit, 100, 3, 500, 7, 500, 500);
chassis.exit_condition_set(chassis.swing_exit, 100, 3, 500, 7, 500, 500);
chassis.exit_condition_set(chassis.drive_exit, 80, 50, 300, 150, 500, 500);
}
```

Expand Down
48 changes: 24 additions & 24 deletions docs/Docs/pid.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ PID liftPID{1, 0.003, 4, 100, "Lift"};

# Functions

## set_constants()
## constants_set()
Sets PID constants.
`p` kP
`i` kI
`d` kD
`p_start_i` i will start when error is within this
**Prototype**
```cpp
void set_constants(double p, double i = 0, double d = 0, double p_start_i = 0);
void constants_set(double p, double i = 0, double d = 0, double p_start_i = 0);
```
**Example**
```cpp
PID liftPID;
void initialize() {
liftPID.set_constants(1, 0, 4);
liftPID.constants_set(1, 0, 4);
}
```

Expand All @@ -80,11 +80,11 @@ void initialize() {



## set_target()
## target_set()
Sets PID target.
**Prototype**
```cpp
void set_target(double input);
void target_set(double input);
```
**Example**
Expand All @@ -94,10 +94,10 @@ pros::Motor lift_motor(1);
void opcontrol() {
while (true) {
if (master.get_digital(DIGITAL_L1)) {
liftPID.set_target(500);
liftPID.target_set(500);
}
else if (master.get_digital(DIGITAL_L2)) {
liftPID.set_target(0);
liftPID.target_set(0);
}
lift_motor = liftPID.compute(lift_motor.get_position());
Expand All @@ -111,7 +111,7 @@ void opcontrol() {



## set_exit_condition()
## exit_condition_set()
Sets the exit condition constants. To disable one of the conditions, set the constants relating to it to `0`.
`p_small_exit_time` time, in ms, before exiting `p_small_error`
`p_small_error` small error threshold
Expand All @@ -121,15 +121,15 @@ Sets the exit condition constants. To disable one of the conditions, set the co
`p_mA_timeout` time, in ms, for `is_over_current` to be true
**Prototype**
```cpp
void set_exit_condition(int p_small_exit_time, double p_small_error, int p_big_exit_time = 0, double p_big_error = 0, int p_velocity_exit_time = 0, int p_mA_timeout = 0);
void exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time = 0, double p_big_error = 0, int p_velocity_exit_time = 0, int p_mA_timeout = 0);

```
**Example**
```cpp
PID liftPID{1, 0.003, 4, 100, "Lift"};
void initialize() {
liftPID.set_exit_condition(100, 3, 500, 7, 500, 500);
liftPID.exit_condition_set(100, 3, 500, 7, 500, 500);
}
```

Expand All @@ -139,18 +139,18 @@ void initialize() {



## set_name()
## name_set()
A string that prints when exit conditions are met. When you have multiple mechanisms using exit conditions and you're debugging, seeing which exit condition is doing what can be useful.
**Prototype**
```cpp
void set_name(std::string name);
void name_set(std::string name);
```
**Example**
```cpp
PID liftPID{1, 0.003, 4, 100};
void initialize() {
liftPID.set_name("Lift");
liftPID.name_set("Lift");
}
```

Expand All @@ -173,10 +173,10 @@ pros::Motor lift_motor(1);
void opcontrol() {
while (true) {
if (master.get_digital(DIGITAL_L1)) {
liftPID.set_target(500);
liftPID.target_set(500);
}
else if (master.get_digital(DIGITAL_L2)) {
liftPID.set_target(0);
liftPID.target_set(0);
}
lift_motor = liftPID.compute(lift_motor.get_position());
Expand Down Expand Up @@ -205,17 +205,17 @@ PID liftPID{1, 0.003, 4, 100, "Lift"};
pros::Motor lift_motor(1);
void initialize() {
liftPID.set_exit_condition(100, 3, 500, 7, 500, 500);
liftPID.exit_condition_set(100, 3, 500, 7, 500, 500);
}
void autonomous() {
liftPID.set_target(500);
liftPID.target_set(500);
while (liftPID.exit_condition(true) == ez::RUNNING) {
lift_motor = liftPID.compute(lift_motor.get_position());
pros::delay(ez::util::DELAY_TIME);
}
liftPID.set_target(0);
liftPID.target_set(0);
while (liftPID.exit_condition(true) == ez::RUNNING) {
lift_motor = liftPID.compute(lift_motor.get_position());
pros::delay(ez::util::DELAY_TIME);
Expand All @@ -241,17 +241,17 @@ PID liftPID{1, 0.003, 4, 100, "Lift"};
pros::Motor lift_motor(1);
void initialize() {
liftPID.set_exit_condition(100, 3, 500, 7, 500, 500);
liftPID.exit_condition_set(100, 3, 500, 7, 500, 500);
}
void autonomous() {
liftPID.set_target(500);
liftPID.target_set(500);
while (liftPID.exit_condition(lift_motor, true) == ez::RUNNING) {
lift_motor = liftPID.compute(lift_motor.get_position());
pros::delay(ez::util::DELAY_TIME);
}
liftPID.set_target(0);
liftPID.target_set(0);
while (liftPID.exit_condition(lift_motor, true) == ez::RUNNING) {
lift_motor = liftPID.compute(lift_motor.get_position());
pros::delay(ez::util::DELAY_TIME);
Expand Down Expand Up @@ -283,17 +283,17 @@ void set_lift(int input) {
}
void initialize() {
liftPID.set_exit_condition(100, 3, 500, 7, 500, 500);
liftPID.exit_condition_set(100, 3, 500, 7, 500, 500);
}
void autonomous() {
liftPID.set_target(500);
liftPID.target_set(500);
while (liftPID.exit_condition({r_lift_motor, l_lift_motor}, true) == ez::RUNNING) {
set_lift(liftPID.compute(lift_motor.get_position()));
pros::delay(ez::util::DELAY_TIME);
}
liftPID.set_target(0);
liftPID.target_set(0);
while (liftPID.exit_condition({r_lift_motor, l_lift_motor}, true) == ez::RUNNING) {
set_lift(liftPID.compute(lift_motor.get_position()));
pros::delay(ez::util::DELAY_TIME);
Expand Down
8 changes: 4 additions & 4 deletions docs/Tutorials/pid.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PID liftPID{0.45, 0, 0, 0, "Lift"};


void lift_auto(double target) {
liftPID.set_target(target);
liftPID.target_set(target);
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());
Expand All @@ -44,7 +44,7 @@ void lift_auto(double target) {
}

void initialize() {
liftPID.set_exit_condition(80, 50, 300, 150, 500, 500);
liftPID.exit_condition_set(80, 50, 300, 150, 500, 500);
}

void autonomous() {
Expand All @@ -54,10 +54,10 @@ void autonomous() {
void opcontrol() {
while (true) {
if (master.get_digital(DIGITAL_L1)) {
liftPID.set_target(500);
liftPID.target_set(500);
}
else if (master.get_digital(DIGITAL_L2)) {
liftPID.set_target(0);
liftPID.target_set(0);
}
set_lift(liftPID.compute(l_lift.get_position()));

Expand Down
28 changes: 14 additions & 14 deletions include/EZ-Template/PID.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class PID {
* \param p_start_i
* error value that i starts within
*/
void set_constants(double p, double i = 0, double d = 0, double p_start_i = 0);
void constants_set(double p, double i = 0, double d = 0, double p_start_i = 0);

/**
* Struct for constants.
*/
struct Constants {
struct constants_ {
double kp;
double ki;
double kd;
Expand Down Expand Up @@ -82,15 +82,15 @@ class PID {
* \param p_velocity_exit_time
* Sets velocity_exit_time. Timer will start when velocity is 0.
*/
void set_exit_condition(int p_small_exit_time, double p_small_error, int p_big_exit_time = 0, double p_big_error = 0, int p_velocity_exit_time = 0, int p_mA_timeout = 0);
void exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time = 0, double p_big_error = 0, int p_velocity_exit_time = 0, int p_mA_timeout = 0);

/**
* Sets target.
*
* \param target
* Target for PID.
*/
void set_target(double input);
void target_set(double input);

/**
* Computes PID.
Expand All @@ -103,22 +103,22 @@ class PID {
/**
* Returns target value.
*/
double get_target();
double target_get();

/**
* Returns constants.
*/
Constants get_constants();
constants_ constants_get();

/**
* Resets all variables to 0. This does not reset constants.
*/
void reset_variables();
void variables_reset();

/**
* Constants
* constants_
*/
Constants constants;
constants_ constants;

/**
* Exit
Expand Down Expand Up @@ -159,7 +159,7 @@ class PID {
* \param name
* a string that is the name you want to print
*/
void set_name(std::string name);
void name_set(std::string name);

/**
* PID variables.
Expand All @@ -168,17 +168,17 @@ class PID {
double cur;
double error;
double target;
double prev_error;
double error_prev;
double integral;
double derivative;
long time;
long prev_time;
long time_prev;

private:
int i = 0, j = 0, k = 0, l = 0;
bool is_mA = false;
void reset_timers();
void timers_reset();
std::string name;
bool is_name = false;
void print_exit(ez::e_exit_output exit_type);
void exit_print(ez::e_exit_output exit_type);
};
Loading

0 comments on commit 5771520

Please sign in to comment.