Retrieving sonar data through pymavlink

Hello Blue Robotics

We are trying to retrieve sonar data through pymavlink, we have the blue robotics sonar Ping Sonar Echosounder for Underwater Distance Measurement and we have connected it using the I2C port on the navigator board which we have mounted on top of a raspberry pi connected to our laptop through ethernet.

We are able to retrieve the IMU data from the navigator board through pymavlink using the following code

from pymavlink import mavutil

# Connect to the autopilot system
connection = mavutil.mavlink_connection('udp:0.0.0.0:14550')

# Request the ATTITUDE message
connection.mav.request_data_stream_send(
    connection.target_system, connection.target_component,
    mavutil.mavlink.MAV_DATA_STREAM_ALL,
    40, 1)

# Wait for the ATTITUDE message


while True:
    msg = connection.recv_match(type='ATTITUDE', blocking=True)
    if msg is not None:

        roll = msg.roll
        pitch = msg.pitch
        yaw = msg.yaw

How do we access the sonar data?

Thanks in advance

Hi @Alstrup,

Our Ping Sonar does not communicate using I2C, so this won’t work. You’ll need to either connect it using one of the serial ports, or connect it to the Raspberry Pi using a serial to USB adaptor (like our BLUART).

Which data are you after?

  • If you only want the distance estimates (and don’t care about changing settings or using Ping Viewer) then you should be able to use a direct serial connection with some appropriate parameters set in the firmware
    • In this case the distances may be accessible via either DISTANCE_SENSOR or NAMED_VALUE_FLOAT messages
    • This approach connects the sonar directly to the autopilot firmware, and BlueOS will not know about it
  • If you want more direct control over the sonar’s settings and/or want to use Ping Viewer then you’ll need to either allow it to pass through from the serial port or connect it via USB
    • This can still allow distance measurements to be provided over MAVLink by turning on the “MAVLink Distances” option on the Ping Sonar Devices page
      • This requires BlueOS 1.1, which currently only has beta releases available, so updating to it needs Pirate Mode to be enabled
    • If you want ping profiles or settings access from your code then you’ll need to use our Ping Python library to talk to the sonar, rather than using pymavlink