# QGroundControl in parallel with Python Script using SITL Environment

**URL:** <https://discuss.bluerobotics.com/t/qgroundcontrol-in-parallel-with-python-script-using-sitl-environment/15059>\
**Category:** Blue Robotics Software\
**Tags:** pymavlink, sitl, simulate\
**Created:** [September 12, 2023, 4:07pm UTC](https://discuss.bluerobotics.com/t/qgroundcontrol-in-parallel-with-python-script-using-sitl-environment/15059 "2023-09-12T16:07:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amhussey](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Amhussey](https://discuss.bluerobotics.com/u/Amhussey)\
**Post date:** [September 12, 2023, 4:07pm UTC](https://discuss.bluerobotics.com/t/qgroundcontrol-in-parallel-with-python-script-using-sitl-environment/15059/1 "2023-09-12T16:07:54Z")

</div>

I am currently trying to run QGroundControl and a python script at the same time to send basic commands to a SITL environment of the ArduSub simulation. My SITL is currently running on my desktop using WSL2 on Ubuntu version 22.04. To start the SITL I follow the recommended guide commands:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/2/2693a48705cd9ad0f6f97e37090a039a1bd033a1.png)  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/e/efb8209c26a74df6d4efc92cdb8fc53a10a5242b.png)  
and I am able to connect with both QGroundControl and python just not at the same time. Checking the outputs on the MAVProxy command window shows 2 outputs:  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/7/726001b79f262470da2f11f712ca6fe2ac97c789.png)  
I want to send commands through the 14551 port so I adjusted the vehicle\_sim.py code line to read:

```auto
sim_vehicle.py -L RATBeach --out=udp:0.0.0.0:14550 --out=udp:0.0.0.0:14551 --map --console

```

which does add the extra output port on the MAVProxy. Then running a heartbeat python test on this line it does not return anything and is stuck at the line 9 as seen below:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/7/731f579903daa7c1487cd463198817ed7431028d.png)  
I thought to resolve this would be simply to add a comm link in QGroundControl and to connect with it but that didn’t work:  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/1/1b4c7c97e5a7222663ca46fc3eb64016c7f376a0.png)

I feel I am very close to resolving this issue but would like some quick assistance to get QGroundControl and python working in parallel. Can anyone explain the misunderstanding that I am having and point me towards getting my system communicating.

---

<div class="post-metadata">

**Author:** ![clyde](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/clyde/32/8563_2.png) [@clyde](https://discuss.bluerobotics.com/u/clyde)\
**Post date:** [September 12, 2023, 7:21pm UTC](https://discuss.bluerobotics.com/t/qgroundcontrol-in-parallel-with-python-script-using-sitl-environment/15059/2 "2023-09-12T19:21:54Z")

</div>

The older `udp:` prefix is a shortcut for the newer `udpin:` prefix, which sets up a server connection.

The option `--out=udp:0.0.0.0:14551` actually means: _Create a socket, bind it to port 14551 on all interfaces, and wait for messages to arrive._

Since your Python script is also using `udpin:` they are both acting as servers waiting for messages to arrive.

Try this option on SITL: `--out=udpout:127.0.0.1:14551`

---

<div class="post-metadata">

**Author:** ![Amhussey](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Amhussey](https://discuss.bluerobotics.com/u/Amhussey)\
**Post date:** [September 12, 2023, 8:20pm UTC](https://discuss.bluerobotics.com/t/qgroundcontrol-in-parallel-with-python-script-using-sitl-environment/15059/4 "2023-09-12T20:20:44Z")

</div>

Thanks for the reply Clyde!  
So by making both receivers (udpin/udp) they will never receive the heartbeat on that port - changing one to a transmitter (udpout) will send the heartbeat.

I made a connection to 127.0.0.1:14551 in QGroundControl and the heartbeat can now be seen in python. My python script returns system 0 and component 0 - I expected system 1 and component 0. Why is there a difference?

---

<div class="post-metadata">

**Author:** ![clyde](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/clyde/32/8563_2.png) [@clyde](https://discuss.bluerobotics.com/u/clyde)\
**Post date:** [September 12, 2023, 9:33pm UTC](https://discuss.bluerobotics.com/t/qgroundcontrol-in-parallel-with-python-script-using-sitl-environment/15059/5 "2023-09-12T21:33:20Z")

</div>

It looks like you are trying to find the _source_ of the `HEARTBEAT` message – for that you’ll need to get a reference to the message object. (`the_connection` is a reference to the connection object, not the message object.)

Try something like this:

```auto
from pymavlink import mavutil

conn = mavutil.mavlink_connection('udpin:0.0.0.0:14551')

heartbeats = {}

while True:
    # Wait for the next heartbeat
    message = conn.recv_match(type=['HEARTBEAT'], blocking=True)
    source_system = message.get_srcSystem()
    source_component = message.get_srcComponent()
    key = f'source_system={source_system}, source_component={source_component}'
    timestamp = getattr(message, '_timestamp', 0.0)
    if key not in heartbeats:
        print(f'Component found: {key}')
    heartbeats[key] = timestamp

```

---

<div class="post-metadata">

**Author:** ![Amhussey](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Amhussey](https://discuss.bluerobotics.com/u/Amhussey)\
**Post date:** [September 14, 2023, 6:03pm UTC](https://discuss.bluerobotics.com/t/qgroundcontrol-in-parallel-with-python-script-using-sitl-environment/15059/6 "2023-09-14T18:03:43Z")

</div>

Not exactly what I am trying to achieve - although thanks for that code I will keep it for later reference. I would like to **control an ROV using python scripts while having my QGroundControl open** at the same time. At the moment I am able to send commands to the SITL ROV using 0.0.0.0:14550 when QGC is closed, but when open it will not because 14550 is used by QGC. My python scripts are very basic at the moment so I can learn in steps and at the end I will make a more complex file later on.

When I added your suggest of _–out=udpout:127.0.0.1:14551_ I was still not able to arm my ROV using:

 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/4/4fac93469db9874833a96bde364cda326d5a868d.png)  
the code will run until it try’s to validate the connection through the heartbeat but will not progress past that. My next question would be why did creating the output port on 14551 not show a heartbeat? Is it the way running the sim\_vehicle.py initializes the MAVProxy GCS when we run the code:  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/9/95c68c13106924f318b2faf1cb7898c125856bc9.png)

Thanks for taking the time to assist with this I do appreciate it.

---

<div class="post-metadata">

**Author:** ![cbusse1](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cbusse1](https://discuss.bluerobotics.com/u/cbusse1)\
**Post date:** [September 17, 2023, 12:35am UTC](https://discuss.bluerobotics.com/t/qgroundcontrol-in-parallel-with-python-script-using-sitl-environment/15059/7 "2023-09-17T00:35:28Z")

</div>

Did you try using `udpin:0:0:0:0:14551` in your python script?

Also, I experienced some issues (with UDP connection, laggy git operations, slow compilation) when trying to run SITL using WSL2. If you want to continue making this work on WSL2 you want to read this: [Accessing network applications with WSL | Microsoft Learn](https://learn.microsoft.com/en-us/windows/wsl/networking)

However, you may also try switching back to WSL 1.

First display the name of your installed WSL Ubuntu version:

```auto
wsl --list --verbose

```

Then:

```auto

wsl --set-version <your-ubuntu-name> 1

```

---

<div class="post-metadata">

**Author:** ![Amhussey](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Amhussey](https://discuss.bluerobotics.com/u/Amhussey)\
**Post date:** [September 19, 2023, 4:45pm UTC](https://discuss.bluerobotics.com/t/qgroundcontrol-in-parallel-with-python-script-using-sitl-environment/15059/8 "2023-09-19T16:45:21Z")

</div>

I originally did try with that _udpin:0.0.0.0:14551_ but it would still wait for the heartbeat in _.wait\_hearbeat()_ and not progress. I am going to try to establish the connection and send the arm command without the .wait\_heartbeat and see if I can arm the SITL environment.

Thanks for that article I’ll be sure to read up on it. Maybe WSL2 is the issue I am having and swapping back to WSL1 will be better for testing purposes. If there are any more suggestions from anyone please do post, I’ll try them out and update the post for anyone else starting out.
