I’m not confident enough in my English to describe this issue clearly on my own, so I used AI to help me organize and phrase this post. The technical details, tests, and observations below are my own.
I’m running a BlueROV2 ROV simulation using ArduSub SITL, Gazebo Harmonic (v8.9.0), and the ardupilot_gazebo plugin.
I’m having an issue where the depth/barometer data is not being updated in the flight controller. The vehicle physically dives in the Gazebo GUI, but ArduSub EKF3 remains frozen at the initial home altitude (583.91 m) and reports EKF3 IMU0 is using GPS. In addition, SCALED_PRESSURE.press_abs is stuck at an invalid negative value (-57,621 hPa).
Here’s what I’ve tried so far:
I added a standard <air_pressure> sensor inside the <link> of my vehicle model’s model.sdf.
I verified that Gazebo is publishing the pressure topic.
I captured the UDP traffic on port 9002 using tcpdump. The JSON messages sent from Gazebo to SITL only contain timestamp, imu, position, quaternion, and velocity. There is no baro or pressure field at all.
I cloned the latest ardupilot_gazebo repository (main branch) and ran a global search in the src/ directory:
Am I correct in concluding that the current ardupilot_gazebo plugin does not natively implement subscription and JSON bridging for the <air_pressure> sensor?
If it does not, what is the recommended way to simulate underwater depth/barometer data for ArduSub SITL in Gazebo Harmonic? Should I manually calculate the pressure (P = P_atm + ρgh) inside ArduPilotPlugin.cc and inject it into the JSON via writer.Key("baro"), or is there a better approach?
Any guidance from the developers or community would be greatly appreciated. Thank you!
Correct. The JSON message sent from Gazebo to AdruPilot SITL does not populate a field for air pressure sensor data.
If it does not, what is the recommended way to simulate underwater depth/barometer data for ArduSub SITL in Gazebo Harmonic? Should I manually calculate the pressure (P = P_atm + ρgh) inside ArduPilotPlugin.cc and inject it into the JSON via writer.Key("baro"), or is there a better approach?
I’ve been meaning to write a library to manage this more generally so the mappings can be configured in YAML with a plugin structure that allows it to be extended for different physics simulations. Modifying the example provided should be enough to get something working for a one-off though. We’ve used the same approach to provide servo position and force feedback from Gazebo to SITL and it works well. Provided there is a suitable DroneCAN message available, and its supported in ArduPilot, this is a workable approach.
Just wanted to share a quick update on how I got this working for now. Before jumping into the DroneCAN route, I actually implemented a quick-and-dirty workaround directly in the ArduPilot SITL source to get my depth data running:
1. Fixed the barometer negative depth crash and unit error
In libraries/AP_Baro/AP_Baro_SITL.cpp, I added a negative depth clamp and fixed the unit conversion for SimpleUnderWaterAtmosphere (it expects kilometers, not meters):
2. Intercepted the raw Gazebo Z-axis depth data
Since SITL internally does an altitude conversion, I bypassed it at the JSON parsing level to capture the raw downward NED Z-axis depth:
In libraries/SITL/SITL.h, added to struct sitl_fdm: float json_depth = 0.0f;
In libraries/SITL/SIM_JSON.cpp, in recv_fdm() after parsing position: sitl->state.json_depth = position.z;
It works well enough for my current RL testing, but I totally see why DroneCAN is the right long-term approach. It’s much cleaner and hardware-consistent. I’ll definitely look into setting up the DroneCAN bridge next, and I’m really looking forward to your YAML-based general library!
Thanks again for the pointers, really appreciate it.
Just wanted to share a quick update on how I got this working for now. Before jumping into the DroneCAN route, I actually implemented a quick-and-dirty workaround directly in the ArduPilot SITL source to get my depth data running:
1. Fixed the barometer negative depth crash and unit error
In libraries/AP_Baro/AP_Baro_SITL.cpp, I added a negative depth clamp and fixed the unit conversion for SimpleUnderWaterAtmosphere (it expects kilometers, not meters):
2. Intercepted the raw Gazebo Z-axis depth data
Since SITL internally does an altitude conversion, I bypassed it at the JSON parsing level to capture the raw downward NED Z-axis depth:
In libraries/SITL/SITL.h, added to struct sitl_fdm: float json_depth = 0.0f;
In libraries/SITL/SIM_JSON.cpp, in recv_fdm() after parsing position: sitl->state.json_depth = position.z;
It works well enough for my current RL testing, but I totally see why DroneCAN is the right long-term approach. It’s much cleaner and hardware-consistent. I’ll definitely look into setting up the DroneCAN bridge next, and I’m really looking forward to your YAML-based general library!
Thanks again for the pointers, really appreciate it.