gazebo_magnetometer_plugin.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Pavel Vechersky, ASL, ETH Zurich, Switzerland
3  * Copyright 2016 Geoffrey Hunter <gbmhunter@gmail.com>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
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_MAGNETOMETER_PLUGIN_H
18 #define ROTORS_GAZEBO_PLUGINS_MAGNETOMETER_PLUGIN_H
19 
20 #include <random>
21 
22 #include <gazebo/common/common.hh>
23 #include <gazebo/common/Plugin.hh>
24 #include <gazebo/gazebo.hh>
25 #include <gazebo/physics/physics.hh>
26 
27 #include "MagneticField.pb.h"
28 
31 
32 namespace gazebo {
33 
34 // Default magnetic field [Tesla] in NED frame, obtained from World Magnetic
35 // Model: (http://www.ngdc.noaa.gov/geomag-web/#igrfwmm) for Zurich:
36 // lat=+47.3667degN, lon=+8.5500degE, h=+500m, WGS84
37 static constexpr double kDefaultRefMagNorth = 0.000021493;
38 static constexpr double kDefaultRefMagEast = 0.000000815;
39 static constexpr double kDefaultRefMagDown = 0.000042795;
40 
41 class GazeboMagnetometerPlugin : public ModelPlugin {
42 
43  public:
44  typedef std::normal_distribution<> NormalDistribution;
45  typedef std::uniform_real_distribution<> UniformDistribution;
46 
48  virtual ~GazeboMagnetometerPlugin();
49 
50  protected:
51  void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
52  void OnUpdate(const common::UpdateInfo&);
53 
54  private:
55 
59 
64  void CreatePubsAndSubs();
65 
66  std::string namespace_;
67  std::string magnetometer_topic_;
68  gazebo::transport::NodePtr node_handle_;
69  gazebo::transport::PublisherPtr magnetometer_pub_;
70  std::string frame_id_;
71 
73  physics::WorldPtr world_;
74 
76  physics::ModelPtr model_;
77 
79  physics::LinkPtr link_;
80 
82  event::ConnectionPtr updateConnection_;
83 
84  ignition::math::Vector3d mag_W_;
85 
89  gz_sensor_msgs::MagneticField mag_message_;
90 
91  NormalDistribution noise_n_[3];
92 
93  std::random_device random_device_;
94  std::mt19937 random_generator_;
95 };
96 
97 } // namespace gazebo
98 
99 #endif // ROTORS_GAZEBO_PLUGINS_MAGNETOMETER_PLUGIN_H
void CreatePubsAndSubs()
Creates all required publishers and subscribers, incl. routing of messages to/from ROS if required...
gz_sensor_msgs::MagneticField mag_message_
Magnetic field message.
bool pubs_and_subs_created_
Flag that is set to true once CreatePubsAndSubs() is called, used to prevent CreatePubsAndSubs() from...
void OnUpdate(const common::UpdateInfo &)
static constexpr double kDefaultRefMagEast
std::uniform_real_distribution UniformDistribution
static constexpr double kDefaultRefMagDown
gazebo::transport::PublisherPtr magnetometer_pub_
physics::LinkPtr link_
Pointer to the link.
physics::ModelPtr model_
Pointer to the model.
void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
static constexpr double kDefaultRefMagNorth
physics::WorldPtr world_
Pointer to the world.


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