pxmlw6n2f/Gazebo_Distributed_TCP/gazebo/physics/GazeboID.cc

137 lines
3.5 KiB
C++
Raw Permalink Normal View History

/*
* Copyright (C) 2019 AIRC 01
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/* Desc: Base class for distributed gazebo
* Author: Zhang Shuai
* Date: 28 March 2019
*/
#ifdef _WIN32
// Ensure that Winsock2.h is included before Windows.h, which can get
// pulled in by anybody (e.g., Boost).
#include <Winsock2.h>
#endif
// #include <tbb/parallel_for.h>
// #include <tbb/blocked_range.h>
// #include <float.h>
// #include <boost/bind.hpp>
// #include <boost/function.hpp>
// #include <boost/thread/recursive_mutex.hpp>
// #include <sstream>
// #include "gazebo/util/OpenAL.hh"
// #include "gazebo/common/KeyFrame.hh"
// #include "gazebo/common/Animation.hh"
// #include "gazebo/common/Plugin.hh"
// #include "gazebo/common/Events.hh"
// #include "gazebo/common/Exception.hh"
// #include "gazebo/common/Console.hh"
// #include "gazebo/common/CommonTypes.hh"
// #include "gazebo/physics/Gripper.hh"
// #include "gazebo/physics/Joint.hh"
// #include "gazebo/physics/JointController.hh"
// #include "gazebo/physics/Link.hh"
// #include "gazebo/physics/World.hh"
// #include "gazebo/physics/PhysicsEngine.hh"
// #include "gazebo/physics/Model.hh"
// #include "gazebo/physics/Contact.hh"
// #include "gazebo/transport/Node.hh"
#include "gazebo/physics/GazeboID.hh"
using namespace gazebo;
using namespace physics;
//////////////////////////////////////////////////
GazeboID::GazeboID()
{
}
//////////////////////////////////////////////////
GazeboID::~GazeboID()
{
this->Fini();
}
//////////////////////////////////////////////////
void GazeboID::Load(sdf::ElementPtr _sdf)
{
if (_sdf)
this->sdf = _sdf;
if (this->sdf->HasAttribute("num"))
this->gazeboID = this->sdf->Get<unsigned int>("num");
if (this->sdf->HasAttribute("ip"))
this->ip = this->sdf->Get<std::string>("ip");
// if (this->sdf->HasElement("ip"))
// {
// sdf::ElementPtr gazeboIdElem = this->sdf->GetElement("ip");
// ip = gazeboIdElem->Get<std::string>();
// }
// if (this->sdf->HasElement("port"))
// {
// sdf::ElementPtr gazeboPortElem = this->sdf->GetElement("port");
// port = gazeboPortElem->Get<int>();
// }
if (this->sdf->HasElement("model_name"))
{
sdf::ElementPtr modelNameElem = this->sdf->GetElement("model_name");
while (modelNameElem)
{
modelNames.push_back(modelNameElem->Get<std::string>());
modelNameElem = modelNameElem->GetNextElement("model_name");
}
}
}
//////////////////////////////////////////////////
unsigned int GazeboID::GetGazeboID()
{
return gazeboID;
}
//////////////////////////////////////////////////
std::string GazeboID::GetGazeboIp()
{
return ip;
}
//////////////////////////////////////////////////
unsigned int GazeboID::GetModelCount()
{
return modelNames.size();
}
//////////////////////////////////////////////////
std::string GazeboID::GetModelName(unsigned int _i)
{
return modelNames[_i];
}
//////////////////////////////////////////////////
void GazeboID::Fini()
{
this->modelNames.clear();
this->sdf.reset();
}