Add judgement of flag to decide whether load plugins and sensors by distribution or not

This commit is contained in:
zhangshuai 2019-04-04 16:01:05 +08:00
parent 18b2f5223e
commit 0271896598
3 changed files with 85 additions and 35 deletions

View File

@ -103,6 +103,8 @@ void Link::Load(sdf::ElementPtr _sdf)
} }
// Modified by zhangshuai 2019.04.02 ----Begin // Modified by zhangshuai 2019.04.02 ----Begin
if (this->GetWorld()->GetFlag() == 1)
{
// Judge if the model to load is simulated in this gazebo // Judge if the model to load is simulated in this gazebo
for (unsigned int i = 0; i < this->GetWorld()->GetDistribution()->GetGazeboIDPtr(this->GetWorld()->GetGazeboLocalID())->GetModelCount(); i++) for (unsigned int i = 0; i < this->GetWorld()->GetDistribution()->GetGazeboIDPtr(this->GetWorld()->GetGazeboLocalID())->GetModelCount(); i++)
{ {
@ -138,6 +140,36 @@ void Link::Load(sdf::ElementPtr _sdf)
// Original part // Original part
} }
} }
}
else
{
if (this->sdf->HasElement("sensor"))
{
sdf::ElementPtr sensorElem = this->sdf->GetElement("sensor");
while (sensorElem)
{
/// \todo This if statement is a hack to prevent Links from creating
/// a force torque sensor. We should make this more generic.
if (sensorElem->Get<std::string>("type") == "force_torque")
{
gzerr << "A link cannot load a [" << sensorElem->Get<std::string>("type") << "] sensor.\n";
}
else if (sensorElem->Get<std::string>("type") != "__default__")
{
// This must match the implementation in Sensors::GetScopedName
std::string sensorName = this->GetScopedName(true) + "::" +
sensorElem->Get<std::string>("name");
// Tell the sensor library to create a sensor.
event::Events::createSensor(sensorElem,
this->GetWorld()->GetName(), this->GetScopedName(), this->GetId());
this->sensors.push_back(sensorName);
}
sensorElem = sensorElem->GetNextElement("sensor");
}
}
}
// Modified by zhangshuai 2019.04.02 ----End // Modified by zhangshuai 2019.04.02 ----End
// Load the lights // Load the lights

View File

@ -277,9 +277,9 @@ void World::Load(sdf::ElementPtr _sdf)
{ {
sdf::ElementPtr distributionElem = this->dataPtr->sdf->GetElement("distribution"); sdf::ElementPtr distributionElem = this->dataPtr->sdf->GetElement("distribution");
gazeboLocalID = distributionElem->Get<unsigned int>("gazebo_local_ID"); this->gazeboLocalID = distributionElem->Get<unsigned int>("gazebo_local_ID");
port = distributionElem->Get<int>("port"); this->port = distributionElem->Get<int>("port");
flag = distributionElem->Get<int>("flag"); this->flag = distributionElem->Get<int>("flag");
std::cout << "================= gazebo_local_ID: " << gazeboLocalID << "\t Port: " << port << "\t Flag: " << flag << " =================" << std::endl; std::cout << "================= gazebo_local_ID: " << gazeboLocalID << "\t Port: " << port << "\t Flag: " << flag << " =================" << std::endl;
@ -454,7 +454,7 @@ void World::Run(unsigned int _iterations)
this->dataPtr->stopIterations = _iterations; this->dataPtr->stopIterations = _iterations;
// Added by zhangshuai based on zenglei 2019.03.19 ----Begin // Added by zhangshuai based on zenglei 2019.03.19 ----Begin
if (1 == flag) if (1 == this->flag)
{ {
if (0 == this->gazeboLocalID) if (0 == this->gazeboLocalID)
{ {
@ -550,7 +550,7 @@ void World::RunLoop()
} }
// Added by zhangshuai based on zenglei 2019.03.19 ----Begin // Added by zhangshuai based on zenglei 2019.03.19 ----Begin
if (1 == flag) if (1 == this->flag)
{ {
if (0 == this->gazeboLocalID) if (0 == this->gazeboLocalID)
{ {
@ -938,7 +938,7 @@ void World::Update()
// Added by zhangshuai 2019.04.03 for count time ----End // Added by zhangshuai 2019.04.03 for count time ----End
// Added by zhangshuai based on zenglei 2019.03.19 ----Begin // Added by zhangshuai based on zenglei 2019.03.19 ----Begin
if (1 == flag) if (1 == this->flag)
{ {
// if (this->dataPtr->iterations % 10 == 0) // if (this->dataPtr->iterations % 10 == 0)
// Modified by zhangshuai 2019.04.02 ----Begin // Modified by zhangshuai 2019.04.02 ----Begin
@ -2373,6 +2373,8 @@ void World::ProcessFactoryMsgs()
{ {
model->Init(); model->Init();
// Modified by zhangshuai 2019.04.02 ----Begin // Modified by zhangshuai 2019.04.02 ----Begin
if (this->flag == 1)
{
// Judge if the model to load is simulated in this gazebo // Judge if the model to load is simulated in this gazebo
for (unsigned int i = 0; i < this->distribution->GetGazeboIDPtr(gazeboLocalID)->GetModelCount(); i++) for (unsigned int i = 0; i < this->distribution->GetGazeboIDPtr(gazeboLocalID)->GetModelCount(); i++)
{ {
@ -2383,6 +2385,12 @@ void World::ProcessFactoryMsgs()
// Original part // Original part
} }
} }
}
else
{
model->LoadPlugins();
}
// Modified by zhangshuai 2019.04.02 ----End // Modified by zhangshuai 2019.04.02 ----End
} }
} }
@ -3303,4 +3311,11 @@ unsigned int World::GetGazeboLocalID()
{ {
return this->gazeboLocalID; return this->gazeboLocalID;
} }
//////////////////////////////////////////////////
/// add for read the element of "flag"
unsigned int World::GetFlag()
{
return this->flag;
}
// Added by zhangshuai 2019.04.02 ----End // Added by zhangshuai 2019.04.02 ----End

View File

@ -757,6 +757,9 @@ public:
public: public:
unsigned int GetGazeboLocalID(); unsigned int GetGazeboLocalID();
public:
unsigned int GetFlag();
// Added by zhangshuai 2019.04.01 ----End // Added by zhangshuai 2019.04.01 ----End
}; };
/// \} /// \}