Revision 71780e9c
ID | 71780e9c3f71dc76792785ada940cacd83cda58e |
tested pid_control and fixed it. added the test file for future reference
control/pid_control.cpp | ||
---|---|---|
1 | 1 |
#include "pid_control.h" |
2 |
#include "assert.h" |
|
3 | 2 |
|
4 |
PID_control::PID_control(int p_term, int d_term, int i_term, float goal);
|
|
3 |
PID_control::PID_control(float p_term, float d_term, float i_term, float goal)
|
|
5 | 4 |
{ |
6 | 5 |
P_err = 0; |
7 | 6 |
I_err = 0; |
... | ... | |
14 | 13 |
set_config = goal; |
15 | 14 |
} |
16 | 15 |
|
17 |
PID_control::PID_control(int p_term, int d_term, int i_term)
|
|
16 |
PID_control::PID_control(float p_term, float d_term, float i_term)
|
|
18 | 17 |
{ |
19 | 18 |
P_err = 0; |
20 | 19 |
I_err = 0; |
... | ... | |
42 | 41 |
|
43 | 42 |
return k_p*P_err + k_i*I_err + k_d * D_err; |
44 | 43 |
} |
45 |
|
control/pid_control.h | ||
---|---|---|
4 | 4 |
class PID_control |
5 | 5 |
{ |
6 | 6 |
public: |
7 |
PID_control(int p_term, int d_term, int i_term, float goal);
|
|
8 |
PID_control(int p_term, int d_term, int i_term);
|
|
7 |
PID_control(float p_term, float d_term, float i_term, float goal);
|
|
8 |
PID_control(float p_term, float d_term, float i_term);
|
|
9 | 9 |
|
10 | 10 |
void change_goal(float goal); |
11 | 11 |
|
12 | 12 |
float pid(float input); |
13 | 13 |
|
14 | 14 |
private: |
15 |
int k_p;
|
|
16 |
int k_i;
|
|
17 |
int k_d;
|
|
15 |
float k_p;
|
|
16 |
float k_i;
|
|
17 |
float k_d;
|
|
18 | 18 |
|
19 | 19 |
float set_config; |
20 | 20 |
float error; |
control/pid_test.cpp | ||
---|---|---|
1 |
#include "pid_control.h" |
|
2 |
#include <stdio.h> |
|
3 |
|
|
4 |
int main() |
|
5 |
{ |
|
6 |
PID_control* meow = new PID_control(.07, .01, .7, 5); |
|
7 |
float result = 1; |
|
8 |
for(int counter = 0; counter < 100; counter++) |
|
9 |
{ |
|
10 |
result = meow->pid(result); |
|
11 |
printf("%f\t", result); |
|
12 |
} |
|
13 |
return 0; |
|
14 |
} |
Also available in: Unified diff