Skip to content

Commit 071333e

Browse files
feat(lane_change): use external velocity limit in safety check (autowarefoundation#6760)
* feat(lane_change): use external velocity limit in safety check Signed-off-by: Muhammad Zulfaqar <zulfaqar.azmi@tier4.jp> * style(pre-commit): autofix * Minor refactoring Signed-off-by: Muhammad Zulfaqar <zulfaqar.azmi@tier4.jp> * Fix spell check and remove headers Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> * Add warning Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> --------- Signed-off-by: Muhammad Zulfaqar <zulfaqar.azmi@tier4.jp> Signed-off-by: Muhammad Zulfaqar Azmi <zulfaqar.azmi@tier4.jp> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 712ab11 commit 071333e

File tree

7 files changed

+48
-6
lines changed

7 files changed

+48
-6
lines changed

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/scene.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ class NormalLaneChange : public LaneChangeBase
170170
bool isVehicleStuck(
171171
const lanelet::ConstLanelets & current_lanes, const double obstacle_check_distance) const;
172172

173+
double get_max_velocity_for_safety_check() const;
174+
173175
bool isVehicleStuck(const lanelet::ConstLanelets & current_lanes) const;
174176

175177
bool check_prepare_phase() const;

planning/behavior_path_lane_change_module/src/scene.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ PathSafetyStatus NormalLaneChange::isLaneChangePathSafe(
19761976
for (const auto & obj_path : obj_predicted_paths) {
19771977
const auto collided_polygons = utils::path_safety_checker::getCollidedPolygons(
19781978
path, ego_predicted_path, obj, obj_path, common_parameters, rss_params, 1.0,
1979-
current_debug_data.second);
1979+
get_max_velocity_for_safety_check(), current_debug_data.second);
19801980

19811981
if (collided_polygons.empty()) {
19821982
utils::path_safety_checker::updateCollisionCheckDebugMap(
@@ -2071,6 +2071,17 @@ bool NormalLaneChange::isVehicleStuck(
20712071
return false;
20722072
}
20732073

2074+
double NormalLaneChange::get_max_velocity_for_safety_check() const
2075+
{
2076+
const auto external_velocity_limit_ptr = planner_data_->external_limit_max_velocity;
2077+
if (external_velocity_limit_ptr) {
2078+
return std::min(
2079+
static_cast<double>(external_velocity_limit_ptr->max_velocity), getCommonParam().max_vel);
2080+
}
2081+
2082+
return getCommonParam().max_vel;
2083+
}
2084+
20742085
bool NormalLaneChange::isVehicleStuck(const lanelet::ConstLanelets & current_lanes) const
20752086
{
20762087
if (current_lanes.empty()) {

planning/behavior_path_planner/include/behavior_path_planner/behavior_path_planner_node.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <tier4_planning_msgs/msg/reroute_availability.hpp>
3939
#include <tier4_planning_msgs/msg/scenario.hpp>
4040
#include <tier4_planning_msgs/msg/stop_reason_array.hpp>
41+
#include <tier4_planning_msgs/msg/velocity_limit.hpp>
4142
#include <visualization_msgs/msg/marker.hpp>
4243

4344
#include <map>
@@ -101,6 +102,8 @@ class BehaviorPathPlannerNode : public rclcpp::Node
101102
rclcpp::Publisher<PoseWithUuidStamped>::SharedPtr modified_goal_publisher_;
102103
rclcpp::Publisher<StopReasonArray>::SharedPtr stop_reason_publisher_;
103104
rclcpp::Publisher<RerouteAvailability>::SharedPtr reroute_availability_publisher_;
105+
rclcpp::Subscription<tier4_planning_msgs::msg::VelocityLimit>::SharedPtr
106+
external_limit_max_velocity_subscriber_;
104107
rclcpp::TimerBase::SharedPtr timer_;
105108

106109
std::map<std::string, rclcpp::Publisher<Path>::SharedPtr> path_candidate_publishers_;
@@ -140,6 +143,9 @@ class BehaviorPathPlannerNode : public rclcpp::Node
140143
void onRoute(const LaneletRoute::ConstSharedPtr route_msg);
141144
void onOperationMode(const OperationModeState::ConstSharedPtr msg);
142145
void onLateralOffset(const LateralOffset::ConstSharedPtr msg);
146+
void on_external_velocity_limiter(
147+
const tier4_planning_msgs::msg::VelocityLimit::ConstSharedPtr msg);
148+
143149
SetParametersResult onSetParam(const std::vector<rclcpp::Parameter> & parameters);
144150

145151
OnSetParametersCallbackHandle::SharedPtr m_set_param_res;

planning/behavior_path_planner/src/behavior_path_planner_node.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ BehaviorPathPlannerNode::BehaviorPathPlannerNode(const rclcpp::NodeOptions & nod
112112
current_scenario_ = std::make_shared<Scenario>(*msg);
113113
},
114114
createSubscriptionOptions(this));
115+
external_limit_max_velocity_subscriber_ =
116+
create_subscription<tier4_planning_msgs::msg::VelocityLimit>(
117+
"/planning/scenario_planning/max_velocity", 1,
118+
std::bind(&BehaviorPathPlannerNode::on_external_velocity_limiter, this, _1),
119+
createSubscriptionOptions(this));
115120

116121
// route_handler
117122
vector_map_subscriber_ = create_subscription<HADMapBin>(
@@ -815,6 +820,19 @@ void BehaviorPathPlannerNode::onOperationMode(const OperationModeState::ConstSha
815820
const std::lock_guard<std::mutex> lock(mutex_pd_);
816821
planner_data_->operation_mode = msg;
817822
}
823+
824+
void BehaviorPathPlannerNode::on_external_velocity_limiter(
825+
const tier4_planning_msgs::msg::VelocityLimit::ConstSharedPtr msg)
826+
{
827+
// Note: Using this parameter during path planning might cause unexpected deceleration or jerk.
828+
// Therefore, do not use it for anything other than safety checks.
829+
if (!msg) {
830+
return;
831+
}
832+
833+
const std::lock_guard<std::mutex> lock(mutex_pd_);
834+
planner_data_->external_limit_max_velocity = msg;
835+
}
818836
void BehaviorPathPlannerNode::onLateralOffset(const LateralOffset::ConstSharedPtr msg)
819837
{
820838
std::lock_guard<std::mutex> lock(mutex_pd_);

planning/behavior_path_planner_common/include/behavior_path_planner_common/data_manager.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <geometry_msgs/msg/pose_stamped.hpp>
3838
#include <nav_msgs/msg/occupancy_grid.hpp>
3939
#include <nav_msgs/msg/odometry.hpp>
40+
#include <tier4_planning_msgs/msg/detail/velocity_limit__struct.hpp>
4041
#include <tier4_planning_msgs/msg/lateral_offset.hpp>
4142

4243
#include <limits>
@@ -64,6 +65,7 @@ using route_handler::RouteHandler;
6465
using tier4_planning_msgs::msg::LateralOffset;
6566
using PlanResult = PathWithLaneId::SharedPtr;
6667
using lanelet::TrafficLight;
68+
using tier4_planning_msgs::msg::VelocityLimit;
6769
using unique_identifier_msgs::msg::UUID;
6870

6971
struct TrafficSignalStamped
@@ -160,6 +162,7 @@ struct PlannerData
160162
std::map<int64_t, TrafficSignalStamped> traffic_light_id_map;
161163
BehaviorPathPlannerParameters parameters{};
162164
drivable_area_expansion::DrivableAreaExpansionParameters drivable_area_expansion_parameters{};
165+
VelocityLimit::ConstSharedPtr external_limit_max_velocity{};
163166

164167
mutable std::vector<geometry_msgs::msg::Pose> drivable_area_expansion_prev_path_poses{};
165168
mutable std::vector<double> drivable_area_expansion_prev_curvatures{};

planning/behavior_path_planner_common/include/behavior_path_planner_common/utils/path_safety_checker/safety_check.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ std::vector<Polygon2d> getCollidedPolygons(
141141
const ExtendedPredictedObject & target_object,
142142
const PredictedPathWithPolygon & target_object_path,
143143
const BehaviorPathPlannerParameters & common_parameters, const RSSparams & rss_parameters,
144-
const double hysteresis_factor, CollisionCheckDebug & debug);
144+
const double hysteresis_factor, const double max_velocity_limit, CollisionCheckDebug & debug);
145145

146146
bool checkPolygonsIntersects(
147147
const std::vector<Polygon2d> & polys_1, const std::vector<Polygon2d> & polys_2);

planning/behavior_path_planner_common/src/utils/path_safety_checker/safety_check.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <boost/geometry/algorithms/union.hpp>
2727
#include <boost/geometry/strategies/strategies.hpp>
2828

29+
#include <limits>
30+
2931
namespace behavior_path_planner::utils::path_safety_checker
3032
{
3133

@@ -478,7 +480,7 @@ bool checkCollision(
478480
{
479481
const auto collided_polygons = getCollidedPolygons(
480482
planned_path, predicted_ego_path, target_object, target_object_path, common_parameters,
481-
rss_parameters, hysteresis_factor, debug);
483+
rss_parameters, hysteresis_factor, std::numeric_limits<double>::max(), debug);
482484
return collided_polygons.empty();
483485
}
484486

@@ -488,7 +490,7 @@ std::vector<Polygon2d> getCollidedPolygons(
488490
const ExtendedPredictedObject & target_object,
489491
const PredictedPathWithPolygon & target_object_path,
490492
const BehaviorPathPlannerParameters & common_parameters, const RSSparams & rss_parameters,
491-
double hysteresis_factor, CollisionCheckDebug & debug)
493+
double hysteresis_factor, const double max_velocity_limit, CollisionCheckDebug & debug)
492494
{
493495
{
494496
debug.ego_predicted_path = predicted_ego_path;
@@ -504,7 +506,7 @@ std::vector<Polygon2d> getCollidedPolygons(
504506
// get object information at current time
505507
const auto & obj_pose = obj_pose_with_poly.pose;
506508
const auto & obj_polygon = obj_pose_with_poly.poly;
507-
const auto & object_velocity = obj_pose_with_poly.velocity;
509+
const auto object_velocity = obj_pose_with_poly.velocity;
508510

509511
// get ego information at current time
510512
// Note: we can create these polygons in advance. However, it can decrease the readability and
@@ -517,7 +519,7 @@ std::vector<Polygon2d> getCollidedPolygons(
517519
}
518520
const auto & ego_pose = interpolated_data->pose;
519521
const auto & ego_polygon = interpolated_data->poly;
520-
const auto & ego_velocity = interpolated_data->velocity;
522+
const auto ego_velocity = std::min(interpolated_data->velocity, max_velocity_limit);
521523

522524
// check overlap
523525
if (boost::geometry::overlaps(ego_polygon, obj_polygon)) {

0 commit comments

Comments
 (0)