APM SITL with FlightGear and Ubuntu

I have ArduPilot Mega Software-In-The-Loop almost working in 64-bit Ubuntu 12.04. Only problem is that there seems to be a lack of MAVLink packet communication. Can anyone help me out?

 

Following is how I set up the simulation software. I hope this will serve as a tutorial once I get past that final problem.

 

  1. Open a terminal console window.
  2. Make a new folder for simulation software and enter the directory:

    mkdir sitl
    cd sitl

  3. Install prerequisites, if missing:

    sudo apt-get install git python-serial g++ autoconf libtool automake gawk

  4. Download MAVProxy, mavlink, JSBSim and APM:

    git clone git://github.com/tridge/MAVProxy.git
    git clone git://github.com/tridge/mavlink.git
    git clone git://github.com/tridge/jsbsim.git
    git clone https://code.google.com/p/ardupilot-mega/

  5. Build and install JSBSim:

    cd jsbsim
    ./autogen.sh
    ./configure --enable-libraries --enable-shared --prefix=/opt/jsbsim
    make
    sudo make install
    cd ..

  6. Build ArduPlane and ArduCopter binaries and copy them from temporary folder:

    cd ardupilot-mega/ArduPlane
    make -f ../libraries/Desktop/Makefile.desktop
    cd ../..
    cp /tmp/ArduPlane.build/ArduPlane.elf .
    cd ardupilot-mega/ArduCopter
    make -f ../libraries/Desktop/Makefile.desktop
    cd ../..
    cp /tmp/ArduCopter.build/ArduPlane.elf .

  7. Install flightgear:

    sudo apt-get install flightgear

Now, because JSBSim did not install it's binaries in the system folders when I ran "make install", I have to make sure that the binaries can be found by simulation scripts. As a temporary hack, I added the following folder to the $PATH variable: "~/sitl/uav/sitl/jsbsim/src". This is where the compiled but uninstalled JSBSim executable is located.

 

I tried to run the simulation, following this tutorial. Opening four separate terminal tabs, I launched these executables, in order.

  1. First terminal:

    cd sitl/ardupilot-mega/Tools/autotest
    ./fg_plane_view.sh

  2. Second:

    cd sitl
    ./ArduPlane.elf

  3. Third:

    cd sitl/MAVProxy
    ./mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501

  4. Fourth:

    cd sitl/ardupilot-mega/Tools/autotest/jsbsim
    ./runsim.py --home=-35.362938,149.165085,584,270 --script=jsbsim/rascal_test.xml --fgout=127.0.0.1:5503

Note that if you execute "./fg_plane_view.sh" last, then FlightGear gets stuck at loading scenery.

 

This is where I ran into problems. The simulation is not moving. In addition, I discovered that the MAVProxy output is too clean -- it has only ASCII text, no binary MAVLink data. The expected output is described here.

What am I missing?

Edit: It seems that things are working. If I type "auto" into the MAVProxy, as Daniel suggested, the plane starts to fly (and crashes into ground in a minute or two). Still, I see no binary data in MAVProxy output, but this may be a feature.

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Hi Rasmus,

    Thanks for your Tutorial, Are you still supporting SITL ? I am referring to this tutorial SITL ArduPlane and having some issues with connecting it to X-Plane.

    • Hi Anand,

      Unfortunalely, I am not currently working on flying systems anymore and because of that I do not have the time to keep up to speed on either SITL or Ardupilot in general.

      • Thanks Rasmus for your reply. Any other discussion you remembered, where SITL is in active discussion now ? I was working towards my Masters research and your thread helped me a lot in getting SITL started but I was hoping to get some more help from the forum.

        • I do not keep an eye on any SITL discussions other than this. Are the official instructions not working? Check out
          http://plane.ardupilot.com/wiki/common-sitl-software-in-the-loop-si...
          and
          http://plane.ardupilot.com/wiki/common-simulation/

          • I faced lot of errors while setting up and I got it working once (and Thank god I saved it to a harddrive with working SITL setup, which I couldn't setup on again due to JSBSim path error, anyway it's working now) with this tutorial

            http://dev.ardupilot.com/wiki/setting-up-sitl-on-windows/

            But I wanted to learn more about running custom missions, adding your custom way-point files etc and also I wanted to know is X-Plane good to go with this SITL setup or Flight gear is preferred as I saw a lot of FG fdm mentioned in the code. 

            • It seems like you have the perfect opportunity to give back to the community by finding out these answers and writing a tutorial or two.

              X-Plane vs Flightgear is probably a never-ending discussion where no one is right or wrong, but if you want to know something as specific as adding custom way-point files, then if documentation is lacking, your best source of information might be the source code. This is, in my opinion, the best thing about open source software. If you were facing a proprietary software with lacking or out-of-date documentation, you would have a much harder time.

              • Thanks Rasmus,

                I am still working on running some simulations with study wind effects. 

                I got to enter my custom way-points and add winds but still working on connecting it to FlightGear or XPLane.  

  • Hi all,

    I’m new to this forum, and just starting out with ArduPilot and UAVs, and I’m also pretty new to using Linux so please forgive me if I’m asking obvious questions.

    I’ve been trying to get SITL running on a Linux VM for about a week now. I’ve worked my way through most of the tutorials on setting up SITL but I don’t seem to be having much luck, however I have made the most progress with this one :)

    I’m getting to the final step of this tutorial and encountering an error running runsim.py, I’ve included the steps I’ve taken below.

    If anyone could offer up any suggestions as to what I’m doing wrong it would be greatly appreciated.

    Thanks in advance!

    ------------------------------

    I’m running Ubuntu 12.04 LTS in VMWare Fusion 6 and this is the installation procedure I have followed so far:

    A1. Open a terminal console window.

    A2. Make a new folder for simulation software and enter the directory:

              cd ~/

              mkdir sitl

              cd sitl

    A3. Install prerequisites, if missing:

              sudo apt-get install git python-serial g++ autoconf libtool automake gawk libexpat1 libexpat1-dev

    A4. Download MAVProxy, mavlink, JSBSim and APM:

              git clone git://github.com/tridge/MAVProxy.git

              git clone git://github.com/tridge/mavlink.git

              git clone git://github.com/tridge/jsbsim.git

              git clone https://code.google.com/p/ardupilot-mega/

              git clone git://github.com/diydrones/ardupilot.git

    A5. Build and install JSBSim:

              cd jsbsim

              ./autogen.sh

             ./configure --enable-libraries --enable-shared --prefix=/opt/jsbsim

             make

              sudo make install

              cd ..

    A6. Build ArduPlane and ArduCopter binaries and copy them from temporary folder:

              cd ardupilot-mega/ArduPlane
              make -f ../libraries/Desktop/Makefile.desktop
              cd ../..
              cp /tmp/ArduPlane.build/ArduPlane.elf .
              cd ardupilot-mega/ArduCopter
              make -f ../libraries/Desktop/Makefile.desktop
              cd ../..
              cp /tmp/ArduCopter.build/ArduPlane.elf . 

              cd ~/sitl/adrupilot/ArduPlane

              make configure

              make sitl

              cd ~/sitl

              cp /tmp/ArduPlane.build/ArduPlane.elf .

    A7. Install flightgear:

              sudo apt-get install flightgear

    Opening four separate terminal tabs, I launched these executables, in order.

    B1. First terminal:

              cd sitl/ardupilot-mega/Tools/autotest

              ./fg_plane_view.sh

    B2. Second:

              cd sitl
              ./ArduPlane.elf

    B3. Third:

              cd sitl/MAVProxy

    Uncomment line 17 of mavproxy.py (to “allow running without installing”)

    Copy entire contents of mavlink folder into MAVProxy folder (before I did this there was an error of the mavproxy.py script not fining a file used in line 2165)

              ./mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501

    B4. Fourth:

    Reading comments about JSBSim not installing it's binaries in the system folders when I ran "make install", I added the following folder to the $PATH variable: "~/sitl/jsbsim/src".

              PATH=~/sitl/jsbsim/src:$PATH

              export PATH

     

              cd sitl/ardupilot/Tools/autotest/jsbsim

              ./runsim.py --home=-35.362938,149.165085,584,270 --script=jsbsim/rascal_test.xml --fgout=127.0.0.1:5503

     

    This last step produces the following error:

    jamiepaton@ubuntu:~/sitl/ardupilot/Tools/autotest/jsbsim$ ./runsim.py --home=-35.362938,149.165085,584,270 --script=jsbsim/rascal_test.xml --fgout=127.0.0.1:5503

    Traceback (most recent call last):

                 File "./runsim.py", line 10, in <module>

                   from pymavlink import fgFDM

    ImportError: No module named pymavlink

     

    I have tried adding the following lines (which I found from another tutorial somewhere too) to the .bashrc file in my home directory, and then retrying step B4.

              export PATH=$PATH:$HOME/ardupilot/Tools/autotest

              export PATH=$PATH:$HOME/MAVProxy

              export PATH=$PATH:$HOME/mavlink/pymavlink/examples

              export PATH=$PATH:$HOME/jsbsim/src

              export PATH=/usr/lib/ccache:$PATH

    And then reloaded the PATH:

              . ~/.bashrc

    But this didn't seem to make any change to the error.

    So if anyone has any suggestions I'd appreciate it :)

  • I have pulled git yesterday and built ArduPlane for SITL. Followed instructions at http://dev.ardupilot.com/software-in-the-loop-sitl/ and it all started up like a charm in my VirtualBox guest machine. Can even connect with MP from my Windows host (to 5762).

    BUT - the plane is rollng from side to side, is pitching up and down both about 45 degrees, there is a "bad gyro health" message and there is no GPS fix. This was after the param load step at the bottom of the manual.

    Anyone? Did I miss something?

  • Hi,

    I am trying to run the SITL simulation and I have been following the tutorials till this step:

    >./runsim.py xxx

    it shows error messages:

    Traceback (most recent call last):
      File "./runsim.py", line 10, in <module>
        import util, fgFDM, atexit, fdpexpect
    ImportError: No module named fgFDM

    I have installed Flightgear by doing: sudo apt-get install flightgear.  So now I am really confused: where can I get the fgFDM module?

    ps: I have done this already:

    PATH=~/AutoPilot/jsbsim-master/src:$PATH

    export PATH

This reply was deleted.

Activity