23 #include <gazebo/common/Assert.hh> 24 #include <gazebo/common/common.hh> 25 #include <gazebo/physics/physics.hh> 35 GZ_REGISTER_MODEL_PLUGIN(WavefieldModelPlugin)
41 class WavefieldModelPluginPrivate
45 public: physics::WorldPtr
world;
48 public: physics::ModelPtr
model;
69 WavefieldModelPlugin::~WavefieldModelPlugin()
72 this->data->wavefieldEntity.reset();
75 this->data->updateConnection.reset();
78 WavefieldModelPlugin::WavefieldModelPlugin() :
92 GZ_ASSERT(_model !=
nullptr,
"Invalid parameter _model");
93 GZ_ASSERT(_sdf !=
nullptr,
"Invalid parameter _sdf");
96 this->
data->model = _model;
97 this->
data->world = _model->GetWorld();
98 GZ_ASSERT(this->
data->world !=
nullptr,
"Model has invalid World");
101 this->
data->updateConnection = event::Events::ConnectWorldUpdateBegin(
109 this->
data->wavefieldEntity.reset( \
110 new ::asv::WavefieldEntity(this->
data->model));
111 this->
data->wavefieldEntity->Load(_sdf);
112 this->
data->wavefieldEntity->Init();
115 this->
data->wavefieldEntity->SetName(
117 this->
data->model->AddChild(this->
data->wavefieldEntity);
135 #if GAZEBO_MAJOR_VERSION >= 8 136 this->
data->prevTime = this->
data->world->SimTime();
138 this->
data->prevTime = this->
data->world->GetSimTime();
144 GZ_ASSERT(this->
data->world !=
nullptr,
"World is NULL");
145 GZ_ASSERT(this->
data->model !=
nullptr,
"Model is NULL");
146 GZ_ASSERT(this->
data->wavefieldEntity !=
nullptr, \
147 "Wavefield Entity is NULL");
149 if (!this->
data->isStatic)
152 auto updatePeriod = 1.0/this->
data->updateRate;
153 #if GAZEBO_MAJOR_VERSION >= 8 154 auto currentTime = this->
data->world->SimTime();
156 auto currentTime = this->
data->world->GetSimTime();
159 if ((currentTime - this->
data->prevTime).Double() < updatePeriod)
163 this->
data->prevTime = currentTime;
166 this->
data->wavefieldEntity->Update();
171 gazebo::physics::WorldPtr _world,
172 const std::string& _waveModelName)
174 GZ_ASSERT(_world !=
nullptr,
"World is null");
175 #if GAZEBO_MAJOR_VERSION >= 8 176 physics::ModelPtr wavefieldModel = _world->ModelByName(_waveModelName);
178 physics::ModelPtr wavefieldModel = _world->GetModel(_waveModelName);
180 if (wavefieldModel ==
nullptr)
182 gzerr <<
"No Wavefield Model found with name '" 183 << _waveModelName <<
"'." << std::endl;
189 physics::BasePtr base = wavefieldModel->GetChild(wavefieldEntityName);
192 if (wavefieldEntity ==
nullptr)
194 gzerr <<
"Wavefield Entity is null: " 195 << wavefieldEntityName << std::endl;
202 return wavefieldEntity->GetWaveParams();
double updateRate
Update rate [30].
This file defines utilities for extracting parameters from SDF.
void OnUpdate()
Callback for World Update events.
event::ConnectionPtr updateConnection
Connection to the World Update events.
std::shared_ptr< WavefieldModelPluginPrivate > data
A class to manage a wave field that can be accessed from the World.
static bool SdfParamBool(sdf::Element &_sdf, const std::string &_paramName, const bool _defaultVal)
Extract a named bool parameter from an SDF element.
void Load(gazebo::physics::ModelPtr _model, sdf::ElementPtr _sdf)
static double SdfParamDouble(sdf::Element &_sdf, const std::string &_paramName, const double _defaultVal)
Extract a named double parameter from an SDF element.
This file defines a Gazebo ModelPlugin used to manage a wave field.
bool isStatic
Set the wavefield to be static [false].
static std::string MakeName(const std::string &_parentName)
Make a wave field entity name given a parent object name.
static std::shared_ptr< const WaveParameters > GetWaveParams(gazebo::physics::WorldPtr _world, const std::string &_waveModelName)
Retrive a pointer to the wavefield parameters from the Wavefield plugin.
physics::WorldPtr world
World pointer.
common::Time prevTime
Previous update time.
This file contains definitions for classes used to manage a wave field. This includes wave parameters...
physics::ModelPtr model
Model pointer.
boost::shared_ptr<::asv::WavefieldEntity > wavefieldEntity
WavefieldEntity pointer.
This file contains the definition for a Gazebo physics object that allows a wave field to be added in...