4
$\begingroup$

I'm programming a quadcopter controller. I've managed to make it fly. But, I'm not sure how to set up the timings schedule for each part of the software.

I have several sensors (gyro, accelerometer, magnetometer, barometer) with output at various frequencies. Those data go into the sensor fusion. Then, the fused data goes through a PID controller. The PID output goes into the motors.

So, my questions are:

  1. How often should I read samples from a sensor (read the register over i2c) with relation to the frequency I configure the sensor to?
  2. How should hardware filters such as a low pass filter on the accelerometer be applied here?
  3. How quickly (frequency wise) should I use that data during sensor fusion (such as a complementary filter)? Should the fusion timing be based on when a new sample is ready or do I run the fusion faster or slower than I sample?
  4. How do sensors sampling at different speeds affect fusion? For example, my magnetometer has a max data rate of 100hz, but currently, my gyroscope is running at 200hz.
  5. Should the PID controller run at a different rate from the fusion?
$\endgroup$
1
$\begingroup$
  1. How often should I read samples from a sensor (read the register over i2c) with relation to the frequency I configure the sensor to?

If you sensor provide data at a certain rate you should not read it at a faster rate because it's note bringing any new info to you just repeating an old/depreciated info.

  1. How should hardware filters such as a low pass filter on the accelerometer be applied here?

You should apply you low pass filter on the raw data and feed the filtered data to the fusion algorithm, note that if you filter too much you will get time delays. If you don't explicitly account for them in the fusion and control, you will get poor results

  1. How quickly (frequency wise) should I use that data during sensor fusion (such as a complementary filter)? Should the fusion timing be based on when a new sample is ready or do I run the fusion faster or slower than I sample?

You should run you fusion algorithm every time you get a new measurements, whatever it is, you can tune the frequency of every sensor to allow your fusion algorithm to finish by the time it gets a new measurements.

  1. How do sensors sampling at different speeds affect fusion? For example, my magnetometer has a max data rate of 100hz, but currently, my gyroscope is running at 200hz

It's not an issue a fusion algorithm takes several quantities as inputs with also their variance (ie how trustworthy is the measurements) to derivate a full state estimate. For example if you have a very precise position system but low frequency and fast accelerometers, the position model will be such that the accelerometers are integrated between the measurements of the position sensor, but once you get a next position the measurement "wins" against the estimate.

  1. Should the PID controller run at a different rate from the fusion?

Your control should run as fast a possible but not faster than the fusion because you don't have information update about your current state, typically they run at the same frequency and both as fast as possible based on your hardware power.

$\endgroup$

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.