UmbilicalPlugin.cc
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 
17 
18 namespace gazebo
19 {
22 {
23  std::cout << __PRETTY_FUNCTION__ << std::endl;
24 }
25 
28 {
29  if (this->updateConnection)
30  {
31 #if GAZEBO_MAJOR_VERSION >= 8
32  this->updateConnection.reset();
33 #else
34  event::Events::DisconnectWorldUpdateBegin(this->updateConnection);
35 #endif
36  }
37 }
38 
40 void UmbilicalPlugin::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
41 {
42  this->model = _model;
43  this->world = _model->GetWorld();
44 
45  GZ_ASSERT(_sdf->HasElement("umbilical_model"),
46  "Could not find umbilical_model.");
47  this->umbilical.reset(
48  UmbilicalModelFactory::GetInstance().CreateUmbilicalModel(
49  _sdf->GetElement("umbilical_model"), _model));
50 
51  this->umbilical->Init();
52 
53  // Initialize the transport node
54  this->node = transport::NodePtr(new transport::Node());
55  std::string worldName;
56 #if GAZEBO_MAJOR_VERSION >= 8
57  worldName = this->world->Name();
58 #else
59  worldName = this->world->GetName();
60 #endif
61  this->node->Init(worldName);
62 
63  // If fluid topic is available, subscribe to it
64  GZ_ASSERT(_sdf->HasElement("flow_velocity_topic"),
65  "Umbilical model requires flow velocity topic");
66  std::string flowTopic = _sdf->Get<std::string>("flow_velocity_topic");
67  GZ_ASSERT(!flowTopic.empty(),
68  "Fluid velocity topic tag cannot be empty");
69  this->flowSubscriber = this->node->Subscribe(flowTopic,
71 
72  // Listen to the update event. This event is broadcast every
73  // simulation iteration.
74  this->updateConnection =
75  event::Events::ConnectWorldUpdateBegin(
76  boost::bind(&UmbilicalPlugin::OnUpdate, this, _1));
77 }
78 
80 void UmbilicalPlugin::UpdateFlowVelocity(ConstVector3dPtr &_msg)
81 {
82  this->flowVelocity.X() = _msg->x();
83  this->flowVelocity.Y() = _msg->y();
84  this->flowVelocity.Z() = _msg->z();
85 }
86 
88 void UmbilicalPlugin::OnUpdate(const common::UpdateInfo &_info)
89 {
90  this->umbilical->OnUpdate(_info, this->flowVelocity);
91 }
92 
94 }
gazebo::physics::ModelPtr model
Pointer to the model structure.
gazebo::transport::SubscriberPtr flowSubscriber
Subcriber to flow message.
static UmbilicalModelFactory & GetInstance()
Return the singleton instance of this factory.
std::shared_ptr< UmbilicalModel > umbilical
Pointer to UmbilicalModel used in this plugin.
GZ_REGISTER_MODEL_PLUGIN(UmbilicalPlugin)
gazebo::transport::NodePtr node
Gazebo node.
Model plugin for the umbilical (tether) of an ROV.
UmbilicalPlugin()
Destructor.
event::ConnectionPtr updateConnection
Pointer to the update event connection.
~UmbilicalPlugin()
Constructor.
ignition::math::Vector3d flowVelocity
Flow velocity vector read from topic.
virtual void OnUpdate(const common::UpdateInfo &)
Update callback from simulation.
void UpdateFlowVelocity(ConstVector3dPtr &_msg)
Reads flow velocity topic.
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load plugin and its configuration from sdf.
gazebo::physics::WorldPtr world
Pointer to the world plugin.


uuv_gazebo_plugins
Author(s): Musa Morena Marcusso Manhaes , Sebastian Scherer , Luiz Ricardo Douat
autogenerated on Thu Jun 18 2020 03:28:24