27 this->
isOn.data =
true;
32 unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
33 this->
rndGen = std::default_random_engine(seed);
48 GZ_ASSERT(this->
world != NULL,
"World object not available");
50 GetSDFParam<std::string>(_sdf,
"robot_namespace", this->
robotNamespace,
"");
51 GZ_ASSERT(!this->robotNamespace.empty(),
"Robot namespace was not provided");
54 std::string sensorTopic;
55 GetSDFParam<std::string>(_sdf,
"sensor_topic", sensorTopic,
"");
56 if (!sensorTopic.empty())
59 "Sensor output topic has not been provided");
62 GetSDFParam<double>(_sdf,
"update_rate", this->
updateRate, 30.0);
69 this->
gazeboNode = transport::NodePtr(
new transport::Node());
70 this->gazeboNode->Init(this->robotNamespace);
75 gzerr <<
"Not loading sensor plugin since ROS has not been properly " 76 <<
"initialized." << std::endl;
83 if (_sdf->HasElement(
"static_reference_frame"))
85 GetSDFParam<std::string>(_sdf,
"static_reference_frame",
87 gzmsg <<
"Static reference frame=" << this->referenceFrameID << std::endl;
92 if (this->referenceFrameID.compare(
"world") != 0)
101 else if (_sdf->HasElement(
"reference_link_name"))
104 "Reference link has not been initialized");
114 #if GAZEBO_MAJOR_VERSION >= 8 122 GetSDFParam<bool>(_sdf,
"is_on", isSensorOn,
true);
123 this->
isOn.data = isSensorOn;
134 GetSDFParam<double>(_sdf,
"noise_sigma", this->
noiseSigma, 0.0);
135 GZ_ASSERT(this->noiseSigma >= 0.0,
136 "Signal noise sigma must be greater or equal to zero");
138 GetSDFParam<double>(_sdf,
"noise_amplitude", this->
noiseAmp, 0.0);
139 GZ_ASSERT(this->noiseAmp >= 0.0,
140 "Signal noise amplitude must be greater or equal to zero");
152 if (_msg->transforms.size() > 0)
154 for (
auto t : _msg->transforms)
156 if (!t.header.frame_id.compare(
"world") &&
160 t.transform.translation.x,
161 t.transform.translation.y,
162 t.transform.translation.z);
165 t.transform.rotation.w,
166 t.transform.rotation.x,
167 t.transform.rotation.y,
168 t.transform.rotation.z);
177 uuv_sensor_ros_plugins_msgs::ChangeSensorState::Request& _req,
178 uuv_sensor_ros_plugins_msgs::ChangeSensorState::Response& _res)
180 this->
isOn.data = _req.on;
188 _res.message = message;
189 gzmsg << message << std::endl;
209 "Gaussian noise model does not exist");
220 this->
noiseModels[_name] = std::normal_distribution<double>(0.0, _sigma);
227 return this->
isOn.data;
233 common::Time current_time = _info.simTime;
245 #if GAZEBO_MAJOR_VERSION >= 8 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...
void publish(const boost::shared_ptr< M > &message) const
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.
ROSCPP_DECL bool isInitialized()
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's node handle for transporting measurement messages.
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.
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's output topic.
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.