125 lines
3.1 KiB
C++
125 lines
3.1 KiB
C++
/*
|
|
* 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
|
|
* distribution under the License is distribution 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 distribution simualtion
|
|
* 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/Distribution.hh"
|
|
|
|
using namespace gazebo;
|
|
using namespace physics;
|
|
|
|
//////////////////////////////////////////////////
|
|
Distribution::Distribution()
|
|
{
|
|
}
|
|
|
|
//////////////////////////////////////////////////
|
|
Distribution::~Distribution()
|
|
{
|
|
this->Fini();
|
|
}
|
|
|
|
//////////////////////////////////////////////////
|
|
void Distribution::Load(sdf::ElementPtr _sdf)
|
|
{
|
|
|
|
if (_sdf)
|
|
this->sdf = _sdf;
|
|
|
|
if (this->sdf->HasElement("gazebo_id"))
|
|
{
|
|
sdf::ElementPtr gazeboIdElem = this->sdf->GetElement("gazebo_id");
|
|
while (gazeboIdElem)
|
|
{
|
|
GazeboIDPtr GazeboID(new physics::GazeboID());
|
|
GazeboID->Load(gazeboIdElem);
|
|
this->gazeboIDs.push_back(GazeboID);
|
|
gazeboIdElem = gazeboIdElem->GetNextElement("gazebo_id");
|
|
}
|
|
}
|
|
}
|
|
|
|
//////////////////////////////////////////////////
|
|
int Distribution::GetGazeboID(unsigned int _i)
|
|
{
|
|
return gazeboIDs[_i]->GetGazeboID();
|
|
}
|
|
|
|
//////////////////////////////////////////////////
|
|
GazeboIDPtr Distribution::GetGazeboIDPtr(int _gazeboID)
|
|
{
|
|
GazeboIDPtr result;
|
|
for (int i = 0; i < this->GetGazeboCount(); i++)
|
|
{
|
|
if (this->GetGazeboID(i) == _gazeboID)
|
|
{
|
|
result = gazeboIDs[i];
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
//////////////////////////////////////////////////
|
|
int Distribution::GetGazeboCount()
|
|
{
|
|
return gazeboIDs.size();
|
|
}
|
|
|
|
//////////////////////////////////////////////////
|
|
void Distribution::Fini()
|
|
{
|
|
this->gazeboIDs.clear();
|
|
this->sdf.reset();
|
|
} |