gazebo_pressure_plugin.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Pavel Vechersky, ASL, ETH Zurich, Switzerland
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ROTORS_GAZEBO_PLUGINS_PRESSURE_PLUGIN_H
18 #define ROTORS_GAZEBO_PLUGINS_PRESSURE_PLUGIN_H
19 
20 #include <random>
21 
22 #include <glog/logging.h>
23 
24 #include <gazebo/common/Plugin.hh>
25 #include <gazebo/common/common.hh>
26 #include <gazebo/gazebo.hh>
27 #include <gazebo/physics/physics.hh>
28 
29 #include "FluidPressure.pb.h"
30 
32 
33 namespace gazebo {
34 // Constants
35 static constexpr double kGasConstantNmPerKmolKelvin = 8314.32;
36 static constexpr double kMeanMolecularAirWeightKgPerKmol = 28.9644;
37 static constexpr double kGravityMagnitude = 9.80665;
38 static constexpr double kEarthRadiusMeters = 6356766.0;
39 static constexpr double kPressureOneAtmospherePascals = 101325.0;
40 static constexpr double kSeaLevelTempKelvin = 288.15;
41 static constexpr double kTempLapseKelvinPerMeter = 0.0065;
42 static constexpr double kAirConstantDimensionless = kGravityMagnitude *
43  kMeanMolecularAirWeightKgPerKmol /
44  (kGasConstantNmPerKmolKelvin * -kTempLapseKelvinPerMeter);
45 
46 // Default values
47 static const std::string kDefaultPressurePubTopic = "air_pressure";
48 static constexpr double kDefaultRefAlt = 500.0; /* m, Zurich: h=+500m, WGS84) */
49 static constexpr double kDefaultPressureVar = 0.0; /* Pa^2, pressure variance */
50 
51 class GazeboPressurePlugin : public ModelPlugin {
52  public:
55 
57  virtual ~GazeboPressurePlugin();
58 
59  typedef std::normal_distribution<> NormalDistribution;
60 
61  protected:
64  void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
65 
67  void OnUpdate(const common::UpdateInfo&);
68 
69  private:
73 
78  void CreatePubsAndSubs();
79 
81  gazebo::transport::NodePtr node_handle_;
82 
84  gazebo::transport::PublisherPtr pressure_pub_;
85 
87  std::string namespace_;
88 
90  std::string pressure_topic_;
91 
93  std::string frame_id_;
94 
96  physics::WorldPtr world_;
97 
99  physics::ModelPtr model_;
100 
102  physics::LinkPtr link_;
103 
105  event::ConnectionPtr updateConnection_;
106 
108  double ref_alt_;
109 
112 
114  NormalDistribution pressure_n_[1];
115 
118  // and then published onto a topic
119  gz_sensor_msgs::FluidPressure pressure_message_;
120 
121  std::mt19937 random_generator_;
122 };
123 }
124 
125 #endif // ROTORS_GAZEBO_PLUGINS_PRESSURE_PLUGIN_H
static constexpr double kEarthRadiusMeters
std::normal_distribution NormalDistribution
event::ConnectionPtr updateConnection_
Pointer to the update event connection.
physics::LinkPtr link_
Pointer to the link.
NormalDistribution pressure_n_[1]
Normal distribution for pressure noise.
double pressure_var_
Pressure measurement variance (Pa^2).
physics::ModelPtr model_
Pointer to the model.
static constexpr double kMeanMolecularAirWeightKgPerKmol
physics::WorldPtr world_
Pointer to the world.
std::string frame_id_
Frame ID for pressure messages.
void OnUpdate(const common::UpdateInfo &)
This gets called by the world update start event.
gz_sensor_msgs::FluidPressure pressure_message_
Fluid pressure message.
gazebo::transport::PublisherPtr pressure_pub_
Pressure message publisher.
gazebo::transport::NodePtr node_handle_
Handle for the Gazebo node.
bool pubs_and_subs_created_
Flag that is set to true once CreatePubsAndSubs() is called, used to prevent CreatePubsAndSubs() from...
static constexpr double kPressureOneAtmospherePascals
static const std::string kDefaultPressurePubTopic
static constexpr double kDefaultPressureVar
double ref_alt_
Reference altitude (meters).
static constexpr double kSeaLevelTempKelvin
static constexpr double kTempLapseKelvinPerMeter
void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Called when the plugin is first created, and after the world has been loaded. This function should no...
static constexpr double kGasConstantNmPerKmolKelvin
static constexpr double kDefaultRefAlt
virtual ~GazeboPressurePlugin()
Destructor.
static constexpr double kAirConstantDimensionless
static constexpr double kGravityMagnitude
void CreatePubsAndSubs()
Creates all required publishers and subscribers, incl. routing of messages to/from ROS if required...
std::string namespace_
Transport namespace.
std::string pressure_topic_
Topic name for pressure messages.


rotors_gazebo_plugins
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Mon Feb 28 2022 23:39:04