Carma-platform v4.10.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.
plan_delegator::PlanDelegator Class Reference

#include <plan_delegator.hpp>

Inheritance diagram for plan_delegator::PlanDelegator:
Inheritance graph
Collaboration diagram for plan_delegator::PlanDelegator:
Collaboration graph

Public Member Functions

 PlanDelegator (const rclcpp::NodeOptions &)
 PlanDelegator constructor. More...
 
void maneuverPlanCallback (carma_planning_msgs::msg::ManeuverPlan::UniquePtr plan)
 Callback function of maneuver plan subscriber. More...
 
void guidanceStateCallback (carma_planning_msgs::msg::GuidanceState::UniquePtr plan)
 Callback function of guidance state subscriber. More...
 
void poseCallback (geometry_msgs::msg::PoseStamped::UniquePtr pose_msg)
 Callback function for vehicle pose subscriber. Updates latest_pose_ and makes calls to publishUpcomingLaneChangeStatus() and publishTurnSignalCommand(). More...
 
carma_ros2_utils::ClientPtr< carma_planning_msgs::srv::PlanTrajectory > getPlannerClientByName (const std::string &planner_name)
 Get PlanTrajectory service client by plugin name and create new PlanTrajectory service client if specified name does not exist. More...
 
bool isManeuverExpired (const carma_planning_msgs::msg::Maneuver &maneuver, rclcpp::Time current_time) const
 Example if a maneuver end time has passed current system time. More...
 
std::shared_ptr< carma_planning_msgs::srv::PlanTrajectory::Request > composePlanTrajectoryRequest (const carma_planning_msgs::msg::TrajectoryPlan &latest_trajectory_plan, const carma_planning_msgs::msg::ManeuverPlan &locked_maneuver_plan, const uint16_t &current_maneuver_index) const
 Generate new PlanTrajecory service request based on current planning progress. More...
 
void lookupFrontBumperTransform ()
 Lookup transfrom from front bumper to base link. More...
 
void updateManeuverParameters (carma_planning_msgs::msg::Maneuver &maneuver)
 Update the starting downtrack, ending downtrack, and maneuver-specific Lanelet ID parameters associated with a given maneuver. These updates are required since the starting and ending downtrack values of each maneuver are shifted based on the distance between the base_link frame and the vehicle_front frame. More...
 
carma_ros2_utils::CallbackReturn handle_on_configure (const rclcpp_lifecycle::State &)
 
carma_ros2_utils::CallbackReturn handle_on_activate (const rclcpp_lifecycle::State &)
 

Static Public Attributes

static const constexpr double MILLISECOND_TO_SECOND = 0.001
 

Protected Attributes

Config config_
 
std::unordered_map< std::string, carma_ros2_utils::ClientPtr< carma_planning_msgs::srv::PlanTrajectory > > trajectory_planners_
 
carma_planning_msgs::msg::ManeuverPlan latest_maneuver_plan_
 
bool received_maneuver_plan_ = false
 
geometry_msgs::msg::PoseStamped latest_pose_
 
geometry_msgs::msg::TwistStamped latest_twist_
 
carma_wm::WMListener wml_
 
carma_wm::WorldModelConstPtr wm_
 

Private Member Functions

void onTrajPlanTick ()
 Callback function for triggering trajectory planning. More...
 
bool isManeuverPlanValid (const carma_planning_msgs::msg::ManeuverPlan &maneuver_plan) const noexcept
 Example if a maneuver plan contains at least one maneuver. More...
 
bool isTrajectoryValid (const carma_planning_msgs::msg::TrajectoryPlan &trajectory_plan) const noexcept
 Example if a trajectory plan contains at least two trajectory points. More...
 
bool isTrajectoryLongEnough (const carma_planning_msgs::msg::TrajectoryPlan &plan) const noexcept
 Example if a trajectory plan is longer than configured time thresheld. More...
 
carma_planning_msgs::msg::TrajectoryPlan planTrajectory ()
 Plan trajectory based on latest maneuver plan via ROS service call to plugins. More...
 
LaneChangeInformation getLaneChangeInformation (const carma_planning_msgs::msg::Maneuver &lane_change_maneuver)
 Function for generating a LaneChangeInformation object from a provided lane change maneuver. More...
 
void publishUpcomingLaneChangeStatus (const boost::optional< LaneChangeInformation > &upcoming_lane_change_information)
 Function for processing an optional LaneChangeInformation object pertaining to an upcoming lane change. If not empty, an UpcomingLaneChangeStatus message is created and published based on the contents of the LaneChangeInformation. The published UpcomingLaneChangeStatus message is stored in upcoming_lane_change_status_. More...
 
void publishTurnSignalCommand (const boost::optional< LaneChangeInformation > &current_lane_change_information, const carma_planning_msgs::msg::UpcomingLaneChangeStatus &upcoming_lane_change_status)
 Function for processing an optional LaneChangeInformation object pertaining to the currently-occurring lane change and an UpcomingLaneChangeStatus message. If the optional object pertaining to the currently-occurring lane change is not empty, then a turn signal command is published based on the current lane change direction. Otherwise, a turn signal command in the direction of the UpcomingLaneChangeStatus message is published if the vehicle is estimated to begin that lane change in under the time threshold defined by config_.duration_to_signal_before_lane_change. The published TurnSignalComand message is stored in latest_turn_signal_command_. More...
 
 FRIEND_TEST (TestPlanDelegator, UnitTestPlanDelegator)
 
 FRIEND_TEST (TestPlanDelegator, TestPlanDelegator)
 
 FRIEND_TEST (TestPlanDelegator, TestLaneChangeInformation)
 
 FRIEND_TEST (TestPlanDelegator, TestUpcomingLaneChangeAndTurnSignals)
 
 FRIEND_TEST (TestPlanDelegator, TestUpdateManeuverParameters)
 

Private Attributes

std::optional< carma_planning_msgs::msg::TrajectoryPlan > last_successful_traj_
 
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::TrajectoryPlan > traj_pub_
 
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::UpcomingLaneChangeStatus > upcoming_lane_change_status_pub_
 
carma_ros2_utils::PubPtr< autoware_msgs::msg::LampCmd > turn_signal_command_pub_
 
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::ManeuverPlan > plan_sub_
 
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_planning_msgs::msg::GuidanceState > guidance_state_sub_
 
rclcpp::TimerBase::SharedPtr traj_timer_
 
rclcpp::CallbackGroup::SharedPtr timer_callback_group_
 
bool guidance_engaged = false
 
int consecutive_traj_gen_failure_num_ = 0
 
double length_to_front_bumper_ = 3.0
 
std::shared_ptr< tf2_ros::Buffer > tf2_buffer_
 
std::shared_ptr< tf2_ros::TransformListener > tf2_listener_
 
boost::optional< LaneChangeInformationupcoming_lane_change_information_
 
boost::optional< LaneChangeInformationcurrent_lane_change_information_
 
carma_planning_msgs::msg::UpcomingLaneChangeStatus upcoming_lane_change_status_
 
autoware_msgs::msg::LampCmd latest_turn_signal_command_
 

Detailed Description

Definition at line 110 of file plan_delegator.hpp.

Constructor & Destructor Documentation

◆ PlanDelegator()

plan_delegator::PlanDelegator::PlanDelegator ( const rclcpp::NodeOptions &  options)
explicit

PlanDelegator constructor.

Definition at line 131 of file plan_delegator.cpp.

131 : carma_ros2_utils::CarmaLifecycleNode(options),
132 tf2_buffer_(std::make_shared<tf2_ros::Buffer>(this->get_clock())),
133 wml_(this->get_node_base_interface(), this->get_node_logging_interface(),
134 this->get_node_topics_interface(), this->get_node_parameters_interface())
135 {
136 // Create initial config
137 config_ = Config();
138
139 config_.planning_topic_prefix = declare_parameter<std::string>("planning_topic_prefix", config_.planning_topic_prefix);
140 config_.planning_topic_suffix = declare_parameter<std::string>("planning_topic_suffix", config_.planning_topic_suffix);
141 config_.trajectory_planning_rate = declare_parameter<double>("trajectory_planning_rate", config_.trajectory_planning_rate);
142 config_.max_trajectory_duration = declare_parameter<double>("trajectory_duration_threshold", config_.max_trajectory_duration);
143 config_.min_crawl_speed = declare_parameter<double>("min_speed", config_.min_crawl_speed);
144 config_.duration_to_signal_before_lane_change = declare_parameter<double>("duration_to_signal_before_lane_change", config_.duration_to_signal_before_lane_change);
145 config_.max_traj_generation_reattempt = declare_parameter<int>("max_traj_generation_reattempt", config_.max_traj_generation_reattempt);
146 config_.tactical_plugin_service_call_timeout = declare_parameter<int>("tactical_plugin_service_call_timeout", config_.tactical_plugin_service_call_timeout);
147 }
std::shared_ptr< tf2_ros::Buffer > tf2_buffer_
std::string planning_topic_suffix
std::string planning_topic_prefix
double duration_to_signal_before_lane_change

References config_, plan_delegator::Config::duration_to_signal_before_lane_change, plan_delegator::Config::max_traj_generation_reattempt, plan_delegator::Config::max_trajectory_duration, plan_delegator::Config::min_crawl_speed, plan_delegator::Config::planning_topic_prefix, plan_delegator::Config::planning_topic_suffix, plan_delegator::Config::tactical_plugin_service_call_timeout, and plan_delegator::Config::trajectory_planning_rate.

Member Function Documentation

◆ composePlanTrajectoryRequest()

std::shared_ptr< carma_planning_msgs::srv::PlanTrajectory::Request > plan_delegator::PlanDelegator::composePlanTrajectoryRequest ( const carma_planning_msgs::msg::TrajectoryPlan &  latest_trajectory_plan,
const carma_planning_msgs::msg::ManeuverPlan &  locked_maneuver_plan,
const uint16_t &  current_maneuver_index 
) const

Generate new PlanTrajecory service request based on current planning progress.

Parameters
latest_trajectory_planThe trajectory plan to append the resulting trajectory
locked_maneuver_planThe maneuver plan to send to the tactical plugin
current_maneuver_indexThe idx of the maneuver in the maneuver plan that this request is for
Returns
a PlanTrajectoryRequest to be used in the service call to the tactical plugin

Definition at line 418 of file plan_delegator.cpp.

422 {
423 auto plan_req = std::make_shared<carma_planning_msgs::srv::PlanTrajectory::Request>();
424 plan_req->maneuver_plan = locked_maneuver_plan;
425
426 // set current vehicle state if we have NOT planned any previous trajectories
427 if(latest_trajectory_plan.trajectory_points.empty())
428 {
429 plan_req->header.stamp = latest_pose_.header.stamp;
430 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "latest_pose_.header.stamp: " << std::to_string(rclcpp::Time(latest_pose_.header.stamp).seconds()));
431 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "plan_req->header.stamp: " << std::to_string(rclcpp::Time(plan_req->header.stamp).seconds()));
432
433 plan_req->vehicle_state.longitudinal_vel = latest_twist_.twist.linear.x;
434 plan_req->vehicle_state.x_pos_global = latest_pose_.pose.position.x;
435 plan_req->vehicle_state.y_pos_global = latest_pose_.pose.position.y;
436 double roll, pitch, yaw;
437 carma_wm::geometry::rpyFromQuaternion(latest_pose_.pose.orientation, roll, pitch, yaw);
438 plan_req->vehicle_state.orientation = yaw;
439 plan_req->maneuver_index_to_plan = current_maneuver_index;
440 }
441 // set vehicle state based on last two planned trajectory points
442 else
443 {
444 carma_planning_msgs::msg::TrajectoryPlanPoint last_point = latest_trajectory_plan.trajectory_points.back();
445 carma_planning_msgs::msg::TrajectoryPlanPoint second_last_point = *(latest_trajectory_plan.trajectory_points.rbegin() + 1);
446 plan_req->vehicle_state.x_pos_global = last_point.x;
447 plan_req->vehicle_state.y_pos_global = last_point.y;
448 auto distance_diff = std::sqrt(std::pow(last_point.x - second_last_point.x, 2) + std::pow(last_point.y - second_last_point.y, 2));
449 rclcpp::Duration time_diff = rclcpp::Time(last_point.target_time) - rclcpp::Time(second_last_point.target_time);
450 auto time_diff_sec = time_diff.seconds();
451 plan_req->maneuver_index_to_plan = current_maneuver_index;
452 // this assumes the vehicle does not have significant lateral velocity
453 plan_req->header.stamp = latest_trajectory_plan.trajectory_points.back().target_time;
454 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "plan_req->header.stamp: " << std::to_string(rclcpp::Time(plan_req->header.stamp).seconds()));
455
456 plan_req->vehicle_state.longitudinal_vel = distance_diff / time_diff_sec;
457 // TODO develop way to set yaw value for future points
458 }
459 return plan_req;
460 }
geometry_msgs::msg::TwistStamped latest_twist_
geometry_msgs::msg::PoseStamped latest_pose_
auto to_string(const UtmZone &zone) -> std::string
Definition: utm_zone.cpp:21
void rpyFromQuaternion(const tf2::Quaternion &q, double &roll, double &pitch, double &yaw)
Extract extrinsic roll-pitch-yaw from quaternion.
Definition: Geometry.cpp:52

References latest_pose_, latest_twist_, carma_wm::geometry::rpyFromQuaternion(), and carma_cooperative_perception::to_string().

Referenced by planTrajectory().

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

◆ FRIEND_TEST() [1/5]

plan_delegator::PlanDelegator::FRIEND_TEST ( TestPlanDelegator  ,
TestLaneChangeInformation   
)
private

◆ FRIEND_TEST() [2/5]

plan_delegator::PlanDelegator::FRIEND_TEST ( TestPlanDelegator  ,
TestPlanDelegator   
)
private

◆ FRIEND_TEST() [3/5]

plan_delegator::PlanDelegator::FRIEND_TEST ( TestPlanDelegator  ,
TestUpcomingLaneChangeAndTurnSignals   
)
private

◆ FRIEND_TEST() [4/5]

plan_delegator::PlanDelegator::FRIEND_TEST ( TestPlanDelegator  ,
TestUpdateManeuverParameters   
)
private

◆ FRIEND_TEST() [5/5]

plan_delegator::PlanDelegator::FRIEND_TEST ( TestPlanDelegator  ,
UnitTestPlanDelegator   
)
private

◆ getLaneChangeInformation()

LaneChangeInformation plan_delegator::PlanDelegator::getLaneChangeInformation ( const carma_planning_msgs::msg::Maneuver &  lane_change_maneuver)
private

Function for generating a LaneChangeInformation object from a provided lane change maneuver.

Parameters
lane_change_maneuverThe lane change maneuver that a LaneChangeInformation object shall be generated from.
Returns
A LaneChangeInformation object containing information on the provided lane change maneuver.

Definition at line 258 of file plan_delegator.cpp.

258 {
259 LaneChangeInformation lane_change_information;
260
261 lane_change_information.starting_downtrack = lane_change_maneuver.lane_change_maneuver.start_dist;
262
263 // Get the starting and ending lanelets for this lane change maneuver
264 lanelet::ConstLanelet starting_lanelet = wm_->getMap()->laneletLayer.get(std::stoi(lane_change_maneuver.lane_change_maneuver.starting_lane_id));
265 lanelet::ConstLanelet ending_lanelet = wm_->getMap()->laneletLayer.get(std::stoi(lane_change_maneuver.lane_change_maneuver.ending_lane_id));
266
267 // Determine if lane change is a left or right lane change and update lane_change_information accordingly
268 bool shared_boundary_found = false;
269
270 lanelet::ConstLanelet current_lanelet = starting_lanelet;
271
272 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "Searching for shared boundary with starting lanechange lanelet " << std::to_string(current_lanelet.id()) << " and ending lanelet " << std::to_string(ending_lanelet.id()));
273 while(!shared_boundary_found){
274 // Assumption: Adjacent lanelets share lane boundary
275
276 if(current_lanelet.leftBound() == ending_lanelet.rightBound()){
277 // If current lanelet's left lane boundary matches the ending lanelet's right lane boundary, it is a left lane change
278 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "Lanelet " << std::to_string(current_lanelet.id()) << " shares left boundary with " << std::to_string(ending_lanelet.id()));
279 lane_change_information.is_right_lane_change = false;
280 shared_boundary_found = true;
281 }
282 else if(current_lanelet.rightBound() == ending_lanelet.leftBound()){
283 // If current lanelet's right lane boundary matches the ending lanelet's left lane boundary, it is a right lane change
284 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "Lanelet " << std::to_string(current_lanelet.id()) << " shares right boundary with " << std::to_string(ending_lanelet.id()));
285 lane_change_information.is_right_lane_change = true;
286 shared_boundary_found = true;
287 }
288 else{
289 // If there are no following lanelets on route, lanechange should be completing before reaching it
290 if(wm_->getMapRoutingGraph()->following(current_lanelet, false).empty())
291 {
292 // Maneuver requires we travel further before completing lane change, but there is no routable lanelet directly ahead;
293 // in this case we have reached a lanelet which does not have a routable lanelet ahead and isn't adjacent to the lanelet where lane change ends.
294 // A lane change should have already happened at this point
295 throw(std::invalid_argument("No following lanelets from current lanelet reachable without a lane change, incorrectly chosen end lanelet"));
296 }
297
298 current_lanelet = wm_->getMapRoutingGraph()->following(current_lanelet, false).front();
299 if(current_lanelet.id() == starting_lanelet.id()){
300 //Looped back to starting lanelet
301 throw(std::invalid_argument("No lane change in path"));
302 }
303 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "Now checking for shared lane boundary with lanelet " << std::to_string(current_lanelet.id()) << " and ending lanelet " << std::to_string(ending_lanelet.id()));
304 }
305 }
306
307 return lane_change_information;
308 }
carma_wm::WorldModelConstPtr wm_

References plan_delegator::LaneChangeInformation::is_right_lane_change, plan_delegator::LaneChangeInformation::starting_downtrack, carma_cooperative_perception::to_string(), and wm_.

Referenced by maneuverPlanCallback().

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

◆ getPlannerClientByName()

carma_ros2_utils::ClientPtr< carma_planning_msgs::srv::PlanTrajectory > plan_delegator::PlanDelegator::getPlannerClientByName ( const std::string &  planner_name)

Get PlanTrajectory service client by plugin name and create new PlanTrajectory service client if specified name does not exist.

Returns
a ServiceClient object which corresponse to the target planner

Definition at line 378 of file plan_delegator.cpp.

379 {
380 if(planner_name.size() == 0)
381 {
382 throw std::invalid_argument("Invalid trajectory planner name because it has zero length!");
383 }
384 if(trajectory_planners_.find(planner_name) == trajectory_planners_.end())
385 {
386 RCLCPP_INFO_STREAM(rclcpp::get_logger("plan_delegator"),"Discovered new trajectory planner: " << planner_name);
387
388 trajectory_planners_.emplace(
389 planner_name, create_client<carma_planning_msgs::srv::PlanTrajectory>(config_.planning_topic_prefix + planner_name + config_.planning_topic_suffix));
390 }
391 return trajectory_planners_[planner_name];
392 }
std::unordered_map< std::string, carma_ros2_utils::ClientPtr< carma_planning_msgs::srv::PlanTrajectory > > trajectory_planners_

References config_, plan_delegator::Config::planning_topic_prefix, plan_delegator::Config::planning_topic_suffix, and trajectory_planners_.

Referenced by planTrajectory().

Here is the caller graph for this function:

◆ guidanceStateCallback()

void plan_delegator::PlanDelegator::guidanceStateCallback ( carma_planning_msgs::msg::GuidanceState::UniquePtr  plan)

Callback function of guidance state subscriber.

Definition at line 191 of file plan_delegator.cpp.

References lightbar_manager::ENGAGED, and guidance_engaged.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ handle_on_activate()

carma_ros2_utils::CallbackReturn plan_delegator::PlanDelegator::handle_on_activate ( const rclcpp_lifecycle::State &  )

Definition at line 182 of file plan_delegator.cpp.

183 {
184 timer_callback_group_ = create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
185 traj_timer_ = create_timer(get_clock(),
186 std::chrono::milliseconds((int)(1 / config_.trajectory_planning_rate * 1000)),
188 return CallbackReturn::SUCCESS;
189 }
void onTrajPlanTick()
Callback function for triggering trajectory planning.
rclcpp::TimerBase::SharedPtr traj_timer_
rclcpp::CallbackGroup::SharedPtr timer_callback_group_

References config_, onTrajPlanTick(), timer_callback_group_, traj_timer_, and plan_delegator::Config::trajectory_planning_rate.

Here is the call graph for this function:

◆ handle_on_configure()

carma_ros2_utils::CallbackReturn plan_delegator::PlanDelegator::handle_on_configure ( const rclcpp_lifecycle::State &  )

Definition at line 149 of file plan_delegator.cpp.

150 {
151 // Reset config
152 config_ = Config();
153
154 get_parameter<std::string>("planning_topic_prefix", config_.planning_topic_prefix);
155 get_parameter<std::string>("planning_topic_suffix", config_.planning_topic_suffix);
156 get_parameter<double>("trajectory_planning_rate", config_.trajectory_planning_rate);
157 get_parameter<double>("trajectory_duration_threshold", config_.max_trajectory_duration);
158 get_parameter<double>("min_speed", config_.min_crawl_speed);
159 get_parameter<double>("duration_to_signal_before_lane_change", config_.duration_to_signal_before_lane_change);
160 get_parameter<int>("tactical_plugin_service_call_timeout", config_.tactical_plugin_service_call_timeout);
161 get_parameter<int>("max_traj_generation_reattempt", config_.max_traj_generation_reattempt);
162
163 RCLCPP_INFO_STREAM(rclcpp::get_logger("plan_delegator"),"Done loading parameters: " << config_);
164
165 // Setup publishers
166 traj_pub_ = create_publisher<carma_planning_msgs::msg::TrajectoryPlan>("plan_trajectory", 5);
167 upcoming_lane_change_status_pub_ = create_publisher<carma_planning_msgs::msg::UpcomingLaneChangeStatus>("upcoming_lane_change_status", 1);
168 turn_signal_command_pub_ = create_publisher<autoware_msgs::msg::LampCmd>("lamp_cmd", 1);
169
170 // Setup subscribers
171 plan_sub_ = create_subscription<carma_planning_msgs::msg::ManeuverPlan>("final_maneuver_plan", 5, std::bind(&PlanDelegator::maneuverPlanCallback, this, std_ph::_1));
172 twist_sub_ = create_subscription<geometry_msgs::msg::TwistStamped>("current_velocity", 5,
173 [this](geometry_msgs::msg::TwistStamped::UniquePtr twist) {this->latest_twist_ = *twist;});
174 pose_sub_ = create_subscription<geometry_msgs::msg::PoseStamped>("current_pose", 5, std::bind(&PlanDelegator::poseCallback, this, std_ph::_1));
175 guidance_state_sub_ = create_subscription<carma_planning_msgs::msg::GuidanceState>("guidance_state", 5, std::bind(&PlanDelegator::guidanceStateCallback, this, std_ph::_1));
176
179 return CallbackReturn::SUCCESS;
180 }
WorldModelConstPtr getWorldModel()
Returns a pointer to an intialized world model instance.
Definition: WMListener.cpp:184
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::GuidanceState > guidance_state_sub_
void poseCallback(geometry_msgs::msg::PoseStamped::UniquePtr pose_msg)
Callback function for vehicle pose subscriber. Updates latest_pose_ and makes calls to publishUpcomin...
carma_ros2_utils::SubPtr< geometry_msgs::msg::TwistStamped > twist_sub_
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::UpcomingLaneChangeStatus > upcoming_lane_change_status_pub_
void guidanceStateCallback(carma_planning_msgs::msg::GuidanceState::UniquePtr plan)
Callback function of guidance state subscriber.
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::ManeuverPlan > plan_sub_
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::TrajectoryPlan > traj_pub_
carma_ros2_utils::PubPtr< autoware_msgs::msg::LampCmd > turn_signal_command_pub_
carma_ros2_utils::SubPtr< geometry_msgs::msg::PoseStamped > pose_sub_
void lookupFrontBumperTransform()
Lookup transfrom from front bumper to base link.
void maneuverPlanCallback(carma_planning_msgs::msg::ManeuverPlan::UniquePtr plan)
Callback function of maneuver plan subscriber.

References config_, plan_delegator::Config::duration_to_signal_before_lane_change, carma_wm::WMListener::getWorldModel(), guidance_state_sub_, guidanceStateCallback(), latest_twist_, lookupFrontBumperTransform(), maneuverPlanCallback(), plan_delegator::Config::max_traj_generation_reattempt, plan_delegator::Config::max_trajectory_duration, plan_delegator::Config::min_crawl_speed, plan_sub_, plan_delegator::Config::planning_topic_prefix, plan_delegator::Config::planning_topic_suffix, pose_sub_, poseCallback(), plan_delegator::Config::tactical_plugin_service_call_timeout, traj_pub_, plan_delegator::Config::trajectory_planning_rate, turn_signal_command_pub_, twist_sub_, upcoming_lane_change_status_pub_, wm_, and wml_.

Here is the call graph for this function:

◆ isManeuverExpired()

bool plan_delegator::PlanDelegator::isManeuverExpired ( const carma_planning_msgs::msg::Maneuver &  maneuver,
rclcpp::Time  current_time 
) const

Example if a maneuver end time has passed current system time.

Returns
if input maneuver is expires NOTE: current_time is assumed to be same clock type as this node

Definition at line 406 of file plan_delegator.cpp.

407 {
408 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "maneuver start time:" << std::to_string(rclcpp::Time(GET_MANEUVER_PROPERTY(maneuver, start_time)).seconds()));
409 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "maneuver end time:" << std::to_string(rclcpp::Time(GET_MANEUVER_PROPERTY(maneuver, end_time)).seconds()));
410 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "current time:" << std::to_string(now().seconds()));
411 bool isexpired = rclcpp::Time(GET_MANEUVER_PROPERTY(maneuver, end_time), get_clock()->get_clock_type()) <= current_time; // TODO maneuver expiration should maybe be based off of distance not time? https://github.com/usdot-fhwa-stol/carma-platform/issues/1107
412 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "isexpired:" << isexpired);
413 // TODO: temporary disabling expiration check
414 return false;
415 }
#define GET_MANEUVER_PROPERTY(mvr, property)
Macro definition to enable easier access to fields shared across the maneuver types.

References GET_MANEUVER_PROPERTY, and carma_cooperative_perception::to_string().

Referenced by planTrajectory().

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

◆ isManeuverPlanValid()

bool plan_delegator::PlanDelegator::isManeuverPlanValid ( const carma_planning_msgs::msg::ManeuverPlan &  maneuver_plan) const
privatenoexcept

Example if a maneuver plan contains at least one maneuver.

Returns
if input maneuver plan is valid

Definition at line 394 of file plan_delegator.cpp.

395 {
396 // currently it only checks if maneuver list is empty
397 return !maneuver_plan.maneuvers.empty();
398 }

Referenced by maneuverPlanCallback().

Here is the caller graph for this function:

◆ isTrajectoryLongEnough()

bool plan_delegator::PlanDelegator::isTrajectoryLongEnough ( const carma_planning_msgs::msg::TrajectoryPlan &  plan) const
privatenoexcept

Example if a trajectory plan is longer than configured time thresheld.

Returns
if input trajectory plan is long enough

Definition at line 462 of file plan_delegator.cpp.

463 {
464 rclcpp::Duration time_diff = rclcpp::Time(plan.trajectory_points.back().target_time) - rclcpp::Time(plan.trajectory_points.front().target_time);
465 return time_diff.seconds() >= config_.max_trajectory_duration;
466 }

Referenced by planTrajectory().

Here is the caller graph for this function:

◆ isTrajectoryValid()

bool plan_delegator::PlanDelegator::isTrajectoryValid ( const carma_planning_msgs::msg::TrajectoryPlan &  trajectory_plan) const
privatenoexcept

Example if a trajectory plan contains at least two trajectory points.

Returns
if input trajectory plan is valid

Definition at line 400 of file plan_delegator.cpp.

401 {
402 // currently it only checks if trajectory contains less than 2 points
403 return !(trajectory_plan.trajectory_points.size() < 2);
404 }

Referenced by onTrajPlanTick(), and planTrajectory().

Here is the caller graph for this function:

◆ lookupFrontBumperTransform()

void plan_delegator::PlanDelegator::lookupFrontBumperTransform ( )

Lookup transfrom from front bumper to base link.

Definition at line 780 of file plan_delegator.cpp.

781 {
782 tf2_listener_ = std::make_shared<tf2_ros::TransformListener>(*tf2_buffer_);
783 tf2_buffer_->setUsingDedicatedThread(true);
784 try
785 {
786 geometry_msgs::msg::TransformStamped tf = tf2_buffer_->lookupTransform("base_link", "vehicle_front", rclcpp::Time(0), rclcpp::Duration(20.0, 0)); //save to local copy of transform 20 sec timeout
787 length_to_front_bumper_ = tf.transform.translation.x;
788 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"length_to_front_bumper_: " << length_to_front_bumper_);
789
790 }
791 catch (const tf2::TransformException &ex)
792 {
793 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"), ex.what());
794 }
795 }
std::shared_ptr< tf2_ros::TransformListener > tf2_listener_

References length_to_front_bumper_, tf2_buffer_, and tf2_listener_.

Referenced by handle_on_configure().

Here is the caller graph for this function:

◆ maneuverPlanCallback()

void plan_delegator::PlanDelegator::maneuverPlanCallback ( carma_planning_msgs::msg::ManeuverPlan::UniquePtr  plan)

Callback function of maneuver plan subscriber.

Definition at line 196 of file plan_delegator.cpp.

197 {
198 RCLCPP_INFO_STREAM(rclcpp::get_logger("plan_delegator"),"Received request to delegate plan ID " << std::string(plan->maneuver_plan_id));
199 // do basic check to see if the input is valid
200 auto copy_plan = *plan;
202 if (isManeuverPlanValid(copy_plan))
203 {
204 latest_maneuver_plan_ = copy_plan;
205 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"Received plan with " << latest_maneuver_plan_.maneuvers.size() << " maneuvers");
206
207 // Update the parameters associated with each maneuver
208 for (auto& maneuver : latest_maneuver_plan_.maneuvers) {
209 updateManeuverParameters(maneuver);
210 }
211 }
212 else {
213 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"),"Received empty plan, no maneuvers found in plan ID " << std::string(plan->maneuver_plan_id));
214 }
215
216 // Update upcoming_lane_change_information_ and current_lane_change_information_ based on the received maneuver plan
217 if(!latest_maneuver_plan_.maneuvers.empty()){
218 // Get ego vehicle's current downtrack
219 lanelet::BasicPoint2d current_loc(latest_pose_.pose.position.x, latest_pose_.pose.position.y);
220 double current_downtrack = wm_->routeTrackPos(current_loc).downtrack;
221
222 // Set upcoming_lane_change_information_ based on the first found lane change in the plan that begins after current_downtrack, if one exists
223 upcoming_lane_change_information_ = boost::optional<LaneChangeInformation>(); // Reset to empty optional
224 for(const auto& maneuver : latest_maneuver_plan_.maneuvers){
225 if(maneuver.type == carma_planning_msgs::msg::Maneuver::LANE_CHANGE){
226 if(current_downtrack >= maneuver.lane_change_maneuver.start_dist){
227 // Skip this lane change maneuver since ego vehicle has passed the lane change start point (this is not an 'upcoming' lane change)
228 continue;
229 }
230 else{
231 LaneChangeInformation upcoming_lane_change_information = getLaneChangeInformation(maneuver);
232 upcoming_lane_change_information_ = boost::optional<LaneChangeInformation>(upcoming_lane_change_information);
233 break;
234 }
235 }
236 }
237
238 // Set current_lane_change_information_ if the first maneuver is a lane change
239 current_lane_change_information_ = boost::optional<LaneChangeInformation>(); // Reset to empty optional
240 if(latest_maneuver_plan_.maneuvers[0].type == carma_planning_msgs::msg::Maneuver::LANE_CHANGE){
241 LaneChangeInformation current_lane_change_information = getLaneChangeInformation(latest_maneuver_plan_.maneuvers[0]);
242 current_lane_change_information_ = boost::optional<LaneChangeInformation>(current_lane_change_information);
243 }
244 }
245 }
LaneChangeInformation getLaneChangeInformation(const carma_planning_msgs::msg::Maneuver &lane_change_maneuver)
Function for generating a LaneChangeInformation object from a provided lane change maneuver.
boost::optional< LaneChangeInformation > upcoming_lane_change_information_
void updateManeuverParameters(carma_planning_msgs::msg::Maneuver &maneuver)
Update the starting downtrack, ending downtrack, and maneuver-specific Lanelet ID parameters associat...
carma_planning_msgs::msg::ManeuverPlan latest_maneuver_plan_
boost::optional< LaneChangeInformation > current_lane_change_information_
bool isManeuverPlanValid(const carma_planning_msgs::msg::ManeuverPlan &maneuver_plan) const noexcept
Example if a maneuver plan contains at least one maneuver.

References current_lane_change_information_, getLaneChangeInformation(), isManeuverPlanValid(), latest_maneuver_plan_, latest_pose_, received_maneuver_plan_, upcoming_lane_change_information_, updateManeuverParameters(), and wm_.

Referenced by handle_on_configure().

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

◆ onTrajPlanTick()

void plan_delegator::PlanDelegator::onTrajPlanTick ( )
private

Callback function for triggering trajectory planning.

Definition at line 726 of file plan_delegator.cpp.

727 {
728 // Guidance not engaged or haven't received a maneuver plan yet
730 {
731 return;
732 }
733 carma_planning_msgs::msg::TrajectoryPlan trajectory_plan = planTrajectory();
734
735 // Check if planned trajectory is valid before send out
736 if(isTrajectoryValid(trajectory_plan))
737 {
738 trajectory_plan.header.stamp = get_clock()->now();
739 last_successful_traj_ = trajectory_plan;
740 traj_pub_->publish(trajectory_plan);
742 }
743 else
744 {
746 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"),
747 "Guidance is engaged, but new planned trajectory has less than 2 points. " <<
748 "It will not be published! Consecutive failure count: "
750
751 // Case where traj generation fails after a successful one
752 if (last_successful_traj_.has_value()
755 {
756 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"),
757 "Instead, last available trajectory is published with outdated timestamp of:"
759 rclcpp::Time(last_successful_traj_.value().header.stamp).seconds()));
760 traj_pub_->publish(last_successful_traj_.value());
761 }
762 // Case where traj generation fails from the beginning.
763 // Attempt replanning for configured number of tries before throwing runtime error.
764 else if (!last_successful_traj_.has_value() &&
766 {
767 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"),
768 "Instead, tried publishing last available trajectory, but it's not available!");
769 }
770 else
771 {
772 RCLCPP_ERROR_STREAM(rclcpp::get_logger("plan_delegator"),
773 "No valid trajectory is available to publish! "
774 "Please check the planner plugins and their configurations.");
775 throw std::runtime_error("No valid trajectory is available to publish!");
776 }
777 }
778 }
carma_planning_msgs::msg::TrajectoryPlan planTrajectory()
Plan trajectory based on latest maneuver plan via ROS service call to plugins.
bool isTrajectoryValid(const carma_planning_msgs::msg::TrajectoryPlan &trajectory_plan) const noexcept
Example if a trajectory plan contains at least two trajectory points.
std::optional< carma_planning_msgs::msg::TrajectoryPlan > last_successful_traj_

References config_, consecutive_traj_gen_failure_num_, guidance_engaged, isTrajectoryValid(), last_successful_traj_, plan_delegator::Config::max_traj_generation_reattempt, planTrajectory(), received_maneuver_plan_, carma_cooperative_perception::to_string(), and traj_pub_.

Referenced by handle_on_activate().

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

◆ planTrajectory()

carma_planning_msgs::msg::TrajectoryPlan plan_delegator::PlanDelegator::planTrajectory ( )
private

Plan trajectory based on latest maneuver plan via ROS service call to plugins.

Returns
a TrajectoryPlan object which contains PlanTrajectory response from plugins

Definition at line 599 of file plan_delegator.cpp.

600 {
601 carma_planning_msgs::msg::TrajectoryPlan latest_trajectory_plan;
602 bool full_plan_generation_failed = false;
604 {
605 RCLCPP_INFO_STREAM(rclcpp::get_logger("plan_delegator"),"Guidance is not engaged. Plan delegator will not plan trajectory.");
606 return latest_trajectory_plan;
607 }
608 // latest_maneuver_plan may get updated, so local copy to avoid race condition
609 auto locked_maneuver_plan = latest_maneuver_plan_;
610
611 // Flag for the first received trajectory plan service response
612 bool first_trajectory_plan = true;
613
614 // Track the index of the starting maneuver in the maneuver plan that this trajectory plan service request is for
615 uint16_t current_maneuver_index = 0;
616
617 // Loop through maneuver list to make service call to applicable Tactical Plugin
618 while(current_maneuver_index < locked_maneuver_plan.maneuvers.size())
619 {
620 auto& maneuver = locked_maneuver_plan.maneuvers[current_maneuver_index];
621
622 // ignore expired maneuvers
623 if(isManeuverExpired(maneuver, get_clock()->now()))
624 {
625 RCLCPP_INFO_STREAM(rclcpp::get_logger("plan_delegator"),"Dropping expired maneuver: " << GET_MANEUVER_PROPERTY(maneuver, parameters.maneuver_id));
626 // Update the maneuver plan index for the next loop
627 ++current_maneuver_index;
628 continue;
629 }
630 lanelet::BasicPoint2d current_loc(latest_pose_.pose.position.x, latest_pose_.pose.position.y);
631 double current_downtrack = wm_->routeTrackPos(current_loc).downtrack;
632 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"current_downtrack" << current_downtrack);
633 double maneuver_end_dist = GET_MANEUVER_PROPERTY(maneuver, end_dist);
634 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"maneuver_end_dist" << maneuver_end_dist);
635
636 // ignore maneuver that is passed.
637 if (current_downtrack > maneuver_end_dist)
638 {
639 RCLCPP_INFO_STREAM(rclcpp::get_logger("plan_delegator"),"Dropping passed maneuver: " << GET_MANEUVER_PROPERTY(maneuver, parameters.maneuver_id));
640 // Update the maneuver plan index for the next loop
641 ++current_maneuver_index;
642 continue;
643 }
644
645 // get corresponding ros service client for plan trajectory
646 auto maneuver_planner = GET_MANEUVER_PROPERTY(maneuver, parameters.planning_tactical_plugin);
647
648 auto client = getPlannerClientByName(maneuver_planner);
649
650 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"Current planner: " << maneuver_planner);
651
652 // compose service request
653 auto plan_req = composePlanTrajectoryRequest(
654 latest_trajectory_plan, locked_maneuver_plan, current_maneuver_index);
655
656 auto future_response = client->async_send_request(plan_req);
657
658 auto future_status = future_response.wait_for(std::chrono::milliseconds(config_.tactical_plugin_service_call_timeout));
659
660 if (future_status != std::future_status::ready)
661 {
662 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"),"Unsuccessful service call to trajectory planner:" << maneuver_planner << " for plan ID " << std::string(locked_maneuver_plan.maneuver_plan_id));
663 // if one service call fails, it should end plan immediately because it is there is no point to generate plan with empty space
664 full_plan_generation_failed = true;
665 break;
666 }
667
668 // If successful service request
669 auto plan_response = future_response.get();
670 // validate trajectory before add to the plan
671 if(!isTrajectoryValid(plan_response->trajectory_plan))
672 {
673 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"),
674 "Found invalid trajectory with less than 2 trajectory "
675 << "points for maneuver_plan_id: "
676 << std::string(locked_maneuver_plan.maneuver_plan_id));
677 full_plan_generation_failed = true;
678 break;
679 }
680 //Remove duplicate point from start of trajectory
681 if(latest_trajectory_plan.trajectory_points.size() != 0 &&
682 latest_trajectory_plan.trajectory_points.back().target_time == plan_response->trajectory_plan.trajectory_points.front().target_time)
683 {
684 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"Removing duplicate point for planner: " << maneuver_planner);
685 plan_response->trajectory_plan.trajectory_points.erase(plan_response->trajectory_plan.trajectory_points.begin());
686 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"plan_response->trajectory_plan size: " << plan_response->trajectory_plan.trajectory_points.size());
687 }
688 latest_trajectory_plan.trajectory_points.insert(latest_trajectory_plan.trajectory_points.end(),
689 plan_response->trajectory_plan.trajectory_points.begin(),
690 plan_response->trajectory_plan.trajectory_points.end());
691 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"new latest_trajectory_plan size: " << latest_trajectory_plan.trajectory_points.size());
692
693 // Assign the trajectory plan's initial longitudinal velocity based on the first tactical plugin's response
694 if(first_trajectory_plan == true)
695 {
696 latest_trajectory_plan.initial_longitudinal_velocity = plan_response->trajectory_plan.initial_longitudinal_velocity;
697 first_trajectory_plan = false;
698 }
699
700 if(isTrajectoryLongEnough(latest_trajectory_plan))
701 {
702 RCLCPP_INFO_STREAM(rclcpp::get_logger("plan_delegator"),"Plan Trajectory completed for " << std::string(locked_maneuver_plan.maneuver_plan_id));
703 break;
704 }
705
706 // Update the maneuver plan index based on the last maneuver index converted to a trajectory
707 // This is required since inlanecruising_plugin can plan a trajectory over contiguous LANE_FOLLOWING maneuvers
708 if(plan_response->related_maneuvers.size() > 0)
709 {
710 current_maneuver_index = plan_response->related_maneuvers.back() + 1;
711 }
712 }
713
714 if (full_plan_generation_failed)
715 {
716 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"),
717 "Plan_delegator's current run wasn't fully able to generate trajectory!");
718
719 carma_planning_msgs::msg::TrajectoryPlan empty_plan;
720 return empty_plan;
721 }
722
723 return latest_trajectory_plan;
724 }
carma_ros2_utils::ClientPtr< carma_planning_msgs::srv::PlanTrajectory > getPlannerClientByName(const std::string &planner_name)
Get PlanTrajectory service client by plugin name and create new PlanTrajectory service client if spec...
std::shared_ptr< carma_planning_msgs::srv::PlanTrajectory::Request > composePlanTrajectoryRequest(const carma_planning_msgs::msg::TrajectoryPlan &latest_trajectory_plan, const carma_planning_msgs::msg::ManeuverPlan &locked_maneuver_plan, const uint16_t &current_maneuver_index) const
Generate new PlanTrajecory service request based on current planning progress.
bool isManeuverExpired(const carma_planning_msgs::msg::Maneuver &maneuver, rclcpp::Time current_time) const
Example if a maneuver end time has passed current system time.
bool isTrajectoryLongEnough(const carma_planning_msgs::msg::TrajectoryPlan &plan) const noexcept
Example if a trajectory plan is longer than configured time thresheld.

References composePlanTrajectoryRequest(), config_, GET_MANEUVER_PROPERTY, getPlannerClientByName(), guidance_engaged, isManeuverExpired(), isTrajectoryLongEnough(), isTrajectoryValid(), latest_maneuver_plan_, latest_pose_, plan_delegator::Config::tactical_plugin_service_call_timeout, and wm_.

Referenced by onTrajPlanTick().

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

◆ poseCallback()

void plan_delegator::PlanDelegator::poseCallback ( geometry_msgs::msg::PoseStamped::UniquePtr  pose_msg)

Callback function for vehicle pose subscriber. Updates latest_pose_ and makes calls to publishUpcomingLaneChangeStatus() and publishTurnSignalCommand().

Parameters
pose_msgThe received pose message.

Definition at line 247 of file plan_delegator.cpp.

248 {
249 latest_pose_ = *pose_msg;
250
251 // Publish the upcoming lane change status
253
254 // Publish the current turn signal command
256 }
carma_planning_msgs::msg::UpcomingLaneChangeStatus upcoming_lane_change_status_
void publishTurnSignalCommand(const boost::optional< LaneChangeInformation > &current_lane_change_information, const carma_planning_msgs::msg::UpcomingLaneChangeStatus &upcoming_lane_change_status)
Function for processing an optional LaneChangeInformation object pertaining to the currently-occurrin...
void publishUpcomingLaneChangeStatus(const boost::optional< LaneChangeInformation > &upcoming_lane_change_information)
Function for processing an optional LaneChangeInformation object pertaining to an upcoming lane chang...

References current_lane_change_information_, latest_pose_, publishTurnSignalCommand(), publishUpcomingLaneChangeStatus(), upcoming_lane_change_information_, and upcoming_lane_change_status_.

Referenced by handle_on_configure().

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

◆ publishTurnSignalCommand()

void plan_delegator::PlanDelegator::publishTurnSignalCommand ( const boost::optional< LaneChangeInformation > &  current_lane_change_information,
const carma_planning_msgs::msg::UpcomingLaneChangeStatus &  upcoming_lane_change_status 
)
private

Function for processing an optional LaneChangeInformation object pertaining to the currently-occurring lane change and an UpcomingLaneChangeStatus message. If the optional object pertaining to the currently-occurring lane change is not empty, then a turn signal command is published based on the current lane change direction. Otherwise, a turn signal command in the direction of the UpcomingLaneChangeStatus message is published if the vehicle is estimated to begin that lane change in under the time threshold defined by config_.duration_to_signal_before_lane_change. The published TurnSignalComand message is stored in latest_turn_signal_command_.

Parameters
current_lane_change_informationAn optional LaneChangeInformation object pertaining to the current lane change. Empty if vehicle is not currently changing lanes.
upcoming_lane_change_statusAn UpcomingLaneChangeStatus message containing the lane change direction of an upcoming lane change, along with the downtrack distance to that lane change.

Definition at line 340 of file plan_delegator.cpp.

341 {
342 // Initialize turn signal command message
343 // NOTE: A LampCmd message can have its 'r' OR 'l' field set to 1 to indicate an activated right or left turn signal, respectively. Both fields cannot be set to 1 at the same time.
344 autoware_msgs::msg::LampCmd turn_signal_command;
345
346 // Publish turn signal command with priority placed on the current lane change, if one exists
347 if(current_lane_change_information){
348 // Publish turn signal command for the current lane change based on the lane change direction
349 if(current_lane_change_information.get().is_right_lane_change){
350 turn_signal_command.r = 1;
351 }
352 else{
353 turn_signal_command.l = 1;
354 }
355 turn_signal_command_pub_->publish(turn_signal_command);
356 }
357 else if(upcoming_lane_change_status.lane_change != carma_planning_msgs::msg::UpcomingLaneChangeStatus::NONE){
358 // Only publish turn signal command for upcoming lane change if it will begin in less than the time defined by config_.duration_to_signal_before_lane_change
359 if((upcoming_lane_change_status.downtrack_until_lanechange / latest_twist_.twist.linear.x) <= config_.duration_to_signal_before_lane_change){
360 if(upcoming_lane_change_status.lane_change == carma_planning_msgs::msg::UpcomingLaneChangeStatus::RIGHT){
361 turn_signal_command.r = 1;
362 }
363 else{
364 turn_signal_command.l = 1;
365 }
366 turn_signal_command_pub_->publish(turn_signal_command);
367 }
368 }
369 else{
370 // Publish turn signal command with neither turn signal activated
371 turn_signal_command_pub_->publish(turn_signal_command);
372 }
373
374 // Store turn signal command in latest_turn_signal_command_
375 latest_turn_signal_command_ = turn_signal_command;
376 }
autoware_msgs::msg::LampCmd latest_turn_signal_command_

References config_, plan_delegator::Config::duration_to_signal_before_lane_change, latest_turn_signal_command_, latest_twist_, and turn_signal_command_pub_.

Referenced by poseCallback().

Here is the caller graph for this function:

◆ publishUpcomingLaneChangeStatus()

void plan_delegator::PlanDelegator::publishUpcomingLaneChangeStatus ( const boost::optional< LaneChangeInformation > &  upcoming_lane_change_information)
private

Function for processing an optional LaneChangeInformation object pertaining to an upcoming lane change. If not empty, an UpcomingLaneChangeStatus message is created and published based on the contents of the LaneChangeInformation. The published UpcomingLaneChangeStatus message is stored in upcoming_lane_change_status_.

Parameters
upcoming_lane_change_informationAn optional LaneChangeInformation object. Empty if no upcoming lane change exists.

Definition at line 310 of file plan_delegator.cpp.

310 {
311 // Initialize an UpcomingLaneChangeStatus message, which will be populated based on upcoming_lane_change_information
312 carma_planning_msgs::msg::UpcomingLaneChangeStatus upcoming_lane_change_status;
313
314 // Update upcoming_lane_change_status
315 if(upcoming_lane_change_information){
316 // Get the downtrack distance between the ego vehicle and the start of the upcoming lane change maneuver
317 lanelet::BasicPoint2d current_loc(latest_pose_.pose.position.x, latest_pose_.pose.position.y);
318 double current_downtrack = wm_->routeTrackPos(current_loc).downtrack;
319 upcoming_lane_change_status.downtrack_until_lanechange = std::max(0.0, upcoming_lane_change_information.get().starting_downtrack - current_downtrack);
320
321 // Set upcoming lane change status as a right lane change or left lane change
322 if(upcoming_lane_change_information.get().is_right_lane_change){
323 upcoming_lane_change_status.lane_change = carma_planning_msgs::msg::UpcomingLaneChangeStatus::RIGHT;
324 }
325 else{
326 upcoming_lane_change_status.lane_change = carma_planning_msgs::msg::UpcomingLaneChangeStatus::LEFT;
327 }
328 }
329 else{
330 upcoming_lane_change_status.lane_change = carma_planning_msgs::msg::UpcomingLaneChangeStatus::NONE;
331 }
332
333 // Publish upcoming_lane_change_status
334 upcoming_lane_change_status_pub_->publish(upcoming_lane_change_status);
335
336 // Store UpcomingLaneChangeStatus in upcoming_lane_change_status_
337 upcoming_lane_change_status_ = upcoming_lane_change_status;
338 }

References latest_pose_, upcoming_lane_change_status_, upcoming_lane_change_status_pub_, and wm_.

Referenced by poseCallback().

Here is the caller graph for this function:

◆ updateManeuverParameters()

void plan_delegator::PlanDelegator::updateManeuverParameters ( carma_planning_msgs::msg::Maneuver &  maneuver)

Update the starting downtrack, ending downtrack, and maneuver-specific Lanelet ID parameters associated with a given maneuver. These updates are required since the starting and ending downtrack values of each maneuver are shifted based on the distance between the base_link frame and the vehicle_front frame.

Parameters
maneuverThe maneuver to be updated.

Definition at line 468 of file plan_delegator.cpp.

469 {
470 if (!wm_->getMap())
471 {
472 RCLCPP_ERROR_STREAM(rclcpp::get_logger("plan_delegator"), "Map is not set yet");
473 return;
474 }
475
476 // Update maneuver starting and ending downtrack distances
477 double original_start_dist = GET_MANEUVER_PROPERTY(maneuver, start_dist);
478 double original_end_dist = GET_MANEUVER_PROPERTY(maneuver, end_dist);
479 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"Changing maneuver distances for planner: " << GET_MANEUVER_PROPERTY(maneuver, parameters.planning_tactical_plugin));
480 double adjusted_start_dist = original_start_dist - length_to_front_bumper_;
481 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"original_start_dist:" << original_start_dist);
482 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"adjusted_start_dist:" << adjusted_start_dist);
483 double adjusted_end_dist = original_end_dist - length_to_front_bumper_;
484 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"original_end_dist:" << original_end_dist);
485 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"adjusted_end_dist:" << adjusted_end_dist);
486 SET_MANEUVER_PROPERTY(maneuver, start_dist, adjusted_start_dist);
487 SET_MANEUVER_PROPERTY(maneuver, end_dist, adjusted_end_dist);
488
489 // Shift maneuver starting and ending lanelets
490 // NOTE: Assumes that maneuver start and end downtrack distances have not been shifted by more than one lanelet
491 if(maneuver.type == carma_planning_msgs::msg::Maneuver::LANE_FOLLOWING && !maneuver.lane_following_maneuver.lane_ids.empty()){
492 // (1) Add new beginning lanelet to maneuver if necessary and (2) remove ending lanelet from maneuver if necessary
493
494 // Obtain the original starting lanelet from the maneuver
495 lanelet::Id original_starting_lanelet_id = std::stoi(maneuver.lane_following_maneuver.lane_ids.front());
496 lanelet::ConstLanelet original_starting_lanelet = wm_->getMap()->laneletLayer.get(original_starting_lanelet_id);
497
498 // Get the downtrack of the start of the original starting lanelet
499 lanelet::BasicPoint2d original_starting_lanelet_centerline_start_point = lanelet::utils::to2D(original_starting_lanelet.centerline()).front();
500 double original_starting_lanelet_centerline_start_point_dt = wm_->routeTrackPos(original_starting_lanelet_centerline_start_point).downtrack;
501
502 if(adjusted_start_dist < original_starting_lanelet_centerline_start_point_dt){
503
504 auto previous_lanelets = wm_->getMapRoutingGraph()->previous(original_starting_lanelet, false);
505
506 if(!previous_lanelets.empty()){
507
508 auto llt_on_route_optional = wm_->getFirstLaneletOnShortestPath(previous_lanelets);
509
510 lanelet::ConstLanelet previous_lanelet_to_add;
511
512 if (llt_on_route_optional){
513 previous_lanelet_to_add = llt_on_route_optional.value();
514 }
515 else{
516 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"), "When adjusting maneuver for lane follow, no previous lanelet found on the shortest path for lanelet "
517 << original_starting_lanelet.id() << ". Picking arbitrary lanelet: " << previous_lanelets[0].id() << ", instead");
518 previous_lanelet_to_add = previous_lanelets[0];
519 }
520
521 // lane_ids array is ordered by increasing downtrack, so this new starting lanelet is inserted at the front
522 maneuver.lane_following_maneuver.lane_ids.insert(maneuver.lane_following_maneuver.lane_ids.begin(), std::to_string(previous_lanelet_to_add.id()));
523
524 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"), "Inserted lanelet " << std::to_string(previous_lanelet_to_add.id()) << " to beginning of maneuver.");
525 }
526 else{
527 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"), "No previous lanelet was found for lanelet " << original_starting_lanelet.id());
528 }
529 }
530
531 // Obtain the maneuver ending lanelet
532 lanelet::Id original_ending_lanelet_id = std::stoi(maneuver.lane_following_maneuver.lane_ids.back());
533 lanelet::ConstLanelet original_ending_lanelet = wm_->getMap()->laneletLayer.get(original_ending_lanelet_id);
534
535 // Get the downtrack of the start of the maneuver ending lanelet
536 lanelet::BasicPoint2d original_ending_lanelet_centerline_start_point = lanelet::utils::to2D(original_ending_lanelet.centerline()).front();
537 double original_ending_lanelet_centerline_start_point_dt = wm_->routeTrackPos(original_ending_lanelet_centerline_start_point).downtrack;
538
539 if(adjusted_end_dist < original_ending_lanelet_centerline_start_point_dt){
540 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("plan_delegator"),"Original ending lanelet " << original_ending_lanelet.id() << " removed from lane_ids since the updated maneuver no longer crosses it");
541
542 // lane_ids array is ordered by increasing downtrack, so the last element in the array corresponds to the original ending lanelet
543 maneuver.lane_following_maneuver.lane_ids.pop_back();
544 }
545 }
546 else if (maneuver.type != carma_planning_msgs::msg::Maneuver::LANE_FOLLOWING){
547 // (1) Update starting maneuver lanelet if necessary and (2) Update ending maneuver lanelet if necessary
548
549 // Obtain the original starting lanelet from the maneuver
550 lanelet::Id original_starting_lanelet_id = std::stoi(getManeuverStartingLaneletId(maneuver));
551 lanelet::ConstLanelet original_starting_lanelet = wm_->getMap()->laneletLayer.get(original_starting_lanelet_id);
552
553 // Get the downtrack of the start of the lanelet
554 lanelet::BasicPoint2d original_starting_lanelet_centerline_start_point = lanelet::utils::to2D(original_starting_lanelet.centerline()).front();
555 double original_starting_lanelet_centerline_start_point_dt = wm_->routeTrackPos(original_starting_lanelet_centerline_start_point).downtrack;
556
557 if(adjusted_start_dist < original_starting_lanelet_centerline_start_point_dt){
558 auto previous_lanelets = wm_->getMapRoutingGraph()->previous(original_starting_lanelet, false);
559 if(!previous_lanelets.empty()){
560 auto llt_on_route_optional = wm_->getFirstLaneletOnShortestPath(previous_lanelets);
561 lanelet::ConstLanelet previous_lanelet_to_add;
562
563 if (llt_on_route_optional){
564 previous_lanelet_to_add = llt_on_route_optional.value();
565 }
566 else{
567 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"), "When adjusting non-lane follow maneuver, no previous lanelet found on the shortest path for lanelet "
568 << original_starting_lanelet.id() << ". Picking arbitrary lanelet: " << previous_lanelets[0].id() << ", instead");
569 previous_lanelet_to_add = previous_lanelets[0];
570 }
571 setManeuverStartingLaneletId(maneuver, previous_lanelet_to_add.id());
572 }
573 else{
574 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"), "No previous lanelet was found for lanelet " << original_starting_lanelet.id());
575 }
576 }
577
578 // Obtain the original ending lanelet from the maneuver
579 lanelet::Id original_ending_lanelet_id = std::stoi(getManeuverEndingLaneletId(maneuver));
580 lanelet::ConstLanelet original_ending_lanelet = wm_->getMap()->laneletLayer.get(original_ending_lanelet_id);
581
582 // Get the downtrack of the start of the ending lanelet
583 lanelet::BasicPoint2d original_ending_lanelet_centerline_start_point = lanelet::utils::to2D(original_ending_lanelet.centerline()).front();
584 double original_ending_lanelet_centerline_start_point_dt = wm_->routeTrackPos(original_ending_lanelet_centerline_start_point).downtrack;
585
586 if(adjusted_end_dist < original_ending_lanelet_centerline_start_point_dt){
587 auto previous_lanelets = wm_->getMapRoutingGraph()->previous(original_ending_lanelet, false);
588
589 if(!previous_lanelets.empty()){
590 setManeuverEndingLaneletId(maneuver, previous_lanelets[0].id());
591 }
592 else{
593 RCLCPP_WARN_STREAM(rclcpp::get_logger("plan_delegator"), "No previous lanelet was found for lanelet " << original_starting_lanelet.id());
594 }
595 }
596 }
597 }
std::string getManeuverEndingLaneletId(carma_planning_msgs::msg::Maneuver mvr)
Anonymous function to get the ending lanelet id for all maneuver types except lane following....
void setManeuverEndingLaneletId(carma_planning_msgs::msg::Maneuver &mvr, lanelet::Id end_id)
Anonymous function to set the ending_lane_id for all maneuver types except lane following....
std::string getManeuverStartingLaneletId(carma_planning_msgs::msg::Maneuver mvr)
Anonymous function to get the starting lanelet id for all maneuver types except lane following....
void setManeuverStartingLaneletId(carma_planning_msgs::msg::Maneuver &mvr, lanelet::Id start_id)
Anonymous function to set the starting_lane_id for all maneuver types except lane following....
#define SET_MANEUVER_PROPERTY(mvr, property, value)

References GET_MANEUVER_PROPERTY, plan_delegator::anonymous_namespace{plan_delegator.cpp}::getManeuverEndingLaneletId(), plan_delegator::anonymous_namespace{plan_delegator.cpp}::getManeuverStartingLaneletId(), length_to_front_bumper_, SET_MANEUVER_PROPERTY, plan_delegator::anonymous_namespace{plan_delegator.cpp}::setManeuverEndingLaneletId(), plan_delegator::anonymous_namespace{plan_delegator.cpp}::setManeuverStartingLaneletId(), carma_cooperative_perception::to_string(), and wm_.

Referenced by maneuverPlanCallback().

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

Member Data Documentation

◆ config_

Config plan_delegator::PlanDelegator::config_
protected

◆ consecutive_traj_gen_failure_num_

int plan_delegator::PlanDelegator::consecutive_traj_gen_failure_num_ = 0
private

Definition at line 220 of file plan_delegator.hpp.

Referenced by onTrajPlanTick().

◆ current_lane_change_information_

boost::optional<LaneChangeInformation> plan_delegator::PlanDelegator::current_lane_change_information_
private

Definition at line 232 of file plan_delegator.hpp.

Referenced by maneuverPlanCallback(), and poseCallback().

◆ guidance_engaged

bool plan_delegator::PlanDelegator::guidance_engaged = false
private

Definition at line 219 of file plan_delegator.hpp.

Referenced by guidanceStateCallback(), onTrajPlanTick(), and planTrajectory().

◆ guidance_state_sub_

carma_ros2_utils::SubPtr<carma_planning_msgs::msg::GuidanceState> plan_delegator::PlanDelegator::guidance_state_sub_
private

Definition at line 213 of file plan_delegator.hpp.

Referenced by handle_on_configure().

◆ last_successful_traj_

std::optional<carma_planning_msgs::msg::TrajectoryPlan> plan_delegator::PlanDelegator::last_successful_traj_
private

Definition at line 204 of file plan_delegator.hpp.

Referenced by onTrajPlanTick().

◆ latest_maneuver_plan_

carma_planning_msgs::msg::ManeuverPlan plan_delegator::PlanDelegator::latest_maneuver_plan_
protected

Definition at line 193 of file plan_delegator.hpp.

Referenced by maneuverPlanCallback(), and planTrajectory().

◆ latest_pose_

geometry_msgs::msg::PoseStamped plan_delegator::PlanDelegator::latest_pose_
protected

◆ latest_turn_signal_command_

autoware_msgs::msg::LampCmd plan_delegator::PlanDelegator::latest_turn_signal_command_
private

Definition at line 238 of file plan_delegator.hpp.

Referenced by publishTurnSignalCommand().

◆ latest_twist_

geometry_msgs::msg::TwistStamped plan_delegator::PlanDelegator::latest_twist_
protected

◆ length_to_front_bumper_

double plan_delegator::PlanDelegator::length_to_front_bumper_ = 3.0
private

Definition at line 222 of file plan_delegator.hpp.

Referenced by lookupFrontBumperTransform(), and updateManeuverParameters().

◆ MILLISECOND_TO_SECOND

const constexpr double plan_delegator::PlanDelegator::MILLISECOND_TO_SECOND = 0.001
staticconstexpr

Definition at line 115 of file plan_delegator.hpp.

◆ plan_sub_

carma_ros2_utils::SubPtr<carma_planning_msgs::msg::ManeuverPlan> plan_delegator::PlanDelegator::plan_sub_
private

Definition at line 210 of file plan_delegator.hpp.

Referenced by handle_on_configure().

◆ pose_sub_

carma_ros2_utils::SubPtr<geometry_msgs::msg::PoseStamped> plan_delegator::PlanDelegator::pose_sub_
private

Definition at line 211 of file plan_delegator.hpp.

Referenced by handle_on_configure().

◆ received_maneuver_plan_

bool plan_delegator::PlanDelegator::received_maneuver_plan_ = false
protected

Definition at line 194 of file plan_delegator.hpp.

Referenced by maneuverPlanCallback(), and onTrajPlanTick().

◆ tf2_buffer_

std::shared_ptr<tf2_ros::Buffer> plan_delegator::PlanDelegator::tf2_buffer_
private

Definition at line 225 of file plan_delegator.hpp.

Referenced by lookupFrontBumperTransform().

◆ tf2_listener_

std::shared_ptr<tf2_ros::TransformListener> plan_delegator::PlanDelegator::tf2_listener_
private

Definition at line 226 of file plan_delegator.hpp.

Referenced by lookupFrontBumperTransform().

◆ timer_callback_group_

rclcpp::CallbackGroup::SharedPtr plan_delegator::PlanDelegator::timer_callback_group_
private

Definition at line 217 of file plan_delegator.hpp.

Referenced by handle_on_activate().

◆ traj_pub_

carma_ros2_utils::PubPtr<carma_planning_msgs::msg::TrajectoryPlan> plan_delegator::PlanDelegator::traj_pub_
private

Definition at line 205 of file plan_delegator.hpp.

Referenced by handle_on_configure(), and onTrajPlanTick().

◆ traj_timer_

rclcpp::TimerBase::SharedPtr plan_delegator::PlanDelegator::traj_timer_
private

Definition at line 215 of file plan_delegator.hpp.

Referenced by handle_on_activate().

◆ trajectory_planners_

std::unordered_map<std::string, carma_ros2_utils::ClientPtr<carma_planning_msgs::srv::PlanTrajectory> > plan_delegator::PlanDelegator::trajectory_planners_
protected

Definition at line 191 of file plan_delegator.hpp.

Referenced by getPlannerClientByName().

◆ turn_signal_command_pub_

carma_ros2_utils::PubPtr<autoware_msgs::msg::LampCmd> plan_delegator::PlanDelegator::turn_signal_command_pub_
private

Definition at line 207 of file plan_delegator.hpp.

Referenced by handle_on_configure(), and publishTurnSignalCommand().

◆ twist_sub_

carma_ros2_utils::SubPtr<geometry_msgs::msg::TwistStamped> plan_delegator::PlanDelegator::twist_sub_
private

Definition at line 212 of file plan_delegator.hpp.

Referenced by handle_on_configure().

◆ upcoming_lane_change_information_

boost::optional<LaneChangeInformation> plan_delegator::PlanDelegator::upcoming_lane_change_information_
private

Definition at line 229 of file plan_delegator.hpp.

Referenced by maneuverPlanCallback(), and poseCallback().

◆ upcoming_lane_change_status_

carma_planning_msgs::msg::UpcomingLaneChangeStatus plan_delegator::PlanDelegator::upcoming_lane_change_status_
private

Definition at line 235 of file plan_delegator.hpp.

Referenced by poseCallback(), and publishUpcomingLaneChangeStatus().

◆ upcoming_lane_change_status_pub_

carma_ros2_utils::PubPtr<carma_planning_msgs::msg::UpcomingLaneChangeStatus> plan_delegator::PlanDelegator::upcoming_lane_change_status_pub_
private

Definition at line 206 of file plan_delegator.hpp.

Referenced by handle_on_configure(), and publishUpcomingLaneChangeStatus().

◆ wm_

◆ wml_

carma_wm::WMListener plan_delegator::PlanDelegator::wml_
protected

Definition at line 199 of file plan_delegator.hpp.

Referenced by handle_on_configure().


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