WavefieldEntity.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Rhys Mainwaring
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 */
17 
18 #include <iostream>
19 #include <string>
20 
21 #include <gazebo/common/Assert.hh>
22 #include <gazebo/physics/physics.hh>
23 
24 #include <ignition/math/Vector2.hh>
25 
29 
30 using namespace gazebo;
31 using namespace common;
32 
33 namespace asv
34 {
35 
37 // WavefieldEntity
38 
42  {
44  public: ignition::math::Vector2d size;
45 
48  public: ignition::math::Vector2d cellCount;
49 
51  public: std::shared_ptr<asv::WaveParameters> waveParams;
52  };
53 
55  WavefieldEntity::~WavefieldEntity()
56  {
57  }
58 
60  WavefieldEntity::WavefieldEntity(physics::BasePtr _parent) :
61  Base(_parent),
62  data(new WavefieldEntityPrivate())
63  {
64  }
65 
67  void WavefieldEntity::Load(sdf::ElementPtr _sdf)
68  {
69  GZ_ASSERT(_sdf != nullptr, "Invalid parameter _sdf");
70 
71  Base::Load(_sdf);
72 
73  // Wavefield Parameters
74  this->data->size = Utilities::SdfParamVector2(*_sdf, "size", \
75  ignition::math::Vector2d(1000, 1000));
76  this->data->cellCount = Utilities::SdfParamVector2(*_sdf, "cell_count", \
77  ignition::math::Vector2d(50, 50));
78 
79  // Wave Parameters
80  gzmsg << "WavefieldEntity: Loading WaveParameters from SDF" << std::endl;
81  this->data->waveParams.reset(new WaveParameters());
82  if (_sdf->HasElement("wave"))
83  {
84  gzmsg << "Found <wave> tag" << std::endl;
85  sdf::ElementPtr sdfWave = _sdf->GetElement("wave");
86  this->data->waveParams->SetFromSDF(*sdfWave);
87  }
88  else
89  {
90  gzmsg << "Missing <wave> tag" << std::endl;
91  }
92  // @DEBUG_INFO
93  this->data->waveParams->DebugPrint();
94  }
95 
98  {
99  Base::Fini();
100  }
101 
104  {
105  }
106 
109  {
110  }
111 
114  {
115  }
116 
118  std::shared_ptr<const WaveParameters> WavefieldEntity::GetWaveParams() const
119  {
120  return this->data->waveParams;
121  }
122 
124  std::string WavefieldEntity::MakeName(const std::string& _parentName)
125  {
126  return std::string(_parentName + "::wavefield_entity");
127  }
128 }
virtual void Update()
Update the object.
virtual void Fini()
Finialize the object.
virtual void Init()
Initialize the object.
This file defines utilities for extracting parameters from SDF.
static ignition::math::Vector2d SdfParamVector2(sdf::Element &_sdf, const std::string &_paramName, const ignition::math::Vector2d _defaultVal)
Extract a named Vector2 parameter from an SDF element.
Definition: Utilities.cc:81
virtual void Load(sdf::ElementPtr _sdf)
Load.
std::shared_ptr< WavefieldEntityPrivate > data
ignition::math::Vector2d cellCount
The number of grid cells in the wavefield. Default value is [50 50].
A class to manage the parameters for generating a wave.
Definition: Wavefield.hh:58
virtual void Reset()
Reset the object.
std::shared_ptr< asv::WaveParameters > waveParams
The wave parameters.
static std::string MakeName(const std::string &_parentName)
Make a wave field entity name given a parent object name.
ignition::math::Vector2d size
The size of the wavefield. Default value is [1000 1000].
Definition: Geometry.hh:28
This file contains definitions for classes used to manage a wave field. This includes wave parameters...
std::shared_ptr< const WaveParameters > GetWaveParams() const
Get a pointer to the wave pararameters.
This file contains the definition for a Gazebo physics object that allows a wave field to be added in...


wave_gazebo_plugins
Author(s): Rhys Mainwaring
autogenerated on Thu May 7 2020 03:54:44