[Swlug] An interesting time with an accelerometer
Colin Law
clanlaw at gmail.com
Sun Jun 26 09:44:30 UTC 2022
I can't help with the code I am afraid, but just to understand how
complex this problem is, consider the case where the plane is flying
in circles at steady speed, banked over in order to go in circles (as
a bicycle does, for example). In that case the accelerometers would
appear exactly as if it were at rest, and horizontal, except that the
'vertical' axis would be slightly higher than 1G. The Gyros would
indicate that it is actually going in a circle, but I have little idea
exactly what they would be indicating. You may have experienced the
same thing when flying, when the plane is turning it is impossible to
tell unless you look out of the window and see that the wing is
pointed at the ground (or the sky).
Colin
Colin
On Sat, 25 Jun 2022 at 19:37, Rhys Sage via Swlug
<swlug at mailman.lug.org.uk> wrote:
>
> After hunting around a bit I found some C++ code that uses accelerometer data (but curiously not gyroscopic data) to produce roll and pitch data. I had to convert from C++ to Python which was not that challenging. I can't test the original as I have Python on my Pi Pico and not C++. I really don't want to have to rig up a Pi Pico with C++ as it's a little out of the scope of what I'm doing so I'm presuming the C++ code actually works. Having said that I'm skeptical because my conversion produced angles in the tens of thousands. This is the original...
>
> https://github.com/mahengunawardena/BeagleboneBlack_I2C_ADXL345/blob/master/ADXL345Accelerometer.cpp
>
> My Python conversion is
>
> from imu import MPU6050
> from time import sleep
> from machine import Pin, I2C
> import math
>
> i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
> imu = MPU6050(i2c)
>
> while True:
> #input('rotate some, hit enter')
> ax=round(imu.accel.x,2)
> ay=round(imu.accel.y,2)
> az=round(imu.accel.z,2)
> AccelerationX = ax * 3.9
> AccelerationY = ay * 3.9
> AccelerationZ = az * 3.9
> Pitch = 180 * math.atan (AccelerationX/math.sqrt(AccelerationY*AccelerationY + AccelerationZ*AccelerationZ))/math.pi;
> Roll = 180 * math.atan (AccelerationY/math.sqrt(AccelerationX*AccelerationX + AccelerationZ*AccelerationZ))/math.pi;
> print("Roll", int(Roll), " Pitch", int(Pitch),end="\r")
>
> I don't see obviously any difference - I think I have encompassed all the necessary code which in C++ looked like this section:
>
> accelerationX = (signed int)(((signed int)rawData_X) * 3.9);
> accelerationY = (signed int)(((signed int)rawData_Y) * 3.9);
> accelerationZ = (signed int)(((signed int)rawData_Z) * 3.9);
> pitch = 180 * atan (accelerationX/sqrt(accelerationY*accelerationY + accelerationZ*accelerationZ))/M_PI;
> roll = 180 * atan (accelerationY/sqrt(accelerationX*accelerationX + accelerationZ*accelerationZ))/M_PI;
>
> The output is not within the anticipated range and looks to be somewhat strange....
>
> MicroPython v1.19 on 2022-06-16; Raspberry Pi Pico with RP2040
> Type "help()" for more information.
> >>> %Run -c $EDITOR_CONTENT
> Roll -1.067217e-07 Pitch 80.44571
> ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> MicroPython v1.19 on 2022-06-16; Raspberry Pi Pico with RP2040
> Type "help()" for more information.
> >>> %Run -c $EDITOR_CONTENT
> Roll 0 Pitch 80977
>
> Has anybody any suggestions? I rather suspect the original github code might be bad since there's no inclusion of gyroscopic data and nothing that looks particularly Kalman.
>
> Rhys Sage
>
> --
> Swlug mailing list
> Swlug at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/swlug
More information about the Swlug
mailing list