Skip to content

Commit

Permalink
Merge branch 'gz-sensors7' into gz-sensors7
Browse files Browse the repository at this point in the history
Signed-off-by: Alaa El Jawad <[email protected]>
  • Loading branch information
ahcorde authored and ejalaa12 committed Aug 9, 2023
2 parents 27f7144 + 49d9aaa commit c99f13d
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)
#============================================================================
# Initialize the project
#============================================================================
project(gz-sensors7 VERSION 7.1.0)
project(gz-sensors7 VERSION 7.2.0)

#============================================================================
# Find gz-cmake
Expand Down
32 changes: 32 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

### Gazebo Sensors 7.X.X

### Gazebo Sensors 7.2.0 (2023-04-13)

1. Cleanup resources in CameraSensor destructor
* [Pull request #340](https://github.com/gazebosim/gz-sensors/pull/340)

1. CI workflow: use checkout v3
* [Pull request #335](https://github.com/gazebosim/gz-sensors/pull/335)

1. Rename COPYING to LICENSE
* [Pull request #334](https://github.com/gazebosim/gz-sensors/pull/334)

1. Fix links in Changelog
* [Pull request #330](https://github.com/gazebosim/gz-sensors/pull/330)

1. Fix flaky triggered bounding box camera test
* [Pull request #329](https://github.com/gazebosim/gz-sensors/pull/329)

1. Fix Camera info test
* [Pull request #326](https://github.com/gazebosim/gz-sensors/pull/326)

1. Added trigger to BoundingBoxCamera
* [Pull request #322](https://github.com/gazebosim/gz-sensors/pull/322)

1. clean up rendering resources
* [Pull request #324](https://github.com/gazebosim/gz-sensors/pull/324)

1. Added Camera Info topic support for cameras
* [Pull request #285](https://github.com/gazebosim/gz-sensors/pull/285)

1. ign -> gz Migrate Ignition Headers : gz-sensors
* [Pull request #260](https://github.com/gazebosim/gz-sensors/pull/260)

### Gazebo Sensors 7.1.0 (2023-02-09)

1. Added airspeed sensor
Expand Down
3 changes: 2 additions & 1 deletion src/BoundingBoxCameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ bool BoundingBoxCameraSensor::Load(const sdf::Sensor &_sdf)
else
{
this->dataPtr->triggerTopic =
transport::TopicUtils::AsValidTopic(this->dataPtr->triggerTopic);
transport::TopicUtils::AsValidTopic(
this->Topic() + "/trigger");

if (this->dataPtr->triggerTopic.empty())
{
Expand Down
3 changes: 2 additions & 1 deletion src/CameraSensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ bool CameraSensor::Load(const sdf::Sensor &_sdf)
else
{
this->dataPtr->triggerTopic =
transport::TopicUtils::AsValidTopic(this->dataPtr->triggerTopic);
transport::TopicUtils::AsValidTopic(
this->Topic() + "/trigger");

if (this->dataPtr->triggerTopic.empty())
{
Expand Down
90 changes: 90 additions & 0 deletions test/integration/triggered_boundingbox_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class TriggeredBoundingBoxCameraTest: public testing::Test,
// Create a BoundingBox Camera sensor from a SDF and gets a boxes message
public: void BoxesWithBuiltinSDF(const std::string &_renderEngine);

// Create a BoundingBox Camera sensor from a SDF with empty trigger topic
public: void EmptyTriggerTopic(const std::string &_renderEngine);
};

/// \brief mutex for thread safety
Expand Down Expand Up @@ -213,12 +215,100 @@ void TriggeredBoundingBoxCameraTest::BoxesWithBuiltinSDF(
gz::rendering::unloadEngine(engine->Name());
}

void TriggeredBoundingBoxCameraTest::EmptyTriggerTopic(
const std::string &_renderEngine)
{
std::string path = gz::common::joinPaths(PROJECT_SOURCE_PATH, "test",
"sdf", "triggered_boundingbox_camera_sensor_topic_builtin.sdf");
sdf::SDFPtr doc(new sdf::SDF());
sdf::init(doc);
ASSERT_TRUE(sdf::readFile(path, doc));
ASSERT_NE(nullptr, doc->Root());
ASSERT_TRUE(doc->Root()->HasElement("model"));
auto modelPtr = doc->Root()->GetElement("model");
ASSERT_TRUE(modelPtr->HasElement("link"));
auto linkPtr = modelPtr->GetElement("link");
ASSERT_TRUE(linkPtr->HasElement("sensor"));
auto sensorPtr = linkPtr->GetElement("sensor");

// Skip unsupported engines
if (_renderEngine != "ogre2")
{
gzdbg << "Engine '" << _renderEngine
<< "' doesn't support bounding box cameras" << std::endl;
return;
}

// Setup gz-rendering with an empty scene
auto *engine = gz::rendering::engine(_renderEngine);
if (!engine)
{
gzdbg << "Engine '" << _renderEngine
<< "' is not supported" << std::endl;
return;
}

gz::rendering::ScenePtr scene = engine->CreateScene("scene");
ASSERT_NE(nullptr, scene);
BuildScene(scene);

gz::sensors::Manager mgr;

sdf::Sensor sdfSensor;
sdfSensor.Load(sensorPtr);

std::string type = sdfSensor.TypeStr();
EXPECT_EQ(type, "boundingbox_camera");

gz::sensors::BoundingBoxCameraSensor *sensor =
mgr.CreateSensor<gz::sensors::BoundingBoxCameraSensor>(sdfSensor);
ASSERT_NE(sensor, nullptr);
EXPECT_FALSE(sensor->HasConnections());
sensor->SetScene(scene);

// trigger camera through topic
std::string triggerTopic =
"/test/integration/triggered_bbcamera/trigger";

gz::transport::Node node;
auto pub = node.Advertise<gz::msgs::Boolean>(triggerTopic);
gz::msgs::Boolean msg;
msg.set_data(true);
pub.Publish(msg);
// sleep to wait for trigger msg to be received before calling mgr.RunOnce
std::this_thread::sleep_for(2s);

// we should receive images and boxes after trigger
{
std::string boxTopic =
"/test/integration/triggered_bbcamera";
WaitForMessageTestHelper<gz::msgs::AnnotatedAxisAligned2DBox_V>
helper(boxTopic);
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
EXPECT_TRUE(helper.WaitForMessage(10s)) << helper;
g_mutex.lock();
EXPECT_EQ(g_boxes.size(), size_t(2));
g_mutex.unlock();
}

// Clean up
mgr.Remove(sensor->Id());
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}

//////////////////////////////////////////////////
TEST_P(TriggeredBoundingBoxCameraTest, BoxesWithBuiltinSDF)
{
BoxesWithBuiltinSDF(GetParam());
}

//////////////////////////////////////////////////
TEST_P(TriggeredBoundingBoxCameraTest, EmptyTriggerTopic)
{
EmptyTriggerTopic(GetParam());
}

INSTANTIATE_TEST_SUITE_P(BoundingBoxCameraSensor,
TriggeredBoundingBoxCameraTest,
RENDER_ENGINE_VALUES, gz::rendering::PrintToStringParam());
Expand Down
77 changes: 77 additions & 0 deletions test/integration/triggered_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class TriggeredCameraTest: public testing::Test,

// Create a Camera sensor from a SDF and gets a image message
public: void ImagesWithBuiltinSDF(const std::string &_renderEngine);

// Create a Camera sensor from a SDF with empty trigger topic
public: void EmptyTriggerTopic(const std::string &_renderEngine);
};

void TriggeredCameraTest::ImagesWithBuiltinSDF(const std::string &_renderEngine)
Expand Down Expand Up @@ -128,6 +131,9 @@ void TriggeredCameraTest::ImagesWithBuiltinSDF(const std::string &_renderEngine)
msg.set_data(true);
pub.Publish(msg);

// sleep to wait for trigger msg to be received before calling mgr.RunOnce
std::this_thread::sleep_for(2s);

// check camera image after trigger
{
std::string imageTopic =
Expand All @@ -154,12 +160,83 @@ void TriggeredCameraTest::ImagesWithBuiltinSDF(const std::string &_renderEngine)
gz::rendering::unloadEngine(engine->Name());
}

void TriggeredCameraTest::EmptyTriggerTopic(const std::string &_renderEngine)
{
std::string path = gz::common::joinPaths(PROJECT_SOURCE_PATH, "test",
"sdf", "triggered_camera_sensor_topic_builtin.sdf");
sdf::SDFPtr doc(new sdf::SDF());
sdf::init(doc);
ASSERT_TRUE(sdf::readFile(path, doc));
ASSERT_NE(nullptr, doc->Root());
ASSERT_TRUE(doc->Root()->HasElement("model"));
auto modelPtr = doc->Root()->GetElement("model");
ASSERT_TRUE(modelPtr->HasElement("link"));
auto linkPtr = modelPtr->GetElement("link");
ASSERT_TRUE(linkPtr->HasElement("sensor"));
auto sensorPtr = linkPtr->GetElement("sensor");

// Setup gz-rendering with an empty scene
auto *engine = gz::rendering::engine(_renderEngine);
if (!engine)
{
gzdbg << "Engine '" << _renderEngine
<< "' is not supported" << std::endl;
return;
}

gz::rendering::ScenePtr scene = engine->CreateScene("scene");

gz::sensors::Manager mgr;

gz::sensors::CameraSensor *sensor =
mgr.CreateSensor<gz::sensors::CameraSensor>(sensorPtr);
ASSERT_NE(sensor, nullptr);
EXPECT_FALSE(sensor->HasConnections());
sensor->SetScene(scene);

sdf::Sensor sdfSensor;
sdfSensor.Load(sensorPtr);
EXPECT_EQ(true, sdfSensor.CameraSensor()->Triggered());

// trigger camera through default generated topic
gz::transport::Node triggerNode;
std::string triggerTopic =
"/test/integration/triggered_camera/trigger";

auto pub = triggerNode.Advertise<gz::msgs::Boolean>(triggerTopic);
gz::msgs::Boolean msg;
msg.set_data(true);
pub.Publish(msg);

// check camera image after trigger
{
std::string imageTopic =
"/test/integration/triggered_camera";
WaitForMessageTestHelper<gz::msgs::Image> helper(imageTopic);
mgr.RunOnce(std::chrono::steady_clock::duration::zero(), true);
EXPECT_TRUE(helper.WaitForMessage(10s)) << helper;
}

// Clean up
auto sensorId = sensor->Id();
EXPECT_TRUE(mgr.Remove(sensorId));
engine->DestroyScene(scene);
gz::rendering::unloadEngine(engine->Name());
}

//////////////////////////////////////////////////
TEST_P(TriggeredCameraTest, ImagesWithBuiltinSDF)
{
gz::common::Console::SetVerbosity(4);
ImagesWithBuiltinSDF(GetParam());
}

//////////////////////////////////////////////////
TEST_P(TriggeredCameraTest, EmptyTriggerTopic)
{
gz::common::Console::SetVerbosity(4);
EmptyTriggerTopic(GetParam());
}

INSTANTIATE_TEST_SUITE_P(CameraSensor, TriggeredCameraTest,
RENDER_ENGINE_VALUES, gz::rendering::PrintToStringParam());
23 changes: 23 additions & 0 deletions test/sdf/triggered_boundingbox_camera_sensor_topic_builtin.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<sdf version="1.6">
<model name="m1">
<link name="link1">
<sensor name="boundingbox_camera" type="boundingbox_camera">
<update_rate>10</update_rate>
<topic>/test/integration/triggered_bbcamera</topic>
<camera>
<triggered>true</triggered>
<horizontal_fov>1.05</horizontal_fov>
<image>
<width>320</width>
<height>240</height>
</image>
<clip>
<near>0.1</near>
<far>10.0</far>
</clip>
</camera>
</sensor>
</link>
</model>
</sdf>
23 changes: 23 additions & 0 deletions test/sdf/triggered_camera_sensor_topic_builtin.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<sdf version="1.6">
<model name="m1">
<link name="link1">
<sensor name="camera1" type="camera">
<update_rate>10</update_rate>
<topic>/test/integration/triggered_camera</topic>
<camera>
<triggered>true</triggered>
<horizontal_fov>1.05</horizontal_fov>
<image>
<width>256</width>
<height>257</height>
</image>
<clip>
<near>0.1</near>
<far>10.0</far>
</clip>
</camera>
</sensor>
</link>
</model>
</sdf>

0 comments on commit c99f13d

Please sign in to comment.