Page 1 of 5

AQ Simulator (HILS) info/discussion

PostPosted: Tue Apr 26, 2016 5:47 am
by Max
This thread is meant for information and discussion about the new AQ hardware-in-the-loop simulator (HILS) functionality. Please feel free to post any questions, issues, or requests here. I will update this post and thread with new information as it becomes available.

  • Early-BETA quality, mostly working but with some performance consistency issues remaining, more widespread testing needed.
  • Limited UI and user-adjustable settings, most simulator parameters can only be changed in the code itself (but that is not required).
  • Limited documentation so far.


What can you simulate with it
Basically anything that AQ can do in the real world can also be done in the HILS virtual world. Everything from manual flight in any mode, to full autonomous missions. The simulated world maps to a location in the real one, so all GPS positioning works as one would expect (you can see the current location and plans missions using QGC or the AQ Android app). There is also a simulated gimbal which can be controlled via AQ like a real one.

The virtual world and vehicle currently can model the following attributes:
  • Geographic location and altitude (Lat., Lon., height above MSL).
  • Earth magnetic field (inclination and declination adjustable to match geographic location).
  • Wind with adjustable base speed/direction (in 3-D) and variance level (how much speed/direction fluctuate over time). Wind will push the vehicle around acting as an external disturbance, and the speed also has an effect on rotor lift capacity.
  • Correct barometric pressure at any altitude.
  • Standard Earth gravity.
  • Vehicle size, mass, drag, moments of inertia, & center of gravity.
  • Rotor position, thrust, torque, spin-up speed. Up to 8 rotors (or other control surfaces) can be used.
  • Vehicle sensors: ACC, GYO, MAG, pressure, GPS. Some artificial sensor noise is introduced into the outputs.
  • 2-D Gimbal with remote roll and pitch control. A gimbal camera view is available, with adjustable zoom to roughly simulate actual camera FoV.

Some current limitations of the virtual world (to be addressed):
  • Air turbulence is not modeled (eg. no ground-effect). The wind model in general is fairly primitive.
  • Sensor noise is static, eg. ACC/GYO/MAG noise will not change with rotor speed as it would in a real MR.
  • Similarly, GPS is always accurate with no way to simulate poor reception, etc.
  • The world is flat. Terrain elevation not modeled yet, though there are "hooks" in place to allow it.
  • There are no objects/obstacles, or collision detection (except with the flat ground).

How it works (architecture)
HILS essentially acts as an external IMU and GPS receiver, temporarily replacing the on-board ones while it is active. Switching between the on-board sensors and simulated sensors can be done at run-time, meaning the same firmware can be used for both actual and simulated flying. This allows full testing of nearly all firmware features in a simulated environment, using the exact same binary (compiled code) as would be used in actual flight. This last point is important especially in embedded systems development, as subtle memory use and code optimization differences can occur between different build configurations.

Code status & license
  • Software (jMAVSim) -- open source, written in Java (
  • AQ Firmware (integration) -- open source, all changes to AQ GPL code published April 14, 2016 ( ... mmits/simu)
  • HILS Firmware module (functionality) -- closed-source HILSim library from Maxim Paperno/World Design Group (info page under construction).
  • HILSim License (summary) -- free for all personal non-commercial use. Binary version of the library (for use in your own firmware builds) is available on request. All other use, including, but not limited to, professional, commercial, educational, or governmental, require a separate license agreement.

My current plan is that all future public firmware releases from me will include the HILS functionality. I may revise that decision if I feel my terms are being abused (or for whatever other reason). In the meantime, I hope this tool is as useful and fun for you as it is for me. This will greatly improve future AQ development and testing. In fact the new acro/rate mode features I recently introduces probably wouldn't have happened without the sim.


Known issue: unstable position hold and other nav functions.

PostPosted: Tue Apr 26, 2016 7:29 am
by Max
I'm going to attempt to transfer some of the things we've learned so far in alpha testing with several participants.

First, the most likely problems are going to be the same as one may have setting up a real AQ -- the motor mix is wrong, bad IMU filp/rotate settings, magnetic inclination/declination are off, wrong/missing Quatos license key... that sort of thing. Most of these settings are provided for you in the configuration file (linked in the full instructions), but there is still room for error. Check and re-check the onboard parameters before assuming something is wrong with the sim itself.

Once basic takeoff and controlled flight have been accomplished, the next common problems seem, in general, related to performance of the computer jMAVSim is running on. From what we've determined so far, especially important seem to be the USB components. More specifically, what else is using the USB at the same time seems to make a big difference. Also possibly the underlying hardware (USB chipset) drivers can make a difference.

Symptoms related to this topic include:
  • Poor position-hold -- usually a "toilet bowl" effect, often spiraling out and getting worse, possibly resulting in crash.
  • Inaccurate navigation -- unable to hit waypoints quickly, poor path following (not straight lines), irregular orbits (in orbit-type wpt).
  • Accelerometer drift -- after flying for a little while in manual mode, AQ looses proper "level" orientation and will want to tilt in some direction w/out any control inputs. This may correct itself after some time, or get worse and result in control loss entirely. (This is only apparent in angle-control mode, not rate/acro modes.)

Some possible fixes to try:
  • Exit unnecessary software applications and terminate any background processes you don't absolutely need.
  • Remove as many other attached USB peripherals as possible.
    • For example an SD card reader attached to the same USB hub as the M4 was found to cause the exact problems described above.
  • Do not use a USB hub for the AQ connection -- go direct to computer.
  • Use a short, good-quality, thick USB cable. If you still have one around with a ferrite bead, use it.
  • Check with your computer/motherboard vendor for updated USB chipset drivers. In some cases it may be better to go directly to the site of the manufacturer of the USB chipset (eg. Intel) and get the latest drivers from there.
    • For example my Asus motherboard has an Intel USB3 chipset on it, but the drivers found on the Asus support site are outdated and do not work well at all (devices not recognized, etc). Installing updated drivers directly from Intel solved many issues.
  • The two main jMAVSim options which can affect performance in the latest releases (v160412.1+) are:

    • -r <Hz> - This is the rate at which the simulated world gets updated. This should mostly affect CPU load on PC. Default is 400Hz. If the computer has trouble keeping up (eg. low frame rates), try lowering this setting to, for example, 200 Hz ("-r 200").
    • -rs <Hz> - This is the rate at which the simulated IMU readings are sent to AQ. This can directly affect stability/precision of AQ control. Default is 400Hz. Increasing this to 600 or 800 Hz may considerably improve stability. (This is basically like "oversampling" the IMU inputs which can provide a steadier average.)
  • Adding -no-gimbal to the startup options will improve performance on the PC side.

This is not necessarily an exhaustive list, and we're still trying to determine all factors which may affect the critical timing between the simulation software and the AQ hardware. It is quite likely that several factors may be involved, perhaps something no one has identified yet.

I'm attaching a couple of examples of an orbit-type waypoint showing the difference between a well-working system and one that had timing problems (thanks Angel (afernan)!). We're not entirely sure what made the difference, but some computer updates were preformed after the "bad" example, and now the same system performs quite well. This was run on an 5th-gen Core i5-based Intel NUC mini-PC.

All ideas, testing, and findings are welcome.


Example of orbit waypoint with poor tracking.
orbit-bad.JPG (36.38 KiB) Viewed 6909 times

Example of orbit waypoint with good tracking. From same system as the "bad" example but after some system updates.
orbit-good.JPG (24.85 KiB) Viewed 6909 times

Re: AQ Simulator (HILS) info/discussion

PostPosted: Tue Apr 26, 2016 8:57 am
by funth1ngs
Hi Max,

can you please upload a waypoint file with an orbit example.

My tests either results in a flyaway or in some strange kind of orbiting with a very large radius of which the orbit waypoint is not the center. I have aqfc-mp-v7.1.1919-hwv8.6-quatos-hils installed.


Re: AQ Simulator (HILS) info/discussion

PostPosted: Tue Apr 26, 2016 9:40 am
by Max
Hi Heiko,

Maybe Angel can upload his (those are his screenshots)... I'm not having any luck either, it just wants to fly away to somewhere else entirely. I think there's an issue with sending the waypoint data to AQ -- I'm not sure if Angel is using the same QGC version... I'm on 1.7 B3... you? I also need to revert to the published firmware and try that... I've been messing with the nav stuff (as you know). Other mission waypoint types seem to be working though. At least if you're on 1919 then I know it's not something I just broke. :)


Re: AQ Simulator (HILS) info/discussion

PostPosted: Tue Apr 26, 2016 10:32 am
by funth1ngs
Hi Max,

I'm also using 1.7 B3, but as I see from Angels screenshot on github, he's still on 1.7 B2.1.

I'll try that one later.


Re: AQ Simulator (HILS) info/discussion

PostPosted: Tue Apr 26, 2016 7:03 pm
by afernan
I´m using "aqfc-mp-v7.1.2603-hwv8.3-quatos-hils" (the first Max send me). My PC it´s an INTEL NUC-i5 (intel serie 5), W10-64Bits.

@Heiko, attached a couple of missions (orbit, wp´s) that works well for me.

Short video showing basic use:


Re: AQ Simulator (HILS) info/discussion

PostPosted: Tue Apr 26, 2016 7:48 pm
by afernan
I´ve verified my USB driver, and it looks it´s the basic Microsoft. It works even thru a USB HUB

Re: AQ Simulator (HILS) info/discussion

PostPosted: Tue Apr 26, 2016 8:04 pm
by Max
Hi Angel,

First of all, nice video! Nice demo of the basics and a quick mission. I'll have to investigate what happened with the orbit waypoint between your version and the latest ones. Could you try one of the "official" firmware releases from the FTP site? I'm not sure if the difference is in the firmware or QGC... I can't find where it would have broken recently in either of those.

As for the drivers, the attached image shows the hardware-level drivers I'm talking about (or an example from my system, anyway). The dialog is showing the base driver for Intel's USB3 controller, which manages all drivers for the Intel entries seen in the controller list of the screenshot. You can see I also have an entirely separate USB chipset on the same motherboard (ASMeida), one on an Asus USB3.1 PCI card, and a few generic USB2/3 hubs (one in my keyboard, a couple on a media card reader, etc).

The usbser.sys is a generic serial driver and I've peronally yet to encounter any special problems with it. It does get updated with Windows sometimes.


Re: AQ Simulator (HILS) info/discussion

PostPosted: Tue Apr 26, 2016 9:45 pm
by funth1ngs

@Angel: Thx for the waypoints, orbit is not working here.

I also tested with QGC 1.7 B2.1, still no luck.

It looks like it's something wrong with the firmware.


Re: AQ Simulator (HILS) info/discussion

PostPosted: Wed Apr 27, 2016 12:19 pm
by Max
The orbit wpt. problem is only with PID attitude controller -- works for me with Quatos in several firmware versions, but not with PID. Trying to track down the problem, not clear at this point which fw. versions are affected.