Debugging Environment (Windows)
There are many points of failure when attempting to run your Python code unrelated to your code. Below are some solutions to common problems.
Problem List
- PX4 won’t connect
- MavSDK won’t connect to PX4
- No module named ‘encodings’ when starting PX4 (Windows)
PX4 Won’t Connect
Most often, this means you forgot to start the Unreal Engine simluation. However, if this is not the case, it’s possible that PX4 is looking at the wrong TCP port.
To fix this:
- find the correct TCP port
- if you haven’t already, run
\scripts\run-servers.ps1
- in PX4’s console, locate the line
Waiting for simulator to accept connection on TCP port XXXX
- the port listed is what you need
- if you haven’t already, run
- open your
\scripts\airsim-settings.json
file in a text editor - replace the value of
Vehicles.PX4.TcpPort
with the port you discovered - save your changes, then run
\scripts\update_settings.bat
- this will update your AirSim settings for you (AirSim has, like, five places it looks for settings files, but this will always put it in the correct location)
- you may have to reopen your Unreal project for changes to take hold
Now, you should be all set!
MavSDK Server Won’t Connect to PX4
Hopefully, the default port provided in \scripts\server-config.json
, will be correct; however, if MavSDK won’t connect to PX4, then the port is likely incorrect.
To fix this:
- run
\scripts\run-servers.ps1
if you haven’t already - wait until PX4 is fully loaded
- you will have to start your Unreal Engine simulation with the
Play
button to ensure PX4 progresses far enough to accept a mavlink connection - if PX4 doesn’t connect to anything after starting the simulation, check the above section for a possible fix
- you will have to start your Unreal Engine simulation with the
- if MavSDK’s console output remains
Waiting to discover system on udp://:insert_port_here...
even after PX4 has connected to the simulation, you likely have the incorrect port. If it connects, then nothing is wrong! - locate the final occurrance of a message similar to
mode: Onboard, data rate: 4000 B/s on udp port 14280 remote port 14030
in PX4’s console output- the listed remote port is the one you need
- replace the value of
drone_port
in your\scripts\server-config.json
file with the remote port you found- if you do not have
\scripts\server-config.json
, then you must first run\scripts\setup.bat
- if you do not have
Now, you should be all good!
No module named ‘encodings’ when starting PX4 (Windows)
This error might be caused by window’s enviroment variables interfering with PX4’s virtual python enviroment.
To fix this:
- Search ‘enviroment variables’ in the window’s search.
- click Environment Variables…
- Delete PYTHONPATH and PYTHONHOME
Now, it should work!