When comparing a couple of I2C (digital) sonars with the normal (analog) sonars I noticed the range reported by the analog sonar appeared to be wrong. A tape measure proved the digital sonars were spot on and the analog data was well off. Other users have reported similar problems (here and here).
Some work with a spread sheet, schematics and the sonar data sheets helps point to the causes of this.
First the sonar module analog output is in proportion to the Vcc input to the sonar - this is a particular problem when running on USB where your Vcc can be down around 4.8 volts - you can not assume an accurate 5 volts to the sensor. This means you can not just measure the analog voltage output and hope to calculate an accurate range.
Second different Maxbotics sonar models output different voltages per centimetre. Even within the XL model range there is a 200% difference in output voltage for the same range. eg (from data sheets):
LV - EZ0 MB1000:(Vcc/512) per inch
XL- EZ0 MB1200: (Vcc/1024) per cm.
XL- EZL0 MB1260: (Vcc/1024) per 2 cm.
Third the analog port on the APM / IMU shield uses the ADS7844 external Analog to digital converter. This device does a 12 bit conversion relative to a reference voltage. The 'Foxtrot' version schematic shows this reference is 3.3 Volts. The ADS7844 data sheets says in this configuration it will digitize a signal in the range 0V to 3.3V. This appears to mean we cannot reliably use the sonars to their maximum range as they will output greater than 3.3 volts at some point (any range over 5 meters for the MB1200 and over 7 metres for the 1260). I wonder if this is why some users report strange 'zoom climb' behaviour when in altitude hold - particularly in the 4 to 8 metres altitude range.
The Rangefinder library makes no allowance for either of the three points above. It assumes the numbers coming out of the ADC are directly proportional to centimetres, and this is not the case at all. If you have a MB 1200 it will read twice the range of a MB1260 if you have a MB1000 then you have to convert from inches to metric and allow for half the resolution. If your power supply voltage (Vcc) is not known then you can not accurately calculate your range. If your sonar signal goes over 3.3 volts you may not get the correct result from the ADC.
Below is a screen grab of my google spreadsheet that shows the difference in reported range and actual range and the ability to calculate an fairly good adjusted range by taking the points above into account. I haven't tried this at longer ranges yet so cannot test the 3.3 Volt limit theory.
Before we charge off and re-write the Rangefinder library I'd like to hear what people think of the theories outlined above.
(for those that are curious the digital (I2C) sonars use timing of pulses to indicate distance so no voltages are involved and so they avoid all of these issues)
We saw this comment and wanted to add some information. The MB1200 is the most sensitive sensor we sell and we believe it may be the most sensitiveness sensor for sale. We suggest testing the MB1240 and comparing it to the SRF02 because the beam pattern of the MB1240 matches the SRF02 best.
Also we recently tested the noise immunity of our sensor and want to ensure you have access to the information. Please click this link to view the post http://diydrones.com/profiles/blog/show?id=705844%3ABlogPost%3A2891....
If you have any questions, please let me know.
Technical Support & Sales
of MaxBotix Inc.
Phone: (218) 454-0766
Fax: (218) 454-0768
Great piece of info linked, as expected from a serious manufacturer.
However, I'm not sure (I don't say I disagree) suggesting the MB1240 (EZ4) over the 1200 (EZ0),
Sensor beams patterns liink
On the other hand you gave valuable piece of info on immunity to "acoustic" noise, but not to electrical noise (ie from ESCs), which is the most probable suspect of causing weird readings from the sensor (and maybe the sensor has not the fault but the signal wire picking noise from the sensor to the ADC)
Thanks anyway, you can never give too much info ;)
Thanks again for the great analysis. I've changed the code in trunk to take all this into account and the accuracy seems much better. There's a new parameter called SONAR_TYPE which can be 0 for the default XL-EZ0, 1 for the cheaper LV-EZ0 or 2 for the 10m range XL-EZL0. I think Michael O will likely update the APMissionPlanner to add a drop-down to make it easy for people to select this but until then it can be done through the CLI's setup menu.
Not sure when the next official version will be pushed out..we're working on APM2 support at the moment but still probably won't be too long.