15#include <wgs84_utils/proj_tools.h>
27 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger,
28 rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock)
29: obj_pub_(obj_pub), logger_(logger), node_clock_(node_clock)
34 carma_perception_msgs::msg::ExternalObjectList::UniquePtr obj_list)
36 carma_perception_msgs::msg::ExternalObjectList sensor_list;
37 sensor_list.header = obj_list->header;
39 if (!obj_list || obj_list->objects.empty()) {
43 for (
auto obj : obj_list->objects) {
56 if (obj.object_type == obj.UNKNOWN) {
58 }
else if (obj.object_type == obj.MOTORCYCLE) {
60 }
else if (obj.object_type == obj.SMALL_VEHICLE) {
62 }
else if (obj.object_type == obj.LARGE_VEHICLE) {
64 }
else if (obj.object_type == obj.PEDESTRIAN) {
67 obj.object_type = obj.UNKNOWN;
71 if (use_ctrv_model ==
true) {
72 obj.predictions = motion_predict::ctrv::predictPeriod(
76 obj.predictions = motion_predict::cv::predictPeriod(
81 sensor_list.objects.emplace_back(obj);
85 carma_perception_msgs::msg::ExternalObjectList synchronization_base_objects;
86 synchronization_base_objects.header =
94 synchronization_base_objects.objects = sensor_list.objects;
99 synchronization_base_objects.objects.clear();
104 "Not configured to publish any data publishing empty "
105 "object list. Operating like this is NOT "
108 obj_pub_(synchronization_base_objects);
129 synchronization_base_objects =
133 obj_pub_(synchronization_base_objects);
149 map_projector_ = std::make_shared<lanelet::projection::LocalFrameProjector>(msg->data.c_str());
152 wgs84_utils::proj_tools::getAxisFromProjString(msg->data);
154 RCLCPP_INFO_STREAM(
logger_->get_logger(),
"Extracted Axis: " << axis);
157 wgs84_utils::proj_tools::getRotationOfNEDFromProjAxis(axis);
160 logger_->get_logger(),
"Extracted NED in Map Rotation (x,y,z,w) : ( "
189 bool enable_sensor_processing,
bool enable_bsm_processing,
bool enable_psm_processing,
190 bool enable_mobility_path_processing)
199 bool enable_ctrv_for_unknown_obj,
bool enable_ctrv_for_motorcycle_obj,
200 bool enable_ctrv_for_small_vehicle_obj,
bool enable_ctrv_for_large_vehicle_obj,
201 bool enable_ctrv_for_pedestrian_obj)
211 const carma_v2x_msgs::msg::MobilityPath::UniquePtr msg)
215 logger_->get_logger(),
"Map projection not available yet so ignoring MobilityPath messages");
222 "enable_mobility_path_processing is false so ignoring MobilityPath messages");
226 carma_perception_msgs::msg::ExternalObject obj_msg;
245 logger_->get_logger(),
"Map projection not available yet so ignoring PSM messages");
251 logger_->get_logger(),
"enable_psm_processing is false so ignoring PSM messages");
255 carma_perception_msgs::msg::ExternalObject obj_msg;
276 logger_->get_logger(),
"Map projection not available yet so ignoring PSM messages");
282 logger_->get_logger(),
"enable_bsm_processing is false so ignoring BSM messages");
286 carma_perception_msgs::msg::ExternalObject obj_msg;
304 const carma_perception_msgs::msg::ExternalObjectList & base_objects,
305 carma_perception_msgs::msg::ExternalObjectList new_objects)
const
307 carma_perception_msgs::msg::ExternalObjectList output_list;
308 output_list.header = base_objects.header;
309 output_list.objects.reserve(base_objects.objects.size() + new_objects.objects.size());
314 for (
auto & obj : new_objects.objects) {
319 output_list.objects.insert(
320 output_list.objects.begin(), base_objects.objects.begin(), base_objects.objects.end());
321 output_list.objects.insert(
322 output_list.objects.end(), new_objects.objects.begin(), new_objects.objects.end());
327 carma_perception_msgs::msg::ExternalObject path,
const rclcpp::Time & time_to_match)
const
329 carma_perception_msgs::msg::ExternalObject output = path;
331 output.predictions = {};
334 carma_perception_msgs::msg::PredictedState prev_state;
335 prev_state.header.stamp = output.header.stamp;
336 prev_state.predicted_position.orientation = output.pose.pose.orientation;
337 prev_state.predicted_velocity = output.velocity.twist;
338 prev_state.predicted_position.position.x = output.pose.pose.position.x;
339 prev_state.predicted_position.position.y = output.pose.pose.position.y;
340 prev_state.predicted_position.position.z = output.pose.pose.position.z;
341 path.predictions.insert(path.predictions.begin(), prev_state);
343 rclcpp::Time curr_time_to_match = time_to_match;
348 bool is_first_point =
true;
349 carma_perception_msgs::msg::PredictedState new_state;
350 for (
auto const & curr_state : path.predictions) {
351 if (curr_time_to_match > curr_state.header.stamp) {
352 prev_state = curr_state;
360 new_state.header.stamp = curr_time_to_match;
361 new_state.predicted_velocity = prev_state.predicted_velocity;
362 new_state.predicted_position.orientation = prev_state.predicted_position.orientation;
365 rclcpp::Duration delta_t = rclcpp::Time(curr_state.header.stamp) - curr_time_to_match;
366 rclcpp::Duration pred_delta_t =
367 rclcpp::Time(curr_state.header.stamp) - rclcpp::Time(prev_state.header.stamp);
369 if (pred_delta_t.seconds() < 0.00000001) {
374 ratio = delta_t.seconds() / pred_delta_t.seconds();
378 curr_state.predicted_position.position.x - prev_state.predicted_position.position.x;
380 curr_state.predicted_position.position.y - prev_state.predicted_position.position.y;
382 curr_state.predicted_position.position.z - prev_state.predicted_position.position.z;
384 new_state.predicted_position.position.x =
385 curr_state.predicted_position.position.x - delta_x * ratio;
386 new_state.predicted_position.position.y =
387 curr_state.predicted_position.position.y - delta_y * ratio;
388 new_state.predicted_position.position.z =
389 curr_state.predicted_position.position.z - delta_z * ratio;
391 output.header.stamp = curr_time_to_match;
392 output.pose.pose.orientation = new_state.predicted_position.orientation;
393 output.velocity.twist = new_state.predicted_velocity;
394 output.pose.pose.position.x = new_state.predicted_position.position.x;
395 output.pose.pose.position.y = new_state.predicted_position.position.y;
396 output.pose.pose.position.z = new_state.predicted_position.position.z;
397 is_first_point =
false;
400 output.predictions.push_back(curr_state);
bool enable_ctrv_for_motorcycle_obj_
carma_perception_msgs::msg::ExternalObjectList bsm_list_
void setConfidenceDropRate(double drop_rate)
void georeferenceCallback(const std_msgs::msg::String::UniquePtr msg)
Callback for map projection string to define lat/lon -> map conversion.
double prediction_period_
bool enable_ctrv_for_pedestrian_obj_
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/...
double prediction_confidence_drop_rate_
double prediction_process_noise_max_
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_
tf2::Quaternion ned_in_map_rotation_
std::string georeference_
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....
bool enable_ctrv_for_small_vehicle_obj_
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_
bool enable_sensor_processing_
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_
bool enable_ctrv_for_unknown_obj_
std::unordered_map< uint32_t, size_t > psm_obj_id_map_
double prediction_time_step_
void setYAccelerationNoise(double noise)
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)
bool enable_mobility_path_processing_
void setXAccelerationNoise(double noise)
bool enable_psm_processing_
void setPredictionPeriod(double period)
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::string map_frame_id_
bool enable_bsm_processing_
void setProcessNoiseMax(double noise_max)
PublishObjectCallback obj_pub_
std::unordered_map< uint32_t, size_t > mobility_path_obj_id_map_
bool enable_ctrv_for_large_vehicle_obj_
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...
void setPredictionTimeStep(double time_step)
void convert(const carma_v2x_msgs::msg::PSM &in_msg, carma_perception_msgs::msg::ExternalObject &out_msg, const std::string &map_frame_id, double pred_period, double pred_step_size, const lanelet::projection::LocalFrameProjector &map_projector, const tf2::Quaternion &ned_in_map_rotation, rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock)