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:
- How often should I read samples from a sensor (read the register over i2c) with relation to the frequency I configure the sensor to?
- How should hardware filters such as a low pass filter on the accelerometer be applied here?
- 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?
- 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.
- Should the PID controller run at a different rate from the fusion?