From 80cf7e84c2bc069fbf032031d7a6791d031fafa2 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Thu, 2 Jun 2022 13:37:27 -0700 Subject: [PATCH 1/3] Check RGBD camera sensor connection (#1513) Signed-off-by: Ian Chen --- src/systems/sensors/Sensors.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/systems/sensors/Sensors.cc b/src/systems/sensors/Sensors.cc index 69222d2209..7ba021d997 100644 --- a/src/systems/sensors/Sensors.cc +++ b/src/systems/sensors/Sensors.cc @@ -841,6 +841,11 @@ bool SensorsPrivate::HasConnections(sensors::RenderingSensor *_sensor) const // \todo(iche033) Remove this function once a virtual // sensors::RenderingSensor::HasConnections function is available + { + auto s = dynamic_cast(_sensor); + if (s) + return s->HasConnections(); + } { auto s = dynamic_cast(_sensor); if (s) From b753afed7b765a217260b1cdc8ee756ba94bbdc9 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Fri, 3 Jun 2022 12:16:55 -0500 Subject: [PATCH 2/3] Fix regression with camera sensors not using the background color set in `` (#1515) Signed-off-by: Addisu Z. Taddese --- src/rendering/RenderUtil.cc | 2 +- test/integration/CMakeLists.txt | 1 + .../camera_sensor_background_from_scene.cc | 109 ++++++++++++++++++ .../worlds/camera_sensor_scene_background.sdf | 58 ++++++++++ 4 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 test/integration/camera_sensor_background_from_scene.cc create mode 100644 test/worlds/camera_sensor_scene_background.sdf diff --git a/src/rendering/RenderUtil.cc b/src/rendering/RenderUtil.cc index 27924b3a87..23348a4cf9 100644 --- a/src/rendering/RenderUtil.cc +++ b/src/rendering/RenderUtil.cc @@ -213,7 +213,7 @@ class ignition::gazebo::RenderUtilPrivate /// \brief Scene background color. This is optional because a is /// always present, which has a default background color value. This /// backgroundColor variable is used to override the value. - public: std::optional backgroundColor = math::Color::Black; + public: std::optional backgroundColor; /// \brief Ambient color. This is optional because an is always /// present, which has a default ambient light value. This ambientLight diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt index 730d0e12b8..5b234d4d4e 100644 --- a/test/integration/CMakeLists.txt +++ b/test/integration/CMakeLists.txt @@ -79,6 +79,7 @@ endif() # Tests that require a valid display set(tests_needing_display camera_sensor_background.cc + camera_sensor_background_from_scene.cc camera_video_record_system.cc depth_camera.cc distortion_camera.cc diff --git a/test/integration/camera_sensor_background_from_scene.cc b/test/integration/camera_sensor_background_from_scene.cc new file mode 100644 index 0000000000..bc9e0259fa --- /dev/null +++ b/test/integration/camera_sensor_background_from_scene.cc @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2022 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include + +#include +#include + +#include "ignition/gazebo/Server.hh" +#include "ignition/gazebo/SystemLoader.hh" +#include "ignition/gazebo/Util.hh" +#include "ignition/gazebo/test_config.hh" + +#include "../helpers/EnvTestFixture.hh" + +using namespace ignition; +using namespace std::chrono_literals; + +std::mutex mutex; +int cbCount = 0; + +////////////////////////////////////////////////// +/// Note: This test is almost identical to the test in +/// camera_sensor_scene_background.cc, and the `cameraCb` could have been +/// reused, but loading the world twice in a single processes causes errors with +/// Ogre. +class CameraSensorBackgroundFixture : + public InternalFixture> +{ +}; + +///////////////////////////////////////////////// +void cameraCb(const msgs::Image & _msg) +{ + ASSERT_EQ(msgs::PixelFormatType::RGB_INT8, + _msg.pixel_format_type()); + + for (unsigned int y = 0; y < _msg.height(); ++y) + { + for (unsigned int x = 0; x < _msg.width(); ++x) + { + // The "/test/worlds/camera_sensor_scene_background.sdf" world has set a + // background color of 1,0,0,1. So, all the pixels returned by the + // camera should be red. + unsigned char r = _msg.data()[y * _msg.step() + x*3]; + ASSERT_EQ(255, static_cast(r)); + + unsigned char g = _msg.data()[y * _msg.step() + x*3+1]; + ASSERT_EQ(0, static_cast(g)); + + unsigned char b = _msg.data()[y * _msg.step() + x*3+2]; + ASSERT_EQ(0, static_cast(b)); + } + } + std::lock_guard lock(mutex); + cbCount++; +} + +///////////////////////////////////////////////// +// Test sensors use the background color of by default +TEST_F(CameraSensorBackgroundFixture, + IGN_UTILS_TEST_DISABLED_ON_MAC(RedBackgroundFromScene)) +{ + const auto sdfFile = common::joinPaths(std::string(PROJECT_SOURCE_PATH), + "test", "worlds", "camera_sensor_scene_background.sdf"); + // Start server + gazebo::ServerConfig serverConfig; + serverConfig.SetSdfFile(sdfFile); + + gazebo::Server server(serverConfig); + EXPECT_FALSE(server.Running()); + EXPECT_FALSE(*server.Running(0)); + + // subscribe to the camera topic + transport::Node node; + cbCount = 0; + node.Subscribe("/camera", &cameraCb); + + // Run server and verify that we are receiving a message + // from the depth camera + server.Run(true, 100, false); + + int i = 0; + while (i < 100 && cbCount <= 0) + { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + i++; + } + + std::lock_guard lock(mutex); + EXPECT_GE(cbCount, 1); + +} diff --git a/test/worlds/camera_sensor_scene_background.sdf b/test/worlds/camera_sensor_scene_background.sdf new file mode 100644 index 0000000000..8371898be4 --- /dev/null +++ b/test/worlds/camera_sensor_scene_background.sdf @@ -0,0 +1,58 @@ + + + + + .001 + 0 + + + + + ogre2 + + + + 1 0 0 + + + + true + 0 0 1.0 0 0 0 + + + + + 0.1 0.1 0.1 + + + + + + + 0.1 0.1 0.1 + + + + + + 1.047 + + 320 + 240 + + + 0.1 + 100 + + + 30 + camera + + + + + From c608355defdc5c69edde40dfc70fc335fae22011 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Tue, 7 Jun 2022 23:19:23 -0500 Subject: [PATCH 3/3] Rename ignition to gz in #1519. Signed-off-by: Addisu Z. Taddese --- .../camera_sensor_background_from_scene.cc | 18 +++++++++--------- test/worlds/camera_sensor_scene_background.sdf | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/integration/camera_sensor_background_from_scene.cc b/test/integration/camera_sensor_background_from_scene.cc index bc9e0259fa..2af43cb94d 100644 --- a/test/integration/camera_sensor_background_from_scene.cc +++ b/test/integration/camera_sensor_background_from_scene.cc @@ -19,17 +19,17 @@ #include -#include -#include +#include +#include -#include "ignition/gazebo/Server.hh" -#include "ignition/gazebo/SystemLoader.hh" -#include "ignition/gazebo/Util.hh" -#include "ignition/gazebo/test_config.hh" +#include "gz/sim/Server.hh" +#include "gz/sim/SystemLoader.hh" +#include "gz/sim/Util.hh" +#include "gz/sim/test_config.hh" #include "../helpers/EnvTestFixture.hh" -using namespace ignition; +using namespace gz; using namespace std::chrono_literals; std::mutex mutex; @@ -80,10 +80,10 @@ TEST_F(CameraSensorBackgroundFixture, const auto sdfFile = common::joinPaths(std::string(PROJECT_SOURCE_PATH), "test", "worlds", "camera_sensor_scene_background.sdf"); // Start server - gazebo::ServerConfig serverConfig; + sim::ServerConfig serverConfig; serverConfig.SetSdfFile(sdfFile); - gazebo::Server server(serverConfig); + sim::Server server(serverConfig); EXPECT_FALSE(server.Running()); EXPECT_FALSE(*server.Running(0)); diff --git a/test/worlds/camera_sensor_scene_background.sdf b/test/worlds/camera_sensor_scene_background.sdf index 8371898be4..86126467ed 100644 --- a/test/worlds/camera_sensor_scene_background.sdf +++ b/test/worlds/camera_sensor_scene_background.sdf @@ -7,11 +7,11 @@ + name="gz::sim::systems::Physics"> + name="gz::sim::systems::Sensors"> ogre2