ArduSub support for Bar02 depth/pressure sensor? Depth hold not functioning

Hi @Haadi,

Apologies for the delay on getting to this, although please be aware that posting the same question in several different places around the forum just contributes to clutter and is considered as spamming.

I’ve combined all your comments on this topic into a single one, along with the relevant posts, so that there’s a single discussion thread on this topic for people to find and track.

There are two possible approaches, as discussed above:

  1. Proper (user-configurable) integration to the ArduPilot codebase, likely using a parameter
    • This is what the discussion at the end of the linked GitHub issue is about, and is awaiting a response from other ArduPilot developers on what the most relevant approach is
      • If you want to push this to happen faster then you’ll likely need to either bring it up on the ArduPilot discord server, or in one of their weekly development calls
      • I will also raise it with our lead ArduSub developer, but I can’t provide guarantees on whether / when we’ll have a chance to work on it from our end
  2. Compiling a custom firmware with a hacky replacement of the current Bar30 (MS5837-30BA) support with Bar02 (MS5837-02BA) support, under the assumption that only Bar02 is necessary for use on the vehicle that will be using that firmware
    • Likely the most straightforward way of approaching this would be to replace the _calculate_5837 function with the conversion factors for the Bar02 sensor, which can be found in this library code

Sorry for creating the clutter, but I really needed your help, I couldn’t do it myself. I have been working on it for days and still was but wasn’t reaching any end.
Sure, I’ll bring it up on their discord server too.
I sincerely hope that you will encourage your lead Ardusub developer to assist me with this, I will be eternally grateful to you and this community.
And for the hacky replacement, I’ll surely do that the first thing tomorrow morning and I will let you know if it worked or not. And so you are also saying, that the Pixhawk (with Arudsub burnt on it) is able to detect the Bar02 pressure sensor? Like I don’t have to add any changes to the code regarding it’s detection itself?
I really request you and hope that you will help me resolve this issue. I will be grateful to you.

If you need fast turnaround support then it’s generally best to go via our support email (support@bluerobotics.com), although in this case you’re putting in a request for somebody to develop new functionality (rather than fixing something broken), which is never guaranteed to happen quickly / to some external timeline.

Is there a particular application you have in mind for this? The Bar02 operating depth is only 10m, which is insufficient for many ArduSub applications, and the higher resolution does not typically make a practical difference to operation compared to a Bar30 or Bar100.

Our Bar02 and Bar30 sensors both use variants of the MS5837 chip, which have the same I2C address and the same communication protocol - the only difference between the variants is how the pressure gets calculated, and the pressure range they work for. Currently if you connect a Bar02 then ArduSub will detect it but will treat it as a Bar30, which results in incorrect pressure and depth readings.

I have to use it in a ROV and AUV.
I contacted the support at the mentioned email and I made several requests, but they didn’t help me out, saying all developers are busy and saddened me.
Also, I would have definitely went for Bar30 pressure sensor, but I am out of budget, the complete price, including the shipping charges(I am from India), sum up to 8k in my currency, which is quite a lot. That is why I am going through this hassle.
And sorry, I didn’t update here on the forum whether your proposed solution worked or not. I will definitely do it as soon possible. Please bear with me.
Once again, I know you have a lot of people to attend to, and I really appreciate the time you are giving me. Thank you.

The following is my new function which I used in the library

void AP_Baro_MS56XX::_calculate_5837()
{
int32_t dT, TEMP;
int64_t OFF, SENS;
int32_t raw_pressure = _D1;
int32_t raw_temperature = _D2;

// int32_t dT = 0;
// int64_t SENS = 0;
// int64_t OFF = 0;
// int32_t SENSi = 0;
// int32_t OFFi = 0;
// int32_t Ti = 0;
// int64_t OFF2 = 0;
// int64_t SENS2 = 0;

// note that MS5837 has no compensation for temperatures below -15C in the datasheet

dT = raw_temperature - (((uint32_t)_cal_reg.c5) << 8);
TEMP = 2000 + ((int64_t)dT * (int64_t)_cal_reg.c6) / 8388608;
OFF = (int64_t)_cal_reg.c2 * (int64_t)131072 + ((int64_t)_cal_reg.c4 * (int64_t)dT) / (int64_t)64;
SENS = (int64_t)_cal_reg.c1 * (int64_t)65536 + ((int64_t)_cal_reg.c3 * (int64_t)dT) / (int64_t)128;

if (TEMP < 2000) {
    // second order temperature compensation when under 20 degrees C
    int32_t T2 = ((int64_t)11 * ((int64_t)dT * (int64_t)dT) / (int64_t)34359738368);
    int64_t aux = (TEMP - 2000) * (TEMP - 2000);
    int64_t OFF2 = 31 * aux / 8;
    int64_t SENS2 = 63 * aux / 32;

    TEMP = TEMP - T2;
    OFF = OFF - OFF2;
    SENS = SENS - SENS2;
}

int32_t pressure = ((int64_t)raw_pressure * SENS / (int64_t)2097152 - OFF) / (int64_t)32768;
pressure = pressure * 0.01f; // MS5837 only reports to 0.1 mbar
float temperature = TEMP * 0.1f;

_copy_to_frontend(_instance, (float)pressure, temperature);

}

QGroundControl is saying depth sensor is not connected


The sensor is not getting detected

I took reading from the same connections using Arduino and I am able to get the readings

Hey, can you please provide some help?

Sure, would you mind sharing all of your current branch/code?

Okay, I’ll upload it soon

Here is the code

I believe the missing part is this one, where the chip is identified by reading the prom

Hey, I uploaded it. You can take a look.

So sorry for not seeing it sooner. I got busy. Also I didn’t received any email that there has been a response. I really apologize for the delay.
How do I integrate this code into Ardusub?
I committed some changes in the repo, in the libraries/AP_Baro/AP_Baro_MS5611.cpp.
Can you please take a look?
I really request you if you could response swiftly. I am really really grateful to you.
Also, I think we need to provide a different PROM start address as given in line 32 or do we need to provide a different function for ms5837 like that at line 181?

Also, I think the crc_crc4 function used in line 260 in libraries/AP_Baro/AP_Baro_MS5611.cpp which is defined in libraries/AP_Math/crc.cpp is not working properly or we might have to change it.

Hey, I would be highly grateful to you if could respond. @williangalvani @EliotBR could you guys please assist me further?

Hey, @williangalvani and @EliotBR , I am hoping if you could please help me out?

Hi @Haadi

Sorry, I’ve been pretty busy. All I can say right now is that your code makes sense.
I would add some debug statements and compare the output of it with the output of the working bluerobotics library to narrow down where the issue is.

There’s some useful data and a crc calculation code in the datasheet.

Yeah, I compared the crc_crc4 function defined in crc.cpp and it’s completely same as the one in the datasheet, I think it’s issue with prom values only now.
And also, I apologise for the inconvenience caused to you by me, but I really need all the help that I can get, so I appreciate your time and efforts to help me out and request you to please help me resolve this issue completely.
Also, I think we seem to modify _read_prom_word function in line 181 in AP_Baro_MS5611.cpp.

@williangalvani and @EliotBR hey, it’s quite a few days, could you guys provide any help?:sweat_smile:I have been trying whatever I can but can’t get any success

@williangalvani I want to request you if you could please help me out.

Hi @Haadi,

I’m focusing on some things I want to get done by the end of the year, so I don’t have time to spare. I recommend you take it step by step.

One straight forward way of debugging it is to add a bunch of “printf()” through the code.

Check every part of the code:

  • if the sensor driver is getting loaded
  • if it is being identified as the correct sensor
  • the the PROM is getting read
  • if the CRC test passes
  • the result of your updated math