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);
148 map_projector_ = std::make_shared<lanelet::projection::LocalFrameProjector>(msg->data.c_str());
151 wgs84_utils::proj_tools::getAxisFromProjString(msg->data);
153 RCLCPP_INFO_STREAM(
logger_->get_logger(),
"Extracted Axis: " << axis);
156 wgs84_utils::proj_tools::getRotationOfNEDFromProjAxis(axis);
159 logger_->get_logger(),
"Extracted NED in Map Rotation (x,y,z,w) : ( "
188 bool enable_sensor_processing,
bool enable_bsm_processing,
bool enable_psm_processing,
189 bool enable_mobility_path_processing)
198 bool enable_ctrv_for_unknown_obj,
bool enable_ctrv_for_motorcycle_obj,
199 bool enable_ctrv_for_small_vehicle_obj,
bool enable_ctrv_for_large_vehicle_obj,
200 bool enable_ctrv_for_pedestrian_obj)
210 const carma_v2x_msgs::msg::MobilityPath::UniquePtr msg)
214 logger_->get_logger(),
"Map projection not available yet so ignoring MobilityPath messages");
221 "enable_mobility_path_processing is false so ignoring MobilityPath messages");
225 carma_perception_msgs::msg::ExternalObject obj_msg;
244 logger_->get_logger(),
"Map projection not available yet so ignoring PSM messages");
250 logger_->get_logger(),
"enable_psm_processing is false so ignoring PSM messages");
254 carma_perception_msgs::msg::ExternalObject obj_msg;
275 logger_->get_logger(),
"Map projection not available yet so ignoring PSM messages");
281 logger_->get_logger(),
"enable_bsm_processing is false so ignoring BSM messages");
285 carma_perception_msgs::msg::ExternalObject obj_msg;
303 const carma_perception_msgs::msg::ExternalObjectList & base_objects,
304 carma_perception_msgs::msg::ExternalObjectList new_objects)
const
306 carma_perception_msgs::msg::ExternalObjectList output_list;
307 output_list.header = base_objects.header;
308 output_list.objects.reserve(base_objects.objects.size() + new_objects.objects.size());
313 for (
auto & obj : new_objects.objects) {
318 output_list.objects.insert(
319 output_list.objects.begin(), base_objects.objects.begin(), base_objects.objects.end());
320 output_list.objects.insert(
321 output_list.objects.end(), new_objects.objects.begin(), new_objects.objects.end());
326 carma_perception_msgs::msg::ExternalObject path,
const rclcpp::Time & time_to_match)
const
328 carma_perception_msgs::msg::ExternalObject output = path;
330 output.predictions = {};
333 carma_perception_msgs::msg::PredictedState prev_state;
334 prev_state.header.stamp = output.header.stamp;
335 prev_state.predicted_position.orientation = output.pose.pose.orientation;
336 prev_state.predicted_velocity = output.velocity.twist;
337 prev_state.predicted_position.position.x = output.pose.pose.position.x;
338 prev_state.predicted_position.position.y = output.pose.pose.position.y;
339 prev_state.predicted_position.position.z = output.pose.pose.position.z;
340 path.predictions.insert(path.predictions.begin(), prev_state);
342 rclcpp::Time curr_time_to_match = time_to_match;
347 bool is_first_point =
true;
348 carma_perception_msgs::msg::PredictedState new_state;
349 for (
auto const & curr_state : path.predictions) {
350 if (curr_time_to_match > curr_state.header.stamp) {
351 prev_state = curr_state;
359 new_state.header.stamp = curr_time_to_match;
360 new_state.predicted_velocity = prev_state.predicted_velocity;
361 new_state.predicted_position.orientation = prev_state.predicted_position.orientation;
364 rclcpp::Duration delta_t = rclcpp::Time(curr_state.header.stamp) - curr_time_to_match;
365 rclcpp::Duration pred_delta_t =
366 rclcpp::Time(curr_state.header.stamp) - rclcpp::Time(prev_state.header.stamp);
368 if (pred_delta_t.seconds() < 0.00000001) {
373 ratio = delta_t.seconds() / pred_delta_t.seconds();
377 curr_state.predicted_position.position.x - prev_state.predicted_position.position.x;
379 curr_state.predicted_position.position.y - prev_state.predicted_position.position.y;
381 curr_state.predicted_position.position.z - prev_state.predicted_position.position.z;
383 new_state.predicted_position.position.x =
384 curr_state.predicted_position.position.x - delta_x * ratio;
385 new_state.predicted_position.position.y =
386 curr_state.predicted_position.position.y - delta_y * ratio;
387 new_state.predicted_position.position.z =
388 curr_state.predicted_position.position.z - delta_z * ratio;
390 output.header.stamp = curr_time_to_match;
391 output.pose.pose.orientation = new_state.predicted_position.orientation;
392 output.velocity.twist = new_state.predicted_velocity;
393 output.pose.pose.position.x = new_state.predicted_position.position.x;
394 output.pose.pose.position.y = new_state.predicted_position.position.y;
395 output.pose.pose.position.z = new_state.predicted_position.position.z;
396 is_first_point =
false;
399 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)