-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.h
39 lines (33 loc) · 881 Bytes
/
control.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef CONTROL_H
#define CONTROL_H
struct Pid {
float Kp;
float Ki;
float Kd;
float value;
float target;
float error;
float iError;
float dError;
float control;
} pid[4] ={ //initialize Pid structures
{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}, //rol
{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}, //pitch
{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}, //throtle
{0.0,0.0,50.0,0.0,0.0,0.0,0.0,0.0,0.0} //yaw
};
#define roll pid[ROL]
#define pitch pid[PTC]
#define throt pid[THR]
#define yaw pid[YAW]
float control_pid(float error,float iError, float dError, float Kp, float Ki, float Kd){
return error*Kp + iError * Ki + dError * Kd;
}
//get inclination on X/Y axes (pitch/roll)
float inclination_deg(float xy , float z){
float incl = asin(xy)*180.0/PI;
if(z < 0 && incl < -45) return -180.0 - incl;
if(z < 0 && incl > 45) return 180.0 - incl;
return incl;
}
#endif