Carma-platform v4.11.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.
inlanecruising_plugin.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 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#include <rclcpp/rclcpp.hpp>
18#include <string>
19#include <algorithm>
20#include <memory>
21#include <boost/uuid/uuid_generators.hpp>
22#include <boost/uuid/uuid_io.hpp>
23#include <lanelet2_core/geometry/Point.h>
24#include <trajectory_utils/trajectory_utils.hpp>
25#include <trajectory_utils/conversions/conversions.hpp>
26#include <sstream>
27#include <Eigen/Core>
28#include <Eigen/Geometry>
29#include <Eigen/LU>
30#include <Eigen/SVD>
33
34
35
36
37using oss = std::ostringstream;
38
40{
41InLaneCruisingPlugin::InLaneCruisingPlugin(std::shared_ptr<carma_ros2_utils::CarmaLifecycleNode> nh,
43 const InLaneCruisingPluginConfig& config,
44 const DebugPublisher& debug_publisher,
45 const std::string& plugin_name,
46 const std::string& version_id)
47 : nh_(nh), wm_(wm), config_(config), debug_publisher_(debug_publisher), plugin_name_(plugin_name), version_id_ (version_id)
48{
49 basic_autonomy::set_logger(nh_->get_logger().get_child("basic_autonomy"));
50}
51
53 carma_planning_msgs::srv::PlanTrajectory::Request::SharedPtr req,
54 carma_planning_msgs::srv::PlanTrajectory::Response::SharedPtr resp)
55{
56 std::chrono::system_clock::time_point start_time = std::chrono::system_clock::now(); // Start timing the execution time for planning so it can be logged
57
58 lanelet::BasicPoint2d veh_pos(req->vehicle_state.x_pos_global, req->vehicle_state.y_pos_global);
59 double current_downtrack = wm_->routeTrackPos(veh_pos).downtrack;
60
61 // Only plan the trajectory for the initial LANE_FOLLOWING maneuver and any immediately sequential maneuvers of the same type
62 std::vector<carma_planning_msgs::msg::Maneuver> maneuver_plan;
63 for(size_t i = req->maneuver_index_to_plan; i < req->maneuver_plan.maneuvers.size(); i++)
64 {
65 if(req->maneuver_plan.maneuvers[i].type == carma_planning_msgs::msg::Maneuver::LANE_FOLLOWING)
66 {
67 maneuver_plan.push_back(req->maneuver_plan.maneuvers[i]);
68 resp->related_maneuvers.push_back((uint8_t)i);
69 }
70 else
71 {
72 break;
73 }
74 }
75
78
82
90
91 auto points_and_target_speeds = basic_autonomy::waypoint_generation::create_geometry_profile(maneuver_plan, std::max((double)0, current_downtrack - config_.back_distance),
92 wm_, ending_state_before_buffer_, req->vehicle_state, wpg_general_config, wpg_detail_config);
93
94 RCLCPP_DEBUG_STREAM(nh_->get_logger(), "points_and_target_speeds: " << points_and_target_speeds.size());
95
96 RCLCPP_DEBUG_STREAM(nh_->get_logger(), "PlanTrajectory");
97
98 carma_planning_msgs::msg::TrajectoryPlan original_trajectory;
99 original_trajectory.header.frame_id = "map";
100 original_trajectory.header.stamp = nh_->now();
101 original_trajectory.trajectory_id = boost::uuids::to_string(boost::uuids::random_generator()());
102
103 original_trajectory.trajectory_points = basic_autonomy:: waypoint_generation::compose_lanefollow_trajectory_from_path(points_and_target_speeds,
104 req->vehicle_state, req->header.stamp, wm_, ending_state_before_buffer_, debug_msg_,
105 wpg_detail_config); // Compute the trajectory
106 original_trajectory.initial_longitudinal_velocity = std::max(req->vehicle_state.longitudinal_vel, config_.minimum_speed);
107
108 // Set the planning plugin field name
109 for (auto& p : original_trajectory.trajectory_points) {
110 p.planner_plugin_name = plugin_name_;
111 }
112
113 resp->trajectory_plan = original_trajectory;
114
115 if (config_.publish_debug) { // Publish the debug message if in debug logging mode
116 debug_msg_.trajectory_plan = resp->trajectory_plan;
118 }
119
120 resp->maneuver_status.push_back(carma_planning_msgs::srv::PlanTrajectory::Response::MANEUVER_IN_PROGRESS);
121
122 std::chrono::system_clock::time_point end_time = std::chrono::system_clock::now(); // Planning complete
123
124 auto duration = end_time - start_time;
125 RCLCPP_DEBUG_STREAM(
126 rclcpp::get_logger("inlanecruising_plugin"),
127 "ILC ExecutionTime: " << std::chrono::duration<double>(duration).count());
128}
129
130} // namespace inlanecruising_plugin
std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode > nh_
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.
carma_debug_ros2_msgs::msg::TrajectoryCurvatureSpeeds debug_msg_
carma_planning_msgs::msg::VehicleState ending_state_before_buffer_
InLaneCruisingPlugin(std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode > nh, carma_wm::WorldModelConstPtr wm, const InLaneCruisingPluginConfig &config, const DebugPublisher &debug_publisher=[](const auto &msg){}, const std::string &plugin_name="inlanecruising_plugin", const std::string &version_id="v1.0")
Constructor.
std::ostringstream oss
GeneralTrajConfig compose_general_trajectory_config(const std::string &trajectory_type, int default_downsample_ratio, int turn_downsample_ratio)
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...
std::vector< carma_planning_msgs::msg::TrajectoryPlanPoint > compose_lanefollow_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, carma_debug_ros2_msgs::msg::TrajectoryCurvatureSpeeds &debug_msg, const DetailedTrajConfig &detailed_config)
Method converts a list of lanelet centerline points and current vehicle state into a usable list of t...
void set_logger(rclcpp::Logger logger)
Replace the module-level logger used by all basic_autonomy functions.
Definition: log.cpp:33
rclcpp::Logger get_logger()
Return the module-level logger used by all basic_autonomy functions.
Definition: log.cpp:32
auto to_string(const UtmZone &zone) -> std::string
Definition: utm_zone.cpp:21
std::shared_ptr< const WorldModel > WorldModelConstPtr
Definition: WorldModel.hpp:454
std::function< void(const carma_debug_ros2_msgs::msg::TrajectoryCurvatureSpeeds &)> DebugPublisher
string version_id
Stuct containing the algorithm configuration values for the InLaneCruisingPlugin.