APM hardware-in-the-loop simulation on non-windows system (mac, linux)

Hi guys,

This is not really a post about something new but rather a summary of steps others did before me and a little help to my personal memory (already forgot once how it works). The post is referring to ArduPlane but I don't see what would be different for ArduCopter. Would also like to say thanks to the developers here :-)

The problem: you want to get a HIL simulation running without windows (i.e., on a Mac or linux system) using the latest APM git repo code and QGroundcontrol as the GCS.

Outline of one possible solution:

  1. Install dependencies: ArduPlane (git version), QGroundcontrol 0.9.0, FlightGear V2.4.0, python 2.7, pyserial-2.5, MAVProxy (git version), pymavlink (git version), arduino-0022 and cmake 2.8.6 for building and uploading APM code straight from console
  2. Copy MAVLink.xml to FlighGear protocol directory (for Mac OS: /Applications/FlightGear.app/Contents/Resources/data/Protocol/ )
  3. Start MAVProxy: python2.7 mavproxy.py --master=/dev/tty.usbserial-A600dLKS --fgout=localhost:5010 --fgin=localhost:5000 --out=localhost:14550
  4. Start FlighGear with parameters: --generic=socket,out,40,localhost,5000,udp,MAVLink --generic=socket,in,45,localhost,5010,udp,MAVLink
  5. Start QGroundcontrol
  6. Enjoy :)

More detailed info on dependencies and configuration:


  1. git clone https://code.google.com/p/ardupilot-mega/
  2. cd ardupilot-mega/ArduPlane
  3. Modify APM_Config.h:  "#define HIL_MODE            HIL_MODE_ATTITUDE"
                                          "#define HIL_PORT            0"
  4. cd ..
  5. Follow instructions in README.txt for building and uploading code (essentially, assuming arduino1280: mkdir build && cd build && cmake .. && make ArduPlane-upload )

B) MAVProxy and pymavlink: (note: should be in the same directory(?)):

  1. mkdir APMHIL
  2. git clone git://git.samba.org/tridge/UAV/pymavlink.git
  3. git clone git://git.samba.org/tridge/UAV/MAVProxy.git

C) Setting stuff up (modify paths according to your installation paths):

  1. export PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7:/Users/andre/pyserial/lib/python2.7/site-packages
  2. export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH

D) Trouble shooting:

For my EasyStar I had to fix rudder control to 0 and invert the direction of elevator control. This is easily done by the two modifications inside mavproxy.py:

status.rc_elevator = (-1.0) * scale_rc(m.servo2_raw, -1.0, 1.0, param='RC2')
status.rc_rudder   = 0.0;

Also: every time one starts FlightGear one needs to start the engine manually by pressing 'S', which is annoying :)

Views: 5274

Comment by Anish on November 2, 2011 at 3:00pm
Awesome post...

Comment by Michael Oborne on November 2, 2011 at 4:13pm

andre did you try the planner? i just tested it this morning, and seems to run fine.

Comment by Andrew Tridgell on November 2, 2011 at 4:28pm

Hi Andre, thanks for writing this up, much appreciated!

A couple of comments:

 - for ArduCopter, the main differences are that you need to specify the --quadcopter option to mavproxy, plus you need to startup hil_quad.py (which is a little python quadcopter simulator)

 - instead of editing mavproxy for rudder/elevator, you should just set the right settings in your transmitter and in the APM parameters. It sounds like you need to set RC2_REV to -1 (just do "param set RC2_REV -1), plus set SWITCH_ENABLE to 0. For zero rudder, just set KFF_RDDRMIX to zero. This matches what you would do for a real plane

Would you like to add this tut to the manual? I'm sure Chris would be happy to give you editing access to add something like this.

Cheers, Tridge


Comment by Randy on November 2, 2011 at 6:25pm

..and there's also a hardware-in-the-loop simulator for the traditional helicopter now as well!


The wikipage is here.

Comment by Michael Pursifull on November 2, 2011 at 8:08pm

I realize you are running MP under ubuntu (via mono, I presume) I experimented with it under mac... it was a mess (mono, not mp) and decided to clean it off my system. Personally, I like Qgroundcontrol, if only for its ability to handle multiple UAVs at the same time. And for having a native mac client. I really, really dislike using windows, and loading mono on my mac is not much better. 

Comment by Michael Pursifull on November 2, 2011 at 8:40pm

no one should understand me wrong; if you know how much I dislike windows, then you'll better understand that I must also like Mission Planner, since it is the singular reason I use Windows at all, at any time, ever.

Comment by Andre S on November 3, 2011 at 12:08am

@all: Thanks for the comments. In no way I wanted to start up the old OS debate. It's just that I actually have no access to windows (but also don't want to have) and also have used linux as my OS of choice in the last 10 years or so (Mac more recently).

@Michael: When I started this I didn't know that it may be possible to run MP via mono, but reading up on the posts of Mike and others it's a mess, so I'm happy that the mavlink folks came up with this python proxy thing.

@Andrew: Thanks for the config hints. I was sure that hacking the script would not be the clean way to go :-) Should mention that my EasyStar does not have the aileron mods, meaning it's 3 channel and I connected the servos as instructed by the manual. Should still check whether there is a cleaner way to set things up on the proxy. I saw that mavproxy respects the reverse-channel options but at the time I was still using the dip switches and had not played around with the sotware-reverse channel options. Yes, I'd be happy to write a page to the wiki about that if someone gives me write access.

Comment by Andrew Tridgell on November 3, 2011 at 4:54am

@andre, I think what Michael meant was that you can run the planner on Linux, by using mono on the windows .exe. It works really quite well and I use it to do things like create missions where a GUI is useful. For HIL I do prefer mavproxy myself though, as I'm one of those strange people that likes command line tools :-)

Regarding the easystar, sorry for my misunderstanding on that, I haven't tried a plane with no ailerons before. I guess that ArduPlane treats it the same as one with ailerons, and you just need a non-zero KFF_RDDRMIX so that it will try to use the rudder to control roll. What model are you using in flightgear to simulate the easystar? I didn't know it had a non-aileron R/C model available. If it doesn't have one, maybe if you ask James Gobbert he could make a model for you? (he's rather good with fg models). I think James may have done an Easystar with ailerons fg model before.

Cheers, Tridge


Comment by Andrew Tridgell on November 3, 2011 at 4:57am

oops, should have read all the comments, you know its mono on linux. When I first heard that MP worked with mono I presumed what Michael meant was trying to build MP using mono on Linux, which I then tried and found it a mess. Then Michael pointed out that I can just run the existing .exe, and I was surprised when it worked.

It's still better to use mavproxy of course :-)



Comment by Michael Pursifull on November 3, 2011 at 5:26am

@Andre S: Or, if you are willing to give it a try, you can have an EasyStar in X-plane (with or without ailerons, or however else you want it) See http://diydrones.com/forum/topics/x-plane-arduplane-bixler-easystar... and let me know how you prefer it...


You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2020   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service