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
|
||||
// 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++)
|
||||
if (this->GetWorld()->GetFlag() == 1)
|
||||
{
|
||||
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->sdf->HasElement("sensor"))
|
||||
if (this->GetModel()->GetName() == this->GetWorld()->GetDistribution()->GetGazeboIDPtr(this->GetWorld()->GetGazeboLocalID())->GetModelName(i))
|
||||
{
|
||||
sdf::ElementPtr sensorElem = this->sdf->GetElement("sensor");
|
||||
while (sensorElem)
|
||||
// Original part
|
||||
if (this->sdf->HasElement("sensor"))
|
||||
{
|
||||
/// \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")
|
||||
sdf::ElementPtr sensorElem = this->sdf->GetElement("sensor");
|
||||
while (sensorElem)
|
||||
{
|
||||
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");
|
||||
/// \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());
|
||||
// Tell the sensor library to create a sensor.
|
||||
event::Events::createSensor(sensorElem,
|
||||
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
|
||||
|
|
|
@ -277,9 +277,9 @@ void World::Load(sdf::ElementPtr _sdf)
|
|||
{
|
||||
sdf::ElementPtr distributionElem = this->dataPtr->sdf->GetElement("distribution");
|
||||
|
||||
gazeboLocalID = distributionElem->Get<unsigned int>("gazebo_local_ID");
|
||||
port = distributionElem->Get<int>("port");
|
||||
flag = distributionElem->Get<int>("flag");
|
||||
this->gazeboLocalID = distributionElem->Get<unsigned int>("gazebo_local_ID");
|
||||
this->port = distributionElem->Get<int>("port");
|
||||
this->flag = distributionElem->Get<int>("flag");
|
||||
|
||||
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;
|
||||
|
||||
// Added by zhangshuai based on zenglei 2019.03.19 ----Begin
|
||||
if (1 == flag)
|
||||
if (1 == this->flag)
|
||||
{
|
||||
if (0 == this->gazeboLocalID)
|
||||
{
|
||||
|
@ -550,7 +550,7 @@ void World::RunLoop()
|
|||
}
|
||||
|
||||
// Added by zhangshuai based on zenglei 2019.03.19 ----Begin
|
||||
if (1 == flag)
|
||||
if (1 == this->flag)
|
||||
{
|
||||
if (0 == this->gazeboLocalID)
|
||||
{
|
||||
|
@ -938,7 +938,7 @@ void World::Update()
|
|||
// Added by zhangshuai 2019.04.03 for count time ----End
|
||||
|
||||
// Added by zhangshuai based on zenglei 2019.03.19 ----Begin
|
||||
if (1 == flag)
|
||||
if (1 == this->flag)
|
||||
{
|
||||
// if (this->dataPtr->iterations % 10 == 0)
|
||||
// Modified by zhangshuai 2019.04.02 ----Begin
|
||||
|
@ -2373,16 +2373,24 @@ void World::ProcessFactoryMsgs()
|
|||
{
|
||||
model->Init();
|
||||
// Modified by zhangshuai 2019.04.02 ----Begin
|
||||
// Judge if the model to load is simulated in this gazebo
|
||||
for (unsigned int i = 0; i < this->distribution->GetGazeboIDPtr(gazeboLocalID)->GetModelCount(); i++)
|
||||
if (this->flag == 1)
|
||||
{
|
||||
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
|
||||
model->LoadPlugins();
|
||||
// Original part
|
||||
if (model->GetName() == this->distribution->GetGazeboIDPtr(gazeboLocalID)->GetModelName(i))
|
||||
{
|
||||
// Original part
|
||||
model->LoadPlugins();
|
||||
// Original part
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
model->LoadPlugins();
|
||||
}
|
||||
|
||||
// Modified by zhangshuai 2019.04.02 ----End
|
||||
}
|
||||
}
|
||||
|
@ -3303,4 +3311,11 @@ unsigned int World::GetGazeboLocalID()
|
|||
{
|
||||
return this->gazeboLocalID;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
/// add for read the element of "flag"
|
||||
unsigned int World::GetFlag()
|
||||
{
|
||||
return this->flag;
|
||||
}
|
||||
// Added by zhangshuai 2019.04.02 ----End
|
|
@ -757,6 +757,9 @@ public:
|
|||
|
||||
public:
|
||||
unsigned int GetGazeboLocalID();
|
||||
|
||||
public:
|
||||
unsigned int GetFlag();
|
||||
// Added by zhangshuai 2019.04.01 ----End
|
||||
};
|
||||
/// \}
|
||||
|
|
Loading…
Reference in New Issue