Which control board are you using?
i designed the board myself according to my requirements. i am using PIC18F4520 microcontroller. In pid tuning of quadcopter, we need to set the output limits for throttle, pitch, yaw and roll and based on the tilting requirement the maximum and minimum values for all these are chosen in order to have a safe flight. with implementation of kalman filter i am able to get angles from -90 to 90 degree. i am posting my code. i am just a beginner so correct me if i have made any mistakes. thank you
#ifndef pidquadchanges
#define pidquadchanges
#define throttle 0
#define roll 1
#define pitch 2
#define yaw 3
// for yaw we apply only the user yaw
//unsigned int count; this variable stores the current time
// setpoints are data of sensors, input are data from my remote(designed according to my requirement) and output is used for setting the values of timers which are generating pwm for bldc motors
// variables used in calculating final throttle of all the motors
#pragma udata my_section_1 //this was necessary otherwise some error was there see word file error on pid quad
unsigned lasttime=0;
// already defined in recievespi module float input[6],setpoint[3],output[4];
float error[3],dinput[3]; //output 4 as yaw is another output that is not calculated here but applied directly
float iterm[3],lastinput[3],min[4],max[4];
#pragma udata my_section_2
float KP[3],KI[3],KD[3];
float kp[4]={0,1.8,1.8,3.6},ki[4]={0,0.48,0.48,1.2},kd[4]={0,0.30,0.30,0.15};
int sampletime=1000; //1 sec
float outmax[3],outmin[3];
unsigned int d;
unsigned inauto=0;
void compute(void);
void setoutputlimits();
void initialize(void);
void compute() // this is the comput function
{
//if(!inauto) return; //manual mode and hence no pid tuning inauto needs to be connected to any pin of microcontroller
setpoint[0]=output[0];
d=0;
while(d<3)
{
unsigned int now=count; //here the value of count is to be assigned
int timechange=(now-lasttime);
if(timechange>=sampletime)
{
//compute all the working variable errors
error[d]=setpoint[d]-input[d];
iterm[d]+=(ki[d]*error[d]);
if(iterm[d]>outmax[d]) iterm[d]=outmax[d];
else if(iterm[d]<outmin[d]) iterm[d]=outmin[d];
dinput[d]=(input[d]-lastinput[d]);
//compute pid output
output[d] = kp[d]*error[d]+iterm[d]-kd[d]*dinput[d];
//remember some variables for the next time
lastinput[d]=input[d];
lasttime=now;
d++;
}
}
setpoint[0]=output[0]; //assigning throttle for the next time
}
be limited to min and max
{
if(min[d] > max[d]) return;
outmin[d] = min[d];
outmax[d] = max[d];
if(output[d] > outmax[d]) output[d] = outmax[d];
else if(output[d] < outmin[d]) output[d] = outmin[d];
if(iterm[d]> outmax[d]) iterm[d]= outmax[d];
else if(iterm[d]< outmin[d]) iterm[d]= outmin[d];
d++;
}
}
void setmode(int mode)
{
char newauto = (mode == automatic);
if(newauto && !inauto)
{ /*we just went from manual to auto*/
initialize();
}
inauto = newauto;
}
void initialize()
{
d=0;
while(d<3)
{
lastinput[d] = input[d];
iterm[d] = output[d];
if(iterm[d]> outmax[d]) iterm[d]= outmax[d];
else if(iterm[d]< outmin[d]) iterm[d]= outmin[d];
d++;
}
}
#endif
help please