AP_BARO Code Confusion in v2.4

I have been taking some time each day to read a bit more of the source in the hopes of hacking on my apm2 when it arrives shortly next week. I was looking at the ./libraries/Ap_Baro/AP_Baro_BMP085.cpp file on line 103 is the AP_Baro_BMP085::read() method, the comments just above it say that it is a state machine  that should read temperature once for every 4 times it reads the pressure. However looking at the code it seems like someone intended this to be so but accidentally has them going at a ratio of 1:1. They mention that state 1 is for temp and states 2-5 are for pressure, but it looks like this code will just switch back between 1 and 2. Maybe I am missing something and can be enlightened, or is this intentional and the comments are no longer up to date?

Thanks,

Matt

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Developer

    Fix8,

         Thanks for looking at this.  I had a read of the datasheet and I think the comments are out of date.  You're right that it seems to be reading the temp and pressure alternatively.  I imagine it was done this way so that it can be read asyncronously...so on one iteration it kicks off the request for a new temperature, the next iteration it actually reads the temperature.  This avoids waiting around 5ms for the result.  This ends up in some ugliness in the main code though because if you search for "barometer.read()" you'll find it in two places not even in the same .pde file!

         By the way, the BMP085 is the older baro, the MS5611 is the newer (and much better one) on the APM2.  To be honest, this is actually the best thing about the APM2 (this and it's smaller size).

         Thanks for spotting this.  I'll clean up the comment and hopefully also eventually fix the ugliness I've mentioned above.

  • So looking at AP_Baro_MS5611.cpp file it appears that the MS5611 code was copied and used as a template to make the BMP085 code, which explains the comment, however there is still a state value used here, instead of a boolean or something simpler, my hunch is that this was just laziness (not calling the devs lazy, you guys are awesome just trying to understand the code, although why change the variable name if laziness?), and that perhaps on the BMP sensor the temperature reads more quickly relative to the pressure so the 1:4 ratio is unnecessary.

This reply was deleted.

Activity