Add judgement of flag to decide whether load plugins and sensors by distribution or not
This commit is contained in:
parent
18b2f5223e
commit
0271896598
|
@ -103,39 +103,71 @@ void Link::Load(sdf::ElementPtr _sdf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modified by zhangshuai 2019.04.02 ----Begin
|
// Modified by zhangshuai 2019.04.02 ----Begin
|
||||||
// Judge if the model to load is simulated in this gazebo
|
if (this->GetWorld()->GetFlag() == 1)
|
||||||
for (unsigned int i = 0; i < this->GetWorld()->GetDistribution()->GetGazeboIDPtr(this->GetWorld()->GetGazeboLocalID())->GetModelCount(); i++)
|
|
||||||
{
|
{
|
||||||
if (this->GetModel()->GetName() == this->GetWorld()->GetDistribution()->GetGazeboIDPtr(this->GetWorld()->GetGazeboLocalID())->GetModelName(i))
|
// 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++)
|
||||||
{
|
{
|
||||||
// Original part
|
if (this->GetModel()->GetName() == this->GetWorld()->GetDistribution()->GetGazeboIDPtr(this->GetWorld()->GetGazeboLocalID())->GetModelName(i))
|
||||||
if (this->sdf->HasElement("sensor"))
|
|
||||||
{
|
{
|
||||||
sdf::ElementPtr sensorElem = this->sdf->GetElement("sensor");
|
// Original part
|
||||||
while (sensorElem)
|
if (this->sdf->HasElement("sensor"))
|
||||||
{
|
{
|
||||||
/// \todo This if statement is a hack to prevent Links from creating
|
sdf::ElementPtr sensorElem = this->sdf->GetElement("sensor");
|
||||||
/// a force torque sensor. We should make this more generic.
|
while (sensorElem)
|
||||||
if (sensorElem->Get<std::string>("type") == "force_torque")
|
|
||||||
{
|
{
|
||||||
gzerr << "A link cannot load a [" << sensorElem->Get<std::string>("type") << "] sensor.\n";
|
/// \todo This if statement is a hack to prevent Links from creating
|
||||||
}
|
/// a force torque sensor. We should make this more generic.
|
||||||
else if (sensorElem->Get<std::string>("type") != "__default__")
|
if (sensorElem->Get<std::string>("type") == "force_torque")
|
||||||
{
|
{
|
||||||
// This must match the implementation in Sensors::GetScopedName
|
gzerr << "A link cannot load a [" << sensorElem->Get<std::string>("type") << "] sensor.\n";
|
||||||
std::string sensorName = this->GetScopedName(true) + "::" +
|
}
|
||||||
sensorElem->Get<std::string>("name");
|
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.
|
// Tell the sensor library to create a sensor.
|
||||||
event::Events::createSensor(sensorElem,
|
event::Events::createSensor(sensorElem,
|
||||||
this->GetWorld()->GetName(), this->GetScopedName(), this->GetId());
|
this->GetWorld()->GetName(), this->GetScopedName(), this->GetId());
|
||||||
|
|
||||||
this->sensors.push_back(sensorName);
|
this->sensors.push_back(sensorName);
|
||||||
|
}
|
||||||
|
sensorElem = sensorElem->GetNextElement("sensor");
|
||||||
}
|
}
|
||||||
sensorElem = sensorElem->GetNextElement("sensor");
|
|
||||||
}
|
}
|
||||||
|
// 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");
|
||||||
}
|
}
|
||||||
// Original part
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Modified by zhangshuai 2019.04.02 ----End
|
// Modified by zhangshuai 2019.04.02 ----End
|
||||||
|
|
|
@ -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,16 +2373,24 @@ void World::ProcessFactoryMsgs()
|
||||||
{
|
{
|
||||||
model->Init();
|
model->Init();
|
||||||
// Modified by zhangshuai 2019.04.02 ----Begin
|
// Modified by zhangshuai 2019.04.02 ----Begin
|
||||||
// Judge if the model to load is simulated in this gazebo
|
if (this->flag == 1)
|
||||||
for (unsigned int i = 0; i < this->distribution->GetGazeboIDPtr(gazeboLocalID)->GetModelCount(); i++)
|
|
||||||
{
|
{
|
||||||
if (model->GetName() == this->distribution->GetGazeboIDPtr(gazeboLocalID)->GetModelName(i))
|
// Judge if the model to load is simulated in this gazebo
|
||||||
|
for (unsigned int i = 0; i < this->distribution->GetGazeboIDPtr(gazeboLocalID)->GetModelCount(); i++)
|
||||||
{
|
{
|
||||||
// Original part
|
if (model->GetName() == this->distribution->GetGazeboIDPtr(gazeboLocalID)->GetModelName(i))
|
||||||
model->LoadPlugins();
|
{
|
||||||
// Original part
|
// Original part
|
||||||
|
model->LoadPlugins();
|
||||||
|
// 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
|
|
@ -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
|
||||||
};
|
};
|
||||||
/// \}
|
/// \}
|
||||||
|
|
Loading…
Reference in New Issue