Yes, major changes are definitely to be undertaken with caution! Ideally there would be some way of testing the read speed in isolation before committing to a major rewrite. Probably the most efficient way would be to use your existing program unchanged with cProfile, start the program as per
Code: Select all
$ cd ~/quadcopter_or_whatever
$ python -m cProfile ~/quadcopter_or_whatever/Quadcopter.py > result.txt
and after a few minutes running stop it and look in the result.txt which you will be able to parse with a spreadsheet. You can then look to see how many times I2C.readList() was called and what the execution time was. That way you can work out the resultant I2C read speed. I would expect it to be capable of MB/s if the I2C is clocked as fast as it will go.
It's definitely worth spending a bit of effort analysing and profiling before starting to modify your code.
PS I note your sceptical silence on my doubts as to whether adding in these missing readings will really make that much difference. Maybe this will explain my thinking better. Below is a copied bit of spreadsheet, the first column is the actual acceleration, really it's a continuous variable so there should be an infinite number of values but I just represent it as having significantly more values than the accelerometer can read: whatever the sample speed there is still some acceleration happening between readings that you haven't measured. The second column is the cumulative sum of accelerations or velocity (really it's infinitesimal integral). The third column is regular sampling. The fourth column is regular sampling but with some readings missed (and "filled in" using the next reading). If you make something similar and play around with it you will see that missing readings do have a detrimental effect but not much. In fact, though I don't know the formula for things like this, it is almost always something over root n.
So if your estimate of the velocity based on getting all the readings was 0.100% out, if you only had 95% of the readings your estimate would be 0.103% out. Or, to put it another way, if the quadcopter went out of control after 10s using 95% of the accelerometer readings I would expect it to go out of control after 10.25s if you used 100% of the readings.
Of course this is assuming all that's happening is sampling, if there is a systematic error that faster reading will solve then that would change things.
Code: Select all
-12.9 -12.9
-12.4 -25.3
-11.8 -37.1
-11.9 -49.0
-12.1 -61.1 -121.3 -121.3
-11.5 -72.6
-11.6 -84.2
-11.8 -96.0
-11.4 -107.5
-11.8 -119.3
-11.6 -130.9
-10.9 -141.8
-11.0 -152.8
-11.0 -163.8
-10.6 -174.4 -227.6 -227.6
-11.3 -185.7
-10.5 -196.2
-10.4 -206.6
-10.6 -217.2
-10.8 -228.0
-10.6 -238.6
-10.2 -248.8
-10.6 -259.4
-9.9 -269.2
-10.0 -279.2 -327.8 -327.8
-10.0 -289.3
-9.3 -298.5
-9.6 -308.1
-9.2 -317.3
-9.0 -326.3
-9.1 -335.4
-9.0 -344.4
-9.2 -353.6
-8.8 -362.4
-8.8 -371.2 -416.2 -327.8 missed
-8.5 -379.7
-8.8 -388.5
-8.5 -397.0
-8.3 -405.3
-8.0 -413.3
-7.8 -421.1
-8.0 -429.1
-7.8 -436.9
-7.9 -444.8
-8.1 -452.9 -497.6 -490.7
-8.2 -461.1
-8.0 -469.1
-7.9 -477.0
-7.2 -484.2
-6.9 -491.1
-7.3 -498.4
-7.5 -505.9
-6.5 -512.4
-6.8 -519.2
-6.9 -526.2 -566.9 -490.7 missed
-6.5 -532.6
-6.4 -539.1
-6.0 -545.1
-6.4 -551.5
-6.0 -557.5
-6.4 -563.9
-6.1 -569.9
-5.6 -575.5
-5.6 -581.1
-5.4 -586.5 -621.0 -599.0
-5.9 -592.4
-5.6 -597.9
-5.2 -603.1
-5.0 -608.1
-5.3 -613.4
-5.2 -618.6
-4.9 -623.6
-5.2 -628.7
-4.7 -633.4
-5.0 -638.4 -671.2 -649.2
-4.9 -643.3
-3.9 -647.3
-4.3 -651.6
-4.5 -656.1
-4.4 -660.5
-4.2 -664.7
-3.9 -668.6
-3.9 -672.5
-4.0 -676.5
-3.8 -680.2 -708.9 -686.9
-3.1 -683.3
-3.3 -686.6
-2.8 -689.4
-2.8 -692.2
-2.4 -694.7
-3.3 -697.9
-3.0 -700.9
-2.9 -703.8
-2.0 -705.8
-2.6 -708.4 -735.4 -686.9 missed
-2.7 -711.2
-2.3 -713.5
-1.9 -715.4
-2.1 -717.5
-1.6 -719.1
-1.9 -721.0
-1.3 -722.3
-1.9 -724.3
-1.7 -726.0
-1.5 -727.5 -750.6 -717.3
-0.9 -728.4
-1.0 -729.4
-1.1 -730.6
-1.1 -731.7
-0.8 -732.5
-0.8 -733.3
-0.2 -733.6
-0.8 -734.3
-0.4 -734.7
-0.4 -735.1 -754.3 -721.0
0.3 -734.8
-0.2 -735.0
-0.2 -735.2
0.1 -735.1
0.6 -734.5
0.2 -734.3
0.1 -734.2
0.7 -733.4
0.7 -732.7
1.0 -731.7 -743.9 -710.6
1.1 -730.6
1.0 -729.7
1.3 -728.3
1.7 -726.6
1.8 -724.8
1.4 -723.4
1.9 -721.5
2.2 -719.3
1.6 -717.7
1.6 -716.1 -728.0 -694.7
2.7 -713.5
2.4 -711.0
2.0 -709.0
2.2 -706.8
2.4 -704.5
2.9 -701.6
2.6 -699.0
3.2 -695.8
3.4 -692.4
3.4 -689.0 -693.9 -660.6
3.6 -685.5
3.0 -682.5
3.4 -679.1
3.6 -675.5
3.4 -672.1
4.3 -667.8
4.1 -663.7
4.1 -659.6
3.7 -655.9
3.9 -652.0 -655.1 -621.8
4.7 -647.3
4.8 -642.5
4.4 -638.1
4.9 -633.2
4.7 -628.4
5.0 -623.5
5.1 -618.4
5.3 -613.1
5.5 -607.6
5.6 -602.0 -599.4 -621.8 missed
5.1 -596.9
5.2 -591.7
6.0 -585.7
6.0 -579.7
5.7 -574.0
5.7 -568.3
6.2 -562.1
6.2 -555.9
6.2 -549.7
6.1 -543.6 -538.8 -500.6
6.3 -537.3
6.6 -530.7
7.2 -523.5
7.2 -516.3
7.0 -509.3
6.9 -502.4
7.4 -495.0
7.4 -487.6
7.4 -480.2
7.6 -472.6 -463.0 -424.9
7.3 -465.4
8.2 -457.1
8.1 -449.1
8.1 -441.0
8.4 -432.6
8.5 -424.0
8.3 -415.7
8.4 -407.3
8.1 -399.1
8.9 -390.2 -373.7 -335.6
9.1 -381.1
9.2 -371.9
8.5 -363.3
9.2 -354.1
9.2 -344.9
-344.9 -373.7 -335.6
Error = -28.8 9.3