PDA

View Full Version : Floats



lokling
11-23-2010, 08:33 PM
For the CHR6DM Honk and I was seeing a lot of noise on the Accelerometer readings, and weŽve been trying to track that down. Tonight I changed all floats to longs and followed the code from reading acccel CHR6DM values to the configurator making sure there were no floats in the calculation. I also removed the smooth(.. ) function altogether.

This seems to have solved our problem with accel noise, so either its the floats, the smooth function or both that was adding it. IŽll look further into this tomorow and get a "all in ints" version with proper scaled values - but for now I just wanted to share this with you to get you thinking.

Commit;
https://github.com/lokling/AeroQuad/commit/4da2ca889e3a9ca57df86077e196059d930b0a03

PS: As this was done with search and replace to prove one point, theres of course many very wrong things in this commit - Kp and Ki looses their decimals for one. So strictly no-fly "look only" version

Honk
11-23-2010, 08:53 PM
Uh-oh! Lokling is on to something big! What if... It was the imprecise Arduino (Atmega emulated) float's doing it all all along? What if... we int the PID too?! I can just imagine all our quads starting to fly themselves now with a nanosecond looptime now! :P

lokling
11-24-2010, 08:12 AM
A questions I thought of on the way to work, put them here as note to self and for others:

https://github.com/AeroQuad/AeroQuad/blob/master/Accel.h#L32
- Why is accelData defined as an int array (Was this something I and Honk introduced?). I think alan mentioned this earlier aswell.


If not for anything else I think this excercise of conerting all to int will clean out some conversion issues. WeŽll put back the floats where they make sense.

ala42
11-24-2010, 03:31 PM
I do not see where you removed float calculations in Accel.h.

In this version the BMA180 reading is buggy. You commented out these lines by mistake:


currentTime = micros();
previousTime = currentTime;

accelData was already an int array in the 2.0.1 code, so you are switching back and forth between ints and floats.

lokling
11-24-2010, 03:52 PM
IŽve only swapped in double and float variables for longs; https://github.com/lokling/AeroQuad/commit/4da2ca889e3a9ca57df86077e196059d930b0a03#diff-0

And as I wrote this code is not intended for flying or anything. At the moment it only proves that we got rid of noise for the CHR6DM by switching to scaled up integer values and removing the smooth( ) function. The goal of the experiment is to test the CHR6DM configuration with all data carried over in scaled up integer values, and is also not intended to be branched back to the master - its a throwaway experiment that we can cherry-pick the good parts from.

The BMA180 error is not from this commit, I guess its from one of Honks updates - blame the Swede ;) , so not really related. Its probably fixed already but I havent pulled in the changes. IŽve not got the BMA180 defined so I dont really care in this setting :-)

Would be great if you want to join in on this by making a clone of the main repo! :-)

ala42
11-24-2010, 04:06 PM
If I knew how the github stuff works... I would fix the bug, also present in https://github.com/AeroQuad/AeroQuad/blob/master/Accel.h

lokling
11-24-2010, 04:22 PM
If you point me to the line number in Accel.h and what you think need changing I can make a commit with the changes for you. Do you mean the commented out block at Accel_AeroQuadMega_v2 ? line 281? Thats part of a quick test mikro did - looks like a typo. https://github.com/AeroQuad/AeroQuad/commit/8a973c20a85dfc30c2e2f2337ad7fb0549daf93a

ala42
11-24-2010, 04:43 PM
In Accel.h it ~line 280 should look like this


void measure(void) {
currentTime = micros();
/*
...

previousTime = currentTime;
}

Otherwise smooth had to no valid values to compute (currentTime - previousTime).

The identical bug is also in Gyro.h ~line 261. Should be


void measure(void) {
currentGyroTime = micros();
/*
...
previousGyroTime = currentGyroTime;
}

lokling
11-24-2010, 04:50 PM
Ok cool - pushed it to my github repo so mikro will spot it when he takes at the changes :-) https://github.com/lokling/AeroQuad/commit/9282876ce739acb3bb72e610d6bcfe3d5bbfcf44

ala42
11-24-2010, 05:01 PM
You did only half of the fix. previousTime = currentTime; and previousGyroTime = currentGyroTime; are still missing.

lokling
11-24-2010, 05:31 PM
hehe, That should teach me not to code while putting the kids to bed. Fixed it now.

ala42
11-25-2010, 02:51 AM
Come on, that can not be so hard to fix, or is it ? :). I did not add the closing brackets for fun, the second assignments belong at the end of the functions, or current-previous will be 0 when used in the smooth call.

Honk
11-26-2010, 03:58 PM
I'll take the punishment for not doing it proper the first time. Glad you're finding these code bugs!