From d49310b2d98f76f589dc86c49cae45adc91636ec Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Wed, 10 Jul 2024 09:24:11 -0700 Subject: [PATCH] Backport frame id fixes (#446) Signed-off-by: Ian Chen --- src/DopplerVelocityLog.cc | 6 +++++ src/GpuLidarSensor.cc | 2 +- src/Sensor.cc | 10 ++++---- test/integration/dvl.cc | 23 +++++++++++++++++ test/integration/gpu_lidar_sensor.cc | 37 +++++++++++++++++++--------- 5 files changed, 60 insertions(+), 18 deletions(-) diff --git a/src/DopplerVelocityLog.cc b/src/DopplerVelocityLog.cc index ded9e25e..77414f49 100644 --- a/src/DopplerVelocityLog.cc +++ b/src/DopplerVelocityLog.cc @@ -1945,6 +1945,9 @@ namespace gz if (this->dataPtr->publishingEstimates) { auto * headerMessage = bottomModeMessage.mutable_header(); + auto frame = headerMessage->add_data(); + frame->set_key("frame_id"); + frame->add_value(this->FrameId()); this->AddSequence(headerMessage, "doppler_velocity_log"); this->dataPtr->pub.Publish(bottomModeMessage); } @@ -1964,6 +1967,9 @@ namespace gz if (this->dataPtr->publishingEstimates) { auto * headerMessage = waterMassModeMessage.mutable_header(); + auto frame = headerMessage->add_data(); + frame->set_key("frame_id"); + frame->add_value(this->FrameId()); this->AddSequence(headerMessage, "doppler_velocity_log"); this->dataPtr->pub.Publish(waterMassModeMessage); } diff --git a/src/GpuLidarSensor.cc b/src/GpuLidarSensor.cc index 0e98cddc..83e44d0d 100644 --- a/src/GpuLidarSensor.cc +++ b/src/GpuLidarSensor.cc @@ -134,7 +134,7 @@ bool GpuLidarSensor::Load(const sdf::Sensor &_sdf) // by ROS1: https://github.com/ros/common_msgs/pull/77. Ideally, memory // alignment should be configured. This same problem is in the // RgbdCameraSensor. - msgs::InitPointCloudPacked(this->dataPtr->pointMsg, this->Name(), true, + msgs::InitPointCloudPacked(this->dataPtr->pointMsg, this->FrameId(), true, {{"xyz", msgs::PointCloudPacked::Field::FLOAT32}, {"intensity", msgs::PointCloudPacked::Field::FLOAT32}, {"ring", msgs::PointCloudPacked::Field::UINT16}}); diff --git a/src/Sensor.cc b/src/Sensor.cc index 326f79f4..b7dbba91 100644 --- a/src/Sensor.cc +++ b/src/Sensor.cc @@ -138,7 +138,7 @@ class gz::sensors::SensorPrivate public: std::map sequences; /// \brief frame id - public: std::string frame_id; + public: std::string frameId; /// \brief If sensor is active or not. public: bool active = true; @@ -187,11 +187,11 @@ bool SensorPrivate::PopulateFromSDF(const sdf::Sensor &_sdf) { if (element->HasElement("gz_frame_id")) { - this->frame_id = element->Get("gz_frame_id"); + this->frameId = element->Get("gz_frame_id"); } else { - this->frame_id = this->name; + this->frameId = this->name; } } @@ -288,13 +288,13 @@ std::string Sensor::Name() const ////////////////////////////////////////////////// std::string Sensor::FrameId() const { - return this->dataPtr->frame_id; + return this->dataPtr->frameId; } ////////////////////////////////////////////////// void Sensor::SetFrameId(const std::string &_frameId) { - this->dataPtr->frame_id = _frameId; + this->dataPtr->frameId = _frameId; } ////////////////////////////////////////////////// diff --git a/test/integration/dvl.cc b/test/integration/dvl.cc index 814d5ccb..5c1c1df2 100644 --- a/test/integration/dvl.cc +++ b/test/integration/dvl.cc @@ -45,6 +45,7 @@ using DopplerVelocityLog = sensors::DopplerVelocityLog; struct DVLConfig { std::string name = "dvl"; + std::string frameId = "dvl_frame"; std::string topic = "/gz/sensors/test/dvl"; double updateRate = 30; // Hz @@ -75,6 +76,7 @@ sdf::ElementPtr MakeDVLSdf(const DVLConfig &_config) << " " << " " << " " + << " " << _config.frameId << "" << " " << _config.alwaysOn << "" << " " << _config.updateRate << "" << " " << _config.topic << "" @@ -345,6 +347,13 @@ TEST_P(DopplerVelocityLogTest, BottomTrackingWhileStatic) } EXPECT_EQ(0, message.status()); + // check frame id + EXPECT_TRUE(message.has_header()); + EXPECT_LT(1, message.header().data().size()); + EXPECT_EQ("frame_id", message.header().data(0).key()); + ASSERT_EQ(1, message.header().data(0).value().size()); + EXPECT_EQ("dvl_frame", message.header().data(0).value(0)); + this->manager.Remove(sensor->Id()); } @@ -436,6 +445,13 @@ TEST_P(DopplerVelocityLogTest, WaterMassTrackingWhileStatic) } EXPECT_EQ(0, message.status()); + // check frame id + EXPECT_TRUE(message.has_header()); + EXPECT_LT(1, message.header().data().size()); + EXPECT_EQ("frame_id", message.header().data(0).key()); + ASSERT_EQ(1, message.header().data(0).value().size()); + EXPECT_EQ("dvl_frame", message.header().data(0).value(0)); + this->manager.Remove(sensor->Id()); } @@ -519,6 +535,13 @@ TEST_P(DopplerVelocityLogTest, BottomTrackingWhileInMotion) } EXPECT_EQ(0, message.status()); + // check frame id + EXPECT_TRUE(message.has_header()); + EXPECT_LT(1, message.header().data().size()); + EXPECT_EQ("frame_id", message.header().data(0).key()); + ASSERT_EQ(1, message.header().data(0).value().size()); + EXPECT_EQ("dvl_frame", message.header().data(0).value(0)); + this->manager.Remove(sensor->Id()); } diff --git a/test/integration/gpu_lidar_sensor.cc b/test/integration/gpu_lidar_sensor.cc index a0753b40..22ef6c7f 100644 --- a/test/integration/gpu_lidar_sensor.cc +++ b/test/integration/gpu_lidar_sensor.cc @@ -65,7 +65,7 @@ sdf::ElementPtr GpuLidarToSdf(const std::string &name, const double vertResolution, const double vertMinAngle, const double vertMaxAngle, const double rangeResolution, const double rangeMin, const double rangeMax, const bool alwaysOn, - const bool visualize) + const bool visualize, const std::string &frameId) { std::ostringstream stream; stream @@ -74,6 +74,7 @@ sdf::ElementPtr GpuLidarToSdf(const std::string &name, << " " << " " << " " + << " " << frameId << "" << " " << pose << "" << " " << topic << "" << " "<< updateRate <<"" @@ -194,6 +195,7 @@ void GpuLidarSensorTest::CreateGpuLidar(const std::string &_renderEngine) const double rangeMax = 10.0; const bool alwaysOn = 1; const bool visualize = 1; + const std::string frameId = "TestGpuLidar_frame"; // Create sensor description in SDF gz::math::Pose3d testPose(gz::math::Vector3d(0, 0, 0.1), @@ -201,7 +203,7 @@ void GpuLidarSensorTest::CreateGpuLidar(const std::string &_renderEngine) sdf::ElementPtr lidarSdf = GpuLidarToSdf(name, testPose, updateRate, topic, horzSamples, horzResolution, horzMinAngle, horzMaxAngle, vertSamples, vertResolution, vertMinAngle, vertMaxAngle, - rangeResolution, rangeMin, rangeMax, alwaysOn, visualize); + rangeResolution, rangeMin, rangeMax, alwaysOn, visualize, frameId); // Setup gz-rendering with an empty scene auto *engine = gz::rendering::engine(_renderEngine); @@ -313,6 +315,7 @@ void GpuLidarSensorTest::DetectBox(const std::string &_renderEngine) const double rangeMax = 10.0; const bool alwaysOn = 1; const bool visualize = 1; + const std::string frameId = "TestGpuLidar_frame"; // Create sensor SDF gz::math::Pose3d testPose(gz::math::Vector3d(0.0, 0.0, 0.1), @@ -320,7 +323,7 @@ void GpuLidarSensorTest::DetectBox(const std::string &_renderEngine) sdf::ElementPtr lidarSdf = GpuLidarToSdf(name, testPose, updateRate, topic, horzSamples, horzResolution, horzMinAngle, horzMaxAngle, vertSamples, vertResolution, vertMinAngle, vertMaxAngle, - rangeResolution, rangeMin, rangeMax, alwaysOn, visualize); + rangeResolution, rangeMin, rangeMax, alwaysOn, visualize, frameId); // Create and populate scene gz::rendering::RenderEngine *engine = @@ -399,7 +402,7 @@ void GpuLidarSensorTest::DetectBox(const std::string &_renderEngine) LASER_TOL); EXPECT_DOUBLE_EQ(laserMsgs.back().ranges(last), gz::math::INF_D); - EXPECT_EQ(laserMsgs.back().frame(), name); + EXPECT_EQ(laserMsgs.back().frame(), frameId); EXPECT_NEAR(laserMsgs.back().angle_min(), horzMinAngle, 1e-4); EXPECT_NEAR(laserMsgs.back().angle_max(), horzMaxAngle, 1e-4); EXPECT_NEAR(laserMsgs.back().count(), horzSamples, 1e-4); @@ -425,6 +428,12 @@ void GpuLidarSensorTest::DetectBox(const std::string &_renderEngine) EXPECT_FALSE(pointMsgs.back().is_dense()); EXPECT_EQ(32u * horzSamples * vertSamples, pointMsgs.back().data().size()); + EXPECT_TRUE(pointMsgs.back().has_header()); + EXPECT_LT(1, pointMsgs.back().header().data().size()); + EXPECT_EQ("frame_id", pointMsgs.back().header().data(0).key()); + ASSERT_EQ(1, pointMsgs.back().header().data(0).value().size()); + EXPECT_EQ(frameId, pointMsgs.back().header().data(0).value(0)); + // Clean up rendering ptrs visualBox1.reset(); @@ -462,6 +471,7 @@ void GpuLidarSensorTest::TestThreeBoxes(const std::string &_renderEngine) const double rangeMax = 10.0; const bool alwaysOn = 1; const bool visualize = 1; + const std::string frameId = "TestGpuLidar_frame"; // Create sensor SDF gz::math::Pose3d testPose1(gz::math::Vector3d(0, 0, 0.1), @@ -469,7 +479,7 @@ void GpuLidarSensorTest::TestThreeBoxes(const std::string &_renderEngine) sdf::ElementPtr lidarSdf1 = GpuLidarToSdf(name1, testPose1, updateRate, topic1, horzSamples, horzResolution, horzMinAngle, horzMaxAngle, vertSamples, vertResolution, vertMinAngle, vertMaxAngle, - rangeResolution, rangeMin, rangeMax, alwaysOn, visualize); + rangeResolution, rangeMin, rangeMax, alwaysOn, visualize, frameId); // Create a second sensor SDF rotated gz::math::Pose3d testPose2(gz::math::Vector3d(0, 0, 0.1), @@ -477,7 +487,7 @@ void GpuLidarSensorTest::TestThreeBoxes(const std::string &_renderEngine) sdf::ElementPtr lidarSdf2 = GpuLidarToSdf(name2, testPose2, updateRate, topic2, horzSamples, horzResolution, horzMinAngle, horzMaxAngle, vertSamples, vertResolution, vertMinAngle, vertMaxAngle, - rangeResolution, rangeMin, rangeMax, alwaysOn, visualize); + rangeResolution, rangeMin, rangeMax, alwaysOn, visualize, frameId); // Create and populate scene gz::rendering::RenderEngine *engine = @@ -618,6 +628,7 @@ void GpuLidarSensorTest::VerticalLidar(const std::string &_renderEngine) const double rangeMax = 10.0; const bool alwaysOn = 1; const bool visualize = 1; + const std::string frameId = "TestGpuLidar_frame"; // Create sensor SDF gz::math::Pose3d testPose(gz::math::Vector3d(0.25, 0.0, 0.5), @@ -625,7 +636,7 @@ void GpuLidarSensorTest::VerticalLidar(const std::string &_renderEngine) sdf::ElementPtr lidarSdf = GpuLidarToSdf(name, testPose, updateRate, topic, horzSamples, horzResolution, horzMinAngle, horzMaxAngle, vertSamples, vertResolution, vertMinAngle, vertMaxAngle, - rangeResolution, rangeMin, rangeMax, alwaysOn, visualize); + rangeResolution, rangeMin, rangeMax, alwaysOn, visualize, frameId); // Create and populate scene gz::rendering::RenderEngine *engine = @@ -745,6 +756,7 @@ void GpuLidarSensorTest::ManualUpdate(const std::string &_renderEngine) const double rangeMax = 10.0; const bool alwaysOn = 1; const bool visualize = 1; + const std::string frameId = "TestGpuLidar_frame"; // Create sensor SDF gz::math::Pose3d testPose1(gz::math::Vector3d(0, 0, 0.1), @@ -752,7 +764,7 @@ void GpuLidarSensorTest::ManualUpdate(const std::string &_renderEngine) sdf::ElementPtr lidarSdf1 = GpuLidarToSdf(name1, testPose1, updateRate, topic1, horzSamples, horzResolution, horzMinAngle, horzMaxAngle, vertSamples, vertResolution, vertMinAngle, vertMaxAngle, - rangeResolution, rangeMin, rangeMax, alwaysOn, visualize); + rangeResolution, rangeMin, rangeMax, alwaysOn, visualize, frameId); // Create a second sensor SDF at an xy offset of 1 gz::math::Pose3d testPose2(gz::math::Vector3d(1, 1, 0.1), @@ -760,7 +772,7 @@ void GpuLidarSensorTest::ManualUpdate(const std::string &_renderEngine) sdf::ElementPtr lidarSdf2 = GpuLidarToSdf(name2, testPose2, updateRate, topic2, horzSamples, horzResolution, horzMinAngle, horzMaxAngle, vertSamples, vertResolution, vertMinAngle, vertMaxAngle, - rangeResolution, rangeMin, rangeMax, alwaysOn, visualize); + rangeResolution, rangeMin, rangeMax, alwaysOn, visualize, frameId); // Create and populate scene gz::rendering::RenderEngine *engine = @@ -871,6 +883,7 @@ void GpuLidarSensorTest::Topic(const std::string &_renderEngine) const bool alwaysOn = 1; const bool visualize = 1; auto testPose = gz::math::Pose3d(); + const std::string frameId = "TestGpuLidar_frame"; // Scene auto engine = gz::rendering::engine(_renderEngine); @@ -892,7 +905,7 @@ void GpuLidarSensorTest::Topic(const std::string &_renderEngine) auto lidarSdf = GpuLidarToSdf(name, testPose, updateRate, topic, horzSamples, horzResolution, horzMinAngle, horzMaxAngle, vertSamples, vertResolution, vertMinAngle, vertMaxAngle, - rangeResolution, rangeMin, rangeMax, alwaysOn, visualize); + rangeResolution, rangeMin, rangeMax, alwaysOn, visualize, frameId); auto lidar = mgr.CreateSensor(lidarSdf); ASSERT_NE(nullptr, lidar); @@ -906,7 +919,7 @@ void GpuLidarSensorTest::Topic(const std::string &_renderEngine) auto lidarSdf = GpuLidarToSdf(name, testPose, updateRate, topic, horzSamples, horzResolution, horzMinAngle, horzMaxAngle, vertSamples, vertResolution, vertMinAngle, vertMaxAngle, - rangeResolution, rangeMin, rangeMax, alwaysOn, visualize); + rangeResolution, rangeMin, rangeMax, alwaysOn, visualize, frameId); auto lidar = mgr.CreateSensor(lidarSdf); ASSERT_NE(nullptr, lidar); @@ -921,7 +934,7 @@ void GpuLidarSensorTest::Topic(const std::string &_renderEngine) auto lidarSdf = GpuLidarToSdf(name, testPose, updateRate, topic, horzSamples, horzResolution, horzMinAngle, horzMaxAngle, vertSamples, vertResolution, vertMinAngle, vertMaxAngle, - rangeResolution, rangeMin, rangeMax, alwaysOn, visualize); + rangeResolution, rangeMin, rangeMax, alwaysOn, visualize, frameId); auto sensor = mgr.CreateSensor(lidarSdf); EXPECT_EQ(nullptr, sensor);