I am running the sitl simulation with iris drone. I notice the drone is publishing gazebo topic /gazebo/default/iris/link/sonar. However, it is not publishing any ros topic.
In general, how do I make a gazebo plugin located in /PX4-Autopilot/Tools/sitl_gazebo/src to publish ros topic? Do I need to use mavros?
This uORB topic gets subscribed by the PX4 module mavlink: PX4-Autopilot/DISTANCE_SENSOR.hpp at master · PX4/PX4-Autopilot · GitHub which sends the MAVLink message DISTANCE_SENSOR to all MAVLink channels. Just to be safe, you can check whether DISTANCE_SENSOR is included in all channels by typing in the PX4 shell: mavlink status streams.
If you connect with QGroundControl to the simulation (usually on UDP port 14550), do you receive the DISTANCE_SENSOR in Analyze > MAVLink inspector?
What is the result for rosparam get /mavros/distance_sensor? Make sure that the orientation (e.g. PITCH_270 for downwards) matches the orientation within the MAVLink message (compare step 4). See mavros/Enumerations - ROS Wiki
As a result, you should get published messages on the topic /mavros/distance_sensor
This might seem a bit too complex for such a simple thing as publishing the sonar topic. However, on a real drone you most likely would have a similar setup where the sonar sensors are connected to your autopilot directly. All the mentioned steps would work the same (except for 1-2 which are SITL-related)
Thanks you very much for the solution.
If running on a real drone, I can subscribe the distance_sensor topic:
/mavros/distance_sensor/hrlv_ez4_pub
However,
If running on a simulated drone (such as typhoon_h480), there is error like the below picture