How to execute example sketch using SITL on Linux

I am trying to understand Copter code and started with advise listed here http://ardupilot.org/dev/docs/learning-ardupilot-the-example-sketches.html

I would like to try the code in SITL which is up and running fine on my linux machine. I can load waypoints and the copter flies etc.

On the above linked page, I followed

./waf configure --board=sitl
./waf build --target examples/INS_generic --upload

I have started sim_vehicle.py in another window.

Does the --upload flag above have any result here? The example expects that I am building for px4.

I tried to execute INS_Generic binary on the console with

./build/sitl/examples/INS_generic -M quad

But that leads to segmentation fault.

Is there a way I can run example code on sitl?

1 Like

I now built example code for navio2 board which I have and it all runs fine there. So the question is can I somehow run the code on SITL? That would make experimentation much faster.

1 Like

The SITL environment provided by sim_vehicle.py is only designed to be used by a full ardupilot build. It doesn’t work with the examples.

The example sketches provided in Library Example Sketches — Dev documentation might work with SITL, but you would need to write up the scripts yourself. Those scripts are designed to be run directly on the hardware (Pixhawk, Navio, etc).

Interestingly, there’s no segmentation fault if you run it with a plane model. If you are able to connect it to a simulation backend, you might be able to get it working.

I’m actually interested in this as well. When you say you need to write up the scripts you’re talking about correctly starting up the simulator and connecting the example sketch to the appropriate ports?

Hi Miguel,

Yes. As Stephen said, sim_vehicle.py is designed to run the full simulation, not the examples - so you need to start them on your own.
Also, the examples are made to be run on real boards, but it is possible they’ll run with SITL too.

@sachinkundu once this PR (https://github.com/ArduPilot/ardupilot/pull/6345) gets merged you should be able to run the example code on SITL. Hope that helps! :slight_smile: