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_node.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2022 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17#pragma once
18
19#include <rclcpp/rclcpp.hpp>
20#include <functional>
21#include <carma_ros2_utils/containers/containers.hpp>
22#include <boost/shared_ptr.hpp>
23#include <boost/uuid/uuid_generators.hpp>
24#include <boost/uuid/uuid_io.hpp>
25#include <boost/property_tree/ptree.hpp>
26#include <boost/property_tree/json_parser.hpp>
27
28#include <geometry_msgs/msg/pose_stamped.hpp>
29#include <geometry_msgs/msg/twist_stamped.hpp>
30#include <lanelet2_core/primitives/Lanelet.h>
31#include <lanelet2_core/geometry/LineString.h>
32#include <carma_v2x_msgs/msg/mobility_response.hpp>
33#include <carma_v2x_msgs/msg/mobility_request.hpp>
34#include <carma_v2x_msgs/msg/bsm.hpp>
35#include <carma_planning_msgs/msg/maneuver_plan.hpp>
36#include <carma_planning_msgs/msg/trajectory_plan.hpp>
37#include <carma_planning_msgs/msg/lane_change_status.hpp>
38#include <carma_perception_msgs/msg/roadway_obstacle.hpp>
40#include <lanelet2_extension/projection/local_frame_projector.h>
41#include <std_msgs/msg/string.hpp>
42
45
47{
49
55 {
56 std::string maneuver_id; // maneuver_id that this object corresponds to
57 std::string original_starting_lane_id; // Original starting_lane_id associated with this lane change maneuver
58 double original_start_dist; // Original start_dist associated with this lane change maneuver
59 double original_longitudinal_vel_ms; // The vehicle velocity (in m/s) when the vehicle first began this lane change
60 bool has_started = false; // Flag to indicate whether the vehicle's downtrack is beyond the original_start_dist of this lane change maneuver
61 };
62
68 {
69
70 private:
71 // Subscribers
72 carma_ros2_utils::SubPtr<geometry_msgs::msg::PoseStamped> pose_sub_;
73 carma_ros2_utils::SubPtr<geometry_msgs::msg::TwistStamped> twist_sub_;
74 carma_ros2_utils::SubPtr<carma_v2x_msgs::msg::MobilityResponse> incoming_mobility_response_sub_;
75 carma_ros2_utils::SubPtr<std_msgs::msg::String> georeference_sub_;
76 carma_ros2_utils::SubPtr<carma_v2x_msgs::msg::BSM> bsm_sub_;
77
78 // Publishers
79 carma_ros2_utils::PubPtr<carma_v2x_msgs::msg::MobilityRequest> outgoing_mobility_request_pub_;
80 carma_ros2_utils::PubPtr<carma_planning_msgs::msg::LaneChangeStatus> lanechange_status_pub_;
81
82 // CooperativeLaneChangePlugin configuration
84
85 // World Model object
87
88 // Map projection string, which defines the lat/lon -> map conversion
89 std::string map_georeference_{""};
90 std::shared_ptr<lanelet::projection::LocalFrameProjector> map_projector_;
91
92 // Trajectory frequency
93 double traj_freq_ = 10;
94
95 // Default recipient ID to be used for cooperative lane change Mobility Requests
96 std::string DEFAULT_STRING_= "";
97
98 // Time at which the cooperative lane change Mobility Request is first sent
99 rclcpp::Time request_sent_time_;
100
101 // Boolean that records whether request has already been sent
102 bool request_sent_ = false;
103
104 // Fraction of the received maneuver that has already been completed by the host vehicle
106
107 // Boolean to check if CLC plugin's plan trajectory service has been called
108 bool clc_called_ = false;
109
110 // The plan ID associated with the cooperative lane change Mobility Request; initialized with a default value
111 std::string clc_request_id_ = "default_request_id";
112
113 // The latest BSM Core Data broadcasted by the host vehicle
114 carma_v2x_msgs::msg::BSMCoreData bsm_core_;
115
116 // Maps maneuver IDs to their corresponding LaneChangeManeuverOriginalValues object
117 std::unordered_map<std::string, LaneChangeManeuverOriginalValues> original_lc_maneuver_values_;
118
123 void pose_cb(const geometry_msgs::msg::PoseStamped::UniquePtr msg);
124
129 void twist_cb(const geometry_msgs::msg::TwistStamped::UniquePtr msg);
130
135 void bsm_cb(const carma_v2x_msgs::msg::BSM::UniquePtr msg);
136
142 std::string bsmIDtoString(carma_v2x_msgs::msg::BSMCoreData bsm_core);
143
144 public:
145 // Internal Variables used in unit testsis_lanechange_accepted_
146 // Current vehicle forward speed
148
149 // Current vehicle pose in map
150 geometry_msgs::msg::PoseStamped pose_msg_;
151
152 // Boolean flag which is updated if lane change request is accepted
154
155 carma_planning_msgs::msg::VehicleState ending_state_before_buffer_;
156
160 explicit CooperativeLaneChangePlugin(const rclcpp::NodeOptions &);
161
165 rcl_interfaces::msg::SetParametersResult
166 parameter_update_callback(const std::vector<rclcpp::Parameter> &parameters);
167
175 std::vector<carma_planning_msgs::msg::TrajectoryPlanPoint> plan_lanechange(carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req);
176
186 double find_current_gap(long veh2_lanelet_id, double veh2_downtrack, carma_planning_msgs::msg::VehicleState& ego_state) const;
187
192 void mobilityresponse_cb(const carma_v2x_msgs::msg::MobilityResponse::UniquePtr msg);
193
199 carma_v2x_msgs::msg::MobilityRequest create_mobility_request(std::vector<carma_planning_msgs::msg::TrajectoryPlanPoint>& trajectory_plan, carma_planning_msgs::msg::Maneuver& maneuver);
200
206 carma_v2x_msgs::msg::Trajectory trajectory_plan_to_trajectory(const std::vector<carma_planning_msgs::msg::TrajectoryPlanPoint>& traj_points) const;
207
214 carma_v2x_msgs::msg::LocationECEF trajectory_point_to_ecef(const carma_planning_msgs::msg::TrajectoryPlanPoint& traj_point) const;
215
222 void add_trajectory_to_response(carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req,
223 carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp,
224 const std::vector<carma_planning_msgs::msg::TrajectoryPlanPoint>& planned_trajectory_points);
225
230 void georeference_cb(const std_msgs::msg::String::UniquePtr msg);
231
233 // Overrides
236 std::shared_ptr<rmw_request_id_t>,
237 carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req,
238 carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp) override;
239
240 bool get_availability() override;
241
242 std::string get_version_id() override;
243
247 carma_ros2_utils::CallbackReturn on_configure_plugin();
248
249 // Unit Tests
250 FRIEND_TEST(CooperativeLaneChangePlugin, TestLaneChangefunctions);
252 FRIEND_TEST(CooperativeLaneChangePlugin,TestNoPath_roadwayobject);
253 };
254
255} // cooperative_lanechange
TacticalPlugin base class which can be extended by user provided plugins which wish to implement the ...
The class responsible for generating cooperative lanechange trajectories from received lane change ma...
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.
carma_planning_msgs::msg::VehicleState ending_state_before_buffer_
bool get_availability() override
Get the availability status of this plugin based on the current operating environment....
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 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...
FRIEND_TEST(CooperativeLaneChangePlugin, TestLaneChangefunctions)
carma_ros2_utils::SubPtr< geometry_msgs::msg::TwistStamped > twist_sub_
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.
void mobilityresponse_cb(const carma_v2x_msgs::msg::MobilityResponse::UniquePtr msg)
Callback to subscribed mobility response topic.
std::unordered_map< std::string, LaneChangeManeuverOriginalValues > original_lc_maneuver_values_
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.
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 traj...
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::BSM > bsm_sub_
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.
CooperativeLaneChangePlugin(const rclcpp::NodeOptions &)
CooperativeLaneChangePlugin constructor.
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_
std::string get_version_id() override
Returns the version id of this plugin.
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_planning_msgs::msg::LaneChangeStatus > lanechange_status_pub_
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.
std::shared_ptr< lanelet::projection::LocalFrameProjector > map_projector_
rcl_interfaces::msg::SetParametersResult parameter_update_callback(const std::vector< rclcpp::Parameter > &parameters)
Callback for dynamic parameter updates.
carma_ros2_utils::CallbackReturn on_configure_plugin()
This method should be used to load parameters and will be called on the configure state transition.
carma_ros2_utils::SubPtr< geometry_msgs::msg::PoseStamped > pose_sub_
FRIEND_TEST(CooperativeLaneChangePlugin, Testcurrentgapcb)
FRIEND_TEST(CooperativeLaneChangePlugin, TestNoPath_roadwayobject)
carma_ros2_utils::SubPtr< carma_v2x_msgs::msg::MobilityResponse > incoming_mobility_response_sub_
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.
std::shared_ptr< const WorldModel > WorldModelConstPtr
Definition: WorldModel.hpp:452
basic_autonomy::waypoint_generation::PointSpeedPair PointSpeedPair
Stuct containing the algorithm configuration values for cooperative_lanechange.
Convenience struct for storing the original start_dist and starting_lane_id associated with a receive...