Address already in use when try to connect MAVLink camera

Hi all, I am trying to communicate with mavlink camera on typhoon_h480 model by using pymavlink.

This is the mavlink camera configuration of h480:

<plugin name="CameraManagerPlugin" filename="libgazebo_camera_manager_plugin.so">
          <robotNamespace>typhoon_h480</robotNamespace>
          <interval>1</interval>
          <width>3840</width>
          <height>2160</height>
          <maximum_zoom>8.0</maximum_zoom>
          <video_uri>udp://127.0.0.1:5600</video_uri>
          <system_id>1</system_id>
          <cam_component_id>100</cam_component_id>
          <mavlink_cam_udp_port>14530</mavlink_cam_udp_port>
      </plugin>

This is my pymavlink code that try to connect the camera:

master = mavutil.mavlink_connection('udpin:127.0.0.1:14530', dialect="common")

But I failed to connect it and got the error:

Traceback (most recent call last):
  File "listen.py", line 23, in <module>
    master: mavutil.mavudp = mavutil.mavlink_connection('udpin:127.0.0.1:14530', dialect="common")
  File "/home/lobbeytan/.local/lib/python3.8/site-packages/pymavlink-2.4.37-py3.8.egg/pymavlink/mavutil.py", line 1757, in mavlink_connection
    return mavudp(device[6:], input=True, source_system=source_system, source_component=source_component, use_native=use_native, timeout=udp_timeout)
  File "/home/lobbeytan/.local/lib/python3.8/site-packages/pymavlink-2.4.37-py3.8.egg/pymavlink/mavutil.py", line 1061, in __init__
    self.port.bind((a[0], int(a[1])))
OSError: [Errno 98] Address already in use

Anyone know how to fix this error? Thanks in advanced

I think the UDP port 14530 might be how PX4 talks to the camera. So if you want to talk to the camera, you need to talk to the autopilot (PX4) via 14550 or 14540 but then talk to the component ID 100.

Thanks for the reply, I have tried to connect port 14540 and 14550 before, it able to connect and communicate with the drone via mavlink commands. I can listen to the mavlink packets. But when i try to use MAV_CMD_REQUEST_MESSAGE to get the camera information even have set the component ID to 100, still I received the ACK response but didn’t get the camera information.

Here is my implementation on trying to the camera information on Typhoon-H480 model:

import time
from pymavlink import mavutil
from pymavlink.dialects.v20 import common as mavlink

# Start a connection listening on a UDP port
master: mavutil.mavudp = mavutil.mavlink_connection('udpin:127.0.0.1:14540', dialect="common")

print("Connection started ...")

# wait_conn()
master.wait_heartbeat()
print("RECEIVE")

while (True):
    try:
        print("System_ID:", master.target_system, " Cam_ID:", mavlink.MAV_COMP_ID_CAMERA)

        master.mav.command_long_send(
            master.target_system,
            mavlink.MAV_COMP_ID_CAMERA,
            mavlink.MAV_CMD_REQUEST_MESSAGE,
            0,
            mavlink.MAVLINK_MSG_ID_CAMERA_INFORMATION,
            0, 0, 0, 0, 0, 0,
        )

        print(master.recv_match(type='CAMERA_INFORMATION').to_dict())
    except:
        pass

    time.sleep(1)

Ok, can you check mavlink status in the pxh> shell to check if forwarding is on between the different mavlink instances?

I have ran the mavlink status command, here is the result:

pxh> mavlink status

instance #0:
        mavlink chan: #0
        type:           GENERIC LINK OR RADIO
        flow control: OFF
        rates:
          tx: 17337.7 B/s
          txerr: 0.0 B/s
          tx rate mult: 1.000
          tx rate max: 4000000 B/s
          rx: 0.0 B/s
          rx loss: 0.0%
        FTP enabled: YES, TX enabled: YES
        mode: Normal
        Forwarding: On
        MAVLink version: 2
        transport protocol: UDP (18570, remote port: 14550)
        Broadcast enabled: NO

instance #1:
        mavlink chan: #1
        type:           GENERIC LINK OR RADIO
        flow control: OFF
        rates:
          tx: 27428.3 B/s
          txerr: 0.0 B/s
          tx rate mult: 1.000
          tx rate max: 4000000 B/s
          rx: 43.8 B/s
          rx loss: 3.1%
        Received Messages:
          sysid:255, compid:  0, Total: 80 (lost: 245)
        FTP enabled: YES, TX enabled: YES
        mode: Onboard
        Forwarding: On
        MAVLink version: 2
        transport protocol: UDP (14580, remote port: 14540)
        Broadcast enabled: NO
        partner IP: 127.0.0.1

instance #2:
        mavlink chan: #2
        type:           GENERIC LINK OR RADIO
        flow control: OFF
        rates:
          tx: 4180.3 B/s
          txerr: 0.0 B/s
          tx rate mult: 0.127
          tx rate max: 4000 B/s
          rx: 0.0 B/s
          rx loss: 0.0%
        FTP enabled: YES, TX enabled: YES
        mode: Onboard
        Forwarding: On
        MAVLink version: 2
        transport protocol: UDP (14280, remote port: 14030)
        Broadcast enabled: NO

instance #3:
        mavlink chan: #3
        type:           GENERIC LINK OR RADIO
        flow control: OFF
        rates:
          tx: 2399.4 B/s
          txerr: 0.0 B/s
          tx rate mult: 1.000
          tx rate max: 400000 B/s
          rx: 618.5 B/s
          rx loss: 0.0%
        Received Messages:
          sysid:  1, compid:154, Total: 1386 (lost: 0)
        FTP enabled: YES, TX enabled: YES
        mode: Gimbal
        Forwarding: Off
        MAVLink version: 2
        transport protocol: UDP (13030, remote port: 13280)
        Broadcast enabled: NO
        partner IP: 127.0.0.1

instance #4:
        mavlink chan: #4
        type:           GENERIC LINK OR RADIO
        flow control: OFF
        rates:
          tx: 4235.1 B/s
          txerr: 0.0 B/s
          tx rate mult: 0.127
          tx rate max: 4000 B/s
          rx: 0.0 B/s
          rx loss: 0.0%
        FTP enabled: YES, TX enabled: YES
        mode: Onboard
        Forwarding: On
        MAVLink version: 2
        transport protocol: UDP (14558, remote port: 14530)
        Broadcast enabled: YES

I didn’t find the mavlink_cam_udp_port 14530 in the list, which cause camera connection failed? What’s ur thoughts based on the mavlink status?

It looks like forwarding is on for all the mavlink instances (except the gimbal one), so that should not be the problem.

I think the problem might be that the MAV_CMD_REQUEST_MESSAGE command is not implemented by the Gazebo camera plugin.

Instead, you have to use the older/deprecated one: MAV_CMD_REQUEST_CAMERA_INFORMATION

See: