Difference between revisions of "NPS"

From PaparazziUAV
Jump to navigation Jump to search
 
(31 intermediate revisions by 8 users not shown)
Line 2: Line 2:
__TOC__
__TOC__


NPS contains a sensors model and can use [http://jsbsim.sourceforge.net/ Jsbsim] as FDM (FlightDynamicModel) to allow fairly complex models.
== Introduction ==
Other FDMs can be integrated easily.


=== Installation ===
NPS ('''N'''ew '''P'''aparazzi '''S'''imulator) is a more advanced simulator with sensor models and can use different FDM backends. By default [[JSBSim]] is used as FDM (FlightDynamicModel) backend, this allow fairly complex airframes.
JSBSim can be replaced by the FDM of your choice, e.g. YASim or a interconnection with MATLAB simulink


See [[Installation|installation of Paparazzi]], [[JSBSim]] and optionally [[FlightGear]].
NPS is capable of simulating rotorcraft and fixedwing airframes, with the possibility to add more complex aircrafts/hybrids if a proper model is built using one of the FDM backends.


==== Compilation ====
== Usage ==


* Compile paparazzi
See [[Installation|installation of Paparazzi]], [[JSBSim]] and optionally [[FlightGear]] (for visualization).
  cd paparazzi
  make


* Compile the vehicle
=== Configuration/Build ===
   make AIRCRAFT=Quad_LisaM_2 clean_ac nps
Add the '''nps''' target to your [[Airframe_Configuration|airframe]] with the fdm you want to use:
{{Box Code|conf/airframes/myaircraft.xml|
<source lang="xml">
   <firmware name="rotorcraft or fixedwing">
    <target name="nps" board="pc">
      <subsystem name="fdm"  type="jsbsim"/>
    </target>
    ...
  </firmware>
</source>
}}
then depending on the aircraft you want to simulate add a NPS simulator section which defines the model, actuators and sensor parameters used:


===Start Simulation===
E.g for a simple quadrotor:
* Start paparazzi_center if you want click to start programs
{{Box Code|conf/airframes/myaircraft.xml|
./paparazzi
<source lang="xml">
  <section name="SIMULATOR" prefix="NPS_">
    <define name="ACTUATOR_NAMES"  value="front_motor, right_motor, back_motor, left_motor" type="string[]"/>
    <define name="JSBSIM_MODEL" value="simple_quad" type="string"/>
    <define name="SENSORS_PARAMS" value="nps_sensors_params_default.h" type="string"/>
  </section>
</source>
}}
You can also take a look at the example airframe [https://github.com/paparazzi/paparazzi/blob/master/conf/airframes/examples/quadrotor_lisa_m_2_pwm_spektrum.xml conf/airframes/examples/quadrotor_lisa_m_2_pwm_spektrum.xml] or use it for your first tests.


* Start messages to monitor the middleware activity ( from the tool menu of paparazzi center) or with
E.g for a fixedwing like a Bixler,Easystar, etc:
./sw/ground_segment/tmtc/messages
{{Box Code|conf/airframes/myaircraft.xml|
<source lang="xml">
  <section name="SIMULATOR" prefix="NPS_">
    <define name="JSBSIM_LAUNCHSPEED" value="15"/>
    <define name="JSBSIM_MODEL" value="easystar" type="string"/>
    <define name="SENSORS_PARAMS" value="nps_sensors_params_default.h" type="string"/>
  </section>
</source>
}}


* Start the sim
* NPS_ACTUATOR_NAMES: mapping of the motors defined in the [[Rotorcraft_Configuration#Motor_Mixing|MOTOR_MIXING section]] to the actuators in the JSBSim model (the order is important, also make sure that your motors in JSBSim spin in the same direction as your real ones)
./var/Quad_LisaM_2/nps/simsitl
* NPS_SENSORS_PARAMS: the parameter file for the sensor simulation (noise/delay) under ''conf/simulator/nps/'' (e.g. [https://github.com/paparazzi/paparazzi/blob/master/conf/simulator/nps/nps_sensors_params_default.h nps_sensors_params_default.h])
* NPS_JSBSIM_MODEL: name of the JSBSim model in ''conf/simulator/jsbsim/aircraft/'' (e.g. [https://github.com/paparazzi/paparazzi/blob/master/conf/simulator/jsbsim/aircraft/simple_quad.xml simple_quad]), if not defined it defaults to AIRCRAFT_NAME
* NPS_JSBSIM_INIT: the xml file containing the initial conditions (location, attitude, wind) for JSBSim in ''conf/simulator/jsbsim/aircraft/'' (e.g. [https://github.com/paparazzi/paparazzi/blob/master/conf/simulator/jsbsim/aircraft/reset00.xml reset00])<br>This define is optional and if not specified the initial position of the aircraft will be set to the flight plan location. Prior to v5.1 this was called INITIAL_CONDITITONS.
* NPS_JSBSIM_LAUNCHSPEED: if defined this sets an initial launchspeed in m/s for fixedwings, available since v5.1.0_testing-54-g2ac094f
* NPS_JS_*: Joystick mappings, see [http://docs.paparazziuav.org/latest/nps__radio__control__joystick_8c.html]
Then build the nps target...


You should now see activity in the "messages" window
== Running the Simulation ==


* Plot the value of a message field.
The most convenient way to start the simulation is via the ''Simulation'' session from the [[Paparazzi Center]].
start 'plotter' (Real-time plotter from the tool menu of paparazzi center) or with
Just select e.g. the Quad_LisaM_2 example airframe and start the ''Simulation'' session with the simulator, GCS and server.
  ./sw/logalizer/plotter
 
for example drag the label 'int32 phi' from the ROTORCRAFT_FP message to the drawing area of the plotter
If you have added PAPARAZZI_HOME AND PAPARAZZI_SRC to the environmental variables of your terminal (See [[Installation#Environment_Variables|Setting up environment variables]]), you can also start it via the generic simulation launcher:
<source lang="bash">sw/simulator/pprzsim-launch --aircraft Quad_LisaM_2 --type nps</source>
 
<div class="toccolours mw-collapsible mw-collapsed">
Prior to '''v5.0''' pprzsim-launch was not available. Click expand to see the details.
<div class="mw-collapsible-content">
In earlier versions, start your tools (e.g. [[GCS]], [[server]] and messages) separately, then launch the nps simulator for your aircraft directly:
<source lang="bash">./var/Quad_LisaM_2/nps/simsitl</source>
</div></div>
 
=== Options ===
Start the simulator with the ''--help'' option to list them all.
 
* ''--ivy_bus'': Set ivy bus broadcast address to use (default 127.255.255.255, 224.255.255.255 on OSX)
* ''--rc_script'': Execute script with specified number to emulate RC input.
* ''--js_dev'': Use joystick for radio control (specify index, normally 0), also see [[NPS#Use_a_Joystick]].
* ''--spektrum_dev'': Spektrum device to use for radio control (e.g. /dev/ttyUSB0)
* ''--fg_host'': Host for FlightGear visualization (e.g. 127.0.0.1)
* ''--fg_port'': Port on FlightGear host to connect to (Default: 5501)
* ''--fg_time_offset'': FlightGear time offset in seconds (e.g. 21600 for 6h), this is useful if it is currently night at the location you are flying and you want to add an offset to fly in daylight. (Since ''v4.9_devel_413-g9d55d6f)
 
=== Typical Simulation ===
In general you go through the same steps as with the real aircraft:
* It should start on the ground and you have to wait a few seconds until the AHRS is aligned.
* If you have a (simulated) RC, you can now arm the motors and fly around in manual.
* To fly autonomously, make sure your ''AUTO2'' mode is ''NAV'', you can change it in the GCS->settings->system->auto2.
** Switch to it if you are using an RC, otherwise you should already be in this mode.
** Arm your motors: either via the resurrect button or by going to the ''Start Motors'' block of the [[Flight Plans|Flight Plan]].
** Takeoff: via the takeoff button or the corresponding flight plan block.
* Do your stuff... :-)
 
=== Pausing or running the sim at a different speed ===
If you start the simulation from a terminal, hit ''CTRL-z'' to pause it. You can then enter a different time factor (default 1.0) to make the simulation run slower or faster than real-time. Hit enter to resume the simulation or ''CTRL-z'' again to suspend it like any normal Unix process (use the ''fg'' (foreground) command to un-suspend it again).
 
This simulation speed parameter ?can be edited? in a configuration file : FIXME
 
=== Use a Joystick ===
You can use a [[joystick]] (or connect your RC transmitter as a joystick) to control the quad in the simulator.
<source lang="bash">sw/simulator/pprzsim-launch --aircraft Quad_LisaM_2 --type nps --js_dev 0</source>
or directly calling the nps simsitl binary:
<source lang="bash">./var/Quad_LisaM_2/nps/simsitl --js_dev 0</source>


Joystick support uses the Simple DirectMedia Layer (SDL) library. Rather than specifying an input device name as one normally does on Linux, you just supply an index value (0, 1, 2,...) of the device you wish to use. Typically, the order of devices is the order in which you plugged them into your computer. The sim will display the name of the device being used to double check. If the <tt>-j</tt> option is used with no argument, the sim defaults to using device on index 0 (which is usually correct if you have only one joystick attached).


* Use the datalink to change the tlemetry mode
Also see [[Joystick#Calibration]].
start 'settings' ( from the tool menu of paparazzi center) or with
  ./sw/ground_segment/tmtc/settings -ac Quad_LisaM_2
start 'server' to dispatch datalink messages ( from the tool menu of paparazzi center) or with
./sw/ground_segment/tmtc/server
change the field "telemetry" on the first page to "Att loop" and send by pressing the green check button. The label on the left or the drop box should change to "Att loop" confirming your essage has been received. "message" should now show that the message "STAB_ATTITUDE_INT" is received


* Use [[FlightGear]] to visualize your vehicle
=== Visualization in [[FlightGear]] ===
If you want a view of a quadrotor in flightgear, make a link from
[[FlightGear#Installation|Install]] and [[FlightGear#Using_FlightGear_for_Visualization|start flightgear]], e.g. with a quadrotor model:
/usr/share/games/flightgear/Models/Aircraft/paparazzi to PAPARAZZI_SRC/conf/simulator/flightgear/
<source lang="bash">fgfs --fdm=null --native-gui=socket,in,30,,5501,udp --prop:/sim/model/path=Models/Aircraft/paparazzi/mikrokopter.xml</source>
  sudo ln -s $PAPARAZZI_SRC/conf/simulator/flightgear/ /usr/share/games/flightgear/Models/Aircraft/paparazzi
restart your simulator with the ''--fg_host'' option:
start flightgear with
<source lang="bash">sw/simulator/pprzsim-launch --aircraft Quad_LisaM_2 --type nps --fg_host 127.0.0.1</source>
fgfs --fdm=null --native-gui=socket,in,30,,5501,udp --prop:/sim/model/path=Models/Aircraft/paparazzi/mikrokopter.xml
restart your simulator with
./var/Quad_LisaM_2/nps/simsitl --fg_host 127.0.0.1


* Save you session
=== Visualization in [[Morse]] ===
The Morse simulator can be used to make simulated (or real) rotorcraft fly inside a virtual environment where simulated sensors such as camera or laser scanners can be added and provide measurements.


==== Troubleshooting ====
=== Troubleshooting ===
* If you get an error like "JSBSim failed to open the configuration file: (null)/conf/simulator/jsbsim/aircraft/BOOZ2_A1.xml", you need to set your $PAPARAZZI_SRC and $PAPARAZZI_HOME environment variables. Add the following to your .bashrc, change paths according to where you put Paparazzi. Open a new terminal and launch the sim again.
* If you get an error like "JSBSim failed to open the configuration file: (null)/conf/simulator/jsbsim/aircraft/BOOZ2_A1.xml", you need to set your $PAPARAZZI_SRC and $PAPARAZZI_HOME environment variables. Add the following to your .bashrc, change paths according to where you put Paparazzi. Open a new terminal and launch the sim again.
  export PAPARAZZI_SRC=~/paparazzi
  export PAPARAZZI_SRC=~/paparazzi
  export PAPARAZZI_HOME=~/paparazzi
  export PAPARAZZI_HOME=~/paparazzi
 
* If you did not install the jsbsim package your JSBSim installation under /opt/jsbsim will be used and you will have to set your library path (either in your shell startup file or when running the sim on the command line), e.g.:
* If you did not install the jsbsim package your JSBSim installation under /opt/jsbsim will be used and you will have to set your library path (either in your shell startup file or when running the sim on the command line), e.g.:
  LD_LIBRARY_PATH=/opt/jsbsim/lib ./var/Quad_LisaM_2/nps/simsitl --fg_host 127.0.0.1
LD_LIBRARY_PATH=/opt/jsbsim/lib ./var/Quad_LisaM_2/nps/simsitl --fg_host 127.0.0.1
 
* If you get an error like "fatal error: gsl/gsl_rng.h: No such file or directory", you need to install the GNU Scientific Library and corresponding development packages (libgsl).
 
* If you get an error like "undefined reference to `pcre_compile'", edit file conf/Makefile.nps, look for the line that begins with LDFLAGS and add -lpcre, e.g.:
LDFLAGS += $($(TARGET).LDFLAGS) -lpcre
 
==== Simulating Multiple Aircraft ====
When simulating multiple aircraft, the ''-udp_broadcast'' argument needs to be specified as part of the datalink invocation:
$PAPARAZZI_HOME/sw/ground_segment/tmtc/link -udp -udp_broadcast
 
In the case of Mac OS X, the IP ADDR must also be specified:
$PAPARAZZI_HOME/sw/ground_segment/tmtc/link -udp -udp_broadcast -udp_broadcast_addr <your_network_broadcast_ip_addr>
 
You can determine the IP ADDR for your network using '''ifconfig''' command:
<pre>
$ ifconfig
...
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 60:03:08:8e:14:9e
inet6 fe80::6203:8ff:fe8e:149e%en0 prefixlen 64 scopeid 0x4
inet 192.168.1.59 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=1<PERFORMNUD>
media: autoselect
status: active
...
</pre>
 
Based on the above sample output, the invocation would look like the following:
$PAPARAZZI_HOME/sw/ground_segment/tmtc/link -udp -udp_broadcast -udp_broadcast_addr 192.168.1.255
 
== Usage Examples ==
 
=== Plot the value of a message field ===
Start the [[RTPlotter|real-time plotter]] tool menu of [[Paparazzi Center]] or with
<source lang="bash">./sw/logalizer/plotter</source>
for example drag the label 'int32 phi' from the ROTORCRAFT_FP message to the drawing area of the plotter


=== Pausing or running the sim at a different speed ===
* Use the datalink to change the telemetry mode
You can pause the simulation with ''CTRL-z'' in the terminal. You can then enter a different time factor (default 1.0) to make the simulation run slower or faster than real-time. Hit enter to resume the simulation or ''CTRL-z'' again to suspend it like any normal Unix process (use the ''fg'' (foreground) command to un-suspend it again).
start 'settings' ( from the tool menu of paparazzi center) or with
  ./sw/ground_segment/tmtc/settings -ac Quad_LisaM_2
start 'server' to dispatch datalink messages ( from the tool menu of paparazzi center) or with
./sw/ground_segment/tmtc/server
change the field "telemetry" on the first page to "Att loop" and send by pressing the green check button. The label on the left or the drop box should change to "Att loop" confirming your message has been received. "message" should now show that the message "STAB_ATTITUDE_INT" is received


=== Tuning the attitude control loop ===
=== Tuning the attitude control loop ===
 
Here we are going to use the simulator to demonstrate a way of tuning the attitude control loop for a multicopter (rotorcraft firmware only).
Here we are going to use the simulator to demonstrate a way of tuning the attitude control loop.


* Restart your previous session
* Restart your previous session
* Set telemetry mode to "attitude_loop"
* Set telemetry mode to "attitude_loop"
* Display two real time plotter windows
* Display two real time plotter windows


Line 79: Line 180:


In the second plotter, plot the fields "delta_a_fb" and "delta_a_ff". Those are respectively the feedback and feedforward part of our roll command. The sum of those two terms is what is used as roll command.The feedforward part is the part used to follow our trajectory and the feedback part is the part used to reject perturbations.
In the second plotter, plot the fields "delta_a_fb" and "delta_a_ff". Those are respectively the feedback and feedforward part of our roll command. The sum of those two terms is what is used as roll command.The feedforward part is the part used to follow our trajectory and the feedback part is the part used to reject perturbations.


* In "Settings", go to the "Att Loop" tab
* In "Settings", go to the "Att Loop" tab
Line 88: Line 188:
If you look at the plotter where you're plotting the commands, you'll notice that during steps, the feedback command has to work hard. This means that our feedforward command is badly tuned, and namely not working hard enough. Increase the value of the feedforward gain ('ddgain p') from 300 to 540. You'll notice that now the feedback command has become marginal during the steps. This is the right value for the gain. Anything bigger will make the feedback command fight against the feedforward command during steps, anything smaller will make the feedback command have to complement the feedforward command.
If you look at the plotter where you're plotting the commands, you'll notice that during steps, the feedback command has to work hard. This means that our feedforward command is badly tuned, and namely not working hard enough. Increase the value of the feedforward gain ('ddgain p') from 300 to 540. You'll notice that now the feedback command has become marginal during the steps. This is the right value for the gain. Anything bigger will make the feedback command fight against the feedforward command during steps, anything smaller will make the feedback command have to complement the feedforward command.


=== Something else ===
* try starting flightgear with
fgfs --fdm=null --native-gui=socket,in,30,,5501,udp --prop:/sim/model/path=Models/Aircraft/paparazzi/simple_bipe.xml
an the sim with
./var/Quad_LisaM_2/nps/simsitl --fg_host 127.0.0.1 --rc_script 1
== Use a Joystick ==
You can use a [[joystick]] (or connect your RC transmitter as a joystick) to control the quad in the simulator.
<source lang="bash">./var/Quad_LisaM_2/nps/simsitl --fg_host 127.0.0.1 -j</source>
or, with a specific device index (0 is default):
<source lang="bash">./var/Quad_LisaM_2/nps/simsitl --fg_host 127.0.0.1 --js_dev 0</source>
Joystick support uses the Simple DirectMedia Layer (SDL) library. Rather than specifying an input device name as one normally does on Linux, you just supply an index value (0, 1, 2,...) of the device you wish to use. Typically, the order of devices is the order in which you plugged them into your computer. The sim will display the name of the device being used to double check. If the <tt>-j</tt> option is used with no argument, the sim defaults to using device on index 0 (which is usually correct if you have only one joystick attached).


[[Category:Simulation]] [[Category:Software]] [[Category:User_Documentation]]
[[Category:Simulation]] [[Category:Software]] [[Category:User_Documentation]]

Latest revision as of 15:38, 11 April 2017

Introduction

NPS (New Paparazzi Simulator) is a more advanced simulator with sensor models and can use different FDM backends. By default JSBSim is used as FDM (FlightDynamicModel) backend, this allow fairly complex airframes. JSBSim can be replaced by the FDM of your choice, e.g. YASim or a interconnection with MATLAB simulink

NPS is capable of simulating rotorcraft and fixedwing airframes, with the possibility to add more complex aircrafts/hybrids if a proper model is built using one of the FDM backends.

Usage

See installation of Paparazzi, JSBSim and optionally FlightGear (for visualization).

Configuration/Build

Add the nps target to your airframe with the fdm you want to use:

File: conf/airframes/myaircraft.xml
  <firmware name="rotorcraft or fixedwing">
    <target name="nps" board="pc">
      <subsystem name="fdm"   type="jsbsim"/>
    </target>
    ...
  </firmware>

then depending on the aircraft you want to simulate add a NPS simulator section which defines the model, actuators and sensor parameters used:

E.g for a simple quadrotor:

File: conf/airframes/myaircraft.xml
  <section name="SIMULATOR" prefix="NPS_">
    <define name="ACTUATOR_NAMES"  value="front_motor, right_motor, back_motor, left_motor" type="string[]"/>
    <define name="JSBSIM_MODEL" value="simple_quad" type="string"/>
    <define name="SENSORS_PARAMS" value="nps_sensors_params_default.h" type="string"/>
  </section>

You can also take a look at the example airframe conf/airframes/examples/quadrotor_lisa_m_2_pwm_spektrum.xml or use it for your first tests.

E.g for a fixedwing like a Bixler,Easystar, etc:

File: conf/airframes/myaircraft.xml
  <section name="SIMULATOR" prefix="NPS_">
    <define name="JSBSIM_LAUNCHSPEED" value="15"/>
    <define name="JSBSIM_MODEL" value="easystar" type="string"/>
    <define name="SENSORS_PARAMS" value="nps_sensors_params_default.h" type="string"/>
  </section>
  • NPS_ACTUATOR_NAMES: mapping of the motors defined in the MOTOR_MIXING section to the actuators in the JSBSim model (the order is important, also make sure that your motors in JSBSim spin in the same direction as your real ones)
  • NPS_SENSORS_PARAMS: the parameter file for the sensor simulation (noise/delay) under conf/simulator/nps/ (e.g. nps_sensors_params_default.h)
  • NPS_JSBSIM_MODEL: name of the JSBSim model in conf/simulator/jsbsim/aircraft/ (e.g. simple_quad), if not defined it defaults to AIRCRAFT_NAME
  • NPS_JSBSIM_INIT: the xml file containing the initial conditions (location, attitude, wind) for JSBSim in conf/simulator/jsbsim/aircraft/ (e.g. reset00)
    This define is optional and if not specified the initial position of the aircraft will be set to the flight plan location. Prior to v5.1 this was called INITIAL_CONDITITONS.
  • NPS_JSBSIM_LAUNCHSPEED: if defined this sets an initial launchspeed in m/s for fixedwings, available since v5.1.0_testing-54-g2ac094f
  • NPS_JS_*: Joystick mappings, see [1]

Then build the nps target...

Running the Simulation

The most convenient way to start the simulation is via the Simulation session from the Paparazzi Center. Just select e.g. the Quad_LisaM_2 example airframe and start the Simulation session with the simulator, GCS and server.

If you have added PAPARAZZI_HOME AND PAPARAZZI_SRC to the environmental variables of your terminal (See Setting up environment variables), you can also start it via the generic simulation launcher:

sw/simulator/pprzsim-launch --aircraft Quad_LisaM_2 --type nps

Prior to v5.0 pprzsim-launch was not available. Click expand to see the details.

In earlier versions, start your tools (e.g. GCS, server and messages) separately, then launch the nps simulator for your aircraft directly:

./var/Quad_LisaM_2/nps/simsitl

Options

Start the simulator with the --help option to list them all.

  • --ivy_bus: Set ivy bus broadcast address to use (default 127.255.255.255, 224.255.255.255 on OSX)
  • --rc_script: Execute script with specified number to emulate RC input.
  • --js_dev: Use joystick for radio control (specify index, normally 0), also see NPS#Use_a_Joystick.
  • --spektrum_dev: Spektrum device to use for radio control (e.g. /dev/ttyUSB0)
  • --fg_host: Host for FlightGear visualization (e.g. 127.0.0.1)
  • --fg_port: Port on FlightGear host to connect to (Default: 5501)
  • --fg_time_offset: FlightGear time offset in seconds (e.g. 21600 for 6h), this is useful if it is currently night at the location you are flying and you want to add an offset to fly in daylight. (Since v4.9_devel_413-g9d55d6f)

Typical Simulation

In general you go through the same steps as with the real aircraft:

  • It should start on the ground and you have to wait a few seconds until the AHRS is aligned.
  • If you have a (simulated) RC, you can now arm the motors and fly around in manual.
  • To fly autonomously, make sure your AUTO2 mode is NAV, you can change it in the GCS->settings->system->auto2.
    • Switch to it if you are using an RC, otherwise you should already be in this mode.
    • Arm your motors: either via the resurrect button or by going to the Start Motors block of the Flight Plan.
    • Takeoff: via the takeoff button or the corresponding flight plan block.
  • Do your stuff... :-)

Pausing or running the sim at a different speed

If you start the simulation from a terminal, hit CTRL-z to pause it. You can then enter a different time factor (default 1.0) to make the simulation run slower or faster than real-time. Hit enter to resume the simulation or CTRL-z again to suspend it like any normal Unix process (use the fg (foreground) command to un-suspend it again).

This simulation speed parameter ?can be edited? in a configuration file : FIXME

Use a Joystick

You can use a joystick (or connect your RC transmitter as a joystick) to control the quad in the simulator.

sw/simulator/pprzsim-launch --aircraft Quad_LisaM_2 --type nps --js_dev 0

or directly calling the nps simsitl binary:

./var/Quad_LisaM_2/nps/simsitl --js_dev 0

Joystick support uses the Simple DirectMedia Layer (SDL) library. Rather than specifying an input device name as one normally does on Linux, you just supply an index value (0, 1, 2,...) of the device you wish to use. Typically, the order of devices is the order in which you plugged them into your computer. The sim will display the name of the device being used to double check. If the -j option is used with no argument, the sim defaults to using device on index 0 (which is usually correct if you have only one joystick attached).

Also see Joystick#Calibration.

Visualization in FlightGear

Install and start flightgear, e.g. with a quadrotor model:

fgfs --fdm=null --native-gui=socket,in,30,,5501,udp --prop:/sim/model/path=Models/Aircraft/paparazzi/mikrokopter.xml

restart your simulator with the --fg_host option:

sw/simulator/pprzsim-launch --aircraft Quad_LisaM_2 --type nps --fg_host 127.0.0.1

Visualization in Morse

The Morse simulator can be used to make simulated (or real) rotorcraft fly inside a virtual environment where simulated sensors such as camera or laser scanners can be added and provide measurements.

Troubleshooting

  • If you get an error like "JSBSim failed to open the configuration file: (null)/conf/simulator/jsbsim/aircraft/BOOZ2_A1.xml", you need to set your $PAPARAZZI_SRC and $PAPARAZZI_HOME environment variables. Add the following to your .bashrc, change paths according to where you put Paparazzi. Open a new terminal and launch the sim again.
export PAPARAZZI_SRC=~/paparazzi
export PAPARAZZI_HOME=~/paparazzi
  • If you did not install the jsbsim package your JSBSim installation under /opt/jsbsim will be used and you will have to set your library path (either in your shell startup file or when running the sim on the command line), e.g.:
LD_LIBRARY_PATH=/opt/jsbsim/lib ./var/Quad_LisaM_2/nps/simsitl --fg_host 127.0.0.1
  • If you get an error like "fatal error: gsl/gsl_rng.h: No such file or directory", you need to install the GNU Scientific Library and corresponding development packages (libgsl).
  • If you get an error like "undefined reference to `pcre_compile'", edit file conf/Makefile.nps, look for the line that begins with LDFLAGS and add -lpcre, e.g.:
LDFLAGS += $($(TARGET).LDFLAGS) -lpcre

Simulating Multiple Aircraft

When simulating multiple aircraft, the -udp_broadcast argument needs to be specified as part of the datalink invocation:

$PAPARAZZI_HOME/sw/ground_segment/tmtc/link -udp -udp_broadcast

In the case of Mac OS X, the IP ADDR must also be specified:

$PAPARAZZI_HOME/sw/ground_segment/tmtc/link -udp -udp_broadcast -udp_broadcast_addr <your_network_broadcast_ip_addr>

You can determine the IP ADDR for your network using ifconfig command:

$ ifconfig
 ...
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	ether 60:03:08:8e:14:9e 
	inet6 fe80::6203:8ff:fe8e:149e%en0 prefixlen 64 scopeid 0x4 
	inet 192.168.1.59 netmask 0xffffff00 broadcast 192.168.1.255
	nd6 options=1<PERFORMNUD>
	media: autoselect
	status: active
 ...

Based on the above sample output, the invocation would look like the following:

$PAPARAZZI_HOME/sw/ground_segment/tmtc/link -udp -udp_broadcast -udp_broadcast_addr 192.168.1.255

Usage Examples

Plot the value of a message field

Start the real-time plotter tool menu of Paparazzi Center or with

./sw/logalizer/plotter

for example drag the label 'int32 phi' from the ROTORCRAFT_FP message to the drawing area of the plotter

  • Use the datalink to change the telemetry mode

start 'settings' ( from the tool menu of paparazzi center) or with

 ./sw/ground_segment/tmtc/settings -ac Quad_LisaM_2

start 'server' to dispatch datalink messages ( from the tool menu of paparazzi center) or with

./sw/ground_segment/tmtc/server 

change the field "telemetry" on the first page to "Att loop" and send by pressing the green check button. The label on the left or the drop box should change to "Att loop" confirming your message has been received. "message" should now show that the message "STAB_ATTITUDE_INT" is received

Tuning the attitude control loop

Here we are going to use the simulator to demonstrate a way of tuning the attitude control loop for a multicopter (rotorcraft firmware only).

  • Restart your previous session
  • Set telemetry mode to "attitude_loop"
  • Display two real time plotter windows

In the first one, plot the field "m_phi" from the "STAB_ATTITUDE_int" message. This is our estimation of roll angle. On top of that, plot the field "phi" from the "STAB_ATTITUDE_REF_INT" message. This is our reference roll angle, that is, the roll value we are trying to achieve.

In the second plotter, plot the fields "delta_a_fb" and "delta_a_ff". Those are respectively the feedback and feedforward part of our roll command. The sum of those two terms is what is used as roll command.The feedforward part is the part used to follow our trajectory and the feedback part is the part used to reject perturbations.

  • In "Settings", go to the "Att Loop" tab

We notice that the vehicle doesn't follow the step trajectory we are trying to make him do accurately.

Start by setting the value of the proportional gain ('pgain_phi') to 1000 instead of 400. The vehicle now follows the trajectory faster but overshoots. To prevent that, increase the value of the derivative gain ('dgain p') from 300 to 700.

If you look at the plotter where you're plotting the commands, you'll notice that during steps, the feedback command has to work hard. This means that our feedforward command is badly tuned, and namely not working hard enough. Increase the value of the feedforward gain ('ddgain p') from 300 to 540. You'll notice that now the feedback command has become marginal during the steps. This is the right value for the gain. Anything bigger will make the feedback command fight against the feedforward command during steps, anything smaller will make the feedback command have to complement the feedforward command.