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.
cooperative_lanechange::CooperativeLaneChangePlugin Class Reference

The class responsible for generating cooperative lanechange trajectories from received lane change maneuvers. More...

#include <cooperative_lanechange_node.hpp>

Inheritance diagram for cooperative_lanechange::CooperativeLaneChangePlugin:
Inheritance graph
Collaboration diagram for cooperative_lanechange::CooperativeLaneChangePlugin:
Collaboration graph

Public Member Functions

 CooperativeLaneChangePlugin (const rclcpp::NodeOptions &)
 CooperativeLaneChangePlugin constructor. More...
 
rcl_interfaces::msg::SetParametersResult parameter_update_callback (const std::vector< rclcpp::Parameter > &parameters)
 Callback for dynamic parameter updates. More...
 
std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > plan_lanechange (carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req)
 Creates a vector of Trajectory Points from maneuver information in trajectory request. More...
 
double find_current_gap (long veh2_lanelet_id, double veh2_downtrack, carma_planning_msgs::msg::VehicleState &ego_state) const
 Calculates distance between subject vehicle and vehicle 2. More...
 
void mobilityresponse_cb (const carma_v2x_msgs::msg::MobilityResponse::UniquePtr msg)
 Callback to subscribed mobility response topic. More...
 
carma_v2x_msgs::msg::MobilityRequest create_mobility_request (std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &trajectory_plan, carma_planning_msgs::msg::Maneuver &maneuver)
 Creates a mobility request message from planned trajectory and requested maneuver info. More...
 
carma_v2x_msgs::msg::Trajectory trajectory_plan_to_trajectory (const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &traj_points) const
 Converts Trajectory Plan to (Mobility) Trajectory. More...
 
carma_v2x_msgs::msg::LocationECEF trajectory_point_to_ecef (const carma_planning_msgs::msg::TrajectoryPlanPoint &traj_point) const
 Converts Trajectory Point to ECEF frame using map projection. More...
 
void add_trajectory_to_response (carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req, carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp, const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &planned_trajectory_points)
 Adds the generated trajectory plan to the service response. More...
 
void georeference_cb (const std_msgs::msg::String::UniquePtr msg)
 Callback for map projection string to define lat/lon -> map conversion. More...
 
void plan_trajectory_callback (std::shared_ptr< rmw_request_id_t >, carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req, carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp) override
 Extending class provided callback which should return a planned trajectory based on the provided trajectory planning request. More...
 
bool get_availability () override
 Get the availability status of this plugin based on the current operating environment. Method must be overriden by extending classes. More...
 
std::string get_version_id () override
 Returns the version id of this plugin. More...
 
carma_ros2_utils::CallbackReturn on_configure_plugin ()
 This method should be used to load parameters and will be called on the configure state transition. More...
 
 FRIEND_TEST (CooperativeLaneChangePlugin, TestLaneChangefunctions)
 
 FRIEND_TEST (CooperativeLaneChangePlugin, Testcurrentgapcb)
 
 FRIEND_TEST (CooperativeLaneChangePlugin, TestNoPath_roadwayobject)
 
- Public Member Functions inherited from carma_guidance_plugins::TacticalPlugin
 TacticalPlugin (const rclcpp::NodeOptions &)
 TacticalPlugin constructor. More...
 
virtual ~TacticalPlugin ()=default
 Virtual destructor for safe deletion. More...
 
virtual void plan_trajectory_callback (std::shared_ptr< rmw_request_id_t > srv_header, carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req, carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp)=0
 Extending class provided callback which should return a planned trajectory based on the provided trajectory planning request. More...
 
std::string get_capability () override
 Get the capability string representing this plugins capabilities Method must be overriden by extending classes. Expectation is that abstract plugin type parent classes will provide a default implementation. More...
 
uint8_t get_type () override final
 Returns the type of this plugin according to the carma_planning_msgs::Plugin type enum. Extending classes for the specific type should override this method. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &) override final
 
carma_ros2_utils::CallbackReturn handle_on_activate (const rclcpp_lifecycle::State &) override final
 
carma_ros2_utils::CallbackReturn handle_on_deactivate (const rclcpp_lifecycle::State &) override final
 
carma_ros2_utils::CallbackReturn handle_on_cleanup (const rclcpp_lifecycle::State &) override final
 
carma_ros2_utils::CallbackReturn handle_on_shutdown (const rclcpp_lifecycle::State &) override final
 
carma_ros2_utils::CallbackReturn handle_on_error (const rclcpp_lifecycle::State &, const std::string &exception_string) override final
 
- Public Member Functions inherited from carma_guidance_plugins::PluginBaseNode
 PluginBaseNode (const rclcpp::NodeOptions &)
 PluginBaseNode constructor. More...
 
virtual ~PluginBaseNode ()=default
 Virtual destructor for safe deletion. More...
 
virtual std::shared_ptr< carma_wm::WMListenerget_world_model_listener () final
 Method to return the default world model listener provided as a convience by this base class If this method or get_world_model() are not called then the world model remains uninitialized and will not create unnecessary subscriptions. More...
 
virtual carma_wm::WorldModelConstPtr get_world_model () final
 Method to return the default world model provided as a convience by this base class If this method or get_world_model_listener() are not called then the world model remains uninitialized and will not create unnecessary subscriptions. More...
 
virtual bool get_activation_status () final
 Returns the activation status of this plugin. The plugins API callbacks will only be triggered when this method returns true. More...
 
virtual uint8_t get_type ()
 Returns the type of this plugin according to the carma_planning_msgs::Plugin type enum. Extending classes for the specific type should override this method. More...
 
std::string get_plugin_name_and_ns () const
 Return the name of this plugin with namespace. NOTE: If only the name of the plugin is required, use get_plugin_name() More...
 
std::string get_plugin_name () const
 Return the name of this plugin. More...
 
virtual bool get_availability ()=0
 Get the availability status of this plugin based on the current operating environment. Method must be overriden by extending classes. More...
 
virtual std::string get_capability ()=0
 Get the capability string representing this plugins capabilities Method must be overriden by extending classes. Expectation is that abstract plugin type parent classes will provide a default implementation. More...
 
virtual std::string get_version_id ()=0
 Returns the version id of this plugin. More...
 
virtual carma_ros2_utils::CallbackReturn on_configure_plugin ()=0
 Method which is triggered when this plugin is moved from the UNCONFIGURED to INACTIVE states. This method should be used to load parameters and is required to be implemented. More...
 
virtual carma_ros2_utils::CallbackReturn on_activate_plugin ()
 Method which is triggered when this plugin is moved from the INACTIVE to ACTIVE states. This method should be used to prepare for future callbacks for plugin's capabilites. More...
 
virtual carma_ros2_utils::CallbackReturn on_deactivate_plugin ()
 Method which is triggered when this plugin is moved from the ACTIVE to INACTIVE states. This method should be used to disable any functionality which should cease execution when plugin is inactive. More...
 
virtual carma_ros2_utils::CallbackReturn on_cleanup_plugin ()
 Method which is triggered when this plugin is moved from the INACTIVE to UNCONFIGURED states. This method should be used to fully reset the plugin such that a future call to on_configure_plugin would leave the plugin in a fresh state as though just launched. More...
 
virtual carma_ros2_utils::CallbackReturn on_shutdown_plugin ()
 Method which is triggered when this plugin is moved from any state to FINALIZED This method should be used to generate any shutdown logs or final cleanup. More...
 
virtual carma_ros2_utils::CallbackReturn on_error_plugin (const std::string &exception_string)
 Method which is triggered when an unhandled exception occurs in this plugin This method should be used to cleanup such that the plugin could be moved to UNCONFIGURED state if possible. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &) override
 
carma_ros2_utils::CallbackReturn handle_on_activate (const rclcpp_lifecycle::State &) override
 
carma_ros2_utils::CallbackReturn handle_on_deactivate (const rclcpp_lifecycle::State &) override
 
carma_ros2_utils::CallbackReturn handle_on_cleanup (const rclcpp_lifecycle::State &) override
 
carma_ros2_utils::CallbackReturn handle_on_shutdown (const rclcpp_lifecycle::State &) override
 
carma_ros2_utils::CallbackReturn handle_on_error (const rclcpp_lifecycle::State &, const std::string &exception_string) override
 
 FRIEND_TEST (carma_guidance_plugins_test, connections_test)
 

Public Attributes

double current_speed_
 
geometry_msgs::msg::PoseStamped pose_msg_
 
bool is_lanechange_accepted_ = false
 
carma_planning_msgs::msg::VehicleState ending_state_before_buffer_
 

Private Member Functions

void pose_cb (const geometry_msgs::msg::PoseStamped::UniquePtr msg)
 Callback for the pose subscriber, which will store latest pose locally. More...
 
void twist_cb (const geometry_msgs::msg::TwistStamped::UniquePtr msg)
 Callback for the twist subscriber, which will store latest twist locally. More...
 
void bsm_cb (const carma_v2x_msgs::msg::BSM::UniquePtr msg)
 Callback for the BSM subscriber, which will store the latest BSM Core Data broadcasted by the host vehicle. More...
 
std::string bsmIDtoString (carma_v2x_msgs::msg::BSMCoreData bsm_core)
 Method for extracting the BSM ID from a BSM Core Data object and converting it to a string. More...
 

Private Attributes

carma_ros2_utils::SubPtr< geometry_msgs::msg::PoseStamped > pose_sub_
 
carma_ros2_utils::SubPtr< geometry_msgs::msg::TwistStamped > twist_sub_
 
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::MobilityResponse > incoming_mobility_response_sub_
 
carma_ros2_utils::SubPtr< std_msgs::msg::String > georeference_sub_
 
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::BSM > bsm_sub_
 
carma_ros2_utils::PubPtr< carma_v2x_msgs::msg::MobilityRequest > outgoing_mobility_request_pub_
 
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::LaneChangeStatus > lanechange_status_pub_
 
Config config_
 
carma_wm::WorldModelConstPtr wm_
 
std::string map_georeference_ {""}
 
std::shared_ptr< lanelet::projection::LocalFrameProjector > map_projector_
 
double traj_freq_ = 10
 
std::string DEFAULT_STRING_ = ""
 
rclcpp::Time request_sent_time_
 
bool request_sent_ = false
 
double maneuver_fraction_completed_ = 0
 
bool clc_called_ = false
 
std::string clc_request_id_ = "default_request_id"
 
carma_v2x_msgs::msg::BSMCoreData bsm_core_
 
std::unordered_map< std::string, LaneChangeManeuverOriginalValuesoriginal_lc_maneuver_values_
 

Detailed Description

The class responsible for generating cooperative lanechange trajectories from received lane change maneuvers.

Definition at line 67 of file cooperative_lanechange_node.hpp.

Constructor & Destructor Documentation

◆ CooperativeLaneChangePlugin()

cooperative_lanechange::CooperativeLaneChangePlugin::CooperativeLaneChangePlugin ( const rclcpp::NodeOptions &  options)
explicit

CooperativeLaneChangePlugin constructor.

Definition at line 22 of file cooperative_lanechange_node.cpp.

24 {
25 // Create initial config
26 config_ = Config();
27
28 // Declare parameters
29 config_.trajectory_time_length = declare_parameter<double>("trajectory_time_length", config_.trajectory_time_length);
30 config_.control_plugin_name = declare_parameter<std::string>("control_plugin_name", config_.control_plugin_name);
31 config_.minimum_speed = declare_parameter<double>("minimum_speed", config_.minimum_speed);
32 config_.max_accel = declare_parameter<double>("max_accel", config_.max_accel);
33 config_.minimum_lookahead_distance = declare_parameter<double>("minimum_lookahead_distance", config_.minimum_lookahead_distance);
34 config_.maximum_lookahead_distance = declare_parameter<double>("maximum_lookahead_distance", config_.maximum_lookahead_distance);
35 config_.minimum_lookahead_speed = declare_parameter<double>("minimum_lookahead_speed", config_.minimum_lookahead_speed);
36 config_.maximum_lookahead_speed = declare_parameter<double>("maximum_lookahead_speed", config_.maximum_lookahead_speed);
37 config_.lateral_accel_limit = declare_parameter<double>("lateral_accel_limit", config_.lateral_accel_limit);
38 config_.speed_moving_average_window_size = declare_parameter<int>("speed_moving_average_window_size", config_.speed_moving_average_window_size);
39 config_.curvature_moving_average_window_size = declare_parameter<int>("curvature_moving_average_window_size", config_.curvature_moving_average_window_size);
40 config_.curvature_calc_lookahead_count = declare_parameter<int>("curvature_calc_lookahead_count", config_.curvature_calc_lookahead_count);
41 config_.downsample_ratio = declare_parameter<int>("downsample_ratio", config_.downsample_ratio);
42 config_.destination_range = declare_parameter<double>("destination_range", config_.destination_range);
43 config_.lanechange_time_out = declare_parameter<double>("lanechange_time_out", config_.lanechange_time_out);
44 config_.min_timestep = declare_parameter<double>("min_timestep", config_.min_timestep);
45 config_.starting_downtrack_range = declare_parameter<double>("starting_downtrack_range", config_.starting_downtrack_range);
46 config_.starting_fraction = declare_parameter<double>("starting_fraction", config_.starting_fraction);
47 config_.mid_fraction = declare_parameter<double>("mid_fraction", config_.mid_fraction);
48 config_.min_desired_gap = declare_parameter<double>("min_desired_gap", config_.min_desired_gap);
49 config_.desired_time_gap = declare_parameter<double>("desired_time_gap", config_.desired_time_gap);
50 config_.turn_downsample_ratio = declare_parameter<int>("turn_downsample_ratio", config_.turn_downsample_ratio);
51 config_.curve_resample_step_size = declare_parameter<double>("curve_resample_step_size", config_.curve_resample_step_size);
52 config_.back_distance = declare_parameter<double>("back_distance", config_.back_distance);
53 config_.buffer_ending_downtrack = declare_parameter<double>("buffer_ending_downtrack", config_.buffer_ending_downtrack);
54 config_.vehicle_id = declare_parameter<std::string>("vehicle_id", config_.vehicle_id);
55 }
TacticalPlugin base class which can be extended by user provided plugins which wish to implement the ...

References cooperative_lanechange::Config::back_distance, cooperative_lanechange::Config::buffer_ending_downtrack, config_, cooperative_lanechange::Config::control_plugin_name, cooperative_lanechange::Config::curvature_calc_lookahead_count, cooperative_lanechange::Config::curvature_moving_average_window_size, cooperative_lanechange::Config::curve_resample_step_size, cooperative_lanechange::Config::desired_time_gap, cooperative_lanechange::Config::destination_range, cooperative_lanechange::Config::downsample_ratio, cooperative_lanechange::Config::lanechange_time_out, cooperative_lanechange::Config::lateral_accel_limit, cooperative_lanechange::Config::max_accel, cooperative_lanechange::Config::maximum_lookahead_distance, cooperative_lanechange::Config::maximum_lookahead_speed, cooperative_lanechange::Config::mid_fraction, cooperative_lanechange::Config::min_desired_gap, cooperative_lanechange::Config::min_timestep, cooperative_lanechange::Config::minimum_lookahead_distance, cooperative_lanechange::Config::minimum_lookahead_speed, cooperative_lanechange::Config::minimum_speed, cooperative_lanechange::Config::speed_moving_average_window_size, cooperative_lanechange::Config::starting_downtrack_range, cooperative_lanechange::Config::starting_fraction, cooperative_lanechange::Config::trajectory_time_length, cooperative_lanechange::Config::turn_downsample_ratio, and cooperative_lanechange::Config::vehicle_id.

Member Function Documentation

◆ add_trajectory_to_response()

void cooperative_lanechange::CooperativeLaneChangePlugin::add_trajectory_to_response ( carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr  req,
carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr  resp,
const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &  planned_trajectory_points 
)

Adds the generated trajectory plan to the service response.

Parameters
reqThe plan trajectory service request
respThe plan trajectory service response
planned_trajectory_pointsThe generated trajectory plan points, which are added to the service response

Definition at line 425 of file cooperative_lanechange_node.cpp.

428 {
429 carma_planning_msgs::msg::TrajectoryPlan trajectory_plan;
430 trajectory_plan.header.frame_id = "map";
431 trajectory_plan.header.stamp = this->now();
432 trajectory_plan.trajectory_id = boost::uuids::to_string(boost::uuids::random_generator()());
433
434 trajectory_plan.trajectory_points = planned_trajectory_points;
435 trajectory_plan.initial_longitudinal_velocity = std::max(req->vehicle_state.longitudinal_vel, config_.minimum_speed);
436 resp->trajectory_plan = trajectory_plan;
437
438 resp->related_maneuvers.push_back(req->maneuver_index_to_plan);
439
440 resp->maneuver_status.push_back(carma_planning_msgs::srv::PlanTrajectory::Response::MANEUVER_IN_PROGRESS);
441 }
auto to_string(const UtmZone &zone) -> std::string
Definition: utm_zone.cpp:21

References config_, cooperative_lanechange::Config::minimum_speed, and carma_cooperative_perception::to_string().

Referenced by plan_trajectory_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bsm_cb()

void cooperative_lanechange::CooperativeLaneChangePlugin::bsm_cb ( const carma_v2x_msgs::msg::BSM::UniquePtr  msg)
private

Callback for the BSM subscriber, which will store the latest BSM Core Data broadcasted by the host vehicle.

Parameters
msgLatest BSM message

Definition at line 257 of file cooperative_lanechange_node.cpp.

258 {
259 bsm_core_ = msg->core_data;
260 }

References bsm_core_.

Referenced by on_configure_plugin().

Here is the caller graph for this function:

◆ bsmIDtoString()

std::string cooperative_lanechange::CooperativeLaneChangePlugin::bsmIDtoString ( carma_v2x_msgs::msg::BSMCoreData  bsm_core)
private

Method for extracting the BSM ID from a BSM Core Data object and converting it to a string.

Parameters
bsm_coreThe BSM Core Data object from which the BSM ID is converted to a string
Returns
The BSM ID (as a string) from the BSM Core Data object

Definition at line 643 of file cooperative_lanechange_node.cpp.

644 {
645 std::string res = "";
646 for (size_t i = 0; i < bsm_core.id.size(); i++){
647 res += std::to_string(bsm_core.id[i]);
648 }
649 return res;
650 }

References process_bag::i, and carma_cooperative_perception::to_string().

Referenced by create_mobility_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_mobility_request()

carma_v2x_msgs::msg::MobilityRequest cooperative_lanechange::CooperativeLaneChangePlugin::create_mobility_request ( std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &  trajectory_plan,
carma_planning_msgs::msg::Maneuver &  maneuver 
)

Creates a mobility request message from planned trajectory and requested maneuver info.

Parameters
trajectory_planA vector of lane change trajectory points
Themobility request message created from trajectory points, for publishing

Definition at line 443 of file cooperative_lanechange_node.cpp.

444 {
445 carma_v2x_msgs::msg::MobilityRequest request_msg;
446 carma_v2x_msgs::msg::MobilityHeader header;
447 header.sender_id = config_.vehicle_id;
448 header.recipient_id = DEFAULT_STRING_;
449 header.sender_bsm_id = bsmIDtoString(bsm_core_);
450 header.plan_id = boost::uuids::to_string(boost::uuids::random_generator()());
451 clc_request_id_ = header.plan_id;
452 header.timestamp = rclcpp::Time(trajectory_plan.front().target_time).nanoseconds() * 1000000;
453 request_msg.m_header = header;
454
455 request_msg.strategy = "carma/cooperative-lane-change";
456 request_msg.plan_type.type = carma_v2x_msgs::msg::PlanType::CHANGE_LANE_LEFT;
457
458 //Urgency- Currently unassigned
459 int urgency;
461 urgency = 10;
462 }
464 urgency = 5;
465 }
466 else{
467 urgency = 1;
468 }
469 RCLCPP_DEBUG_STREAM(get_logger(), "Maneuver fraction completed:"<<maneuver_fraction_completed_);
470 request_msg.urgency = urgency;
471
472 //Strategy params
473 //Encode JSON with Boost Property Tree
474 using boost::property_tree::ptree;
475 ptree pt;
476 double end_speed_floor = std::floor(maneuver.lane_change_maneuver.end_speed);
477 int end_speed_fractional = (maneuver.lane_change_maneuver.end_speed - end_speed_floor) * 10;
478
479 RCLCPP_DEBUG_STREAM(get_logger(), "end_speed_floor: " << end_speed_floor);
480 RCLCPP_DEBUG_STREAM(get_logger(), "end_speed_fractional: " << end_speed_fractional);
481 RCLCPP_DEBUG_STREAM(get_logger(), "start_lanelet_id: " << maneuver.lane_change_maneuver.starting_lane_id);
482 RCLCPP_DEBUG_STREAM(get_logger(), "end_lanelet_id: " << maneuver.lane_change_maneuver.ending_lane_id);
483
484 pt.put("s",(int)end_speed_floor);
485 pt.put("f",end_speed_fractional);
486 pt.put("sl",maneuver.lane_change_maneuver.starting_lane_id);
487 pt.put("el", maneuver.lane_change_maneuver.ending_lane_id);
488
489 std::stringstream body_stream;
490 boost::property_tree::json_parser::write_json(body_stream,pt);
491 request_msg.strategy_params = body_stream.str();
492 RCLCPP_DEBUG_STREAM(get_logger(), "request_msg.strategy_params: " << request_msg.strategy_params);
493
494 //Trajectory
495 carma_v2x_msgs::msg::Trajectory trajectory;
496 if (map_projector_) {
497 trajectory = trajectory_plan_to_trajectory(trajectory_plan);
498 //Location
499 carma_planning_msgs::msg::TrajectoryPlanPoint temp_loc_to_convert;
500 temp_loc_to_convert.x = pose_msg_.pose.position.x;
501 temp_loc_to_convert.y = pose_msg_.pose.position.y;
502 carma_v2x_msgs::msg::LocationECEF location = trajectory_point_to_ecef(temp_loc_to_convert);
503
504 //Using trajectory first point time as location timestamp
505 location.timestamp = rclcpp::Time(trajectory_plan.front().target_time).nanoseconds() * 1000000;
506
507 request_msg.location = location;
508 }
509 else
510 {
511 RCLCPP_ERROR_STREAM(get_logger(), "Map projection not available to be used with request message");
512 }
513
514 request_msg.trajectory = trajectory;
515 request_msg.expiration = rclcpp::Time(trajectory_plan.back().target_time).seconds();
516 RCLCPP_DEBUG_STREAM(get_logger(), "request_msg.expiration: " << request_msg.expiration << " of which string size: " << std::to_string(request_msg.expiration).size());
517
518 return request_msg;
519 }
carma_v2x_msgs::msg::LocationECEF trajectory_point_to_ecef(const carma_planning_msgs::msg::TrajectoryPlanPoint &traj_point) const
Converts Trajectory Point to ECEF frame using map projection.
std::string bsmIDtoString(carma_v2x_msgs::msg::BSMCoreData bsm_core)
Method for extracting the BSM ID from a BSM Core Data object and converting it to a string.
std::shared_ptr< lanelet::projection::LocalFrameProjector > map_projector_
carma_v2x_msgs::msg::Trajectory trajectory_plan_to_trajectory(const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &traj_points) const
Converts Trajectory Plan to (Mobility) Trajectory.

References bsm_core_, bsmIDtoString(), clc_request_id_, config_, DEFAULT_STRING_, maneuver_fraction_completed_, map_projector_, cooperative_lanechange::Config::mid_fraction, pose_msg_, cooperative_lanechange::Config::starting_fraction, carma_cooperative_perception::to_string(), trajectory_plan_to_trajectory(), trajectory_point_to_ecef(), and cooperative_lanechange::Config::vehicle_id.

Referenced by plan_trajectory_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_current_gap()

double cooperative_lanechange::CooperativeLaneChangePlugin::find_current_gap ( long  veh2_lanelet_id,
double  veh2_downtrack,
carma_planning_msgs::msg::VehicleState &  ego_state 
) const

Calculates distance between subject vehicle and vehicle 2.

Parameters
veh2_lanelet_idCurrent lanelet id of vehicle 2
veh2_downtrackDowntrack of vehicle 2 in its current lanelet
ego_statevehicle state of the ego vehicle
Returns
the distance between subject vehicle and vehicle 2

Definition at line 188 of file cooperative_lanechange_node.cpp.

189 {
190 //find downtrack distance between ego and lag vehicle
191 RCLCPP_DEBUG_STREAM(get_logger(), "entered find_current_gap");
192 double current_gap = 0.0;
193 lanelet::BasicPoint2d ego_pos(ego_state.x_pos_global, ego_state.y_pos_global);
194 //double ego_current_downtrack = wm_->routeTrackPos(ego_pos).downtrack;
195
196 lanelet::LaneletMapConstPtr const_map(wm_->getMap());
197 lanelet::ConstLanelet veh2_lanelet = const_map->laneletLayer.get(veh2_lanelet_id);
198 RCLCPP_DEBUG_STREAM(get_logger(), "veh2_lanelet id " << veh2_lanelet.id());
199
200 auto current_lanelets = lanelet::geometry::findNearest(const_map->laneletLayer, ego_pos, 10);
201 if(current_lanelets.size() == 0)
202 {
203 RCLCPP_WARN_STREAM(get_logger(), "Cannot find any lanelet in map!");
204 return true;
205 }
206 lanelet::ConstLanelet current_lanelet = current_lanelets[0].second;
207 RCLCPP_DEBUG_STREAM(get_logger(), "current llt id " << current_lanelet.id());
208
209 //Create temporary route between the two vehicles
210 lanelet::ConstLanelet start_lanelet = veh2_lanelet;
211 lanelet::ConstLanelet end_lanelet = current_lanelet;
212
213 auto map_graph = wm_->getMapRoutingGraph();
214 RCLCPP_DEBUG_STREAM(get_logger(), "Graph created");
215
216 auto temp_route = map_graph->getRoute(start_lanelet, end_lanelet);
217 RCLCPP_DEBUG_STREAM(get_logger(), "Route created");
218
219 //Throw exception if there is no shortest path from veh2 to subject vehicle
220 lanelet::routing::LaneletPath shortest_path2;
221 if(temp_route)
222 {
223 shortest_path2 = temp_route.get().shortestPath();
224 }
225 else{
226 RCLCPP_ERROR_STREAM(get_logger(), "No path exists from roadway object to subject");
227 throw std::invalid_argument("No path exists from roadway object to subject");
228 }
229
230 RCLCPP_DEBUG_STREAM(get_logger(), "Shorted path created size: " << shortest_path2.size());
231 for (auto llt : shortest_path2)
232 {
233 RCLCPP_DEBUG_STREAM(get_logger(), "llt id route: " << llt.id());
234 }
235
236 //To find downtrack- creating temporary route from veh2 to veh1(ego vehicle)
237 double veh1_current_downtrack = wm_->routeTrackPos(ego_pos).downtrack;
238 RCLCPP_DEBUG_STREAM(get_logger(), "ego_current_downtrack:" << veh1_current_downtrack);
239
240 current_gap = veh1_current_downtrack - veh2_downtrack;
241 RCLCPP_DEBUG_STREAM(get_logger(), "Finding current gap");
242 RCLCPP_DEBUG_STREAM(get_logger(), "Veh1 current downtrack: " << veh1_current_downtrack << " veh2 downtrack: " << veh2_downtrack);
243
244 return current_gap;
245 }

References wm_.

Referenced by plan_trajectory_callback().

Here is the caller graph for this function:

◆ FRIEND_TEST() [1/3]

cooperative_lanechange::CooperativeLaneChangePlugin::FRIEND_TEST ( CooperativeLaneChangePlugin  ,
Testcurrentgapcb   
)

◆ FRIEND_TEST() [2/3]

cooperative_lanechange::CooperativeLaneChangePlugin::FRIEND_TEST ( CooperativeLaneChangePlugin  ,
TestLaneChangefunctions   
)

◆ FRIEND_TEST() [3/3]

cooperative_lanechange::CooperativeLaneChangePlugin::FRIEND_TEST ( CooperativeLaneChangePlugin  ,
TestNoPath_roadwayobject   
)

◆ georeference_cb()

void cooperative_lanechange::CooperativeLaneChangePlugin::georeference_cb ( const std_msgs::msg::String::UniquePtr  msg)

Callback for map projection string to define lat/lon -> map conversion.

msg The proj string defining the projection.

Definition at line 634 of file cooperative_lanechange_node.cpp.

635 {
636 if (map_georeference_ != msg->data)
637 {
638 map_georeference_ = msg->data;
639 map_projector_ = std::make_shared<lanelet::projection::LocalFrameProjector>(msg->data.c_str()); // Build projector from proj string
640 }
641 }

References map_georeference_, and map_projector_.

Referenced by on_configure_plugin().

Here is the caller graph for this function:

◆ get_availability()

bool cooperative_lanechange::CooperativeLaneChangePlugin::get_availability ( )
overridevirtual

Get the availability status of this plugin based on the current operating environment. Method must be overriden by extending classes.

Returns
This method should return true if the plugin's current understanding of the world means it would be capable of planning or executing its capability.

Implements carma_guidance_plugins::PluginBaseNode.

Definition at line 652 of file cooperative_lanechange_node.cpp.

652 {
653 return true;
654 }

◆ get_version_id()

std::string cooperative_lanechange::CooperativeLaneChangePlugin::get_version_id ( )
overridevirtual

Returns the version id of this plugin.

Returns
The version id represented as a string

Implements carma_guidance_plugins::PluginBaseNode.

Definition at line 656 of file cooperative_lanechange_node.cpp.

656 {
657 return "v4.0"; // Version ID matches the value set in this package's package.xml
658 }

◆ mobilityresponse_cb()

void cooperative_lanechange::CooperativeLaneChangePlugin::mobilityresponse_cb ( const carma_v2x_msgs::msg::MobilityResponse::UniquePtr  msg)

Callback to subscribed mobility response topic.

Parameters
msgLatest mobility response message

Definition at line 161 of file cooperative_lanechange_node.cpp.

161 {
162 //@SONAR_STOP@
163 if (clc_called_ && clc_request_id_ == msg->m_header.plan_id)
164 {
165 carma_planning_msgs::msg::LaneChangeStatus lc_status_msg;
166 if(msg->is_accepted)
167 {
169 lc_status_msg.status = carma_planning_msgs::msg::LaneChangeStatus::ACCEPTANCE_RECEIVED;
170 lc_status_msg.description = "Received lane merge acceptance";
171 }
172 else
173 {
175 lc_status_msg.status = carma_planning_msgs::msg::LaneChangeStatus::REJECTION_RECEIVED;
176 lc_status_msg.description = "Received lane merge rejection";
177 }
178 lanechange_status_pub_->publish(lc_status_msg);
179 //@SONAR_START@
180 }
181 else
182 {
183 RCLCPP_DEBUG_STREAM(get_logger(), "received mobility response is not related to CLC");
184 }
185
186 }
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::LaneChangeStatus > lanechange_status_pub_

References clc_called_, clc_request_id_, is_lanechange_accepted_, and lanechange_status_pub_.

Referenced by on_configure_plugin().

Here is the caller graph for this function:

◆ on_configure_plugin()

carma_ros2_utils::CallbackReturn cooperative_lanechange::CooperativeLaneChangePlugin::on_configure_plugin ( )
virtual

This method should be used to load parameters and will be called on the configure state transition.

Implements carma_guidance_plugins::PluginBaseNode.

Definition at line 98 of file cooperative_lanechange_node.cpp.

99 {
100 RCLCPP_INFO_STREAM(get_logger(), "CooperativeLaneChangePlugin trying to configure");
101
102 // Reset config
103 config_ = Config();
104
105 // Load parameters
106 get_parameter<double>("trajectory_time_length", config_.trajectory_time_length);
107 get_parameter<std::string>("control_plugin_name", config_.control_plugin_name);
108 get_parameter<double>("minimum_speed", config_.minimum_speed);
109 get_parameter<double>("max_accel", config_.max_accel);
110 get_parameter<double>("minimum_lookahead_distance", config_.minimum_lookahead_distance);
111 get_parameter<double>("maximum_lookahead_distance", config_.maximum_lookahead_distance);
112 get_parameter<double>("minimum_lookahead_speed", config_.minimum_lookahead_speed);
113 get_parameter<double>("maximum_lookahead_speed", config_.maximum_lookahead_speed);
114 get_parameter<double>("lateral_accel_limit", config_.lateral_accel_limit);
115 get_parameter<int>("speed_moving_average_window_size", config_.speed_moving_average_window_size);
116 get_parameter<int>("curvature_moving_average_window_size", config_.curvature_moving_average_window_size);
117 get_parameter<int>("curvature_calc_lookahead_count", config_.curvature_calc_lookahead_count);
118 get_parameter<int>("downsample_ratio", config_.downsample_ratio);
119 get_parameter<double>("destination_range", config_.destination_range);
120 get_parameter<double>("lanechange_time_out", config_.lanechange_time_out);
121 get_parameter<double>("min_timestep", config_.min_timestep);
122 get_parameter<double>("starting_downtrack_range", config_.starting_downtrack_range);
123 get_parameter<double>("starting_fraction", config_.starting_fraction);
124 get_parameter<double>("mid_fraction", config_.mid_fraction);
125 get_parameter<double>("min_desired_gap", config_.min_desired_gap);
126 get_parameter<double>("desired_time_gap", config_.desired_time_gap);
127 get_parameter<int>("turn_downsample_ratio", config_.turn_downsample_ratio);
128 get_parameter<double>("curve_resample_step_size", config_.curve_resample_step_size);
129 get_parameter<double>("back_distance", config_.back_distance);
130 get_parameter<double>("buffer_ending_downtrack", config_.buffer_ending_downtrack);
131 get_parameter<std::string>("vehicle_id", config_.vehicle_id);
132
133 // Register runtime parameter update callback
134 add_on_set_parameters_callback(std::bind(&CooperativeLaneChangePlugin::parameter_update_callback, this, std_ph::_1));
135
136 RCLCPP_INFO_STREAM(get_logger(), "Loaded params: " << config_);
137
138 // Setup subscribers
139 pose_sub_ = create_subscription<geometry_msgs::msg::PoseStamped>("current_pose", 1,
140 std::bind(&CooperativeLaneChangePlugin::pose_cb, this, std_ph::_1));
141 twist_sub_ = create_subscription<geometry_msgs::msg::TwistStamped>("current_velocity", 1,
142 std::bind(&CooperativeLaneChangePlugin::twist_cb, this, std_ph::_1));
143 incoming_mobility_response_sub_ = create_subscription<carma_v2x_msgs::msg::MobilityResponse>("incoming_mobility_response", 1,
144 std::bind(&CooperativeLaneChangePlugin::mobilityresponse_cb, this, std_ph::_1));
145 georeference_sub_ = create_subscription<std_msgs::msg::String>("georeference", 1,
146 std::bind(&CooperativeLaneChangePlugin::georeference_cb, this, std_ph::_1));
147 bsm_sub_ = create_subscription<carma_v2x_msgs::msg::BSM>("bsm_outbound", 1,
148 std::bind(&CooperativeLaneChangePlugin::bsm_cb, this, std_ph::_1));
149
150 // Setup publishers
151 outgoing_mobility_request_pub_ = create_publisher<carma_v2x_msgs::msg::MobilityRequest>("outgoing_mobility_request", 5); // Rate from yield plugin
152 lanechange_status_pub_ = create_publisher<carma_planning_msgs::msg::LaneChangeStatus>("cooperative_lane_change_status", 10);
153
154 // Initialize World Model
156
157 // Return success if everything initialized successfully
158 return CallbackReturn::SUCCESS;
159 }
virtual carma_wm::WorldModelConstPtr get_world_model() final
Method to return the default world model provided as a convience by this base class If this method or...
void bsm_cb(const carma_v2x_msgs::msg::BSM::UniquePtr msg)
Callback for the BSM subscriber, which will store the latest BSM Core Data broadcasted by the host ve...
carma_ros2_utils::SubPtr< geometry_msgs::msg::TwistStamped > twist_sub_
void mobilityresponse_cb(const carma_v2x_msgs::msg::MobilityResponse::UniquePtr msg)
Callback to subscribed mobility response topic.
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::BSM > bsm_sub_
void pose_cb(const geometry_msgs::msg::PoseStamped::UniquePtr msg)
Callback for the pose subscriber, which will store latest pose locally.
carma_ros2_utils::SubPtr< std_msgs::msg::String > georeference_sub_
void twist_cb(const geometry_msgs::msg::TwistStamped::UniquePtr msg)
Callback for the twist subscriber, which will store latest twist locally.
carma_ros2_utils::PubPtr< carma_v2x_msgs::msg::MobilityRequest > outgoing_mobility_request_pub_
void georeference_cb(const std_msgs::msg::String::UniquePtr msg)
Callback for map projection string to define lat/lon -> map conversion.
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
Callback for dynamic parameter updates.
carma_ros2_utils::SubPtr< geometry_msgs::msg::PoseStamped > pose_sub_
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::MobilityResponse > incoming_mobility_response_sub_

References cooperative_lanechange::Config::back_distance, bsm_cb(), bsm_sub_, cooperative_lanechange::Config::buffer_ending_downtrack, config_, cooperative_lanechange::Config::control_plugin_name, cooperative_lanechange::Config::curvature_calc_lookahead_count, cooperative_lanechange::Config::curvature_moving_average_window_size, cooperative_lanechange::Config::curve_resample_step_size, cooperative_lanechange::Config::desired_time_gap, cooperative_lanechange::Config::destination_range, cooperative_lanechange::Config::downsample_ratio, georeference_cb(), georeference_sub_, carma_guidance_plugins::PluginBaseNode::get_world_model(), incoming_mobility_response_sub_, lanechange_status_pub_, cooperative_lanechange::Config::lanechange_time_out, cooperative_lanechange::Config::lateral_accel_limit, cooperative_lanechange::Config::max_accel, cooperative_lanechange::Config::maximum_lookahead_distance, cooperative_lanechange::Config::maximum_lookahead_speed, cooperative_lanechange::Config::mid_fraction, cooperative_lanechange::Config::min_desired_gap, cooperative_lanechange::Config::min_timestep, cooperative_lanechange::Config::minimum_lookahead_distance, cooperative_lanechange::Config::minimum_lookahead_speed, cooperative_lanechange::Config::minimum_speed, mobilityresponse_cb(), outgoing_mobility_request_pub_, parameter_update_callback(), pose_cb(), pose_sub_, cooperative_lanechange::Config::speed_moving_average_window_size, cooperative_lanechange::Config::starting_downtrack_range, cooperative_lanechange::Config::starting_fraction, cooperative_lanechange::Config::trajectory_time_length, cooperative_lanechange::Config::turn_downsample_ratio, twist_cb(), twist_sub_, cooperative_lanechange::Config::vehicle_id, and wm_.

Here is the call graph for this function:

◆ parameter_update_callback()

rcl_interfaces::msg::SetParametersResult cooperative_lanechange::CooperativeLaneChangePlugin::parameter_update_callback ( const std::vector< rclcpp::Parameter > &  parameters)

Callback for dynamic parameter updates.

Definition at line 57 of file cooperative_lanechange_node.cpp.

58 {
59 auto error = update_params<std::string>(
60 {{"control_plugin_name", config_.control_plugin_name},
61 {"vehicle_id", config_.vehicle_id}}, parameters);
62
63 auto error_2 = update_params<double>(
64 {{"trajectory_time_length", config_.trajectory_time_length},
65 {"minimum_speed", config_.minimum_speed},
66 {"max_accel", config_.max_accel},
67 {"minimum_lookahead_distance", config_.minimum_lookahead_distance},
68 {"maximum_lookahead_distance", config_.maximum_lookahead_distance},
69 {"minimum_lookahead_speed", config_.minimum_lookahead_speed},
70 {"maximum_lookahead_speed", config_.maximum_lookahead_speed},
71 {"lateral_accel_limit", config_.lateral_accel_limit},
72 {"destination_range", config_.destination_range},
73 {"lanechange_time_out", config_.lanechange_time_out},
74 {"min_timestep", config_.min_timestep},
75 {"starting_downtrack_range", config_.starting_downtrack_range},
76 {"starting_fraction", config_.starting_fraction},
77 {"mid_fraction", config_.mid_fraction},
78 {"min_desired_gap", config_.min_desired_gap},
79 {"curve_resample_step_size", config_.curve_resample_step_size},
80 {"back_distance", config_.back_distance},
81 {"buffer_ending_downtrack", config_.buffer_ending_downtrack},
82 {"desired_time_gap", config_.desired_time_gap}}, parameters);
83
84 auto error_3 = update_params<int>(
85 {{"speed_moving_average_window_size", config_.speed_moving_average_window_size},
86 {"curvature_moving_average_window_size", config_.curvature_moving_average_window_size},
87 {"curvature_calc_lookahead_count", config_.curvature_calc_lookahead_count},
88 {"downsample_ratio", config_.downsample_ratio},
89 {"turn_downsample_ratio", config_.turn_downsample_ratio}}, parameters);
90
91 rcl_interfaces::msg::SetParametersResult result;
92
93 result.successful = !error && !error_2 && !error_3;
94
95 return result;
96 }

References cooperative_lanechange::Config::back_distance, cooperative_lanechange::Config::buffer_ending_downtrack, config_, cooperative_lanechange::Config::control_plugin_name, cooperative_lanechange::Config::curvature_calc_lookahead_count, cooperative_lanechange::Config::curvature_moving_average_window_size, cooperative_lanechange::Config::curve_resample_step_size, cooperative_lanechange::Config::desired_time_gap, cooperative_lanechange::Config::destination_range, cooperative_lanechange::Config::downsample_ratio, cooperative_lanechange::Config::lanechange_time_out, cooperative_lanechange::Config::lateral_accel_limit, cooperative_lanechange::Config::max_accel, cooperative_lanechange::Config::maximum_lookahead_distance, cooperative_lanechange::Config::maximum_lookahead_speed, cooperative_lanechange::Config::mid_fraction, cooperative_lanechange::Config::min_desired_gap, cooperative_lanechange::Config::min_timestep, cooperative_lanechange::Config::minimum_lookahead_distance, cooperative_lanechange::Config::minimum_lookahead_speed, cooperative_lanechange::Config::minimum_speed, cooperative_lanechange::Config::speed_moving_average_window_size, cooperative_lanechange::Config::starting_downtrack_range, cooperative_lanechange::Config::starting_fraction, cooperative_lanechange::Config::trajectory_time_length, cooperative_lanechange::Config::turn_downsample_ratio, and cooperative_lanechange::Config::vehicle_id.

Referenced by on_configure_plugin().

Here is the caller graph for this function:

◆ plan_lanechange()

std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > cooperative_lanechange::CooperativeLaneChangePlugin::plan_lanechange ( carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr  req)

Creates a vector of Trajectory Points from maneuver information in trajectory request.

Parameters
reqThe service request
Returns
vector of unobstructed lane change trajectory points

Definition at line 564 of file cooperative_lanechange_node.cpp.

565 {
566 lanelet::BasicPoint2d veh_pos(req->vehicle_state.x_pos_global, req->vehicle_state.y_pos_global);
567 double current_downtrack = wm_->routeTrackPos(veh_pos).downtrack;
568
569 // Only plan the trajectory for the requested LANE_CHANGE maneuver
570 std::vector<carma_planning_msgs::msg::Maneuver> maneuver_plan;
571 if(req->maneuver_plan.maneuvers[req->maneuver_index_to_plan].type != carma_planning_msgs::msg::Maneuver::LANE_CHANGE) {
572 throw std::invalid_argument ("Cooperative Lane Change Plugin doesn't support this maneuver type");
573 }
574 maneuver_plan.push_back(req->maneuver_plan.maneuvers[req->maneuver_index_to_plan]);
575
576 if(current_downtrack >= maneuver_plan.front().lane_change_maneuver.end_dist){
577 request_sent_ = false;
578 }
579
582
584
591
592 RCLCPP_DEBUG_STREAM(get_logger(), "Current downtrack: " << current_downtrack);
593
594 std::string maneuver_id = maneuver_plan.front().lane_change_maneuver.parameters.maneuver_id;
595 double original_start_dist = current_downtrack; // Initialize so original_start_dist cannot be less than the current downtrack
596
597 if (original_lc_maneuver_values_.find(maneuver_id) != original_lc_maneuver_values_.end()) {
598 // Obtain the original start_dist associated with this lane change maneuver
599 original_start_dist = original_lc_maneuver_values_[maneuver_id].original_start_dist;
600 RCLCPP_DEBUG_STREAM(get_logger(), "Maneuver id " << maneuver_id << " original start_dist is " << original_start_dist);
601
602 // Set this maneuver's starting_lane_id to the original starting_lane_id associated with this lane change maneuver
603 maneuver_plan.front().lane_change_maneuver.starting_lane_id = original_lc_maneuver_values_[maneuver_id].original_starting_lane_id;
604 RCLCPP_DEBUG_STREAM(get_logger(), "Updated maneuver id " << maneuver_id << " starting_lane_id to its original value of " << original_lc_maneuver_values_[maneuver_id].original_starting_lane_id);
605
606 // If the vehicle has started this lane change, set the request's vehicle_state.longitudinal_vel to the velocity that the vehicle began this lane change at
607 if(original_lc_maneuver_values_[maneuver_id].has_started) {
608 req->vehicle_state.longitudinal_vel = original_lc_maneuver_values_[maneuver_id].original_longitudinal_vel_ms;
609 RCLCPP_DEBUG_STREAM(get_logger(), "Updating vehicle_state.longitudinal_vel to the initial lane change value of " << original_lc_maneuver_values_[maneuver_id].original_longitudinal_vel_ms);
610 }
611 }
612 else {
613 RCLCPP_WARN_STREAM(get_logger(), "No original values for lane change maneuver were found!");
614 }
615
616 double starting_downtrack = std::min(current_downtrack, original_start_dist);
617
618 auto points_and_target_speeds = basic_autonomy::waypoint_generation::create_geometry_profile(maneuver_plan, starting_downtrack, wm_, ending_state_before_buffer_, req->vehicle_state, wpg_general_config, wpg_detail_config);
619
620 // Calculate maneuver fraction completed (current_downtrack/(ending_downtrack-starting_downtrack)
621 auto maneuver_end_dist = maneuver_plan.back().lane_change_maneuver.end_dist;
622 auto maneuver_start_dist = maneuver_plan.front().lane_change_maneuver.start_dist;
623 maneuver_fraction_completed_ = (maneuver_start_dist - current_downtrack)/(maneuver_end_dist - maneuver_start_dist);
624
625 RCLCPP_DEBUG_STREAM(get_logger(), "Maneuvers to points size: " << points_and_target_speeds.size());
626 auto downsampled_points = carma_ros2_utils::containers::downsample_vector(points_and_target_speeds, config_.downsample_ratio);
627
628 std::vector<carma_planning_msgs::msg::TrajectoryPlanPoint> trajectory_points = basic_autonomy::waypoint_generation::compose_lanechange_trajectory_from_path(downsampled_points, req->vehicle_state, req->header.stamp,
629 wm_, ending_state_before_buffer_, wpg_detail_config);
630 RCLCPP_DEBUG_STREAM(get_logger(), "Compose Trajectory size: " << trajectory_points.size());
631 return trajectory_points;
632 }
carma_planning_msgs::msg::VehicleState ending_state_before_buffer_
std::unordered_map< std::string, LaneChangeManeuverOriginalValues > original_lc_maneuver_values_
GeneralTrajConfig compose_general_trajectory_config(const std::string &trajectory_type, int default_downsample_ratio, int turn_downsample_ratio)
std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > compose_lanechange_trajectory_from_path(const std::vector< PointSpeedPair > &points, const carma_planning_msgs::msg::VehicleState &state, const rclcpp::Time &state_time, const carma_wm::WorldModelConstPtr &wm, const carma_planning_msgs::msg::VehicleState &ending_state_before_buffer, const DetailedTrajConfig &detailed_config)
Method converts a list of lanelet centerline points and current vehicle state into a usable list of t...
DetailedTrajConfig compose_detailed_trajectory_config(double trajectory_time_length, double curve_resample_step_size, double minimum_speed, double max_accel, double lateral_accel_limit, int speed_moving_average_window_size, int curvature_moving_average_window_size, double back_distance, double buffer_ending_downtrack, std::string desired_controller_plugin="default")
std::vector< PointSpeedPair > create_geometry_profile(const std::vector< carma_planning_msgs::msg::Maneuver > &maneuvers, double max_starting_downtrack, const carma_wm::WorldModelConstPtr &wm, carma_planning_msgs::msg::VehicleState &ending_state_before_buffer, const carma_planning_msgs::msg::VehicleState &state, const GeneralTrajConfig &general_config, const DetailedTrajConfig &detailed_config)
Creates geometry profile to return a point speed pair struct for LANE FOLLOW and LANE CHANGE maneuver...

References cooperative_lanechange::Config::back_distance, cooperative_lanechange::Config::buffer_ending_downtrack, basic_autonomy::waypoint_generation::compose_detailed_trajectory_config(), basic_autonomy::waypoint_generation::compose_general_trajectory_config(), basic_autonomy::waypoint_generation::compose_lanechange_trajectory_from_path(), config_, basic_autonomy::waypoint_generation::create_geometry_profile(), cooperative_lanechange::Config::curvature_moving_average_window_size, cooperative_lanechange::Config::curve_resample_step_size, cooperative_lanechange::Config::downsample_ratio, ending_state_before_buffer_, cooperative_lanechange::Config::lateral_accel_limit, maneuver_fraction_completed_, cooperative_lanechange::Config::max_accel, cooperative_lanechange::Config::minimum_speed, original_lc_maneuver_values_, request_sent_, cooperative_lanechange::Config::speed_moving_average_window_size, cooperative_lanechange::Config::trajectory_time_length, cooperative_lanechange::Config::turn_downsample_ratio, and wm_.

Referenced by plan_trajectory_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plan_trajectory_callback()

void cooperative_lanechange::CooperativeLaneChangePlugin::plan_trajectory_callback ( std::shared_ptr< rmw_request_id_t >  srv_header,
carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr  req,
carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr  resp 
)
overridevirtual

Extending class provided callback which should return a planned trajectory based on the provided trajectory planning request.

Parameters
srv_headerRCL header for services calls. Can usually be ignored by implementers.
reqThe service request containing the maneuvers to plan trajectories for and current vehicle state
respThe response containing the planned trajectory

Implements carma_guidance_plugins::TacticalPlugin.

Definition at line 262 of file cooperative_lanechange_node.cpp.

266 {
267 // Set boolean flag if this is the first time this service has been called
268 if (!clc_called_)
269 {
270 clc_called_ = true;
271 }
272
273 // Only plan the trajectory for the requested LANE_CHANGE maneuver
274 std::vector<carma_planning_msgs::msg::Maneuver> maneuver_plan;
275 if(req->maneuver_plan.maneuvers[req->maneuver_index_to_plan].type != carma_planning_msgs::msg::Maneuver::LANE_CHANGE)
276 {
277 throw std::invalid_argument ("Cooperative Lane Change Plugin doesn't support this maneuver type");
278 }
279 maneuver_plan.push_back(req->maneuver_plan.maneuvers[req->maneuver_index_to_plan]);
280
281 // Currently only checking for first lane change maneuver message
282 long target_lanelet_id = stol(maneuver_plan[0].lane_change_maneuver.ending_lane_id);
283 double target_downtrack = maneuver_plan[0].lane_change_maneuver.end_dist;
284
285 // Get subject vehicle info
286 lanelet::BasicPoint2d veh_pos(req->vehicle_state.x_pos_global, req->vehicle_state.y_pos_global);
287 double current_downtrack = wm_->routeTrackPos(veh_pos).downtrack;
288
289 RCLCPP_DEBUG_STREAM(get_logger(), "target_lanelet_id: " << target_lanelet_id);
290 RCLCPP_DEBUG_STREAM(get_logger(), "target_downtrack: " << target_downtrack);
291 RCLCPP_DEBUG_STREAM(get_logger(), "current_downtrack: " << current_downtrack);
292 RCLCPP_DEBUG_STREAM(get_logger(), "Starting CLC downtrack: " << maneuver_plan[0].lane_change_maneuver.start_dist);
293
294 if(current_downtrack < maneuver_plan[0].lane_change_maneuver.start_dist - config_.starting_downtrack_range){
295 RCLCPP_DEBUG_STREAM(get_logger(), "Lane change trajectory will not be planned. current_downtrack is more than " << config_.starting_downtrack_range << " meters before starting CLC downtrack");
296 return;
297 }
298 auto current_lanelets = lanelet::geometry::findNearest(wm_->getMap()->laneletLayer, veh_pos, 10);
299 long current_lanelet_id = current_lanelets[0].second.id();
300 if(current_lanelet_id == target_lanelet_id && current_downtrack >= target_downtrack - config_.destination_range){
301 carma_planning_msgs::msg::LaneChangeStatus lc_status_msg;
302 lc_status_msg.status = carma_planning_msgs::msg::LaneChangeStatus::PLANNING_SUCCESS;
303 //No description as per UI documentation
304 lanechange_status_pub_->publish(lc_status_msg);
305 }
306
307 long veh2_lanelet_id = 0;
308 double veh2_downtrack = 0.0, veh2_speed = 0.0;
309 bool foundRoadwayObject = false;
310 bool negotiate = true;
311 std::vector<carma_perception_msgs::msg::RoadwayObstacle> rwol = wm_->getRoadwayObjects();
312 //Assuming only one connected vehicle in list
313 for(int i = 0; i < rwol.size(); i++){
314 if(rwol[i].connected_vehicle_type.type == carma_perception_msgs::msg::ConnectedVehicleType::NOT_CONNECTED){
315 veh2_lanelet_id = rwol[0].lanelet_id;
316 veh2_downtrack = rwol[0].down_track; //Returns downtrack
317 veh2_speed = rwol[0].object.velocity.twist.linear.x;
318 foundRoadwayObject = true;
319 break;
320 }
321 }
322 if(foundRoadwayObject){
323 RCLCPP_DEBUG_STREAM(get_logger(), "Found Roadway object");
324 //get current_gap
325 RCLCPP_DEBUG_STREAM(get_logger(), "veh2_lanelet_id: " << veh2_lanelet_id << ", veh2_downtrack: " << veh2_downtrack);
326
327 double current_gap = find_current_gap(veh2_lanelet_id, veh2_downtrack, req->vehicle_state);
328 RCLCPP_DEBUG_STREAM(get_logger(), "Current gap: " << current_gap);
329
330 //get desired gap - desired time gap (default 3s)* relative velocity
331 double relative_velocity = current_speed_ - veh2_speed;
332 RCLCPP_DEBUG_STREAM(get_logger(), "Relative velocity: " << relative_velocity);
333 double desired_gap = config_.desired_time_gap * relative_velocity;
334 RCLCPP_DEBUG_STREAM(get_logger(), "Desired gap: " << desired_gap);
335
336 if(desired_gap < config_.min_desired_gap){
337 desired_gap = config_.min_desired_gap;
338 }
339 // TODO - this condition needs to be re-enabled after testing
340 // if(current_gap > desired_gap){
341 // negotiate = false; //No need for negotiation
342 // }
343
344 }
345 else{
346 RCLCPP_DEBUG_STREAM(get_logger(), "No roadway object");
347 negotiate = false;
348 }
349
350 //plan lanechange without filling in response
351 RCLCPP_DEBUG_STREAM(get_logger(), "Planning lane change trajectory");
352
353 std::string maneuver_id = maneuver_plan[0].lane_change_maneuver.parameters.maneuver_id;
354 if (original_lc_maneuver_values_.find(maneuver_id) == original_lc_maneuver_values_.end()) {
355 // If this lane change maneuver ID is being received for this first time, store its original start_dist and starting_lane_id locally
356 RCLCPP_DEBUG_STREAM(get_logger(), "Received maneuver id " << maneuver_id << " for the first time");
357 RCLCPP_DEBUG_STREAM(get_logger(), "Original start dist is " << maneuver_plan[0].lane_change_maneuver.start_dist);
358 RCLCPP_DEBUG_STREAM(get_logger(), "Original starting_lane_id is " << maneuver_plan[0].lane_change_maneuver.starting_lane_id);
359
360 // Create LaneChangeManeuverOriginalValues object for this lane change maneuver and add it to original_lc_maneuver_values_
361 LaneChangeManeuverOriginalValues original_lc_values;
362 original_lc_values.maneuver_id = maneuver_id;
363 original_lc_values.original_starting_lane_id = maneuver_plan[0].lane_change_maneuver.starting_lane_id;
364 original_lc_values.original_start_dist = maneuver_plan[0].lane_change_maneuver.start_dist;
365
366 original_lc_maneuver_values_[maneuver_id] = original_lc_values;
367 }
368 else {
369 // If the vehicle has just started this lane change, store its initial velocity locally; this velocity will be maintained throughout the lane change
370 if (current_downtrack >= (original_lc_maneuver_values_[maneuver_id]).original_start_dist && !(original_lc_maneuver_values_[maneuver_id]).has_started) {
371 original_lc_maneuver_values_[maneuver_id].has_started = true;
372 original_lc_maneuver_values_[maneuver_id].original_longitudinal_vel_ms = std::max(req->vehicle_state.longitudinal_vel, config_.minimum_speed);
373
374 RCLCPP_DEBUG_STREAM(get_logger(), "Lane change maneuver " << maneuver_id << " has started, maintaining speed (in m/s): " <<
375 original_lc_maneuver_values_[maneuver_id].original_longitudinal_vel_ms << " throughout lane change");
376 }
377 }
378
379 std::vector<carma_planning_msgs::msg::TrajectoryPlanPoint> planned_trajectory_points = plan_lanechange(req);
380
381 if(negotiate){
382 RCLCPP_DEBUG_STREAM(get_logger(), "Negotiating");
383 //send mobility request
384 //Planning for first lane change maneuver
385 carma_v2x_msgs::msg::MobilityRequest request = create_mobility_request(planned_trajectory_points, maneuver_plan[0]);
386 outgoing_mobility_request_pub_->publish(request);
387 if(!request_sent_){
388 request_sent_time_ = this->now();
389 request_sent_ = true;
390 }
391 carma_planning_msgs::msg::LaneChangeStatus lc_status_msg;
392 lc_status_msg.status = carma_planning_msgs::msg::LaneChangeStatus::PLAN_SENT;
393 lc_status_msg.description = "Requested lane merge";
394 lanechange_status_pub_->publish(lc_status_msg);
395 }
396
397 //if ack mobility response, send lanechange response
398 if(!negotiate || is_lanechange_accepted_){
399 RCLCPP_DEBUG_STREAM(get_logger(), "negotiate:" << negotiate);
400 RCLCPP_DEBUG_STREAM(get_logger(), "is_lanechange_accepted:" << is_lanechange_accepted_);
401
402 RCLCPP_DEBUG_STREAM(get_logger(), "Adding to response");
403 add_trajectory_to_response(req,resp,planned_trajectory_points);
404
405 }
406 else{
407 if(!negotiate && !request_sent_){
408 request_sent_time_ = this->now();
409 request_sent_ = true;
410 }
411 rclcpp::Time planning_end_time = this->now();
412 rclcpp::Duration passed_time = planning_end_time - request_sent_time_;
413 if(passed_time.seconds() >= config_.lanechange_time_out){
414 carma_planning_msgs::msg::LaneChangeStatus lc_status_msg;
415 lc_status_msg.status = carma_planning_msgs::msg::LaneChangeStatus::TIMED_OUT;
416 lc_status_msg.description = "Request timed out for lane merge";
417 lanechange_status_pub_->publish(lc_status_msg);
418 request_sent_ = false; //Reset variable
419 }
420 }
421
422 return;
423 }
carma_v2x_msgs::msg::MobilityRequest create_mobility_request(std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &trajectory_plan, carma_planning_msgs::msg::Maneuver &maneuver)
Creates a mobility request message from planned trajectory and requested maneuver info.
void add_trajectory_to_response(carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req, carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp, const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &planned_trajectory_points)
Adds the generated trajectory plan to the service response.
std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > plan_lanechange(carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req)
Creates a vector of Trajectory Points from maneuver information in trajectory request.
double find_current_gap(long veh2_lanelet_id, double veh2_downtrack, carma_planning_msgs::msg::VehicleState &ego_state) const
Calculates distance between subject vehicle and vehicle 2.

References add_trajectory_to_response(), clc_called_, config_, create_mobility_request(), current_speed_, cooperative_lanechange::Config::desired_time_gap, cooperative_lanechange::Config::destination_range, find_current_gap(), process_bag::i, is_lanechange_accepted_, lanechange_status_pub_, cooperative_lanechange::Config::lanechange_time_out, cooperative_lanechange::LaneChangeManeuverOriginalValues::maneuver_id, cooperative_lanechange::Config::min_desired_gap, cooperative_lanechange::Config::minimum_speed, original_lc_maneuver_values_, cooperative_lanechange::LaneChangeManeuverOriginalValues::original_start_dist, cooperative_lanechange::LaneChangeManeuverOriginalValues::original_starting_lane_id, outgoing_mobility_request_pub_, plan_lanechange(), request_sent_, request_sent_time_, cooperative_lanechange::Config::starting_downtrack_range, and wm_.

Here is the call graph for this function:

◆ pose_cb()

void cooperative_lanechange::CooperativeLaneChangePlugin::pose_cb ( const geometry_msgs::msg::PoseStamped::UniquePtr  msg)
private

Callback for the pose subscriber, which will store latest pose locally.

Parameters
msgLatest pose message

Definition at line 247 of file cooperative_lanechange_node.cpp.

248 {
249 pose_msg_ = *msg;
250 }

References pose_msg_.

Referenced by on_configure_plugin().

Here is the caller graph for this function:

◆ trajectory_plan_to_trajectory()

carma_v2x_msgs::msg::Trajectory cooperative_lanechange::CooperativeLaneChangePlugin::trajectory_plan_to_trajectory ( const std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > &  traj_points) const

Converts Trajectory Plan to (Mobility) Trajectory.

Parameters
traj_pointsvector of Trajectory Plan points to be converted to Trajectory type message
Returns
The Trajectory type message in world frame

Definition at line 521 of file cooperative_lanechange_node.cpp.

522 {
523 carma_v2x_msgs::msg::Trajectory traj;
524 carma_v2x_msgs::msg::LocationECEF ecef_location = trajectory_point_to_ecef(traj_points[0]);
525
526 if (traj_points.size() < 2){
527 RCLCPP_WARN_STREAM(get_logger(), "Received Trajectory Plan is too small");
528 traj.offsets = {};
529 }
530 else{
531 carma_v2x_msgs::msg::LocationECEF prev_point = ecef_location;
532 for (size_t i = 1; i < traj_points.size(); i++){
533
534 carma_v2x_msgs::msg::LocationOffsetECEF offset;
535 carma_v2x_msgs::msg::LocationECEF new_point = trajectory_point_to_ecef(traj_points[i]); // m to cm to fit the msg standard
536 offset.offset_x = (int16_t)(new_point.ecef_x - prev_point.ecef_x);
537 offset.offset_y = (int16_t)(new_point.ecef_y - prev_point.ecef_y);
538 offset.offset_z = (int16_t)(new_point.ecef_z - prev_point.ecef_z);
539 prev_point = new_point;
540 traj.offsets.push_back(offset);
541 }
542 }
543
544 traj.location = ecef_location;
545
546 return traj;
547 }

References process_bag::i, and trajectory_point_to_ecef().

Referenced by create_mobility_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ trajectory_point_to_ecef()

carma_v2x_msgs::msg::LocationECEF cooperative_lanechange::CooperativeLaneChangePlugin::trajectory_point_to_ecef ( const carma_planning_msgs::msg::TrajectoryPlanPoint &  traj_point) const

Converts Trajectory Point to ECEF frame using map projection.

Parameters
traj_pointsA Trajectory Plan point to be converted to Trajectory type message
Exceptions
std::invalid_argumentIf the map_projector_ member variable has not been set
Returns
The trajectory point message transformed to ecef frame

Definition at line 549 of file cooperative_lanechange_node.cpp.

550 {
551 if (!map_projector_) {
552 throw std::invalid_argument("No map projector available for ecef conversion");
553 }
554 carma_v2x_msgs::msg::LocationECEF location;
555
556 lanelet::BasicPoint3d ecef_point = map_projector_->projectECEF({traj_point.x, traj_point.y, 0.0}, 1);
557 location.ecef_x = ecef_point.x() * 100.0; // Convert cm to m
558 location.ecef_y = ecef_point.y() * 100.0;
559 location.ecef_z = ecef_point.z() * 100.0;
560
561 return location;
562 }

References map_projector_.

Referenced by create_mobility_request(), and trajectory_plan_to_trajectory().

Here is the caller graph for this function:

◆ twist_cb()

void cooperative_lanechange::CooperativeLaneChangePlugin::twist_cb ( const geometry_msgs::msg::TwistStamped::UniquePtr  msg)
private

Callback for the twist subscriber, which will store latest twist locally.

Parameters
msgLatest twist message

Definition at line 252 of file cooperative_lanechange_node.cpp.

253 {
254 current_speed_ = msg->twist.linear.x;
255 }

References current_speed_.

Referenced by on_configure_plugin().

Here is the caller graph for this function:

Member Data Documentation

◆ bsm_core_

carma_v2x_msgs::msg::BSMCoreData cooperative_lanechange::CooperativeLaneChangePlugin::bsm_core_
private

Definition at line 114 of file cooperative_lanechange_node.hpp.

Referenced by bsm_cb(), and create_mobility_request().

◆ bsm_sub_

carma_ros2_utils::SubPtr<carma_v2x_msgs::msg::BSM> cooperative_lanechange::CooperativeLaneChangePlugin::bsm_sub_
private

Definition at line 76 of file cooperative_lanechange_node.hpp.

Referenced by on_configure_plugin().

◆ clc_called_

bool cooperative_lanechange::CooperativeLaneChangePlugin::clc_called_ = false
private

◆ clc_request_id_

std::string cooperative_lanechange::CooperativeLaneChangePlugin::clc_request_id_ = "default_request_id"
private

◆ config_

◆ current_speed_

double cooperative_lanechange::CooperativeLaneChangePlugin::current_speed_

Definition at line 147 of file cooperative_lanechange_node.hpp.

Referenced by plan_trajectory_callback(), and twist_cb().

◆ DEFAULT_STRING_

std::string cooperative_lanechange::CooperativeLaneChangePlugin::DEFAULT_STRING_ = ""
private

Definition at line 96 of file cooperative_lanechange_node.hpp.

Referenced by create_mobility_request().

◆ ending_state_before_buffer_

carma_planning_msgs::msg::VehicleState cooperative_lanechange::CooperativeLaneChangePlugin::ending_state_before_buffer_

Definition at line 155 of file cooperative_lanechange_node.hpp.

Referenced by plan_lanechange().

◆ georeference_sub_

carma_ros2_utils::SubPtr<std_msgs::msg::String> cooperative_lanechange::CooperativeLaneChangePlugin::georeference_sub_
private

Definition at line 75 of file cooperative_lanechange_node.hpp.

Referenced by on_configure_plugin().

◆ incoming_mobility_response_sub_

carma_ros2_utils::SubPtr<carma_v2x_msgs::msg::MobilityResponse> cooperative_lanechange::CooperativeLaneChangePlugin::incoming_mobility_response_sub_
private

Definition at line 74 of file cooperative_lanechange_node.hpp.

Referenced by on_configure_plugin().

◆ is_lanechange_accepted_

bool cooperative_lanechange::CooperativeLaneChangePlugin::is_lanechange_accepted_ = false

◆ lanechange_status_pub_

carma_ros2_utils::PubPtr<carma_planning_msgs::msg::LaneChangeStatus> cooperative_lanechange::CooperativeLaneChangePlugin::lanechange_status_pub_
private

◆ maneuver_fraction_completed_

double cooperative_lanechange::CooperativeLaneChangePlugin::maneuver_fraction_completed_ = 0
private

Definition at line 105 of file cooperative_lanechange_node.hpp.

Referenced by create_mobility_request(), and plan_lanechange().

◆ map_georeference_

std::string cooperative_lanechange::CooperativeLaneChangePlugin::map_georeference_ {""}
private

Definition at line 89 of file cooperative_lanechange_node.hpp.

Referenced by georeference_cb().

◆ map_projector_

std::shared_ptr<lanelet::projection::LocalFrameProjector> cooperative_lanechange::CooperativeLaneChangePlugin::map_projector_
private

◆ original_lc_maneuver_values_

std::unordered_map<std::string, LaneChangeManeuverOriginalValues> cooperative_lanechange::CooperativeLaneChangePlugin::original_lc_maneuver_values_
private

Definition at line 117 of file cooperative_lanechange_node.hpp.

Referenced by plan_lanechange(), and plan_trajectory_callback().

◆ outgoing_mobility_request_pub_

carma_ros2_utils::PubPtr<carma_v2x_msgs::msg::MobilityRequest> cooperative_lanechange::CooperativeLaneChangePlugin::outgoing_mobility_request_pub_
private

◆ pose_msg_

geometry_msgs::msg::PoseStamped cooperative_lanechange::CooperativeLaneChangePlugin::pose_msg_

Definition at line 150 of file cooperative_lanechange_node.hpp.

Referenced by create_mobility_request(), and pose_cb().

◆ pose_sub_

carma_ros2_utils::SubPtr<geometry_msgs::msg::PoseStamped> cooperative_lanechange::CooperativeLaneChangePlugin::pose_sub_
private

Definition at line 72 of file cooperative_lanechange_node.hpp.

Referenced by on_configure_plugin().

◆ request_sent_

bool cooperative_lanechange::CooperativeLaneChangePlugin::request_sent_ = false
private

Definition at line 102 of file cooperative_lanechange_node.hpp.

Referenced by plan_lanechange(), and plan_trajectory_callback().

◆ request_sent_time_

rclcpp::Time cooperative_lanechange::CooperativeLaneChangePlugin::request_sent_time_
private

Definition at line 99 of file cooperative_lanechange_node.hpp.

Referenced by plan_trajectory_callback().

◆ traj_freq_

double cooperative_lanechange::CooperativeLaneChangePlugin::traj_freq_ = 10
private

Definition at line 93 of file cooperative_lanechange_node.hpp.

◆ twist_sub_

carma_ros2_utils::SubPtr<geometry_msgs::msg::TwistStamped> cooperative_lanechange::CooperativeLaneChangePlugin::twist_sub_
private

Definition at line 73 of file cooperative_lanechange_node.hpp.

Referenced by on_configure_plugin().

◆ wm_

carma_wm::WorldModelConstPtr cooperative_lanechange::CooperativeLaneChangePlugin::wm_
private

The documentation for this class was generated from the following files: