ROSBasePlugin.hh
Go to the documentation of this file.
1 // Copyright (c) 2016 The UUV Simulator Authors.
2 // All rights reserved.
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 #ifndef __ROS_BASE_PLUGIN_HH__
17 #define __ROS_BASE_PLUGIN_HH__
18 
19 #include <gazebo/common/common.hh>
20 #include <gazebo/physics/physics.hh>
22 #include <ros/ros.h>
23 #include <std_msgs/Bool.h>
24 #include <uuv_sensor_ros_plugins_msgs/ChangeSensorState.h>
25 #include <geometry_msgs/TransformStamped.h>
26 #include <gazebo/sensors/Noise.hh>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/bind.hpp>
29 #include <tf/tfMessage.h>
30 #include <tf/tf.h>
31 #include <chrono>
32 #include <random>
33 #include <string>
34 #include <map>
35 
36 
37 namespace gazebo
38 {
40  {
42  public: ROSBasePlugin();
43 
45  public: virtual ~ROSBasePlugin();
46 
48  public: bool InitBasePlugin(sdf::ElementPtr _sdf);
49 
51  public: virtual bool OnUpdate(const common::UpdateInfo&) = 0;
52 
54  public: bool AddNoiseModel(std::string _name, double _sigma);
55 
57  protected: std::string robotNamespace;
58 
60  protected: std::string sensorOutputTopic;
61 
63  protected: physics::WorldPtr world;
64 
66  protected: event::ConnectionPtr updateConnection;
67 
69  protected: common::Time lastMeasurementTime;
70 
72  protected: double updateRate;
73 
75  protected: double noiseSigma;
76 
78  protected: double noiseAmp;
79 
83  protected: bool gazeboMsgEnabled;
84 
86  protected: std::default_random_engine rndGen;
87 
89  protected: std::map<std::string, std::normal_distribution<double>>
91 
93  protected: std_msgs::Bool isOn;
94 
97 
99  protected: transport::NodePtr gazeboNode;
100 
103 
105  protected: transport::PublisherPtr gazeboSensorOutputPub;
106 
109 
112 
114  protected: ignition::math::Pose3d referenceFrame;
115 
118 
120  protected: std::string referenceFrameID;
121 
123  protected: bool isReferenceInit;
124 
126  protected: physics::LinkPtr referenceLink;
127 
129  protected: bool IsOn();
130 
132  protected: void PublishState();
133 
135  protected: bool ChangeSensorState(
136  uuv_sensor_ros_plugins_msgs::ChangeSensorState::Request& _req,
137  uuv_sensor_ros_plugins_msgs::ChangeSensorState::Response& _res);
138 
140  protected: void GetTFMessage(const tf::tfMessage::ConstPtr &_msg);
141 
144  protected: double GetGaussianNoise(double _amp);
145 
148  protected: double GetGaussianNoise(std::string _name, double _amp);
149 
152  protected: bool EnableMeasurement(const common::UpdateInfo& _info) const;
153 
155  protected: void UpdateReferenceFramePose();
156  };
157 }
158 
159 #endif // __ROS_BASE_PLUGIN_HH__
physics::LinkPtr referenceLink
Reference link.
double updateRate
Sensor update rate.
double GetGaussianNoise(double _amp)
Returns noise value for a function with zero mean from the default Gaussian noise model...
bool EnableMeasurement(const common::UpdateInfo &_info) const
Enables generation of simulated measurement if the timeout since the last update has been reached...
ignition::math::Pose3d referenceFrame
Pose of the reference frame wrt world frame.
physics::WorldPtr world
Pointer to the world.
ROSBasePlugin()
Class constructor.
common::Time lastMeasurementTime
(Simulation) time when the last sensor measurement was generated.
double noiseAmp
Noise amplitude.
std::map< std::string, std::normal_distribution< double > > noiseModels
Normal distribution describing the noise models.
event::ConnectionPtr updateConnection
Pointer to the update event connection.
bool ChangeSensorState(uuv_sensor_ros_plugins_msgs::ChangeSensorState::Request &_req, uuv_sensor_ros_plugins_msgs::ChangeSensorState::Response &_res)
Change sensor state (ON/OFF)
void UpdateReferenceFramePose()
Updates the pose of the reference frame wrt the world frame.
bool AddNoiseModel(std::string _name, double _sigma)
Add noise normal distribution to the list.
transport::NodePtr gazeboNode
Gazebo&#39;s node handle for transporting measurement messages.
virtual bool OnUpdate(const common::UpdateInfo &)=0
Update callback from simulation.
bool InitBasePlugin(sdf::ElementPtr _sdf)
Initialize base plugin.
double noiseSigma
Noise standard deviation.
std_msgs::Bool isOn
Flag to control the generation of output messages.
transport::PublisherPtr gazeboSensorOutputPub
Gazebo&#39;s publisher for transporting measurement messages.
std::string referenceFrameID
Frame ID of the reference frame.
virtual ~ROSBasePlugin()
Class destructor.
ros::ServiceServer changeSensorSrv
Service server object.
std::default_random_engine rndGen
Pseudo random number generator.
std::string sensorOutputTopic
Name of the sensor&#39;s output topic.
ros::Publisher rosSensorOutputPub
Gazebo&#39;s publisher for transporting measurement messages.
boost::shared_ptr< ros::NodeHandle > rosNode
ROS node handle for communication with ROS.
ros::Publisher pluginStatePub
ROS publisher for the switchable sensor data.
std::string robotNamespace
Robot namespace.
bool isReferenceInit
Flag set to true if reference frame initialized.
ros::Subscriber tfStaticSub
ROS subscriber for the TF static reference frame.
bool gazeboMsgEnabled
Flag set to true if the Gazebo sensors messages are supposed to be published as well (it can avoid un...
void PublishState()
Publish the current state of the plugin.
bool IsOn()
Returns true if the plugin is activated.
void GetTFMessage(const tf::tfMessage::ConstPtr &_msg)
Callback function for the static TF message.


uuv_sensor_ros_plugins
Author(s): Musa Morena Marcusso Manhaes , Sebastian Scherer , Luiz Ricardo Douat
autogenerated on Mon Jul 1 2019 19:39:20