From 7338e3a6c223c65316b6d3b4531683bfee3b3654 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 21 Aug 2020 13:10:07 +0200 Subject: [PATCH 1/6] Use the symbols if they are already loaded Signed-off-by: ahcorde --- src/SystemLoader.cc | 6 +++++- src/systems/sensors/CMakeLists.txt | 6 ++---- src/systems/sensors/Sensors.cc | 20 +++++++++++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/SystemLoader.cc b/src/SystemLoader.cc index 3a78dda509..55e985f27f 100644 --- a/src/SystemLoader.cc +++ b/src/SystemLoader.cc @@ -78,7 +78,11 @@ class ignition::gazebo::SystemLoaderPrivate return false; } - auto pluginName = *pluginNames.begin(); + std::string pluginName = ""; + for (auto name : pluginNames) + { + pluginName = name; + } if (pluginName.empty()) { ignerr << "Failed to load system plugin [" << _filename << diff --git a/src/systems/sensors/CMakeLists.txt b/src/systems/sensors/CMakeLists.txt index da081b2dff..f8dd886e24 100644 --- a/src/systems/sensors/CMakeLists.txt +++ b/src/systems/sensors/CMakeLists.txt @@ -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 ) - diff --git a/src/systems/sensors/Sensors.cc b/src/systems/sensors/Sensors.cc index 828c66fcd3..f6bc31c2e8 100644 --- a/src/systems/sensors/Sensors.cc +++ b/src/systems/sensors/Sensors.cc @@ -473,7 +473,25 @@ std::string Sensors::CreateSensor(const Entity &_entity, } // Create within ign-sensors - auto sensorId = this->dataPtr->sensorManager.CreateSensor(_sdf); + ignition::sensors::SensorId sensorId; + if (_sdf.Type() == sdf::SensorType::CAMERA) + { + std::unique_ptr cameraSensor = + std::make_unique(); + cameraSensor->Load(_sdf); + sensorId = this->dataPtr->sensorManager.AddSensor(std::move(cameraSensor)); + } + else if (_sdf.Type() == sdf::SensorType::THERMAL_CAMERA) + { + std::unique_ptr thermalCameraSensor = + std::make_unique(); + thermalCameraSensor->Load(_sdf); + sensorId = this->dataPtr->sensorManager.AddSensor(std::move(thermalCameraSensor)); + } + else + { + sensorId = this->dataPtr->sensorManager.CreateSensor(_sdf); + } auto sensor = this->dataPtr->sensorManager.Sensor(sensorId); // Add to sensorID -> entity map From db5dde64c10a198f33f71e99f4f110f83738830e Mon Sep 17 00:00:00 2001 From: ahcorde Date: Fri, 21 Aug 2020 17:49:20 +0200 Subject: [PATCH 2/6] Fixed IMU, magnetometer, air_pressure and altimeter sensors Signed-off-by: ahcorde --- src/systems/air_pressure/AirPressure.cc | 4 ++-- src/systems/altimeter/Altimeter.cc | 4 ++-- src/systems/imu/Imu.cc | 4 ++-- src/systems/magnetometer/Magnetometer.cc | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/systems/air_pressure/AirPressure.cc b/src/systems/air_pressure/AirPressure.cc index 051fdfa196..8197449183 100644 --- a/src/systems/air_pressure/AirPressure.cc +++ b/src/systems/air_pressure/AirPressure.cc @@ -134,8 +134,8 @@ void AirPressurePrivate::CreateAirPressureEntities(EntityComponentManager &_ecm) data.SetTopic(topic); } std::unique_ptr sensor = - this->sensorFactory.CreateSensor< - sensors::AirPressureSensor>(data); + std::make_unique(); + sensor->Load(data); // set sensor parent std::string parentName = _ecm.Component( _parent->Data())->Data(); diff --git a/src/systems/altimeter/Altimeter.cc b/src/systems/altimeter/Altimeter.cc index ea75360784..d24f8d088f 100644 --- a/src/systems/altimeter/Altimeter.cc +++ b/src/systems/altimeter/Altimeter.cc @@ -136,8 +136,8 @@ void AltimeterPrivate::CreateAltimeterEntities(EntityComponentManager &_ecm) data.SetTopic(topic); } std::unique_ptr sensor = - this->sensorFactory.CreateSensor< - sensors::AltimeterSensor>(data); + std::make_unique(); + sensor->Load(data); // set sensor parent std::string parentName = _ecm.Component( _parent->Data())->Data(); diff --git a/src/systems/imu/Imu.cc b/src/systems/imu/Imu.cc index 09a4aaa66f..9d2e9c57db 100644 --- a/src/systems/imu/Imu.cc +++ b/src/systems/imu/Imu.cc @@ -155,8 +155,8 @@ void ImuPrivate::CreateImuEntities(EntityComponentManager &_ecm) data.SetTopic(topic); } std::unique_ptr sensor = - this->sensorFactory.CreateSensor< - sensors::ImuSensor>(data); + std::make_unique(); + sensor->Load(data); // set sensor parent std::string parentName = _ecm.Component( _parent->Data())->Data(); diff --git a/src/systems/magnetometer/Magnetometer.cc b/src/systems/magnetometer/Magnetometer.cc index 523580cb8b..4c8eee1b01 100644 --- a/src/systems/magnetometer/Magnetometer.cc +++ b/src/systems/magnetometer/Magnetometer.cc @@ -151,8 +151,8 @@ void MagnetometerPrivate::CreateMagnetometerEntities( data.SetTopic(topic); } std::unique_ptr sensor = - this->sensorFactory.CreateSensor< - sensors::MagnetometerSensor>(data); + std::make_unique(); + sensor->Load(data); // set sensor parent std::string parentName = _ecm.Component( _parent->Data())->Data(); From 075b66ab61ecc9369ff4ff6f80d65733cb0bb9d3 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Tue, 25 Aug 2020 11:20:01 +0200 Subject: [PATCH 3/6] Fixed logical camera Signed-off-by: ahcorde --- src/systems/logical_camera/LogicalCamera.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/systems/logical_camera/LogicalCamera.cc b/src/systems/logical_camera/LogicalCamera.cc index 263f396084..92a608ce69 100644 --- a/src/systems/logical_camera/LogicalCamera.cc +++ b/src/systems/logical_camera/LogicalCamera.cc @@ -138,8 +138,8 @@ void LogicalCameraPrivate::CreateLogicalCameraEntities( data->GetElement("topic")->Set(topic); } std::unique_ptr sensor = - this->sensorFactory.CreateSensor< - sensors::LogicalCameraSensor>(data); + std::make_unique(); + sensor->Load(data); // set sensor parent std::string parentName = _ecm.Component( _parent->Data())->Data(); From e423cf73f17ecf48d37b5baa5e1e09d142f1557a Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 27 Aug 2020 12:31:35 +0200 Subject: [PATCH 4/6] make linters happy Signed-off-by: ahcorde --- src/systems/sensors/Sensors.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/systems/sensors/Sensors.cc b/src/systems/sensors/Sensors.cc index f6bc31c2e8..7793f3a0bd 100644 --- a/src/systems/sensors/Sensors.cc +++ b/src/systems/sensors/Sensors.cc @@ -486,7 +486,8 @@ std::string Sensors::CreateSensor(const Entity &_entity, std::unique_ptr thermalCameraSensor = std::make_unique(); thermalCameraSensor->Load(_sdf); - sensorId = this->dataPtr->sensorManager.AddSensor(std::move(thermalCameraSensor)); + sensorId = this->dataPtr->sensorManager.AddSensor( + std::move(thermalCameraSensor)); } else { From 3f42c0031e2d1aa60dd109371992de32a382a1b6 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 2 Sep 2020 11:09:37 +0200 Subject: [PATCH 5/6] Added Init method when initialized the sensors Signed-off-by: ahcorde --- src/systems/air_pressure/AirPressure.cc | 11 ++++++++++- src/systems/altimeter/Altimeter.cc | 12 +++++++++++- src/systems/imu/Imu.cc | 12 +++++++++++- src/systems/logical_camera/LogicalCamera.cc | 12 +++++++++++- src/systems/magnetometer/Magnetometer.cc | 11 ++++++++++- 5 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/systems/air_pressure/AirPressure.cc b/src/systems/air_pressure/AirPressure.cc index 8197449183..50aaeb8744 100644 --- a/src/systems/air_pressure/AirPressure.cc +++ b/src/systems/air_pressure/AirPressure.cc @@ -135,7 +135,16 @@ void AirPressurePrivate::CreateAirPressureEntities(EntityComponentManager &_ecm) } std::unique_ptr sensor = std::make_unique(); - sensor->Load(data); + if (!sensor->Load(data)) + { + 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( _parent->Data())->Data(); diff --git a/src/systems/altimeter/Altimeter.cc b/src/systems/altimeter/Altimeter.cc index d24f8d088f..2a7608cb10 100644 --- a/src/systems/altimeter/Altimeter.cc +++ b/src/systems/altimeter/Altimeter.cc @@ -137,7 +137,17 @@ void AltimeterPrivate::CreateAltimeterEntities(EntityComponentManager &_ecm) } std::unique_ptr sensor = std::make_unique(); - sensor->Load(data); + if (!sensor->Load(data)) + { + 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 std::string parentName = _ecm.Component( _parent->Data())->Data(); diff --git a/src/systems/imu/Imu.cc b/src/systems/imu/Imu.cc index 9d2e9c57db..bff32be122 100644 --- a/src/systems/imu/Imu.cc +++ b/src/systems/imu/Imu.cc @@ -156,7 +156,17 @@ void ImuPrivate::CreateImuEntities(EntityComponentManager &_ecm) } std::unique_ptr sensor = std::make_unique(); - sensor->Load(data); + if (!sensor->Load(data)) + { + 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 std::string parentName = _ecm.Component( _parent->Data())->Data(); diff --git a/src/systems/logical_camera/LogicalCamera.cc b/src/systems/logical_camera/LogicalCamera.cc index 92a608ce69..faf93e07ec 100644 --- a/src/systems/logical_camera/LogicalCamera.cc +++ b/src/systems/logical_camera/LogicalCamera.cc @@ -139,7 +139,17 @@ void LogicalCameraPrivate::CreateLogicalCameraEntities( } std::unique_ptr sensor = std::make_unique(); - sensor->Load(data); + if (!sensor->Load(data)) + { + 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 std::string parentName = _ecm.Component( _parent->Data())->Data(); diff --git a/src/systems/magnetometer/Magnetometer.cc b/src/systems/magnetometer/Magnetometer.cc index 4c8eee1b01..e15edd4e81 100644 --- a/src/systems/magnetometer/Magnetometer.cc +++ b/src/systems/magnetometer/Magnetometer.cc @@ -152,7 +152,16 @@ void MagnetometerPrivate::CreateMagnetometerEntities( } std::unique_ptr sensor = std::make_unique(); - sensor->Load(data); + if (!sensor->Load(data)) + { + 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( _parent->Data())->Data(); From 2f674e6736a5e7a726187f01963c19bf943c6c00 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Fri, 29 Jan 2021 09:57:38 -0800 Subject: [PATCH 6/6] Utilize sensor manager to creat sensors Signed-off-by: Nate Koenig --- src/SystemLoader.cc | 2 +- src/systems/sensors/Sensors.cc | 24 +++--------------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/SystemLoader.cc b/src/SystemLoader.cc index 55e985f27f..ab18134643 100644 --- a/src/SystemLoader.cc +++ b/src/SystemLoader.cc @@ -79,7 +79,7 @@ class ignition::gazebo::SystemLoaderPrivate } std::string pluginName = ""; - for (auto name : pluginNames) + for (const auto &name : pluginNames) { pluginName = name; } diff --git a/src/systems/sensors/Sensors.cc b/src/systems/sensors/Sensors.cc index a3beab0ed7..16a0aaf764 100644 --- a/src/systems/sensors/Sensors.cc +++ b/src/systems/sensors/Sensors.cc @@ -498,27 +498,9 @@ std::string Sensors::CreateSensor(const Entity &_entity, return std::string(); } - // Create within ign-sensors - ignition::sensors::SensorId sensorId; - if (_sdf.Type() == sdf::SensorType::CAMERA) - { - std::unique_ptr cameraSensor = - std::make_unique(); - cameraSensor->Load(_sdf); - sensorId = this->dataPtr->sensorManager.AddSensor(std::move(cameraSensor)); - } - else if (_sdf.Type() == sdf::SensorType::THERMAL_CAMERA) - { - std::unique_ptr thermalCameraSensor = - std::make_unique(); - thermalCameraSensor->Load(_sdf); - sensorId = this->dataPtr->sensorManager.AddSensor( - std::move(thermalCameraSensor)); - } - else - { - 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