Closed loop autopilot simulation with FlightGear - Part 1

I don't have the cash right now to buy a plane, ArduIMU, an auto pilot, and associated hardware. So, while I'm saving for the hardware, I want to play with the various algorithms out there in a simulation environment - to gain a deeper understanding and feel for it. I want to be able to code in C, so I can use the code directly in the hardware autopilot when I reach that point.

I want to use a flight dynamics model to generate sensor inputs to the autopilot (3 axis gyro, 3 axis accelerometer, GPS - just like ArduIMU), and have the autopilot generate control surface inputs to the simulated plane in the flight dynamics model.

Phase 1: Open loop. Tuning/experimenting with the AHRS algorithm. This would not require the flight dynamics model to accept control surface input from the autopilot. I would load the simulation and fly an airplane around in some pattern. The FDM would generate and log the sensor readings and the "ground truth" pitch-roll-yaw angles. My AHRS code would read in the sensor log, compute the pitch-roll-yaw angles, and would allow me to compare it with the "ground truth" data generated by the FDM.

Phase 2: Close the loop. Use the autopilot to accept sensor inputs from the FDM, and send back control surface inputs.

Right now I'm concentrating on Phase 1. Has this been done before? I've looked around a bit and it seems that FlightGear is well suited for this type of hackery. Are these properties the ones I should use to generate the correct sensor data, emulating an ArduIMU? How can I get the values I need out of FlightGear (I read that a UDP socket is used?).

*Gyro sensors*


*ground truth data to be logged and compared with my own AHRS output*

How does everyone here test their algorithms before sending it up in the air? Anyone else run their autopilot code in a closed loop with a flight dynamics model? If not, I wouldn't mind putting in some extra effort to make this interface nice/easy-to-use so that it can be used by the community out of the box for autopilot testing.

Thanks in advance!

Views: 1249

Comment by Hugo Vincent on October 26, 2009 at 2:54am
Looks like you're on the right track.

Don't forget to add noise, drift (random walk), and saturation/clipping to your angular rate and acceleration data coming out of the simulator, otherwise getting your AHRS algorithm working is too easy (just integrate rate data, that's it).
Comment by Faisal Shah on October 26, 2009 at 8:04am
Yes, most certainly. I have not included adding noise to the sensor data - and it will surely be added. As a first step, I just wanted to be able to record data, and have a closed loop simulation. Now that I am able to close the control loop with FlightGear ( , I can focus on the finer details of having realistic sensor data, testing AHRS algorithm, navigation, etc ....
Comment by Tiago Antunes on June 28, 2013 at 12:02pm

Hi guys,

I would like know how capture the image (Screenshot) of simulator with command line --jpg-httpd=port. Somebody know help me ??


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

Join DIY Drones


Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service