Set-Up: SITL with MATLAB Physics Backend


I’m trying get the SITL environment working, but ran into some issues when trying to use my own model, which is implmented in MATLAB/Simulink. For now I’m trying to get the example from the official doc to work, but no luck so far.

If I start the provided MATLAB script and run

sudo ./Tools/autotest/ -v ArduCopter -f json:<IP_ADRESS> --console

inside the WSL a VsXsrc X Server window opens and displays

Set parameter SIM_SPEEDUP to 1.000000
Vehicle model (json:<IP_ADRESS>) not found

VSCode Terminal Output:

SIM_VEHICLE: Run ArduCopter
SIM_VEHICLE: "<...>/ardupilot/Tools/autotest/" "ArduCopter" "/home/oskar/ardupilot/build/sitl/bin/arducopter" "-S" "-I0" "--model" "json:" "--speedup" "1"
SIM_VEHICLE: "" "--master" "tcp:" "--sitl" "" "--out" "" "--out" "" "--console"
RiTW: Starting ArduCopter : /home/oskar/ardupilot/build/sitl/bin/arducopter -S -I0 --model json:<IP_ADRESS> --speedup 1
Connect tcp: source_system=255
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
[Errno 111] Connection refused sleeping
Failed to connect to tcp: : [Errno 111] Connection refused
SIM_VEHICLE: MAVProxy exited
SIM_VEHICLE: Killing tasks

Set-Up: Win10, MATLAB R2021a, VisualStudio Code + WSL, ArduCopter 4.0.7.
Running the SITL with MavProxy and connecting to Mission Planner works fine.

Any ideas?

What version of WSL (1 or 2)? What version of ArduCopter? I had better luck when starting the physics first and then SITL.

I always start the physics backend first and then launch the ArduPilot SITL.
I’m using WSL 1. I’ll try upgrading to Version 2 and see if that works.

WSL1 should work fine, I suspect your problem is ArduCopter 4.0.7 try on latest.

That solved it. Thank you very much @iampete !

I have a little follow up question for all the STIL experts here. Let me give you a little context first: I built an Eletric Ducted Fan UAV (“SingleCoper” Frame), got it flying pretty well and built a model in MATLAB, which I am now trying to validate against real flight data.

  1. Method: feed Servo (RCOut) data to the MATLAB model and compare simulated IMU and attitude data against the actual one.
  2. Method: feed recorded desired Angles/Rates/Throttle (RCIn) data to the SITL (Ardupilot Controller + MATLAB model) and, again, compare the simulated against the real data.

I already tried the first method and it yielded good results, however doing trying to validate a model like that is probelmatic on many levels, which is why I’m currently working on making the second method work.

  • How would one preferably set this up (high level)? At the moment I’m running the ardupilot SITL and the physics backend in MATLAB/Simulink. However to my knownledge there’s no way to automatically feed the RCIn/Desired Attitude/Throttle values to the SITL. Can this be done? Preferably also via MATLAB using the JSON Interface.

No way to do this currently, you would have to add something.

Yeah i’d love to contribute something. As far as I can tell you did a lot of work in that department. Would you be interested in collaborating? If so, is there any way to get in touch?

Hi Oskar,

Best place is the simulation channel over on the developer discord,

We would love some more vehicle examples.