0

When running sim_vehicle, Ubuntu 22.04, WSL2, Win10, all seems to work, except the connection to MAVLINK/MAVproxy. The map appears, the Mavlink window etc., but writing commands: mode guided etc. don't reach the vehicle. WSL has strange IP addresses and networking, the IPs use to change, I guess something is wrong there, but I can't fix it yet.

sim_vehicle.py -v ArduCopter -f gazebo-iris --model JSON --map --console

MAV> Connection reset or closed by peer on TCP socket
Attempting reconnect
[Errno 111] Connection refused sleeping

    SIM_VEHICLE: Using defaults from (default_params/copter.parm,default_params/gazebo-iris.parm)
    SIM_VEHICLE: Run ArduCopter
    SIM_VEHICLE: "/home/tosh/ardupilot/Tools/autotest/run_in_terminal_window.sh" "ArduCopter" "/home/tosh/ardupilot/build/sitl/bin/arducopter" "-S" "--model" "JSON" "--speedup" "1" "--slave" "0" "--defaults" "default_params/copter.parm,default_params/gazebo-iris.parm" "--sim-address=127.0.0.1" "-I0"
    RiTW: Starting ArduCopter : /home/tosh/ardupilot/build/sitl/bin/arducopter -S --model JSON --speedup 1 --slave 0 --defaults default_params/copter.parm,default_params/gazebo-iris.parm --sim-address=127.0.0.1 -I0
    SIM_VEHICLE: Run MavProxy
    SIM_VEHICLE: "mavproxy.py" "--out" "172.27.208.1:14550" "--master" "tcp:127.0.0.1:5760" "--sitl" "127.0.0.1:5501" "--map" "--console"
    Connect tcp:127.0.0.1:5760 source_system=255
    [Errno 111] Connection refused sleeping
    Loaded module console
    Loaded module map
    Log Directory:
    Telemetry log: mav.tlog
    Waiting for heartbeat from tcp:127.0.0.1:5760
    MAV> SIM_VEHICLE: Keyboard Interrupt received ...
    SIM_VEHICLE: Killing tasks
    Connection reset or closed by peer on TCP socket
    Attempting reconnect

While the ifconfig is:

 ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.27.219.35  netmask 255.255.240.0  broadcast 172.27.223.255
        inet6 fe80::215:5dff:fe09:b1c7  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:09:b1:c7  txqueuelen 1000  (Ethernet)
        RX packets 2053  bytes 1209800 (1.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1818  bytes 243494 (243.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 509  bytes 35673 (35.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 509  bytes 35673 (35.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.27.208.1
nameserver 8.8.8.8

WSL generates that strange 172.27.208.1 as a DNS, I added the Google DNS otherwise it doesn't "see" domains.

SIM_VEHICLE: "mavproxy.py" "--out" "172.27.208.1:14550" "--master" "tcp:127.0.0.1:5760" "--sitl" "127.0.0.1:5501" "--map" "--console"

This seems to use that wrong address, but it doesn't read it from the file as changing the order of the IPs doesn't change the behavior.

sudo cat /etc/hosts
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1       localhost
127.0.1.1       DESKTOP-LQSDBBS.        DESKTOP-LQSDBBS

192.168.0.100   host.docker.internal
192.168.0.100   gateway.docker.internal
127.0.0.1       kubernetes.docker.internal

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

I can find the address 172.27.208.0"" below (fib_trie): but I don't know how to continue. Another strategy is to try to "hack" sim_vehicle.py, I just glanced it so far.

Can anyone hint me?

Thanks.

 sudo cat  /proc/net/fib_trie
Main:
  +-- 0.0.0.0/0 3 0 5
     |-- 0.0.0.0
        /0 universe UNICAST
     +-- 127.0.0.0/8 2 0 2
        +-- 127.0.0.0/31 1 0 0
           |-- 127.0.0.0
              /8 host LOCAL
           |-- 127.0.0.1
              /32 host LOCAL
        |-- 127.255.255.255
           /32 link BROADCAST
     +-- 172.27.208.0/20 2 0 1
        |-- 172.27.208.0
           /20 link UNICAST
        |-- 172.27.219.35
           /32 host LOCAL
        |-- 172.27.223.255
           /32 link BROADCAST
Local:
  +-- 0.0.0.0/0 3 0 5
     |-- 0.0.0.0
        /0 universe UNICAST
     +-- 127.0.0.0/8 2 0 2
        +-- 127.0.0.0/31 1 0 0
           |-- 127.0.0.0
              /8 host LOCAL
           |-- 127.0.0.1
              /32 host LOCAL
        |-- 127.255.255.255
           /32 link BROADCAST
     +-- 172.27.208.0/20 2 0 1
        |-- 172.27.208.0
           /20 link UNICAST
        |-- 172.27.219.35
           /32 host LOCAL
        |-- 172.27.223.255
           /32 link BROADCAST

UPDATE: I found where the IP comes from in sim_vehicle, there's a function which takes it from wsl for that purpose. Changing it to either the ifconfig IP or to 127.0.0.1 doesn't help. The IP in the output of a colleague on pure Linux is 127.0.0.1. Either way that's seems to be the "-out" address, so maybe it's not the reason anyway.

-iris.parm --sim-address=127.0.0.1 -I0
###DEBUG###
wsl2_host_ip:172.27.208.1
###CHANGED TO:###
:127.0.0.1
SIM_VEHICLE: Run MavProxy
SIM_VEHICLE: "mavproxy.py" "--out" "127.0.0.1:14550" "--master" "tcp:127.0.0.1:5760" "--sitl" "127.0.0.1:5501" "--map" "--console"
Connect tcp:127.0.0.1:5760 source_system=255
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping


def wsl2_host_ip():
if not under_wsl2():
    return None

pipe = subprocess.Popen("ip route show default | awk '{print $3}'",
                        shell=True,
                        stdout=subprocess.PIPE)
output_lines = pipe.stdout.read().decode('utf-8').strip(' \r\n')
ret = pipe.wait()

if ret != 0:
    # Command exited with an error. The output it generated probably isn't what we're expecting
    return None

if not output_lines:
    # No output detected, maybe there's no nameserver or WSL2 has some abnormal firewalls/network settings?
    return None
    
print("###DEBUG###\nwsl2_host_ip:"+output_lines)
#output_lines = "172.27.219.35"
output_lines = "127.0.0.1"
print("###CHANGED TO:###\n:"+output_lines)
return str(output_lines)
enter code here

enter image description here

enter image description here enter image description here enter image description here

Twenkid
  • 825
  • 7
  • 15

1 Answers1

0

Success! The problem wasn't in the IP. Sometimes there were some issues with setting the env.vars correctly, not running a simulation, but the main simple thing seems to be that just the gz sim should be running before the sim_vehicle.py...

You must have a successfully running something like:

gz sim -v4 -r --render-engine ogre iris_runway.sdf

or even gz sim -v4 -r --render-engine ogre shapes.sdf

If there are some "unsolvable" problems with the environment variables, specifying the paths explicitly should work.

When it does, there is a connection with the Mavproxy/mavlink console and the drone receives commands etc. The connection interrupts if the gz sim is closed, but then it recovers if a simulation is started again. As of the communication going, it seems the simulation could be any e.g. shapes.sdf. (That's just for testing purposes.)

SIM_VEHICLE: Run MavProxy
SIM_VEHICLE: "mavproxy.py" "--out" "172.27.208.1:14550" "--master" "tcp:127.0.0.1:5760" "--sitl" "127.0.0.1:5501" "--map" "--console"
Connect tcp:127.0.0.1:5760 source_system=255
Loaded module console
Loaded module map
Log Directory:
Telemetry log: mav.tlog
Waiting for heartbeat from tcp:127.0.0.1:5760
MAV> Detected vehicle 1:1 on link 0
STABILIZE> Received 1353 parameters (ftp)
Saved 1353 parameters to mav.parm

enter image description here

Twenkid
  • 825
  • 7
  • 15