Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nps_fdm_gazebo.cpp File Reference

Flight Dynamics Model (FDM) for NPS using Gazebo. More...

#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/sensors/sensors.hh>
#include <gazebo/gazebo_config.h>
#include <sys/time.h>
#include "nps_fdm.h"
#include "math/pprz_algebra_double.h"
#include "generated/airframe.h"
#include "autopilot.h"
+ Include dependency graph for nps_fdm_gazebo.cpp:

Go to the source code of this file.

Macros

#define NPS_GAZEBO_WORLD   "ardrone.world"
 
#define NPS_GAZEBO_AC_NAME   "paparazzi_uav"
 

Functions

static void init_gazebo (void)
 Set up a Gazebo server. More...
 
static void gazebo_read (void)
 Read Gazebo's simulation state and store the results in the fdm struct used by NPS. More...
 
static void gazebo_write (double commands[], int commands_nb)
 Write actuator commands to Gazebo. More...
 
struct EcefCoor_d to_pprz_ecef (ignition::math::Vector3d ecef_i)
 
struct NedCoor_d to_pprz_ned (ignition::math::Vector3d global)
 
struct LlaCoor_d to_pprz_lla (ignition::math::Vector3d lla_i)
 
struct DoubleVect3 to_pprz_body (gazebo::math::Vector3 body_g)
 
struct DoubleRates to_pprz_rates (gazebo::math::Vector3 body_g)
 
struct DoubleEulers to_pprz_eulers (gazebo::math::Quaternion quat)
 
struct DoubleVect3 to_pprz_ltp (gazebo::math::Vector3 xyz)
 
void nps_fdm_init (double dt)
 Set JSBsim specific fields that are not used for Gazebo. More...
 
void nps_fdm_run_step (bool launch, double *commands, int commands_nb)
 Update the simulation state. More...
 
void nps_fdm_set_wind (double speed, double dir)
 
void nps_fdm_set_wind_ned (double wind_north, double wind_east, double wind_down)
 
void nps_fdm_set_turbulence (double wind_speed, int turbulence_severity)
 
void nps_fdm_set_temperature (double temp, double h)
 Set temperature in degrees Celcius at given height h above MSL. More...
 

Variables

struct NpsFdm fdm
 Holds all necessary NPS FDM state information. More...
 
static bool gazebo_initialized = false
 
static gazebo::physics::ModelPtr model = NULL
 

Detailed Description

Flight Dynamics Model (FDM) for NPS using Gazebo.

This is an FDM for NPS that uses Gazebo as the simulation engine.

Definition in file nps_fdm_gazebo.cpp.

Macro Definition Documentation

#define NPS_GAZEBO_AC_NAME   "paparazzi_uav"

Definition at line 68 of file nps_fdm_gazebo.cpp.

Referenced by init_gazebo().

#define NPS_GAZEBO_WORLD   "ardrone.world"

Definition at line 65 of file nps_fdm_gazebo.cpp.

Referenced by init_gazebo().

Function Documentation

static void gazebo_write ( double  commands[],
int  commands_nb 
)
static

Write actuator commands to Gazebo.

This function takes the normalized commands and applies them as forces and torques in Gazebo. Since the commands are normalized in [0,1], their thrusts (NPS_ACTUATOR_THRUSTS) and torques (NPS_ACTUATOR_TORQUES) need to be specified in the airframe file. Their values need to be specified in the same order as the NPS_ACTUATOR_NAMES and should be provided in SI units. See conf/airframes/examples/ardrone2_gazebo.xml for an example.

The forces and torques are applied to (the origin of) the links named in NPS_ACTUATOR_NAMES. See conf/simulator/gazebo/models/ardrone/ardrone.sdf for an example.

Parameters
commands
commands_nb

Definition at line 434 of file nps_fdm_gazebo.cpp.

References autopilot, model, and pprz_autopilot::motors_on.

Referenced by nps_fdm_run_step().

+ Here is the caller graph for this function:

static void init_gazebo ( void  )
static

Set up a Gazebo server.

Starts a Gazebo server, adds conf/simulator/gazebo/models to its model path and loads the world specified by NPS_GAZEBO_WORLD.

This function also obtaines a pointer to the aircraft model, named NPS_GAZEBO_AC_NAME ('paparazzi_uav' by default). This pointer, 'model', is used to read the state and write actuator commands in gazebo_read and _write.

Definition at line 251 of file nps_fdm_gazebo.cpp.

References model, NPS_GAZEBO_AC_NAME, and NPS_GAZEBO_WORLD.

Referenced by nps_fdm_run_step().

+ Here is the caller graph for this function:

void nps_fdm_init ( double  dt)

Set JSBsim specific fields that are not used for Gazebo.

Parameters
dt

Definition at line 168 of file nps_fdm_gazebo.cpp.

References NpsFdm::curr_dt, fdm, NpsFdm::init_dt, and NpsFdm::nan_count.

void nps_fdm_run_step ( bool  launch,
double *  commands,
int  commands_nb 
)

Update the simulation state.

Parameters
launch
commands
commands_nb

Definition at line 181 of file nps_fdm_gazebo.cpp.

References gazebo_initialized, gazebo_read(), gazebo_write(), init_gazebo(), and model.

+ Here is the call graph for this function:

void nps_fdm_set_temperature ( double  temp,
double  h 
)

Set temperature in degrees Celcius at given height h above MSL.

Definition at line 233 of file nps_fdm_gazebo.cpp.

void nps_fdm_set_turbulence ( double  wind_speed,
int  turbulence_severity 
)

Definition at line 226 of file nps_fdm_gazebo.cpp.

void nps_fdm_set_wind ( double  speed,
double  dir 
)

Definition at line 213 of file nps_fdm_gazebo.cpp.

void nps_fdm_set_wind_ned ( double  wind_north,
double  wind_east,
double  wind_down 
)

Definition at line 219 of file nps_fdm_gazebo.cpp.

struct DoubleVect3 to_pprz_body ( gazebo::math::Vector3  body_g)

Definition at line 126 of file nps_fdm_gazebo.cpp.

References DoubleVect3::x, DoubleVect3::y, and DoubleVect3::z.

Referenced by gazebo_read().

+ Here is the caller graph for this function:

struct EcefCoor_d to_pprz_ecef ( ignition::math::Vector3d  ecef_i)

Definition at line 99 of file nps_fdm_gazebo.cpp.

References EcefCoor_d::x, EcefCoor_d::y, and EcefCoor_d::z.

Referenced by gazebo_read().

+ Here is the caller graph for this function:

struct DoubleEulers to_pprz_eulers ( gazebo::math::Quaternion  quat)

Definition at line 144 of file nps_fdm_gazebo.cpp.

References DoubleEulers::phi, DoubleEulers::psi, and DoubleEulers::theta.

Referenced by gazebo_read().

+ Here is the caller graph for this function:

struct LlaCoor_d to_pprz_lla ( ignition::math::Vector3d  lla_i)

Definition at line 117 of file nps_fdm_gazebo.cpp.

References LlaCoor_d::alt, LlaCoor_d::lat, and LlaCoor_d::lon.

Referenced by gazebo_read().

+ Here is the caller graph for this function:

struct DoubleVect3 to_pprz_ltp ( gazebo::math::Vector3  xyz)

Definition at line 153 of file nps_fdm_gazebo.cpp.

References DoubleVect3::x, DoubleVect3::y, and DoubleVect3::z.

Referenced by gazebo_read().

+ Here is the caller graph for this function:

struct NedCoor_d to_pprz_ned ( ignition::math::Vector3d  global)

Definition at line 108 of file nps_fdm_gazebo.cpp.

References NedCoor_d::x, NedCoor_d::y, and NedCoor_d::z.

Referenced by gazebo_read().

+ Here is the caller graph for this function:

struct DoubleRates to_pprz_rates ( gazebo::math::Vector3  body_g)

Definition at line 135 of file nps_fdm_gazebo.cpp.

References DoubleRates::p, DoubleRates::q, and DoubleRates::r.

Referenced by gazebo_read().

+ Here is the caller graph for this function:

Variable Documentation

struct NpsFdm fdm

Holds all necessary NPS FDM state information.

Definition at line 87 of file nps_fdm_gazebo.cpp.

Referenced by gazebo_read(), and nps_fdm_init().

bool gazebo_initialized = false
static

Definition at line 90 of file nps_fdm_gazebo.cpp.

Referenced by nps_fdm_run_step().

gazebo::physics::ModelPtr model = NULL
static