In last days I'm working on baro code, but for a long time I have one idea. I found that in MWC code there are som functions called periodically like:
- RC idle in 50HZ
- getEstimatedAltitude() 40Hz
and some function that not to be called in every idle like:
- Baro_update()
- Mag_getADC()
So I enable LOG_VALUES, and start to analyze. At start I have idle in range 2700-4200 with four sensors ADXL345, L3G4200, MS5611, HMCL5883. Hmm quite big cycle time jitter. So I start to optimize my baro functions (yes, it wasn't optimized). So I get cycle time 2700-3600. Better but still not satisfied. So then I decide to add switch and call only one of above function in one loop. So I add this code:
Code: Select all
// ******** Main Loop *********
void loop () {
...
static int8_t idle_idx=0;
#if defined(SPEKTRUM)
if (rcFrameComplete) computeRC();
#endif
//never call all function in the same loop - this increase jitter for this funtion, but less cycle time
switch (idle_idx)
{
case 0:
idle_idx++;
break;
case 1:
idle_idx++;
#if MAG
Mag_getADC();
break;
#endif
case 2:
idle_idx++;
#if BARO
Baro_update();
break;
#endif
case 3:
idle_idx++;
#if BARO
getEstimatedAltitude();
break;
#endif
default:
idle_idx=0;
break;
}
if (currentTime > rcTime && idle_idx == 0) { // 50Hz - only called when idle_idx == 0
Now I have a cycle time in range ~2700-2800 using all my four sensors! I ofcourse remove function called in this switch from other place.
In attached file you can find r568 with my patches for baro some extras, and this cycle time optimization.
I've made some test and fly with this code and everything seems to work fine but, I still learning this code so maybe I miss something.
What do you think Alex, Ziss, other devs?
Cheers,
Marcin.