20#include <carma_planning_msgs/msg/trajectory_plan.hpp>
21#include <carma_planning_msgs/msg/trajectory_plan_point.hpp>
22#include <carma_planning_msgs/msg/plugin.hpp>
23#include <carma_v2x_msgs/msg/mobility_request.hpp>
24#include <carma_v2x_msgs/msg/mobility_response.hpp>
25#include <carma_v2x_msgs/msg/bsm.hpp>
26#include <carma_planning_msgs/msg/lane_change_status.hpp>
27#include <boost/shared_ptr.hpp>
28#include <carma_ros2_utils/carma_lifecycle_node.hpp>
29#include <boost/geometry.hpp>
33#include <unordered_set>
34#include <carma_planning_msgs/srv/plan_trajectory.hpp>
35#include <std_msgs/msg/string.hpp>
36#include <geometry_msgs/msg/pose_stamped.hpp>
37#include <trajectory_utils/quintic_coefficient_calculator.hpp>
38#include <boost/property_tree/json_parser.hpp>
39#include <lanelet2_extension/projection/local_frame_projector.h>
40#include <carma_v2x_msgs/msg/location_ecef.hpp>
41#include <carma_v2x_msgs/msg/trajectory.hpp>
42#include <carma_v2x_msgs/msg/plan_type.hpp>
52using LaneChangeStatusCB = std::function<void(
const carma_planning_msgs::msg::LaneChangeStatus&)>;
100 carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req,
101 carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp);
110 carma_planning_msgs::msg::TrajectoryPlan
update_traj_for_object(
const carma_planning_msgs::msg::TrajectoryPlan& original_tp,
const std::vector<carma_perception_msgs::msg::ExternalObject>& external_objects,
double initial_velocity);
134 double max_trajectory_speed(
const std::vector<carma_planning_msgs::msg::TrajectoryPlanPoint>& trajectory_points,
double timestamp_in_sec_to_search_until)
const;
141 std::vector<double>
get_relative_downtracks(
const carma_planning_msgs::msg::TrajectoryPlan& trajectory_plan)
const;
153 void bsm_cb(
const carma_v2x_msgs::msg::BSM::UniquePtr msg);
169 lanelet::BasicPoint2d
ecef_to_map_point(
const carma_v2x_msgs::msg::LocationECEF& ecef_point)
const;
178 carma_v2x_msgs::msg::MobilityResponse
compose_mobility_response(
const std::string& resp_recipient_id,
const std::string& req_plan_id,
bool response)
const;
193 carma_planning_msgs::msg::TrajectoryPlan
generate_JMT_trajectory(
const carma_planning_msgs::msg::TrajectoryPlan& original_tp,
double initial_pos,
double goal_pos,
194 double initial_velocity,
double goal_velocity,
double planning_time,
double original_max_speed);
210 std::vector<std::pair<int, lanelet::BasicPoint2d>>
detect_trajectories_intersection(std::vector<lanelet::BasicPoint2d> self_trajectory, std::vector<lanelet::BasicPoint2d> incoming_trajectory)
const;
220 void set_incoming_request_info(std::vector <lanelet::BasicPoint2d> req_trajectory,
double req_speed,
double req_planning_time,
double req_timestamp);
244 void set_external_objects(
const std::vector<carma_perception_msgs::msg::ExternalObject>& object_list);
256 std::optional<GetCollisionResult>
get_collision(
const carma_planning_msgs::msg::TrajectoryPlan& trajectory1,
const std::vector<carma_perception_msgs::msg::PredictedState>& trajectory2,
double collision_radius,
double trajectory1_max_speed);
266 std::optional<rclcpp::Time>
get_collision_time(
const carma_planning_msgs::msg::TrajectoryPlan& original_tp,
const carma_perception_msgs::msg::ExternalObject& curr_obstacle,
double original_tp_max_speed);
278 bool is_object_behind_vehicle(uint32_t object_id,
const rclcpp::Time& collision_time,
double vehicle_point,
double object_downtrack);
287 std::optional<std::pair<carma_perception_msgs::msg::ExternalObject, double>>
get_earliest_collision_object_and_time(
const carma_planning_msgs::msg::TrajectoryPlan& original_tp,
const std::vector<carma_perception_msgs::msg::ExternalObject>& external_objects);
296 std::unordered_map<uint32_t, rclcpp::Time>
get_collision_times_concurrently(
const carma_planning_msgs::msg::TrajectoryPlan& original_tp,
const std::vector<carma_perception_msgs::msg::ExternalObject>& external_objects,
double original_tp_max_speed);
306 double get_predicted_velocity_at_time(
const geometry_msgs::msg::Twist& object_velocity_in_map_frame,
const carma_planning_msgs::msg::TrajectoryPlan& original_tp,
double timestamp_in_sec_to_predict);
315 std::shared_ptr<carma_ros2_utils::CarmaLifecycleNode>
nh_;
344 std::string res =
"";
345 for (
size_t i=0;
i<bsm_core.id.size();
i++)
Class containing primary business logic for the In-Lane Cruising Plugin.
std::string georeference_
std::set< lanelet::Id > route_llt_ids_
void plan_trajectory_callback(carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req, carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp)
Service callback for trajectory planning.
std::vector< double > get_relative_downtracks(const carma_planning_msgs::msg::TrajectoryPlan &trajectory_plan) const
calculates distance between trajectory points in a plan
geometry_msgs::msg::Vector3 host_vehicle_size
LaneChangeStatusCB lc_status_publisher_
void set_incoming_request_info(std::vector< lanelet::BasicPoint2d > req_trajectory, double req_speed, double req_planning_time, double req_timestamp)
set values for member variables related to cooperative behavior
std::vector< lanelet::BasicPoint2d > req_trajectory_points_
void mobilityrequest_cb(const carma_v2x_msgs::msg::MobilityRequest::UniquePtr msg)
callback for mobility request
double check_traj_for_digital_min_gap(const carma_planning_msgs::msg::TrajectoryPlan &original_tp) const
checks trajectory for minimum gap associated with it
double get_predicted_velocity_at_time(const geometry_msgs::msg::Twist &object_velocity_in_map_frame, const carma_planning_msgs::msg::TrajectoryPlan &original_tp, double timestamp_in_sec_to_predict)
Given the object velocity in map frame with x,y components, this function returns the projected veloc...
std::shared_ptr< lanelet::projection::LocalFrameProjector > map_projector_
std::vector< lanelet::BasicPoint2d > convert_eceftrajectory_to_mappoints(const carma_v2x_msgs::msg::Trajectory &ecef_trajectory) const
convert a carma trajectory from ecef frame to map frame ecef trajectory consists of the point and a s...
std::optional< std::pair< carma_perception_msgs::msg::ExternalObject, double > > get_earliest_collision_object_and_time(const carma_planning_msgs::msg::TrajectoryPlan &original_tp, const std::vector< carma_perception_msgs::msg::ExternalObject > &external_objects)
Return the earliest collision object and time of collision pair from the given trajectory and list of...
std::optional< rclcpp::Time > get_collision_time(const carma_planning_msgs::msg::TrajectoryPlan &original_tp, const carma_perception_msgs::msg::ExternalObject &curr_obstacle, double original_tp_max_speed)
Return collision time given two trajectories with one being external object with predicted steps.
void lookup_ecef_to_map_transform()
Looks up the transform between map and earth frames, and sets the member variable.
void bsm_cb(const carma_v2x_msgs::msg::BSM::UniquePtr msg)
callback for bsm message
double ecef_traj_timestep_
MobilityResponseCB mobility_response_publisher_
std::string bsmIDtoString(carma_v2x_msgs::msg::BSMCoreData bsm_core)
void set_external_objects(const std::vector< carma_perception_msgs::msg::ExternalObject > &object_list)
Setter for external objects with predictions in the environment.
YieldPlugin(std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode > nh, carma_wm::WorldModelConstPtr wm, YieldPluginConfig config, MobilityResponseCB mobility_response_publisher, LaneChangeStatusCB lc_status_publisher)
Constructor.
std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode > nh_
void set_georeference_string(const std::string &georeference)
Setter for map projection string to define lat/lon -> map conversion.
std::unordered_map< uint32_t, rclcpp::Time > get_collision_times_concurrently(const carma_planning_msgs::msg::TrajectoryPlan &original_tp, const std::vector< carma_perception_msgs::msg::ExternalObject > &external_objects, double original_tp_max_speed)
Given the list of objects with predicted states, get all collision times concurrently using multi-thr...
YieldPluginConfig config_
std::optional< GetCollisionResult > get_collision(const carma_planning_msgs::msg::TrajectoryPlan &trajectory1, const std::vector< carma_perception_msgs::msg::PredictedState > &trajectory2, double collision_radius, double trajectory1_max_speed)
Return naive collision time and locations based on collision radius given two trajectories with one b...
std::vector< std::pair< int, lanelet::BasicPoint2d > > detect_trajectories_intersection(std::vector< lanelet::BasicPoint2d > self_trajectory, std::vector< lanelet::BasicPoint2d > incoming_trajectory) const
detect intersection point(s) of two trajectories
lanelet::BasicPoint2d ecef_to_map_point(const carma_v2x_msgs::msg::LocationECEF &ecef_point) const
convert a point in ecef frame (in cm) into map frame (in meters)
carma_planning_msgs::msg::TrajectoryPlan update_traj_for_object(const carma_planning_msgs::msg::TrajectoryPlan &original_tp, const std::vector< carma_perception_msgs::msg::ExternalObject > &external_objects, double initial_velocity)
trajectory is modified to safely avoid obstacles on the road
carma_planning_msgs::msg::TrajectoryPlan generate_JMT_trajectory(const carma_planning_msgs::msg::TrajectoryPlan &original_tp, double initial_pos, double goal_pos, double initial_velocity, double goal_velocity, double planning_time, double original_max_speed)
generate a Jerk Minimizing Trajectory(JMT) with the provided start and end conditions
carma_v2x_msgs::msg::MobilityResponse compose_mobility_response(const std::string &resp_recipient_id, const std::string &req_plan_id, bool response) const
compose a mobility response message
double req_target_plan_time_
bool cooperative_request_acceptable_
carma_planning_msgs::msg::TrajectoryPlan update_traj_for_cooperative_behavior(const carma_planning_msgs::msg::TrajectoryPlan &original_tp, double current_speed)
update trajectory for yielding to an incoming cooperative behavior
std::unordered_map< uint32_t, int > consecutive_clearance_count_for_obstacles_
std::vector< carma_perception_msgs::msg::ExternalObject > external_objects_
lanelet::Id previous_llt_id_
bool is_object_behind_vehicle(uint32_t object_id, const rclcpp::Time &collision_time, double vehicle_point, double object_downtrack)
Check if object location is behind the vehicle using estimates of the vehicle's length and route down...
int timesteps_since_last_req_
double max_trajectory_speed(const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &trajectory_points, double timestamp_in_sec_to_search_until) const
calculates the maximum speed in a set of tajectory points
double polynomial_calc(std::vector< double > coeff, double x) const
calculate quintic polynomial equation for a given x
double polynomial_calc_d(std::vector< double > coeff, double x) const
calculate derivative of quintic polynomial equation for a given x
carma_wm::WorldModelConstPtr wm_
auto to_string(const UtmZone &zone) -> std::string
std::shared_ptr< const WorldModel > WorldModelConstPtr
std::function< void(const carma_planning_msgs::msg::LaneChangeStatus &)> LaneChangeStatusCB
std::function< void(const carma_v2x_msgs::msg::MobilityResponse &)> MobilityResponseCB
Stuct containing the algorithm configuration values for the YieldPluginConfig.
Convenience class for saving collision results.
lanelet::BasicPoint2d point1
rclcpp::Time collision_time
lanelet::BasicPoint2d point2
Convenience class for pairing 2d points with speeds.
lanelet::BasicPoint2d point