microtrigger / ardu-imu

Automatically exported from code.google.com/p/ardu-imu
0 stars 0 forks source link

BMP085 and HMC5843 #14

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
BMP085 and HMC5843 can be used simultaneously on arduimu? how?

Original issue reported on code.google.com by vito.amm...@gmail.com on 28 Apr 2011 at 4:01

GoogleCodeExporter commented 9 years ago
I have applied some changes, now compile with MAGNETOMETER = 1 and I have 
insert code for BMP058 - BAROMETER = 2 (BMP058)
I think that the alti() function isn't correct.
can you test it?

Original comment by vito.amm...@gmail.com on 30 Apr 2011 at 3:04

Attachments:

GoogleCodeExporter commented 9 years ago
I have been wanting to add a BMP085 to my IMU for a while.  I am willing to 
help.  I have the hardware to try the BMP085, but I don't have the magnetometer.

You haven't tried this on any hardware yet, or you have tried it and it appears 
that the alti() isn't working?

Original comment by krssch...@gmail.com on 30 Apr 2011 at 10:14

GoogleCodeExporter commented 9 years ago
I haven't tried it yet, but I think that the correct algorithm
is:
        APM_BMP085.Read();
        x = (APM_BMP085.Press/101325.0);
        x = pow(x,0.190295);
        press_alt = 44330*(1.0-x)*1000;

Original comment by vito.amm...@gmail.com on 30 Apr 2011 at 11:22

GoogleCodeExporter commented 9 years ago
Ok. Well I moved my BMP085 to the I2C port on the IMU. I will give it a try 
tonight and let you know. 

Original comment by krssch...@gmail.com on 1 May 2011 at 12:12

GoogleCodeExporter commented 9 years ago
I have tried but don't work.
I think that the problem is that the APM_BMP058 class use the pin pc7.

#define BMP085_EOC 30        // End of conversion pin PC7

arduimu haven't the pc7 pin

Original comment by vito.amm...@gmail.com on 1 May 2011 at 9:35

GoogleCodeExporter commented 9 years ago

I just tried it too.  This is what I got...

???You are using Hardware Veion 2...***
???Software Version 1.9.0***
???Enabling Pressure Altitude...***
???Ground Start!***
???Ground Start!***
379.78
378.81
372.95
505.45
540.55
534.68

Original comment by krssch...@gmail.com on 1 May 2011 at 11:36

GoogleCodeExporter commented 9 years ago
It seemed to hang after what I show above.

I have had used this sensor in my parallax propeller autopilot.  It was 
connected directly to the propeller, but I want to move it to the IMU.  I had 
to use some filtering to reduce noise.  I found that a running average filter 
using the last 16 values works well with a band pass filter that limits the 
change in pressure.  I know the aircraft will only change altitude withing a 
certain amount over a certain time, so I limited the change in pressure.

Also, I think a more accurate barometric function would use temperature.  
Something like ln(Ph/Po)*temp*Pcon=delta height.  Pcon would be equal to 
Boltzmann constant /(-mass of air molecule * gravity). Temp is in Kelvin.

Original comment by krssch...@gmail.com on 1 May 2011 at 11:56

GoogleCodeExporter commented 9 years ago
Another thought could the PWM1 pin be used?

Original comment by krssch...@gmail.com on 2 May 2011 at 6:53

GoogleCodeExporter commented 9 years ago
I hane tried to use PWM0 and 1 but arduimu freeze

Original comment by vito.amm...@gmail.com on 2 May 2011 at 7:07

GoogleCodeExporter commented 9 years ago
It might take some work, but the parallax propeller site has a driver for the 
bmp085 that only uses the two i2C pins. I have used it and it works well.  I 
know I am not up to the task to convert the spin code to C, but it might be 
some help to you. It should be easy to find if you search for BMP085 on the 
object exchange. If you can't find it I can sent it later. 

Original comment by krssch...@gmail.com on 2 May 2011 at 7:26

GoogleCodeExporter commented 9 years ago
Work!!! 
If GPS is fix Arduimu should work!!!!
The problem is in this code:

    while ((gps_fix_count > 0) && (USE_BAROMETER > 0)) {
        GPS.update();
        //  Serial.print(gpsFix);
        //  Serial.print(", ");
        //  Serial.println(gpsFixnew);
        if ((GPS.fix == 1) && (GPS.new_data == 1)) {
            GPS.new_data = 0;
            gps_fix_count--;
        }
    }

If this code is commented arduimu seems work correctly.
Please verify the code and if really work! 

Original comment by vito.amm...@gmail.com on 4 May 2011 at 6:15

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is new code

Original comment by vito.amm...@gmail.com on 4 May 2011 at 6:17

Attachments:

GoogleCodeExporter commented 9 years ago
Thats great, So what was done with the EOC pin?  Did you connect it to a PWM 
pin?

Original comment by krssch...@gmail.com on 4 May 2011 at 6:31

GoogleCodeExporter commented 9 years ago
I have yet to solve the above code, but for the use of pwm pins there should
be problems

Original comment by vito.amm...@gmail.com on 4 May 2011 at 6:37

GoogleCodeExporter commented 9 years ago
-I tested it indoors (it's raining outside) disabling the following code

while ((gps_fix_count> 0) & &
(USE_BAROMETER> 0)) {
GPS.update ();
/ / Serial.println ("test ->");
/ / Serial.println (gps_fix_count);
/ / Serial.println (GPS.fix);
/ / Serial.println (GPS.new_data);
if ((GPS.fix == 1) & & (GPS.new_data == 1)) {
GPS.new_data = 0;
gps_fix_count -;
}
}

this code waits the 3D GPS fix, the height range is of 5 meters
- the 3d GPS fix code is need but work only in outdoor  
- The EOC pin seems useless I modified the original code and it seems
work directly in i2c

test it and tell me if it really works thanks!

Original comment by vito.amm...@gmail.com on 4 May 2011 at 8:09

Attachments:

GoogleCodeExporter commented 9 years ago
I got it to compile.  I see what you did with the EOC issue.  I looked at the 
spec for the BMP085 and it says a max of 25.5ms is reqired for oversampling 
setting 3.  I am pretty sure that the EOC was to prevent a new sample before 
the oversampling had taken place.  I was thinking the EOC could be replaced 
with this:

    if (BMP085_State==1)
    {
                if ((millis()-timer)>=26)
        {

                ReadTemp();             // On state 1 we read temp
            BMP085_State++;
            Command_ReadPress();
                        timer = millis();
        }
    }
    else
    {
        if (BMP085_State==5)
        {
            if ((millis()-timer)>=26)
            {
                ReadPress();
                Calculate();
                BMP085_State = 1;    // Start again from state=1
                Command_ReadTemp();  // Read Temp
                result=1;            // New pressure reading
                                timer = millis();
            }
        }
        else
        {
            if ((millis()-timer)>=26)
            {
                ReadPress();
                Calculate();
                BMP085_State++;
                Command_ReadPress();
                result=1;            // New pressure reading
                                timer = millis();
            }
        }
    }

Haven't had a chance to test what you sent last though, so it might work just 
fine without the EOC or timers.

Thanks-

Original comment by krssch...@gmail.com on 4 May 2011 at 11:44

GoogleCodeExporter commented 9 years ago
If the tests show that the sensor output values ​​are incorrect, we should 
use the EOC pin and not the code that you specified (the code does not seem 
correct, the datasheet says you have to wait until 25.5ms  between request and  
reading, you should insert a sleep between demand and reading)

Original comment by vito.amm...@gmail.com on 5 May 2011 at 8:26

GoogleCodeExporter commented 9 years ago
ok got some good news.  The code works.  I think the initial gps alt point 
algorithm needs to be corrected.  The initial GPS altitude point might not be 
accurate enough, so there was a 70m offset from the gps value (see attached 
sheet).

I put my setup in my car and drove up a hill.  The low point is the bottom and 
high point is the top of the hill.

It did wait for a GPS fix.

The good thing is the diffrence between gps alt and pressure alt is very close. 
 I need to look at a map to get another estimate of the altitude change to 
check against.

Very Nice Work! 

Original comment by krssch...@gmail.com on 5 May 2011 at 7:36

Attachments:

GoogleCodeExporter commented 9 years ago
I tried to increase the number of satalites required at startup, but it didn't 
seem to help.  You can see the initial pressure and GPS alt don't quite match.  
Not sure yet how to fix this.  Here is the data, Lat Long removed...:

int gps_fix_count = 7;

First Two Lines:
!!!VER:1.9.0,RLL:-0.95,PCH:-0.16,YAW:-0.05,IMUH:253,Temp:31.10,Pressure: 
84055,Alt: 1548,LAT:**,LON:-**,ALT:1555,COG:0,SOG:0,FIX:1,SAT:0,TOW:434218000***
!!!VER:1.9.0,RLL:-1.44,PCH:-0.25,YAW:-0.06,IMUH:253,Temp:31.10,Pressure: 
84055,Alt: 1548,LAT:**,LON:-**,ALT:1544,COG:0,SOG:0,FIX:1,SAT:0,TOW:434218500***

After a couple min:
!!!VER:1.9.0,RLL:-4.07,PCH:-0.60,YAW:-111.24,IMUH:253,Temp:38.20,Pressure: 
84315,Alt: 
1523,LAT:**,LON:-**,ALT:1554,COG:226,SOG:0,FIX:1,SAT:0,TOW:434380750***

!!!VER:1.9.0,RLL:-4.08,PCH:-0.63,YAW:-111.30,IMUH:253,Temp:38.20,Pressure: 
84312,Alt: 
1523,LAT:**,LON:-**,ALT:1555,COG:226,SOG:0,FIX:1,SAT:0,TOW:434381000***

int gps_fix_count = 10;

First Two Lines:
!!!VER:1.9.0,RLL:-0.02,PCH:0.01,YAW:-0.01,IMUH:253,Temp:37.60,Pressure: 
84168,Alt: 1537,LAT:**,LON:-**,ALT:1581,COG:0,SOG:0,FIX:1,SAT:0,TOW:434779250***

!!!VER:1.9.0,RLL:-0.05,PCH:-0.01,YAW:-0.01,IMUH:253,Temp:37.60,Pressure: 
84165,Alt: 1537,LAT:**,LON:-**,ALT:1581,COG:0,SOG:0,FIX:1,SAT:0,TOW:434779750***

After a couple min:
!!!VER:1.9.0,RLL:-0.26,PCH:-0.03,YAW:-20.87,IMUH:253,Temp:42.40,Pressure: 
84326,Alt: 1522,LAT:**,LON:-**,ALT:1560,COG:0,SOG:0,FIX:1,SAT:0,TOW:434922000***

!!!VER:1.9.0,RLL:-0.24,PCH:-0.03,YAW:-20.90,IMUH:253,Temp:42.40,Pressure: 
84332,Alt: 1521,LAT:**,LON:-**,ALT:1560,COG:0,SOG:0,FIX:1,SAT:0,TOW:434922250***

Original comment by krssch...@gmail.com on 6 May 2011 at 12:59

GoogleCodeExporter commented 9 years ago
Looking at the code more, it looks like the GPS_fix_count is not the number of 
satalites.  It is a count of GPS updates that have a fix.  I am now thinking 
that I want to increase this number from 5 to something like 240.  This would 
wait about 1 min for the GPS to get an accurate altitude before the IMU records 
the refrence ground altitude number. (the UBlox GPS is 4hz, so 60sec*4Hz = 
240).  What do you think?

Original comment by krssch...@gmail.com on 6 May 2011 at 7:01

GoogleCodeExporter commented 9 years ago
I changed GPS_fix_count to 120.

It looks like this helped the GPS get a more accurate gruond altitude before 
writing it to the eprom and using it for the base pressure altitude.  Here is 
the data.  Notice how much closer the first line and last line of GPS and 
Pressure altitudes are:

First line received:
!!!VER:1.9.0,RLL:-0.00,PCH:0.00,YAW:0.01,IMUH:253,Temp:20.10,Pressure: 
83672,Alt: 
1585,LAT:3**,LON:-**,ALT:1580,COG:0,SOG:0,FIX:1,SAT:0,TOW:561552250***

Many many lines later...
!!!VER:1.9.0,RLL:0.03,PCH:-0.02,YAW:-7.30,IMUH:253,Temp:21.50,Pressure: 
83710,Alt: 1582,LAT:**,LON:-**,ALT:1578,COG:0,SOG:0,FIX:1,SAT:0,TOW:561641500***

Original comment by krssch...@gmail.com on 7 May 2011 at 12:05

GoogleCodeExporter commented 9 years ago
how long is need for running 120 GPS_fix_count?

Original comment by vito.amm...@gmail.com on 8 May 2011 at 8:39

GoogleCodeExporter commented 9 years ago
Well the GPS found a fix when I had power to the board for uploading code.  I 
am using the DIY Drones adapter on my Ublox GPS which has the battery, so I 
think it already had satalites.  Totaly estimating, it took about 1 min from 
power on the IMU to showing data.

BTW I also tried showing binary data and sent it to the happykillmore GCS.  
Everything looked good.  I did disable the mixing of GPS with pressuer data.

This line was removed:
tempint=(press_alt * ALT_MIX + GPS.altitude * (100-ALT_MIX)) / 10000;

And replaced with:
tempint = press_alt/1000;

for binary output

Original comment by krssch...@gmail.com on 8 May 2011 at 1:30

GoogleCodeExporter commented 9 years ago
44 sec from power on to blue light

Original comment by krssch...@gmail.com on 8 May 2011 at 1:55

GoogleCodeExporter commented 9 years ago
good. GPS_fix_count = 120 seems reasonable 

Original comment by vito.amm...@gmail.com on 8 May 2011 at 2:15

GoogleCodeExporter commented 9 years ago
It looks like there is still a bit of noise.  The attached file was collected 
at about 4hz.  This is the altitude data in meters with the BMP085 sitting 
still.  I think the noise can be reduced so that you don't see any change when 
looking at 1m resolution.

I think a filer like this would work well.

pressure=(last_pressure*5+current_pressure)/6
last_pressure=pressure

the constant 5 could be varied to make the filter more or less agressive.

I also am not sure the conversion is fully happening.  The data sheet says at 
ultra high resolution there should be .03 hPa noise (RMS).  That is .25m RMS.  
I am seeing variation of 10m in my data, so something is not quite right.

I am going to play around with these ideas.  Let me know if you have any input.

Original comment by krssch...@gmail.com on 8 May 2011 at 11:17

Attachments:

GoogleCodeExporter commented 9 years ago
I have been scratching my head on the issue with the altitude diffence between 
gps and pressure. I finally found that you replaced the altitude calculation 
with the one in he BMP085 manual but used standard pressure as Po and didn't 
include a calibration to starting ground position. This neglects all local 
variation in barometric pressure. You must use the gps to set a start altitude 
to calibrate the calculation for that days barometric pressure. This explains 
why one day (a clear sky day) I was getting good numbers and the next day 
(storm approaching) I got bad numbers. I am working on a fix. 

Original comment by krssch...@gmail.com on 11 May 2011 at 7:01

GoogleCodeExporter commented 9 years ago
D'oh! I forgot to warn you that I had changed it

Original comment by vito.amm...@gmail.com on 11 May 2011 at 7:23

GoogleCodeExporter commented 9 years ago
Ok. Here is my latest.  I think I got it.

It waits for a gps altitude that changes less than 3 meters.  I added pressure 
filtering so the pressure accuracy should be +/- 1m with some slight delay.  I 
corrected the pressure calc to account for local pressure changes and it uses 
the ground temperature.

Make sure you use the BMP085 library that vito.amm... created not the 
AMP_BMP085.

please test and post issues.  I havent had a chance to do any moving tests yet, 
but static tests look good.

Original comment by krssch...@gmail.com on 13 May 2011 at 1:25

Attachments: