control loop frequency in apm2.5 and pixhawk

hi every body . 

i build a sensor board, and used same sensors(except mpu6000, i used 6050) implemented on amp2.5 and try to gather the data from these sensors.

the problem i have is that i think the gathering data from sensors in my board take abnormal time. for example for mpu6050 , gathering gyroscope (reading 6 register from i2c) take about 2.5ms.

after reading all sensor data i can not refresh my sensors data more than 80Hz(gyro,baro,accel,megneto)

what i want is to know amp2.5 how many time in 1 second read data from senors (like gyro)??

and the frequency of control loop ?? what about pixhawk which has 4times faster microcontroller??

the frequency of normal servo motors in 50hz. so is it necessary that we should at least update data in 50hz??

thanks in advance .

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –


  • Make sure your I2C buss is running at 400Khz.  Make sure you request all of the data in a single read sequence.  Here's the code from the library I wrote for myself to get data from the MPU6050:

    void MPU6050::retrieve(){
        Wire.beginTransmission(MPU6050_ADD);    //start transmission to device
        Wire.requestFrom(MPU6050_ADD, 14);      // request 14 bytes from device
        aXi  = 8 |;
        aYi  =  8 |;
        aZi  =  8 |;
        _tempRaw  =  8 |;
        gXi  =  8 |;
        gYi  =  8 |;
        gZi  =  8 |;   
        Wire.write(0x3B);// send pointer back to the beginning of data, saves time
        Wire.endTransmission(); //end transmission
    I think when called from an Atmega328P this requires roughly 500us, but I haven't checked lately. I might be remembering wrong, but I know it's significantly less than 1ms.
    The only sensor that needs to be sampled at 400Hz is the gyro.  (On an MPU6050m, I sample both the gyro and accel at 400Hz since it requires very little extra time to do this.)  All other sensors should be sampled less frequently in such a way that they do not interfere  with the 400Hz loop. 
    I hope that this helps.
    EDIT:  In the code above there should be a left bit-shift (double less-than sign) between the and the 8.  Unfortunately this silly editor strips them out.
    •   I just noticed you post indicating that you're controlling a fixed wing aircraft.  You probably don't need 400Hz gyro sampling with an airplane, but it won't hurt if you can swing it as it does reduce the error from the constant rotational rate assumption most attitude estimators use.

        As a side note, I have used my MPU6050 on a 800kHz I2C buss without issue (and it does save a lot of time), but do so at your own risk as the MPU6050 isn't rated above 400kHz.


      • thanks phillip and Randy

        i found what i needed from your post.

        thanks lot

  • Developer


    The problem with the 6050 is perhaps the I2C connection which is quite slow.  That's why we've stuck with the mpu6k on the APM and Pixhawk.  I believe some of the later models also have the SPI interface.

    I think the APM reads from the mpu6k at 200hz.  The pixhawk reads at 1000hz.

    It depends on the vehicle, for multicopters, 50hz is far too slow and they simply won't fly.  For planes you can probably get away with reading at 100hz, I'm much less sure about 50hz.

    • thanks Randy.

      my major concern is about fix wing airplane.

      recently i could get gyro data in 1.6khz and also same for accel and compass(each one separately) through i2c . if i take all sensors data in about 600hrz (just getting data without controlling loop like simple PID)and with calculation for example for a simple stabilize with PID i hopefully think that i can have controlling loop in 200Hz.

      i mean i can refresh my pwm that goes to my servos in 200hz(servos are simple 50hz servos).

      because somewhere in this forum i read from one of pixhawk  and apm developer that apm controlling loop executes in 100hz and pixhawk 400hz ?

      so am i right ??

      if i,m right ,so i can't use all of my micro's capability because my micro is same as pixhawk . and i have to review my code seriously .

      • Developer

        The arducopter multicopter software runs at 400hz, plane runs at 50hz main loop speed so I think you'll be ok.

This reply was deleted.


Hiroki Tanaka liked Hiroki Tanaka's profile
Oct 13
Derrick Davies liked lisa TDrones's profile
Sep 23
xemone liked Max Gilson's profile
Aug 31