UmbilicalModel.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  sdf::ElementPtr _sdf,
29  physics::ModelPtr _model)
30 {
31  std::cout << __PRETTY_FUNCTION__ << std::endl;
32  if (!_sdf->HasElement("type"))
33  {
34  std::cerr << "umbilical_model does not have an type element"
35  << std::endl;
36  return NULL;
37  }
38 
39  std::string identifier = _sdf->Get<std::string>("type");
40 
41  if (creators_.find(identifier) == creators_.end())
42  {
43  std::cerr << "Cannot create UmbilicalModel with unknown identifier: "
44  << identifier << std::endl;
45  return NULL;
46  }
47 
48  return creators_[identifier](_sdf, _model);
49 }
50 
53 {
54  static UmbilicalModelFactory instance;
55  return instance;
56 }
57 
59 bool UmbilicalModelFactory::RegisterCreator(const std::string& _identifier,
60  UmbilicalModelCreator _creator)
61 {
62  if (creators_.find(_identifier) != creators_.end())
63  {
64  std::cerr << "Warning: Registering UmbilicalModel with identifier: "
65  << _identifier << " twice" << std::endl;
66  }
67  creators_[_identifier] = _creator;
68 
69  std::cout << "Registered UmbilicalModel type "
70  << _identifier << std::endl;
71  return true;
72 }
73 
75 const std::string UmbilicalModelBerg::IDENTIFIER = "Berg";
77 
78 UmbilicalModelBerg::UmbilicalModelBerg(sdf::ElementPtr _sdf,
79  physics::ModelPtr _model)
80 {
81  GZ_ASSERT(_sdf->HasElement("connector_link"),
82  "Could not find connector_link.");
83  std::string connectorLinkName = _sdf->Get<std::string>("connector_link");
84  this->connector = _model->GetLink(connectorLinkName);
85  GZ_ASSERT(this->connector, "connector_link is invalid");
86 
87  GZ_ASSERT(_sdf->HasElement("diameter"), "Could not find diameter.");
88  this->diameter = _sdf->Get<double>("diameter");
89 
90  GZ_ASSERT(_sdf->HasElement("water_density"), "Could not find water_density.");
91  this->rho = _sdf->Get<double>("water_density");
92 }
93 
96  physics::ModelPtr _model)
97 {
98  std::cout << __PRETTY_FUNCTION__ << std::endl;
99  return new UmbilicalModelBerg(_sdf, _model);
100 }
101 
103 void UmbilicalModelBerg::OnUpdate(const common::UpdateInfo &_info,
104  const ignition::math::Vector3d& _flow)
105 {
106  ignition::math::Pose3d pose;
107 #if GAZEBO_MAJOR_VERSION >= 8
108  pose = this->connector->WorldPose();
109 #else
110  pose = this->connector->GetWorldPose().Ign();
111 #endif
112 
113  double h = -pose.Pos().Z();
114 
115  GZ_ASSERT(h < 10.0, // Allow for some wiggle room when the UUV emerges.
116  "z coordinate should be negative");
117 
118  ignition::math::Vector3d uvR;
119 
120 #if GAZEBO_MAJOR_VERSION >= 8
121  uvR = _flow - this->connector->WorldLinearVel();
122 #else
123  uvR = _flow - this->connector->GetWorldLinearVel().Ign();
124 #endif
125 
126  double uR2 = uvR.X() * std::abs(uvR.X());
127  double vR2 = uvR.Y() * std::abs(uvR.Y());
128  double factor = 0.25 * 1.2 * this->rho;
129 
130  ignition::math::Vector3d fWorld(uR2, vR2, 0.);
131  this->connector->AddForce(fWorld * factor);
132 }
133 }
Factory singleton class that creates an UmbilicalModel from sdf.
static const std::string IDENTIFIER
The unique identifier of this UmbilicalModel.
static UmbilicalModelFactory & GetInstance()
Return the singleton instance of this factory.
physics::LinkPtr connector
Moving connector link of this umbilical.
static UmbilicalModel * create(sdf::ElementPtr _sdf, physics::ModelPtr _model)
Create UmbilicalModel according to its description.
Various umbilical models.
UmbilicalModel * CreateUmbilicalModel(sdf::ElementPtr _sdf, physics::ModelPtr _model)
Create a ConversionFunction object according to its sdf Description.
virtual void Init()
Initialize model.
virtual void OnUpdate(const common::UpdateInfo &_info, const ignition::math::Vector3d &_flow)
Update Umbilical (and apply forces)
#define REGISTER_UMBILICALMODEL_CREATOR(type, creator)
Use the following macro before a ThrusterDynamics&#39;s definition:
bool RegisterCreator(const std::string &_identifier, UmbilicalModelCreator _creator)
Register an UmbilicalModel class with its creator.
UmbilicalModel *(* UmbilicalModelCreator)(sdf::ElementPtr, physics::ModelPtr)
Function pointer to create a certain conversion function.


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