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.
motion_computation_worker.hpp
Go to the documentation of this file.
1// Copyright 2019-2023 Leidos
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef MOTION_COMPUTATION__MOTION_COMPUTATION_WORKER_HPP_
16#define MOTION_COMPUTATION__MOTION_COMPUTATION_WORKER_HPP_
17
18#include <gtest/gtest_prod.h>
19#include <lanelet2_extension/projection/local_frame_projector.h>
20#include <tf2/LinearMath/Transform.h>
21#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
22
23#include <functional>
24#include <memory>
25#include <string>
26#include <tuple>
27#include <unordered_map>
28
29#include <motion_predict/motion_predict.hpp>
30#include <motion_predict/predict_ctrv.hpp>
31#include <rclcpp/rclcpp.hpp>
32
33#include <carma_perception_msgs/msg/external_object.hpp>
34#include <carma_perception_msgs/msg/external_object_list.hpp>
35#include <carma_v2x_msgs/msg/bsm.hpp>
36#include <carma_v2x_msgs/msg/mobility_path.hpp>
37#include <carma_v2x_msgs/msg/psm.hpp>
38#include <std_msgs/msg/string.hpp>
39
40namespace motion_computation
41{
47{
48public:
50 std::function<void(const carma_perception_msgs::msg::ExternalObjectList &)>;
51 using LookUpTransform = std::function<void()>;
52
57 const PublishObjectCallback & obj_pub,
58 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger,
59 rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock);
65 void predictionLogic(carma_perception_msgs::msg::ExternalObjectList::UniquePtr obj_list);
66
67 // Setters for the prediction parameters
68 void setPredictionTimeStep(double time_step);
69 void setPredictionPeriod(double period);
70 void setXAccelerationNoise(double noise);
71 void setYAccelerationNoise(double noise);
72 void setProcessNoiseMax(double noise_max);
73 void setConfidenceDropRate(double drop_rate);
75 bool enable_sensor_processing, bool enable_bsm_processing, bool enable_psm_processing,
76 bool enable_mobility_path_processing);
78 bool enable_ctrv_for_unknown_obj, bool enable_ctrv_for_motorcycle_obj,
79 bool enable_ctrv_for_small_vehicle_obj, bool enable_ctrv_for_large_vehicle_obj,
80 bool enable_ctrv_for_pedestrian_obj);
81
82 // callbacks
83 void mobilityPathCallback(const carma_v2x_msgs::msg::MobilityPath::UniquePtr msg);
84
85 void bsmCallback(const carma_v2x_msgs::msg::BSM::UniquePtr msg);
86
87 void psmCallback(const carma_v2x_msgs::msg::PSM::UniquePtr msg);
88
93 void georeferenceCallback(const std_msgs::msg::String::UniquePtr msg);
94
101 carma_perception_msgs::msg::ExternalObject mobilityPathToExternalObject(
102 const carma_v2x_msgs::msg::MobilityPath::UniquePtr & msg) const;
103
113 carma_perception_msgs::msg::ExternalObjectList synchronizeAndAppend(
114 const carma_perception_msgs::msg::ExternalObjectList & base_objects,
115 carma_perception_msgs::msg::ExternalObjectList new_objects) const;
116
127 carma_perception_msgs::msg::ExternalObject matchAndInterpolateTimeStamp(
128 carma_perception_msgs::msg::ExternalObject path, const rclcpp::Time & time_to_match) const;
129
130private:
131 // Local copy of external object publisher
133
134 // Prediction parameters
135
136 double prediction_time_step_ = 0.1; // Seconds
137 double prediction_period_ = 2.0; // Seconds
138 double cv_x_accel_noise_ = 9.0;
139 double cv_y_accel_noise_ = 9.0;
142
143 // Flags for the different possible detection inputs
148
149 // Flags for the different possible motion models for detections
155
156 // Map frame
157 std::string map_frame_id_ = "map";
158
159 // Logger interface
160 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_;
161 // Clock interface - gets the ros simulated clock from Node
162 rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock_;
163
164 // Queue for v2x msgs to synchronize them with sensor msgs
165 carma_perception_msgs::msg::ExternalObjectList mobility_path_list_;
166 carma_perception_msgs::msg::ExternalObjectList bsm_list_;
167 carma_perception_msgs::msg::ExternalObjectList psm_list_;
168
169 // Maps of external object id to index in synchronization queues
170 std::unordered_map<uint32_t, size_t> mobility_path_obj_id_map_;
171 std::unordered_map<uint32_t, size_t> bsm_obj_id_map_;
172 std::unordered_map<uint32_t, size_t> psm_obj_id_map_;
173
174 std::string georeference_{""};
175 std::shared_ptr<lanelet::projection::LocalFrameProjector> map_projector_;
176
177 // Rotation of a North East Down frame located on the map origin described in the map frame
178 tf2::Quaternion ned_in_map_rotation_;
179
180 // Unit Test Accessors
181 FRIEND_TEST(MotionComputationWorker, MobilityPathToExternalObject);
184};
185
186} // namespace motion_computation
187
188#endif // MOTION_COMPUTATION__MOTION_COMPUTATION_WORKER_HPP_
The class containing the primary business logic for the Motion Computation Package.
carma_perception_msgs::msg::ExternalObjectList bsm_list_
void georeferenceCallback(const std_msgs::msg::String::UniquePtr msg)
Callback for map projection string to define lat/lon -> map conversion.
void predictionLogic(carma_perception_msgs::msg::ExternalObjectList::UniquePtr obj_list)
Function to populate duplicated detected objects along with their velocity, yaw, yaw_rate and static/...
carma_perception_msgs::msg::ExternalObjectList psm_list_
void setDetectionMotionModelFlags(bool enable_ctrv_for_unknown_obj, bool enable_ctrv_for_motorcycle_obj, bool enable_ctrv_for_small_vehicle_obj, bool enable_ctrv_for_large_vehicle_obj, bool enable_ctrv_for_pedestrian_obj)
carma_perception_msgs::msg::ExternalObjectList mobility_path_list_
carma_perception_msgs::msg::ExternalObjectList synchronizeAndAppend(const carma_perception_msgs::msg::ExternalObjectList &base_objects, carma_perception_msgs::msg::ExternalObjectList new_objects) const
Appends external objects list behind base_objects. This does not do sensor fusion....
void psmCallback(const carma_v2x_msgs::msg::PSM::UniquePtr msg)
std::unordered_map< uint32_t, size_t > bsm_obj_id_map_
void bsmCallback(const carma_v2x_msgs::msg::BSM::UniquePtr msg)
std::shared_ptr< lanelet::projection::LocalFrameProjector > map_projector_
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_
std::unordered_map< uint32_t, size_t > psm_obj_id_map_
std::function< void(const carma_perception_msgs::msg::ExternalObjectList &)> PublishObjectCallback
void setDetectionInputFlags(bool enable_sensor_processing, bool enable_bsm_processing, bool enable_psm_processing, bool enable_mobility_path_processing)
FRIEND_TEST(MotionComputationWorker, PsmToExternalObject)
FRIEND_TEST(MotionComputationWorker, MobilityPathToExternalObject)
FRIEND_TEST(MotionComputationWorker, BSMtoExternalObject)
rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock_
void mobilityPathCallback(const carma_v2x_msgs::msg::MobilityPath::UniquePtr msg)
MotionComputationWorker(const PublishObjectCallback &obj_pub, rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger, rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock)
Constructor for MotionComputationWorker.
std::unordered_map< uint32_t, size_t > mobility_path_obj_id_map_
carma_perception_msgs::msg::ExternalObject mobilityPathToExternalObject(const carma_v2x_msgs::msg::MobilityPath::UniquePtr &msg) const
Converts from MobilityPath's predicted points in ECEF to local map and other fields in an ExternalObj...
carma_perception_msgs::msg::ExternalObject matchAndInterpolateTimeStamp(carma_perception_msgs::msg::ExternalObject path, const rclcpp::Time &time_to_match) const
It cuts ExternalObject's prediction points before the time_to_match. And uses the average velocity in...