Simulation
This page describes the steps needed to run a simulated flight with an UAS.
Compiling and starting
From the Paparazzi Center select the Microjet aircraft (from the A/C combo box) which is configured with the basic.xml flight plan. From the Target combo box, select sim and click the Build button to compile the airbone code to be run on your Linux box. From the Session combo box, select Simulation entry and click Execute to start the simulation. It will start three processes which are listed in the window below:
- Microjet is the interface of a simulator program. It runs the same code as the one for the autopilot processor plus a rudimentary flight dynamic model. it allows you to test the interactions with the UAV and the flight plan execution.
- GCS (Ground Control Station) is the main window. It displays the track of the aircraft, as well as informations about the execution of its flight plans. This program provide menus for the datalink functions and is able to edit a flight plan.
- Server is a hidden process which won't be described here (see the architecture of the system)
Start the Simulation
The aircraft has automatically been booted, as if the autopilot board had been powered. Its position and its flight parameters are displayed in the GCS window. If you omit the -boot option of the sim the aircraft is not automatically booted and you can first place the aircraft where you want it to start from and then boot.
The map widget is able use many map formats and display them according to many projections. To make things simple, we start by using images from Google. From the toolbar in the top right corner of the GCS, click the Google Earth icon (Google maps fill). The program attempts to download the required satellite images from the Google servers. If it succeeds, you should now see the nice countryside of Muret (a city close to Toulouse, France). Navigation and other features of the map are described on the GCS page.
The lower part of the GCS displays the flight plan in a tree view. You see that the current flight plan is composed of several blocks:
- wait GPS and geo init which are instructions to run this flight plan anywhere in the world, by translating the waypoints around the current location of aircraft as soon as it is reported by the GPS.
- Holding point (it should be the current active block) which instructs the autopilot to wait for launch.
- Takeoff which will instruct the aircraft to climb full throttle to a security altitude
- Standby which is a simple circle around the STDBY waypoint.
Switch to the Takeoff block by a double click on the line or using the corresponding button (an icon figuring an airway) on the left side of the strip.
Fly
In the Simulator (Microjet window), press the Launch button to simulate a hand launch or click the launch button in the GCS (the green aircraft icon). The autopilot detects the launch by monitoring the groundspeed. The flight time (in the aircraft label on the GCS) then starts to count.
Position of the aircraft is displayed on the map: the aircraft goes to the CLIMB waypoint (to the norht-west) and then around the STDBY waypoint. Current block also changes accordingly in the flight plan display.
The orange triangle (the carrot) on the map is the point that the aircraft is navigating toward.
Line
Jump to this block with double-click on the Line 1-2 line in the flight plan or using the corresponding button in the strip (figuring a blue line between two white points). The aircraft will try to follow a line joining the waypoints 1 and 2, doing nice U-turns at both ends.
Move waypoints
While the aircraft is flying (or here while the simulator is integrating differential equations), you can move the waypoints on the GCS interface by cliking and dragging (with the left button). When the mouse button is released, a popup window allows you to change the altitude of the waypoint. After validation, the waypoint changes are sent to the autopilot and the followed track is changed accordingly.
Coming back around
Select the Standby block (the home blue icon) to instruct the aircraft to fly around the STDBY waypoint.
Fly too far
If you unzoom the map (using the PageDown key or he mouse wheel), you will see a large circle around the waypoints. This circle show the allowed flying zone that the autopilot must not leave or it will enter an emergency navigation mode and circles the HOME waypoint until the further direction is received.
Move the waypoint 2 out of this circle (close to the circle in the north-east corner) and switch back to the 'Line 1-2 block to force the plane to get out of this safety zone.
The aircraft flies to the 2 waypoint, cross the protection enveloppe and switches to home mode: the AP mode in the aircraft strip switches from AUTO2 to HOME.
To get out of this mode and switch back to the default AUTO2, click on the AUTO2 button in the aircraft strip. The aircraft then flies again towards too far and again swithes to HOME mode.
Change the environment
Launch the Environment Simulator from the Tools' menu in the Paparazzi Center.
This interface (also calledGaia) allows the user to change:
- The wind: Set up a wind speed of 5m/s and observe the trajectory and the speed evolution (in the aircraft strip and in the PFD page of the notebook).
- The GPS coverage: Shut down the GPS (GPS OFF) and observe the resulting mode (NO_GPS) and trajectory. In this mode, the autopilot uses the failsafe roll, pitch and throttle settings defined in the airframe file. Note that in a real flight, an aircraft without GPS won't be able to send its position ... The simulation is cheating here !
- The time scale: If you are in a hurry ... Do not use a time higher than 2 for this first demonstration.
Using the buttons in the strip, you can play with other navigation patterns: figure of eights, oval, survey of a rectangle (with a north-south sweeping), Turn around here (which sets a waypoint to the current location of the plane and flies a circle around).
Landing
To automatically land the aircraft:
- Set the TD (Touch Down) waypoint where you want to land. Be sure that the waypoint is on the ground (185m in Muret)
- Set the AF (Approach Fix) waypoint where you want to start the final descent (the glide). If you have set some wind with Gaia, you probably want to fly AF-TD upwind (an estimation of the wind experienced by the aircraft is displayed in the left-upper corner of the map).
- Switch to the Land right or the Land left block (icons in the strip) according to the direction of the last turn you want to do (for example, if AF is on the east side of TD and you want to maneuvre from the north, choose a Land right)
Multiple UAV Simulation
To simulate multiple aircrafts, you just have to launch a second simulator (tools->simulator, then -a yourairframe) and the server and the GCS should take care of the rest.
View the simulation in Flight Gear
To view the simulation in Flight Gear, do the following:
- in your root folder:
sudo apt-get install flightgear
- go to Paparazzi
cd ~/paparazzi ./paparazzi
- In Paparazzi Center, add to the simulator command the -fg option plus the IP address of the machine running flightgear:
.../sw/simulator/launchsitl -a TJ1 -fg 127.0.0.1 -boot -norc
- Launch Flight Gear with the following command:
fgfs --fdm=null --native-gui=socket,in,30,,5501,udp
For Flight Gear visualization, version 2.6 or greater is best. If you wish to use version 2.4 or lower, you must add the following to the firmware section of your airframe file:
File: conf/airframes/myplane.xml |
<firmware name="fixedwing or rotorcraft">
...
<define name="FG_2_4" value="1"/>
...
</firmware>
|
Why is it night in Flight Gear, if my sim is flying during the day?
The time that is sent to Flight Gear is hard coded into the code, so if you try to view the output of the simulation and your simulated flight is located far from France, in Flight Gear, everything may be dark. If your simulated flight is in France, then you will always have daylight in Flight Gear.
If you have flightgear 2.4 or higher adding the command line option
--timeofday=noon
to your flightgear options might solve your issue.
If not, then fix this, do the following (you will need to have paparazzi-dev installed to do this):
- Get the Unix time during your local daylight hours by running the following command in your terminal:
date +%s
- In the file: paparazzi/sw/simulator/fg.c find the line(line 44):
msg.cur_time = 3213092700ul;//time(NULL);
- Paste the output from "date +%s" in place of "3213092700"
- Now you will have to rebuild paparazzi, so in the terminal change to the paparazzi directory and run:
make clean make
- In Paparazzi Center clean and rebuild your simulation
- Launch the simulation and Flight Gear, and Flight Gear should be flying in daylight.
JSBSim
Paparazzi can work with JSBSim, a great open source flight dynamics library. For instructions on JSBSIM on Mac OS X go here.
For a fixed wing aircraft:
In your airframe file add the following section:
<section name="SIMU"> <define name="JSBSIM_MODEL" value=""Malolo1""/> <define name="JSBSIM_IR_ROLL_NEUTRAL" value="RadOfDeg(0.)"/> <define name="JSBSIM_IR_PITCH_NEUTRAL" value="RadOfDeg(0.)"/> </section>
In this case, the JSBSim model used is conf/simulator/Malolo1. To create your own model make a new directory under conf/simulator and put your JSBSim model there, and adapt the "JSBSIM_MODEL" in the SIMU section accordingly.
Add another target to the "fixedwing" firmware section of your airframe file:
<target name="jsbsim" board="pc" />
Now you can can compile the airframe for the jsbsim target. Launch the simulator as normal, but add the option -jsbsim. Note that FlightGear visualization can be used in conjunction with the JSBSim simulation, just be sure to add the -fg 127.0.0.1 option as described above. Using both JSBSim and FlightGear, it would be:
<paparazzi home directory>/sw/simulator/launchsitl -a <aircraft_name> -jsbsim -boot -norc -fg 127.0.0.1
You will notice the default control parameters do not fly the Malolo1 airframe particularly well.
The Microjet aircraft can be used as an example; it has the right target and "SIMU" section added.
Using Optional Parameters
There are a few optional parameters that can be used with a JSBSim simulation.
The initial body-aligned forward speed of the aircraft in m/s can be specified in the "SIMU" section of the airframe file:
<section name="SIMU"> ... <define name="JSBSIM_LAUNCHSPEED" value="15.0"/> ... </section>
The initial conditions for the simulation can be set with an initialization file. Add the following to the "SIMU" section of the airframe file:
<section name="SIMU"> ... <define name="JSBSIM_INIT" value=""Malolo1-IC""/> ... </section>
In this case, the initialization file for the Malolo1 used is conf/simulator/Malolo1/Malolo1-IC.xml. To create your own initialization file, use this file as an example, place the file into your JSBSim model directory, and adapt "JSBSIM_INIT" in the SIMU section accordingly.
These options are demonstrated in the jsbsim.xml example airframe file in /conf/airframes/jsbsim.xml. The control parameters in this example are much better in controlling the Malolo1 airframe.