Closed loop Simulation with X-Plane and ArduPilot

Well I'm back in the basement tinkering after a brief hiatus. After a couple in-air resets of the Ardupilot, I decided that I really wanted to do some simulation before commiting anything into the air again. I think the resets (and crashes) were caused by running out of RAM on the Arduino, but at least now I can give code changes a thorough shakedown before flight.

My workplace does avionics integration for real aircraft, and in most of our labs we use X-Plane and Labview to do simulation testing of aircraft avionics systems. We already have a set of VI's developed that handle all of the UDP communication between Labview and X-Plane.

I borrowed these VIs from work and wrote an interface to take the flight variables and pass them to and from the ArduPilot. I finally got everything working and my ArduPilot spent yesterday evening flying the X-Plane Cessna 172 around Ottawa.

One neat feature (I think) is how I'm getting the servo commands back into X-Plane. I built a 2-servo pitch/roll tray. On the tray I mounted my ArduIMU. The Ardupilot drives the two servos which causes the tray to pitch/roll. The ArduIMU senses this motion and sends its Euler angles back to the Labview computer. The labview computer decodes the ArduIMU pitch and Roll and sends these values over to X-Plane as Joystick positions. A couple of advantages of this method over simply outputting servo commands from the Ardupilot Serial port are:


- I'm testing the whole system (including the PWM signal code and the mux chip).
- I can fly the X-Plane aircraft in manual mode using my transmitter (more realistic, and makes a good way of positioning the aircraft for testing.)
- It's cool to see this little robot arm shift around while the aircraft flies along the flight plan.

I'll post a little video clip of the system in action later tonight.

Here are the details of my closed-loop path.

1. The computer running X-plane sends the aircraft position data (lat/long/alt/pitch/roll/heading) over the LAN to the Labview PC.
2. The Labview PC takes the X-Plane data, formats per the ArduIMU binary message protocol and sends it out the Serial port to the ArduPilot.
3. Ardupilot is set to GPS Protocol 3 (IMU) and listens to the serial data from labview thinking it's from an ArduIMU and does it's autopilot work.
4. The Channel 1 and 2 servo output from ArduPilot is connected to the little tilt table I built.
5. On the tilt table, the ArduIMU outputs Euler Angle Data (Pitch/Roll). I'm using a Sparkfun XBee USB explorer (without the XBEE) to translate the serial output from the ArduIMU back into USB format.
6. Labview reads the Pitch/Roll Data in, formats this data as a joystick position, and sends it to X-Plane.
7. Go back to step 1.

As you can see in the pictures, I am also powering the ArduPilot and ArduIMU from the computer's USB ports. This seems to work well, and I don't have to keep an eye on the voltage of a lipo pack during testing.

I can share the labview VI's I personally created for this little project. (Basically they create the simulated ArduIMU output, and read the ArduPilot and ArduIMU telemetry), however, the VIs that do the communication with X-Plane, while not complicated are not something I can give away (I like my job too much ;) )

The picture at the top of this post is the Local Map screenshot from X-Plane after completing a flightplan consisting of 15 waypoints.

Below are a couple pictures of my setup.

Views: 4068

Comment by Tom Yochum on July 16, 2010 at 2:12pm
Very nice! I especially like the tilt mechanism!
I might have to look into X-Plane. I have been trying to get data in and out of Flightgear and it's not cooperating.
Keep us posted on your progress.
Comment by David Ankers on July 16, 2010 at 2:47pm
Very nice! This makes testing much easier doesn't it, you can catch things on the ground before they cause crashes in real life.

In what way is it not cooperating Tom? I know there is some issues with version 2 in this regard, at least last time I looked, might want to have a look at the OpenPilot Wiki for the correct version and how we do it:

http://wiki.openpilot.org/HITL_Simulation

We have been doing this a while and also support IL2 as well.

What's the situation with Xplane, I know their native UDP is forever changing and they recommend to use a plugin, so I take it you are using a plugin for Xplane to output the data to Labview?

Great work.
Comment by Tom Yochum on July 16, 2010 at 3:38pm
David,

Funny you should mention OP. I have been looking for answers to my issues there already.
I am trying to get Flightgear and SciLab to talk together. I have prototype flight plan and lateral navigation code in SciLab I am trying to test. I get the two programs to start talking to each other, but the servo commands are from SciLab are delayed approx. 2 seconds. I have tried both version 1.9 and 2.0 with no success. If you have any ideas I would love to hear them.

Tom
Comment by hopslink on July 16, 2010 at 4:03pm
Great work Tom!

Tom Y, can you tell if the delay is in the SciLab or Flightgear side? And are you using a TCP or UDP link?
Comment by Curt Olson on July 16, 2010 at 5:07pm
I can't think of a reason why FlightGear would delay processing incoming packets. Definitely go with UDP style sockets if you aren't already doing that.
Comment by Tom Hastie on July 16, 2010 at 8:18pm
Here's some video of the simulator in action:

http://www.youtube.com/watch?v=aTlJF7A1kJc

Developer
Comment by Jason Short on July 17, 2010 at 12:24am
I finally started getting data out of Xplane into Perl. I'm going to make an Ardupilot - Perl - Xplane simulator that should be running completely in software. No extra hardware or soldering required. Can anyone tell me how to do the IO in X plane? I just spent an hour guessing at the Network IO panels before I found out how to set the outgoing UDP port. I can't seem to find the incoming port. Not very user friendly.
Comment by hopslink on July 17, 2010 at 1:56am
"X-Plane actually binds two ports - 49000 and 49001. It uses 49000 only to receive data, and 49001 only to send data (this is the difference from previous versions - it used to use 49000 to transmit and receive). These are hard coded into X-Plane, and there's no option to change them."

for X-Plane 9, from here.
Comment by Roy Brewer on July 18, 2010 at 2:04pm
Tom Y

What are your plans for the scilab - flightgear interface? I assume since both tools are "free", that your tool will be made available as well (once this delay is resolved)

- Roy
Comment by Tom Yochum on July 19, 2010 at 8:47am
I don't want to hijack Tom's thread, so I am going to create a forum discussion to answer some of your questions.

Comment

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

Join DIY Drones

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service