Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the symbols if they are already loaded #304

Closed
wants to merge 11 commits into from
6 changes: 5 additions & 1 deletion src/SystemLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ class ignition::gazebo::SystemLoaderPrivate
return false;
}

auto pluginName = *pluginNames.begin();
std::string pluginName = "";
for (const auto &name : pluginNames)
{
pluginName = name;
}
if (pluginName.empty())
{
ignerr << "Failed to load system plugin [" << _filename <<
Expand Down
16 changes: 9 additions & 7 deletions src/systems/air_pressure/AirPressure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ void AirPressurePrivate::CreateAirPressureEntities(EntityComponentManager &_ecm)
data.SetTopic(topic);
}
std::unique_ptr<sensors::AirPressureSensor> sensor =
this->sensorFactory.CreateSensor<
sensors::AirPressureSensor>(data);
if (nullptr == sensor)
std::make_unique<sensors::AirPressureSensor>();
if (!sensor->Load(data))
{
ignerr << "Failed to create sensor [" << sensorScopedName << "]"
<< std::endl;
return true;
ignerr << "Sensor::Load failed for plugin [AirPressureSensor]\n";
return false;
}
if (!sensor->Init())
{
ignerr << "Sensor::Init failed for plugin [AirPressureSensor]\n";
return false;
}

// set sensor parent
std::string parentName = _ecm.Component<components::Name>(
_parent->Data())->Data();
Expand Down
15 changes: 9 additions & 6 deletions src/systems/altimeter/Altimeter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,16 @@ void AltimeterPrivate::CreateAltimeterEntities(EntityComponentManager &_ecm)
data.SetTopic(topic);
}
std::unique_ptr<sensors::AltimeterSensor> sensor =
this->sensorFactory.CreateSensor<
sensors::AltimeterSensor>(data);
if (nullptr == sensor)
std::make_unique<sensors::AltimeterSensor>();
if (!sensor->Load(data))
{
ignerr << "Failed to create sensor [" << sensorScopedName << "]"
<< std::endl;
return true;
ignerr << "Sensor::Load failed for plugin [AltimeterSensor]\n";
return false;
}
if (!sensor->Init())
{
ignerr << "Sensor::Init failed for plugin [AltimeterSensor]\n";
return false;
}

// set sensor parent
Expand Down
15 changes: 9 additions & 6 deletions src/systems/imu/Imu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,16 @@ void ImuPrivate::CreateImuEntities(EntityComponentManager &_ecm)
data.SetTopic(topic);
}
std::unique_ptr<sensors::ImuSensor> sensor =
this->sensorFactory.CreateSensor<
sensors::ImuSensor>(data);
if (nullptr == sensor)
std::make_unique<sensors::ImuSensor>();
if (!sensor->Load(data))
{
ignerr << "Failed to create sensor [" << sensorScopedName << "]"
<< std::endl;
return true;
ignerr << "Sensor::Load failed for plugin [ImuSensor]\n";
return false;
}
if (!sensor->Init())
{
ignerr << "Sensor::Init failed for plugin [ImuSensor]\n";
return false;
}

// set sensor parent
Expand Down
15 changes: 9 additions & 6 deletions src/systems/logical_camera/LogicalCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ void LogicalCameraPrivate::CreateLogicalCameraEntities(
data->GetElement("topic")->Set(topic);
}
std::unique_ptr<sensors::LogicalCameraSensor> sensor =
this->sensorFactory.CreateSensor<
sensors::LogicalCameraSensor>(data);
if (nullptr == sensor)
std::make_unique<sensors::LogicalCameraSensor>();
if (!sensor->Load(data))
{
ignerr << "Failed to create sensor [" << sensorScopedName << "]"
<< std::endl;
return true;
ignerr << "Sensor::Load failed for plugin [LogicalCameraSensor]\n";
return false;
}
if (!sensor->Init())
{
ignerr << "Sensor::Init failed for plugin [LogicalCameraSensor]\n";
return false;
}

// set sensor parent
Expand Down
16 changes: 9 additions & 7 deletions src/systems/magnetometer/Magnetometer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,17 @@ void MagnetometerPrivate::CreateMagnetometerEntities(
data.SetTopic(topic);
}
std::unique_ptr<sensors::MagnetometerSensor> sensor =
this->sensorFactory.CreateSensor<
sensors::MagnetometerSensor>(data);
if (nullptr == sensor)
std::make_unique<sensors::MagnetometerSensor>();
if (!sensor->Load(data))
{
ignerr << "Failed to create sensor [" << sensorScopedName << "]"
<< std::endl;
return true;
ignerr << "Sensor::Load failed for plugin [MagnetometerSensor]\n";
return false;
}
if (!sensor->Init())
{
ignerr << "Sensor::Init failed for plugin [MagnetometerSensor]\n";
return false;
}

// set sensor parent
std::string parentName = _ecm.Component<components::Name>(
_parent->Data())->Data();
Expand Down
6 changes: 2 additions & 4 deletions src/systems/sensors/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ gz_add_system(sensors
PUBLIC_LINK_LIBS
ignition-common${IGN_COMMON_VER}::ignition-common${IGN_COMMON_VER}
ignition-sensors${IGN_SENSORS_VER}::ignition-sensors${IGN_SENSORS_VER}
${PROJECT_LIBRARY_TARGET_NAME}-rendering
PRIVATE_LINK_LIBS
ignition-sensors${IGN_SENSORS_VER}::camera
ignition-sensors${IGN_SENSORS_VER}::gpu_lidar
ignition-sensors${IGN_SENSORS_VER}::depth_camera
ignition-sensors${IGN_SENSORS_VER}::thermal_camera
${PROJECT_LIBRARY_TARGET_NAME}-rendering
)

5 changes: 3 additions & 2 deletions src/systems/sensors/Sensors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,9 @@ std::string Sensors::CreateSensor(const Entity &_entity,
return std::string();
}

// Create within ign-sensors
auto sensorId = this->dataPtr->sensorManager.CreateSensor(_sdf);
// Create using ign-sensors
ignition::sensors::SensorId sensorId =
this->dataPtr->sensorManager.CreateSensor(_sdf);
auto sensor = this->dataPtr->sensorManager.Sensor(sensorId);

// Add to sensorID -> entity map
Expand Down