-
Notifications
You must be signed in to change notification settings - Fork 30
Implement Ros2PublishRadarScanNode with tests #247
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ac75312
Implement Ros2PublishRadarScanNode
prybicki ee7443c
Add test for Ros2PublishRadarScanNode
prybicki e0057c6
Fix copyright year
prybicki 6858e46
Add API Call
prybicki 1d497cd
Apply suggestions from code review
prybicki 62f4633
Review fixes
prybicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Copyright 2024 Robotec.AI | ||
| // | ||
| // 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 <graph/NodesRos2.hpp> | ||
| #include <scene/Scene.hpp> | ||
|
|
||
| void Ros2PublishRadarScanNode::setParameters(const char* topicName, const char* frameId, | ||
| rgl_qos_policy_reliability_t qosReliability, | ||
| rgl_qos_policy_durability_t qosDurability, rgl_qos_policy_history_t qosHistory, | ||
| int32_t qosHistoryDepth) | ||
| { | ||
| ros2InitGuard = Ros2InitGuard::acquire(); | ||
|
|
||
| ros2Message.header.frame_id = frameId; | ||
|
|
||
| auto qos = rclcpp::QoS(qosHistoryDepth); | ||
| qos.reliability(static_cast<rmw_qos_reliability_policy_t>(qosReliability)); | ||
| qos.durability(static_cast<rmw_qos_durability_policy_t>(qosDurability)); | ||
| qos.history(static_cast<rmw_qos_history_policy_t>(qosHistory)); | ||
| ros2Publisher = ros2InitGuard->createUniquePublisher<radar_msgs::msg::RadarScan>(topicName, qos); | ||
| } | ||
|
|
||
| void Ros2PublishRadarScanNode::validateImpl() | ||
| { | ||
| IPointsNodeSingleInput::validateImpl(); | ||
| if (input->getHeight() != 1) { | ||
| throw InvalidPipeline("ROS2 radar publish supports unorganized pointclouds only"); | ||
| } | ||
| } | ||
|
|
||
| void Ros2PublishRadarScanNode::enqueueExecImpl() | ||
| { | ||
| ros2Message.header.stamp = Scene::instance().getTime().has_value() ? | ||
| Scene::instance().getTime().value().asRos2Msg() : | ||
| static_cast<builtin_interfaces::msg::Time>(ros2InitGuard->getNode().get_clock()->now()); | ||
| std::vector<rgl_field_t> fields = this->getRequiredFieldList(); | ||
| FormatPointsNode::formatAsync(formattedData, input, fields, fieldDescBuilder); | ||
| ros2Message.returns.resize(input->getPointCount()); | ||
| CHECK_CUDA(cudaMemcpyAsync(ros2Message.returns.data(), formattedData->getReadPtr(), | ||
| formattedData->getSizeOf() * formattedData->getCount(), cudaMemcpyDeviceToHost, | ||
| formattedData->getStream()->getHandle())); | ||
| CHECK_CUDA(cudaStreamSynchronize(formattedData->getStream()->getHandle())); | ||
| ros2Publisher->publish(ros2Message); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #include <helpers/commonHelpers.hpp> | ||
| #include <helpers/sceneHelpers.hpp> | ||
| #include <helpers/graphHelpers.hpp> | ||
| #include <helpers/testPointCloud.hpp> | ||
|
|
||
| #include <rgl/api/extensions/ros2.h> | ||
|
|
||
| #include <rclcpp/rclcpp.hpp> | ||
| #include <radar_msgs/msg/radar_scan.hpp> | ||
| class Ros2PublishRadarScanNodeTest : public RGLTest | ||
| {}; | ||
|
|
||
| TEST_F(Ros2PublishRadarScanNodeTest, should_receive_sent_data) | ||
| { | ||
| const auto POINT_COUNT = 5; | ||
| const auto TOPIC_NAME = "rgl_test_radar_scan"; | ||
| const auto FRAME_ID = "rgl_test_frame_id"; | ||
| const auto NODE_NAME = "rgl_test_node"; | ||
| const auto WAIT_TIME_SECS = 1; | ||
| const auto MESSAGE_REPEATS = 3; | ||
| TestPointCloud input({DISTANCE_F32, AZIMUTH_F32, ELEVATION_F32, RADIAL_SPEED_F32}, POINT_COUNT); | ||
|
|
||
| // Create nodes | ||
| rgl_node_t inputNode = input.createUsePointsNode(), radarScanNode = nullptr; | ||
| ASSERT_RGL_SUCCESS( | ||
| rgl_node_publish_ros2_radarscan(&radarScanNode, TOPIC_NAME, FRAME_ID, QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT, | ||
| QOS_POLICY_DURABILITY_SYSTEM_DEFAULT, QOS_POLICY_HISTORY_SYSTEM_DEFAULT, 0)); | ||
|
|
||
| // Connect nodes | ||
| ASSERT_RGL_SUCCESS(rgl_graph_node_add_child(inputNode, radarScanNode)); | ||
|
|
||
| // Synchronization primitives | ||
| std::atomic<int> messageCount = 0; | ||
|
|
||
| // Create ROS2 subscriber to receive RadarScan messages on topic "radar_scan" | ||
| auto node = std::make_shared<rclcpp::Node>(NODE_NAME, rclcpp::NodeOptions{}); | ||
| auto qos = rclcpp::QoS(10); | ||
| qos.reliability(static_cast<rmw_qos_reliability_policy_t>(QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT)); | ||
| qos.durability(static_cast<rmw_qos_durability_policy_t>(QOS_POLICY_DURABILITY_SYSTEM_DEFAULT)); | ||
| qos.history(static_cast<rmw_qos_history_policy_t>(QOS_POLICY_HISTORY_SYSTEM_DEFAULT)); | ||
| auto subscriber = node->create_subscription<radar_msgs::msg::RadarScan>( | ||
| TOPIC_NAME, qos, [&](const radar_msgs::msg::RadarScan::ConstSharedPtr msg) { | ||
| EXPECT_EQ(msg->returns.size(), POINT_COUNT); | ||
| EXPECT_EQ(msg->header.frame_id, FRAME_ID); | ||
| EXPECT_NE(msg->header.stamp.sec + msg->header.stamp.nanosec, 0); | ||
|
|
||
| for (int i = 0; i < POINT_COUNT; ++i) { | ||
| EXPECT_EQ(msg->returns[i].range, input.getFieldValue<DISTANCE_F32>(i)); | ||
| EXPECT_EQ(msg->returns[i].azimuth, input.getFieldValue<AZIMUTH_F32>(i)); | ||
| EXPECT_EQ(msg->returns[i].elevation, input.getFieldValue<ELEVATION_F32>(i)); | ||
| EXPECT_EQ(msg->returns[i].doppler_velocity, input.getFieldValue<RADIAL_SPEED_F32>(i)); | ||
| } | ||
| ++messageCount; | ||
| }); | ||
|
|
||
| // Run | ||
| for (int i = 0; i < MESSAGE_REPEATS; ++i) { | ||
| ASSERT_RGL_SUCCESS(rgl_graph_run(inputNode)); | ||
| } | ||
|
|
||
| // Wait for messages | ||
| { | ||
| auto start = std::chrono::steady_clock::now(); | ||
| do { | ||
| rclcpp::spin_some(node); | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(10)); | ||
| } while (messageCount != MESSAGE_REPEATS && | ||
| std::chrono::steady_clock::now() - start < std::chrono::seconds(WAIT_TIME_SECS)); | ||
| ASSERT_EQ(messageCount, MESSAGE_REPEATS); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.