18 #include <boost/algorithm/string.hpp>    19 #include <boost/bind.hpp>    20 #include <boost/shared_ptr.hpp>    22 #include <gazebo/gazebo.hh>    23 #include <gazebo/msgs/msgs.hh>    24 #include <gazebo/physics/Link.hh>    25 #include <gazebo/physics/Model.hh>    26 #include <gazebo/physics/PhysicsEngine.hh>    27 #include <gazebo/physics/World.hh>    28 #include <gazebo/transport/TransportTypes.hh>    48 #if GAZEBO_MAJOR_VERSION >= 8    58   GZ_ASSERT(_world != NULL, 
"World pointer is invalid");
    59   GZ_ASSERT(_sdf != NULL, 
"SDF pointer is invalid");
    65   this->
ns = _sdf->Get<std::string>(
"namespace");
    67   gzmsg << 
"Loading underwater world..." << std::endl;
    69   this->
node = transport::NodePtr(
new transport::Node());
    70 #if GAZEBO_MAJOR_VERSION >= 8    76   GZ_ASSERT(this->
sdf->HasElement(
"constant_current"),
    77     "Constant current configuration not available");
    78   sdf::ElementPtr currentVelocityParams = this->
sdf->GetElement(
    82   if (currentVelocityParams->HasElement(
"topic"))
    84       currentVelocityParams->Get<std::string>(
"topic");
    89     "Empty current velocity topic");
    91   if (currentVelocityParams->HasElement(
"velocity"))
    93     sdf::ElementPtr elem = currentVelocityParams->GetElement(
"velocity");
    94     if (elem->HasElement(
"mean"))
    96     if (elem->HasElement(
"min"))
    98     if (elem->HasElement(
"max"))
   100     if (elem->HasElement(
"mu"))
   102     if (elem->HasElement(
"noiseAmp"))
   106       "Invalid current velocity limits");
   108       "Mean velocity must be greater than minimum");
   110       "Mean velocity must be smaller than maximum");
   112       "Invalid process constant");
   114       this->currentVelModel.noiseAmp >= 0,
   115       "Noise amplitude has to be smaller than 1");
   119   gzmsg << 
"Current velocity [m/s] Gauss-Markov process model:" << std::endl;
   122   if (currentVelocityParams->HasElement(
"horizontal_angle"))
   124     sdf::ElementPtr elem =
   125       currentVelocityParams->GetElement(
"horizontal_angle");
   127     if (elem->HasElement(
"mean"))
   129     if (elem->HasElement(
"min"))
   131     if (elem->HasElement(
"max"))
   133     if (elem->HasElement(
"mu"))
   135     if (elem->HasElement(
"noiseAmp"))
   139       this->currentHorzAngleModel.max,
   140       "Invalid current horizontal angle limits");
   142       this->currentHorzAngleModel.min,
   143       "Mean horizontal angle must be greater than minimum");
   145       this->currentHorzAngleModel.max,
   146       "Mean horizontal angle must be smaller than maximum");
   148       this->currentHorzAngleModel.mu < 1,
   149       "Invalid process constant");
   151       this->currentHorzAngleModel.noiseAmp >= 0,
   152       "Noise amplitude for horizontal angle has to be between 0 and 1");
   157     "Current velocity horizontal angle [rad] Gauss-Markov process model:"   161   if (currentVelocityParams->HasElement(
"vertical_angle"))
   163     sdf::ElementPtr elem = currentVelocityParams->GetElement(
"vertical_angle");
   165     if (elem->HasElement(
"mean"))
   167     if (elem->HasElement(
"min"))
   169     if (elem->HasElement(
"max"))
   171     if (elem->HasElement(
"mu"))
   173     if (elem->HasElement(
"noiseAmp"))
   177       this->currentVertAngleModel.max, 
"Invalid current vertical angle limits");
   179       this->currentVertAngleModel.min,
   180       "Mean vertical angle must be greater than minimum");
   182       this->currentVertAngleModel.max,
   183       "Mean vertical angle must be smaller than maximum");
   185       this->currentVertAngleModel.mu < 1,
   186       "Invalid process constant");
   188       this->currentVertAngleModel.noiseAmp >= 0,
   189       "Noise amplitude for vertical angle has to be between 0 and 1");
   194     "Current velocity horizontal angle [rad] Gauss-Markov process model:"   199 #if GAZEBO_MAJOR_VERSION >= 8   210     this->
node->Advertise<msgs::Vector3d>(
   213   gzmsg << 
"Current velocity topic name: " <<
   221   gzmsg << 
"Underwater current plugin loaded!" << std::endl
   222     << 
"\tWARNING: Current velocity calculated in the ENU frame"   235 #if GAZEBO_MAJOR_VERSION >= 8   236   common::Time time = this->
world->SimTime();
   238   common::Time time = this->
world->GetSimTime();
   254       currentVelMag * cos(horzAngle) * cos(vertAngle),
   255       currentVelMag * sin(horzAngle) * cos(vertAngle),
   256       currentVelMag * sin(vertAngle));
   266   msgs::Vector3d currentVel;
   267   msgs::Set(¤tVel, ignition::math::Vector3d(this->
currentVelocity.X(),
 GaussMarkovProcess currentVelModel
Gauss-Markov process instance for the current velocity. 
 
double min
Minimum limit for the process variable. 
 
std::string currentVelocityTopic
Current velocity topic. 
 
double Update(double _time)
Update function for a new time stamp. 
 
double noiseAmp
Gaussian white noise amplitude. 
 
void PublishCurrentVelocity()
Publish current velocity and the pose of its frame. 
 
sdf::ElementPtr sdf
Pointer to sdf. 
 
void Print()
Print current model paramters. 
 
virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
 
common::Time lastUpdate
Last update time stamp. 
 
std::map< std::string, transport::PublisherPtr > publishers
Map of publishers. 
 
GaussMarkovProcess currentHorzAngleModel
Gauss-Markov process instance for horizontal angle model. 
 
virtual ~UnderwaterCurrentPlugin()
Class destructor. 
 
double mean
Mean process value. 
 
transport::NodePtr node
Pointer to a node for communication. 
 
event::ConnectionPtr updateConnection
Update event. 
 
double max
Maximum limit for the process variable. 
 
GaussMarkovProcess currentVertAngleModel
Gauss-Markov process instance for vertical angle model. 
 
double var
Process variable. 
 
ignition::math::Vector3d currentVelocity
Current linear velocity vector. 
 
physics::WorldPtr world
Pointer to world. 
 
Class for the underwater current plugin TODO: Add option to make the underwater current also a functi...
 
double mu
Process constant, if zero, process becomes a random walk. 
 
void Update(const common::UpdateInfo &_info)
Update the simulation state. 
 
double lastUpdate
Timestamp for the last update. 
 
Plugin that for the underwater world. 
 
std::string ns
Namespace for topics and services.