gazebo_wind_plugin.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Fadri Furrer, ASL, ETH Zurich, Switzerland
3  * Copyright 2015 Michael Burri, ASL, ETH Zurich, Switzerland
4  * Copyright 2015 Mina Kamel, ASL, ETH Zurich, Switzerland
5  * Copyright 2015 Janosch Nikolic, ASL, ETH Zurich, Switzerland
6  * Copyright 2015 Markus Achtelik, ASL, ETH Zurich, Switzerland
7  * Copyright 2016 Geoffrey Hunter <gbmhunter@gmail.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 
23 #ifndef ROTORS_GAZEBO_PLUGINS_GAZEBO_WIND_PLUGIN_H
24 #define ROTORS_GAZEBO_PLUGINS_GAZEBO_WIND_PLUGIN_H
25 
26 #include <string>
27 
28 #include <gazebo/common/common.hh>
29 #include <gazebo/common/Plugin.hh>
30 #include <gazebo/gazebo.hh>
31 #include <gazebo/physics/physics.hh>
32 
33 #include <mav_msgs/default_topics.h> // This comes from the mav_comm repo
34 
36 
37 #include "WindSpeed.pb.h" // Wind speed message
38 #include "WrenchStamped.pb.h" // Wind force message
39 
40 namespace gazebo {
41 // Default values
42 static const std::string kDefaultFrameId = "world";
43 static const std::string kDefaultLinkName = "base_link";
44 static const std::string kDefaultWindSpeedPubTopic = "wind_speed";
45 
46 static constexpr double kDefaultWindForceMean = 0.0;
47 static constexpr double kDefaultWindForceVariance = 0.0;
48 static constexpr double kDefaultWindGustForceMean = 0.0;
49 static constexpr double kDefaultWindGustForceVariance = 0.0;
50 
51 static constexpr double kDefaultWindGustStart = 10.0;
52 static constexpr double kDefaultWindGustDuration = 0.0;
53 
54 static constexpr double kDefaultWindSpeedMean = 0.0;
55 static constexpr double kDefaultWindSpeedVariance = 0.0;
56 
57 static const ignition::math::Vector3d kDefaultWindDirection = ignition::math::Vector3d (1, 0, 0);
58 static const ignition::math::Vector3d kDefaultWindGustDirection = ignition::math::Vector3d (0, 1, 0);
59 
60 static constexpr bool kDefaultUseCustomStaticWindField = false;
61 
62 
63 
67 class GazeboWindPlugin : public ModelPlugin {
68  public:
70  : ModelPlugin(),
72  wind_force_pub_topic_(mav_msgs::default_topics::EXTERNAL_FORCE),
73  wind_speed_pub_topic_(mav_msgs::default_topics::WIND_SPEED),
74  wind_force_mean_(kDefaultWindForceMean),
75  wind_force_variance_(kDefaultWindForceVariance),
76  wind_gust_force_mean_(kDefaultWindGustForceMean),
77  wind_gust_force_variance_(kDefaultWindGustForceVariance),
78  wind_speed_mean_(kDefaultWindSpeedMean),
79  wind_speed_variance_(kDefaultWindSpeedVariance),
80  wind_direction_(kDefaultWindDirection),
81  wind_gust_direction_(kDefaultWindGustDirection),
82  use_custom_static_wind_field_(kDefaultUseCustomStaticWindField),
83  frame_id_(kDefaultFrameId),
84  link_name_(kDefaultLinkName),
85  node_handle_(nullptr),
86  pubs_and_subs_created_(false) {}
87 
88  virtual ~GazeboWindPlugin();
89 
90  protected:
91 
95  void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
96 
99  void OnUpdate(const common::UpdateInfo& /*_info*/);
100 
101  private:
102 
106 
111  void CreatePubsAndSubs();
112 
114  event::ConnectionPtr update_connection_;
115 
116  physics::WorldPtr world_;
117  physics::ModelPtr model_;
118  physics::LinkPtr link_;
119 
120  std::string namespace_;
121 
122  std::string frame_id_;
123  std::string link_name_;
126 
133 
134  ignition::math::Vector3d xyz_offset_;
135  ignition::math::Vector3d wind_direction_;
136  ignition::math::Vector3d wind_gust_direction_;
137 
138  common::Time wind_gust_end_;
139  common::Time wind_gust_start_;
140 
143  float min_x_;
144  float min_y_;
145  int n_x_;
146  int n_y_;
147  float res_x_;
148  float res_y_;
149  std::vector<float> vertical_spacing_factors_;
150  std::vector<float> bottom_z_;
151  std::vector<float> top_z_;
152  std::vector<float> u_;
153  std::vector<float> v_;
154  std::vector<float> w_;
155 
158  void ReadCustomWindField(std::string& custom_wind_field_path);
159 
161 
168  ignition::math::Vector3d LinearInterpolation(double position, ignition::math::Vector3d * values, double* points) const;
169 
179  ignition::math::Vector3d BilinearInterpolation(double* position, ignition::math::Vector3d * values, double* points) const;
180 
190  ignition::math::Vector3d TrilinearInterpolation(ignition::math::Vector3d link_position, ignition::math::Vector3d * values, double* points) const;
191 
192  gazebo::transport::PublisherPtr wind_force_pub_;
193  gazebo::transport::PublisherPtr wind_speed_pub_;
194 
195  gazebo::transport::NodePtr node_handle_;
196 
200  gz_geometry_msgs::WrenchStamped wrench_stamped_msg_;
201 
205  gz_mav_msgs::WindSpeed wind_speed_msg_;
206 };
207 }
208 
209 #endif // ROTORS_GAZEBO_PLUGINS_GAZEBO_WIND_PLUGIN_H
static const std::string kDefaultFrameId
ignition::math::Vector3d BilinearInterpolation(double *position, ignition::math::Vector3d *values, double *points) const
Bilinear interpolation.
static constexpr double kDefaultWindGustForceVariance
static const std::string kDefaultLinkName
std::vector< float > u_
event::ConnectionPtr update_connection_
Pointer to the update event connection.
void OnUpdate(const common::UpdateInfo &)
Called when the world is updated.
static constexpr bool kDefaultUseCustomStaticWindField
static constexpr double kDefaultWindForceMean
std::vector< float > vertical_spacing_factors_
static constexpr double kDefaultWindGustStart
static const ignition::math::Vector3d kDefaultWindGustDirection
static constexpr double kDefaultWindGustForceMean
static constexpr double kDefaultWindSpeedMean
static const std::string kDefaultNamespace
Definition: common.h:48
bool pubs_and_subs_created_
Flag that is set to true once CreatePubsAndSubs() is called, used to prevent CreatePubsAndSubs() from...
void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load the plugin.
ignition::math::Vector3d wind_direction_
static const std::string kDefaultWindSpeedPubTopic
bool use_custom_static_wind_field_
Variables for custom wind field generation.
std::vector< float > w_
std::vector< float > top_z_
static constexpr double kDefaultWindGustDuration
gazebo::transport::NodePtr node_handle_
ignition::math::Vector3d wind_gust_direction_
gz_mav_msgs::WindSpeed wind_speed_msg_
Gazebo message for sending wind speed data.
ignition::math::Vector3d xyz_offset_
gazebo::transport::PublisherPtr wind_force_pub_
static constexpr double kDefaultWindForceVariance
ignition::math::Vector3d LinearInterpolation(double position, ignition::math::Vector3d *values, double *points) const
Functions for trilinear interpolation of wind field at aircraft position.
This gazebo plugin simulates wind acting on a model.
void CreatePubsAndSubs()
Creates all required publishers and subscribers, incl. routing of messages to/from ROS if required...
ignition::math::Vector3d TrilinearInterpolation(ignition::math::Vector3d link_position, ignition::math::Vector3d *values, double *points) const
Trilinear interpolation.
gz_geometry_msgs::WrenchStamped wrench_stamped_msg_
Gazebo message for sending wind data.
std::vector< float > bottom_z_
static constexpr double kDefaultWindSpeedVariance
static const ignition::math::Vector3d kDefaultWindDirection
gazebo::transport::PublisherPtr wind_speed_pub_
void ReadCustomWindField(std::string &custom_wind_field_path)
Reads wind data from a text file and saves it.
std::vector< float > v_


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