I have succeeded in making my first quadcopter from scratch with a readymade frame. I designed the flight controller myself with help from YMFC-3D youtube series of videos. https://www.youtube.com/watch?v=2pHdO8m6T7c

But in the process, I discovered that using the euler angles or the 'ypr' values from the MPU6050 as the feeback to the PID loop makes it super difficult to tune the quadcopter and even then it doesn't fly great.

Whereas although not intuitive to me, using the gyroscope values with a complementary filter instantly made the quad respond much better and the tuning also was not too difficult.

Let me clearly define the response in both cases.

Using ypr values:- +Always keeps overshooting or 'underreaching' +Very small range of values that can let the quad fly stable +Drastic Reactions to extreme values of P (Kp)values

Using gyro values:- +Reaction is much more stable +Tuning the PID was also simple + Even under high values of P(Kp) the quad might crash due to oscillations but not flip or react extremely

Below is a portion of the PID loop:

//gyrox_temp is the current gyroscope output

gyro_x_input=(gyro_x_input*.8)+(gyrox_temp*0.2);//complementary filter

pidrate_error_temp =gyro_x_input - setpoint;//error value for PID loop

pidrate_i_mem_roll += pidrate_i_gain_roll * pidrate_error_temp;
//integral portion

pidrate_output_roll = pidrate_p_gain_roll * pidrate_error_temp + pidrate_i_mem_roll + pidrate_d_gain_roll * (pidrate_error_temp - pidrate_last_roll_d_error);
//output of the pid loop
//this output is given as the pwm signal to the quad plus throttle
  • $\begingroup$ Was your controller configured to adjust speed or angle? How are you processing gyro data? Can you provide a block diagram of the before and after code? As it stands, your question is very vague. $\endgroup$ – Chuck Apr 29 '16 at 21:26
  • 1
    $\begingroup$ Also, check the units on ypr - are you neglecting a 2*pi factor in the angles? I know it sounds silly but incorrect units on variables could cause this behavior. $\endgroup$ – SteveO Apr 30 '16 at 5:56
  • $\begingroup$ I added the 2*pi factor @SteveO $\endgroup$ – WizardOfRobots May 1 '16 at 6:51

The gyro is a less-noisy sensor with gradual drift, the accelerometer is a noisy sensor with integration error (due to the noise). Using them both in conjunction, with a set ratio of either sensor's information can improve the performance of an IMU (Inertial Measurement Unit) dramatically, as well as tuning the sample rate of either sensor.

The problem with the MEMS accelerometers and gyros you get in cheaper implementations of flight controllers etc is that they're actually so susceptible to noise that their drift is usually measured in degrees a second, so the longer they're running the worse they get.

A 'step-up' from complementary filtering is sensor fusion, which involves blending in data from sensors external to your IMU, usually GPS, to further combat the issues you've been having.

To further understand the characteristics of these sensors and the constraints I'd recommend this primer on 'Allan Deviation' which shows you how to characterise accelerometers and gyroscopes in order to optimise drift and noise removal, as well as sample rates. There's also this incredible AHRS algorithm developed by Sebastian Madgwick which blows my mind a bit.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.