JonasVautherin / px4-gazebo-headless

An unofficial Ubuntu-based container building and running PX4 SITL (Software In The Loop) through gazebo.
Apache License 2.0
74 stars 42 forks source link

Broadcasting does not work with docker-compose #32

Closed elpiel closed 1 year ago

elpiel commented 1 year ago

Image version == 1.10.1

The key line this one which does not happen on newer versions of the image:

px4-gazebo-headless | MAV_BROADCAST: curr: 0 -> new: 1 After the broadcast is changed, mavsdk_server running in docker finds it and it works.

mavsdk-grpc-server     | [10:08:34|Info ] MAVSDK version: v1.4.4 (mavsdk_impl.cpp:20)
mavsdk-grpc-server     | [10:08:34|Info ] Waiting to discover system on udp://:14540... (connection_initiator.h:20)
mavsdk-grpc-server     | [10:08:37|Info ] New system on: 192.168.128.2:14580 (with sysid: 1) (udp_connection.cpp:192)
mavsdk-grpc-server     | [10:08:37|Debug] New: System ID: 1 Comp ID: 1 (mavsdk_impl.cpp:482)
mavsdk-grpc-server     | [10:08:37|Debug] Component Autopilot (1) added. (system_impl.cpp:377)
mavsdk-grpc-server     | [10:08:37|Debug] MAVLink: info: [logger] file: ./log/2022-08-09/10_08_37.ulg (system_impl.cpp:250)
...
px4-gazebo-headless    | INFO  [logger] Opened full log file: ./log/2022-08-09/10_08_37.ulg
px4-gazebo-headless    | INFO  [mavlink] MAVLink only on localhost (set param MAV_BROADCAST = 1 to enable network)
px4-gazebo-headless    | INFO  [mavlink] MAVLink only on localhost (set param MAV_BROADCAST = 1 to enable network)
px4-gazebo-headless    |   MAV_BROADCAST: curr: 0 -> new: 1
px4-gazebo-headless    | INFO  [mavlink] using network interface eth0, IP: 192.168.128.2
px4-gazebo-headless    | INFO  [mavlink] with netmask: 255.255.240.0
px4-gazebo-headless    | INFO  [mavlink] and broadcast IP: 192.168.143.255
px4-gazebo-headless    | INFO  [px4] Startup script returned successfully
px4-gazebo-headless    | pxh> INFO  [mavlink] using network interface eth0, IP: 192.168.128.2
px4-gazebo-headless    | INFO  [mavlink] with netmask: 255.255.240.0
px4-gazebo-headless    | INFO  [mavlink] and broadcast IP: 192.168.143.255
px4-gazebo-headless    | INFO  [ekf2] Mag sensor ID changed to 197388
px4-gazebo-headless    | INFO  [ecl/EKF] EKF aligned, (pressure height, IMU buf: 22, OBS buf: 14)
px4-gazebo-headless    | INFO  [ecl/EKF] 732000: EKF GPS checks passed (WGS-84 origin set)
mavsdk-grpc-server     | [10:08:38|Debug] Discovered 1 component(s) (system_impl.cpp:578)
mavsdk-grpc-server     | [10:08:38|Info ] System discovered (connection_initiator.h:63)
px4-gazebo-headless    | INFO  [mavlink] partner IP: 192.168.128.3
mavsdk-grpc-server     | [10:08:38|Info ] Server started (grpc_server.cpp:53)
mavsdk-grpc-server     | [10:08:38|Info ] Server set to listen on 0.0.0.0:4000 (grpc_server.cpp:54)
px4-gazebo-headless    | INFO  [ecl/EKF] 5200000: EKF commencing GPS fusion

Image version > 1.10.1

Using later versions > 1.10.1 this is the output I get with no arguments passed to the container:

px4-gazebo-headless    | INFO  [mavlink] partner IP: 127.0.0.1
px4-gazebo-headless    | INFO  [mavlink] mode: Onboard, data rate: 4000 B/s on udp port 14558 remote port 14530
px4-gazebo-headless    | INFO  [logger] logger started (mode=all)
px4-gazebo-headless    | INFO  [logger] Start file log (type: full)
px4-gazebo-headless    | INFO  [logger] [logger] ./log/2022-08-09/09_55_24.ulg  
px4-gazebo-headless    | INFO  [logger] Opened full log file: ./log/2022-08-09/09_55_24.ulg
px4-gazebo-headless    | INFO  [mavlink] MAVLink only on localhost (set param MAV_{i}_BROADCAST = 1 to enable network)
px4-gazebo-headless    | INFO  [mavlink] MAVLink only on localhost (set param MAV_{i}_BROADCAST = 1 to enable network)
px4-gazebo-headless    | INFO  [px4] Startup script returned successfully

I tried different solutions like:

Setting a custom network with static IPs:

    networks:
      internal-ip:
          ipv4_address: 172.20.0.6 # and 172.20.0.5 for px4-gazebo-headless
networks:
  internal-ip:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 172.20.0.0/24

Using the services name (for mavsdk server) - udp://px4-gazebo-headless:14540...

It does not find any system:

mavsdk-grpc-server     | [09:32:08|Info ] MAVSDK version: v1.4.4 (mavsdk_impl.cpp:20)
mavsdk-grpc-server     | [09:32:08|Info ] Waiting to discover system on udp://px4-gazebo-headless:14540... (connection_initiator.h:20)
mavsdk-grpc-server     | [09:32:08|Debug] Initializing connection to remote system... (mavsdk_impl.cpp:480)

I'm passing Environment variables:

    environment:
      MAV_BROADCAST: 1
      MAV_0_BROADCAST: 1
      MAV_1_BROADCAST: 1

but still nothing

elpiel commented 1 year ago

Ok, this gives me a headache. When I don't pass any parameters to mavsdk_server (it uses udp://:14540 by default) and although mavlink says: px4-gazebo-headless | 14540 will be associated to 172.20.0.6 ( -v typhoon_h480 172.20.0.6 )

somehow the system is found on 172.20.0.5:14580. In a nutshell: You have to use a custom subnet and assign static IPs for mavsdk & mavlink (and pass that IP to the entrypoint script) otherwise the system is not found.

I also tried (but mavsdk_server still does not find it):

mavsdk-grpc-server     | [10:05:12|Info ] MAVSDK version: v1.4.4 (mavsdk_impl.cpp:20)
mavsdk-grpc-server     | [10:05:12|Info ] Waiting to discover system on udp://:14540... (connection_initiator.h:20)
mavsdk-grpc-server     | [10:05:12|Info ] New system on: 172.20.0.5:14580 (with sysid: 1) (udp_connection.cpp:192)
mavsdk-grpc-server     | [10:05:12|Debug] New: System ID: 1 Comp ID: 1 (mavsdk_impl.cpp:482)
mavsdk-grpc-server     | [10:05:12|Debug] Component Autopilot (1) added. (system_impl.cpp:377)
mavsdk-grpc-server     | [10:05:12|Debug] Component Gimbal (154) added. (system_impl.cpp:377)
mavsdk-grpc-server     | [10:05:13|Debug] Discovered 2 component(s) (system_impl.cpp:578)
mavsdk-grpc-server     | [10:05:13|Info ] System discovered (connection_initiator.h:63)
mavsdk-grpc-server     | [10:05:13|Info ] Server started (grpc_server.cpp:53)

This docker-compose setup now works:

https://github.com/AeroRust/mav/blob/658bbbe934a99c17616d4dded2a6c0030d456ba3/docker-compose.yml

I'm not sure why it's not finding the system anymore directly even though the port is published on the host.