Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
object_detection_tracking_node.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2021 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
17
18namespace object{
19
20 using std::placeholders::_1;
21 using std::placeholders::_2;
22 using std::placeholders::_3;
23
25 : carma_ros2_utils::CarmaLifecycleNode(options),
26 object_worker_(
27 std::bind(&ObjectDetectionTrackingNode::publishObject, this, _1),
28 std::bind(&ObjectDetectionTrackingNode::lookupTransform, this, _1, _2, _3),
29 get_node_logging_interface()
30 )
31 {
32 // Initialize tf buffer with clock and duration
33 tfBuffer_ = std::make_shared<tf2_ros::Buffer>(this->get_clock());
34 // Initialize transform listener with buffer
35 tfListener_ = std::make_shared<tf2_ros::TransformListener>(*tfBuffer_);
36 map_frame_ = this->declare_parameter<std::string>("map_frame", map_frame_);
37 }
38
39 carma_ros2_utils::CallbackReturn ObjectDetectionTrackingNode::handle_on_configure(const rclcpp_lifecycle::State &) {
40
41 // Load parameters
42 this->get_parameter<std::string>("map_frame", map_frame_);
44
45 this->add_on_set_parameters_callback(
46 [this](auto param_vec) {
47
48 auto error = update_params<std::string>({ {"map_frame", map_frame_} }, param_vec);
49
50 rcl_interfaces::msg::SetParametersResult result;
51
52 result.successful = !error;
53
54 if (error) {
55 result.reason = error.get();
56 } else {
58 }
59
60 return result;
61 }
62 );
63
64
65 // Setup pub/sub
66 autoware_obj_sub_= create_subscription<autoware_auto_msgs::msg::TrackedObjects>("detected_objects",10,
68 );
69
70 carma_obj_pub_= create_publisher<carma_perception_msgs::msg::ExternalObjectList>("external_objects", 10);
71
72 return CallbackReturn::SUCCESS;
73 }
74
75 void ObjectDetectionTrackingNode::publishObject(const carma_perception_msgs::msg::ExternalObjectList& obj_msg)
76 {
77 carma_obj_pub_->publish(obj_msg);
78 }
79
80 boost::optional<geometry_msgs::msg::TransformStamped>
81 ObjectDetectionTrackingNode::lookupTransform(const std::string& parent, const std::string& child, const rclcpp::Time& stamp) {
82 try {
83 return tfBuffer_->lookupTransform(parent, child, stamp);
84
85 } catch (tf2::TransformException &ex) {
86
87 RCLCPP_WARN_STREAM(get_logger(), "Failed to find transform with exception " << ex.what());
88 return boost::none;
89 }
90 }
91
92
93
94}//object
95
96#include "rclcpp_components/register_node_macro.hpp"
97
98// Register the component with class_loader
99RCLCPP_COMPONENTS_REGISTER_NODE(object::ObjectDetectionTrackingNode)
carma_ros2_utils::SubPtr< autoware_auto_msgs::msg::TrackedObjects > autoware_obj_sub_
void publishObject(const carma_perception_msgs::msg::ExternalObjectList &obj_msg)
Callback to publish ObjectList.
carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &)
boost::optional< geometry_msgs::msg::TransformStamped > lookupTransform(const std::string &parent, const std::string &child, const rclcpp::Time &stamp)
Callback to lookup a transform between two frames.
std::shared_ptr< tf2_ros::TransformListener > tfListener_
ObjectDetectionTrackingNode(const rclcpp::NodeOptions &)
ObjectDetectionTrackingNode constructor.
carma_ros2_utils::PubPtr< carma_perception_msgs::msg::ExternalObjectList > carma_obj_pub_
std::shared_ptr< tf2_ros::Buffer > tfBuffer_
void detectedObjectCallback(autoware_auto_msgs::msg::TrackedObjects::UniquePtr msg)
detectedObjectCallback populates detected object along with its velocity,yaw, yaw_rate and static/dyn...