0
$\begingroup$

Is it possible to speed up execution time of a c++ program in raspberry pi solely by increasing the i2c baudrate and increasing the sampling frequency of the sensors?

I have the issue of sudden jerkiness of my quadcopter and found the culprit which is the frequency at which my loop excecutes which is only about 14Hz. The minimum requirement for a quadcopter is 100-200hz. It is similar to the issue he faces here Raspberry Pi quadcopter thrashes at high speeds

He said that he was able to increase his sampling rate from 66hz to 200hz by increasing the i2c baudrate. I am confused on how that is done.

In the wiring pi library, it says that we can set the baudrate using this command:

gpio load i2c 1000

will set the baud rate to 1000Kbps – ie. 1,000,000 bps. (K here is times 1000)

What I am curious about is how to set this baudrate to achieve my desired sampling rate?

I plan on optimizing it further to achieve at least a 100Hz sampling rate

As of now, the execution time of each loop in my quadcopter program is at 0.07ms or 14Hz.

It takes 0.01ms to 0.02ms to obtain data from the complementary filter.

I have already adjusted the registers of my sensors to output readings at 190Hz (Gyroscope L3GD20H) and 200Hz (Accelerometer LSM303) and 220Hz (Magnetometer LSM303).

$\endgroup$
2
  • $\begingroup$ By increasing the i2c baudrate of the Raspberry Pi I was able to reach 0.007s to 0.019s of loop execution time or 50Hz to 150Hz. $\endgroup$ Jan 18, 2016 at 1:10
  • 1
    $\begingroup$ I am now able to get 250Hz consistently :) $\endgroup$ Jan 18, 2016 at 7:26

1 Answer 1

0
$\begingroup$

It turns out, the default i2c baudrate becomes a bottle neck in reading the measurement data from the IMU's so increasing it from 100kbps to 400kbps was able to boost my execution frequency from 150Hz (After optimizing) to ~ 210Hz (0.00419s)

$\endgroup$
1
  • $\begingroup$ I've removed the cout's (printing data on the terminal) and now the control loop is now 400Hz-540Hz $\endgroup$ Mar 24, 2016 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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