-
Notifications
You must be signed in to change notification settings - Fork 2
Xplane
http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/Xplane.png
It's easy to create a powerful "hardware in the loop" simulator with APM, with a Flight Simulator "fooling" APM with sensor and GPS data like it would experience in flight, and then APM flying the plane accordingly.
The overall setup looks like this:
http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/X-Plain-Sim.jpg
- Purchase the X-Plane flight simulator, which is just $29. You can also download a free demo that runs for 10 minutes.
- Load the Xplane Simulations version of the APM software with the Mission Planner (the green plane in the screen below).
- If you haven't done a setup already, press "APM Setup" on the Mission Planner Firmware page, which opens another dialog. Follow the instructions on the "Reset", "Radio Input" and "Mode" tabs of the dialog. Then you're ready to sim!
http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/missionplannerfirmware.PNG
Alternatively, you can upload the code via Arduino, as described here. If you do that, you will need to change your APM_config.h file to the following:
#define HIL_PROTOCOL HIL_PROTOCOL_MAVLINK
#define HIL_MODE HIL_MODE_ATTITUDE
#define HIL_PORT 0
#define GCS_PROTOCOL GCS_PROTOCOL_MAVLINK
#define GCS_PORT 3
The Mission Planner will serve as your bridge to X-plane and will send the output from your APM's serial port connection to the flight simulator. Instructions on using it are here.
NOTE: CLI mode (and the slider switch) is disabled when you are in simulation mode. Please do all your setup via the Mission Planner Configuration tab instead.
wiki:comment If you're using a Mac, you can use a Perl-based solution (this also works on Windows, if you prefer Perl). Here's what you need:
Here is the Perl file: X-Plane.pl </wiki:comment>
X-Plane communicates over a network interface to the Flight Planner. Because of this you can run X-Plane and the Flight Planner on different computers. This is helpful if X-Plane running on a slower computer. Frame rate is very impotent.
These are the screen shots that show the necessary settings you need to set in the Settings Menu – Data Input and Output:
http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/Xplane_menu.jpg
http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/mavlinkhil.png
You may also want to turn on the Frame Rate to display on the screen.
On the IP screen on Xplane, change the UDP data port to 49005 as shown below. (The Mission Planner also has an advanced IP setting dialog, but leave it at the default of 49000. 49005 is the UDP port coming in from Xplane, 49000 is the UDP port going out from the Mission Planner.)
http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/xplane2.PNG
If you are running X-plane on the same computer as APM Mission Planner, then enter the loopback IP address (127.0.0.1) as shown above. If you are running X-plane on a different computer, enter the IP address of the other computer here(for example 192.168.1.1).
Now you're ready to run the simulation. Start the Mission Planner, selecting the COM port APMis assigned to and 115200 baud as the speed. Click on the Simulation tab and you will be taken to this screen:
http://ardupilot-mega.googlecode.com/svn/ArduPilotMegaImages/missionplannersim.PNG
If you are running APM Mission Planner on the same computer as X-Plane, then the default IP settings should be fine. But if you're in doubt, you can check the "Advanced IP Settings". The IP address should be 127.0.0.1 and the port should be 49000, as shown. If you are running X-plane on a different computer, though, enter the IP address of the other computer here (for example 192.168.1.2). The port should be 49000 in either case.
Once you've selected Connect, if APM is connected and Xplane is running, you should see the Mission Planner Sim screen fill with data.
Turn your transmitter on and check your link to your receiver. (Remember that you must plug an ESC and LiPo into the RC pins of APM to power the RC receiver). When you move the sticks you should see the APM outputs change on the Flight Planner Simulator window.
For first testing, set your three RC toggle switch modes to Manual, Stabilize and RTL. You can do that via the Mission Planner's MAVLink setup (remember that the usual CLI setup doesn't work in flight simulator mode). Hit control-G in the Mission Planner once you're connect to go to the setup screen, where you will find the Modes setup.
Now fly the plane in the sim with your RC transmitter. First, hit the "C" key so you can see your plane up close and from the side. Try each stick on your RC transmitter and make sure that the control surfaces go in the right direction in manual mode. If they don't, reverse them at your RC transmitter as you would with a normal RC airplane.
You can now try a flight. Reload the aircraft in Xplane, hit "a" so you can see it from behind, and hit "b" to release the brakes. The aircraft should begin moving forward. You can steer it on the ground with your rudder stick. Once it's picked up speed, give it a little up elevator to take off. You should be able to fly it like a RC flight simulator.
If it's flying well, try moving your toggle switch into stabilize mode. The aircraft should immediately start flying flat and level. If it rolls upside down and wants to fly that way, you'll need to reverse the ailerons on the DIP switches of your APM board. Likewise for diving, in which case you should reverse the elevator with the DIP switch.
If stabilization works well, try RTL. The aircraft should return to the start of the runway and circle there at 100m.
Once that is working, trying entering some waypoints and flying an auto mission. In the Mission Planner read the stored waypoints and let it reset home to the stored position (which will now be the airport in your Xplane simulator that you're flying from. Click to add a few waypoints and switch into auto to watch the show!
In general, the correct order to load and run everything is as follows:
- Use the Mission Planner to load the Simulator version of the APM code and perform the setup.
- Start Xplane. After it is initialized and while the plane is sitting on the ground hit the "a" key for a rear view and then the "p" key to pause.
- Start the Mission Planner, select the right port and baud for your APM board and connect to APM.
- In the Mission Planner simulation tab, click the button in !ArduPilotSim to connect. You should see values appear in the output fields. Switch your TX mode switch to the manual position and verify that the outputs are moving with your TX sticks.
- Make sure your throttle stick is down.
- Switch to Xplane. You are ready to go. Click the "p" key to unpause. Hit the "b" key to unlock the brakes. Advance the throttle and take off!
Notes:
- I have been using the stock PT-60 in Xplane with good results. I would recommend a cruise airspeed of 15 m/s
- One quirk of the PT-60 is that it bounces around a lot on the ground and if you are not careful it has prop-strikes followed by simulated engine failure, which is really annoying. If the engine has stopped, reload the plane. Hold the pitch stick for a modest climb and go to full throttle.
- Remember that APM always sets its "home" location automatically at the field, which in this case is whichever airport you've set Xplane to start at. It will overwrite any home you may have set in the Mission Planner. If you want the flight sim to start at a different airport, you must select that from Xplane's "Location" menu. You can only select the provided airports, not just any place in the world you want to fly.
- Remember the the CLI mode is disabled, so that you must do all setup via the Mission Planner!
-
Can't open serial port : The comport has not been selected or the comport is in use. Do you have a terminal open to the APM?
-
Socket (IP) setup problem. Do you have this open already? : You have another program running that is using the IP Port and conflicting with the data communications between Xplanes and APM Planner.
-
Xplane Data Problem - You need DATA IN/OUT 3, 18, 19, 20 : Please redo the setup and make sure all the boxes are ticked. You may need to restart X-Plane.
-
Bad Gains!!! : One of the simulator gain numbers is invalid.
-
NO SIM data : Ardupilot Mega Planner is not receiving any data from Xplane. Please check your Xplane settings.
-
The radio has no control--you push the sticks and nothing happens. Are your PID setting zero? Have you setup up your Radio inputs. Go through the APM setup again.
-
Flight controls are way off. You need to push the sticks way over to fly the plane. Check your Radio setup in the APM. Did you configure the Radio?
-
The on-screen status details only update after a valid connection to the APM has been made.
-
Open Terminal, and verify what you see. If the text is readable go to 2b, if it is not look at 2a
2a. When you click Connect you should see the APM header printed in the text box. If you don't you may not have the correct Comport or Baudrate
2b. Verify the setup by opening the Terminal in APM Planner and see what it prints out. it should start with the APM header and continually spit out AAA???? forever. If you don't see the AAA's then you may have uploaded the wrong firmware (not simulation mode) or if you're loading the code manually, not made the necessary changes to the APM_Config.h file.