Skip to content

Commit fd5827e

Browse files
add abandon function
checkConsistency() is not supported yet Signed-off-by: Yuki Takagi <yuki.takagi@tier4.jp>
1 parent d5e691e commit fd5827e

File tree

4 files changed

+167
-93
lines changed

4 files changed

+167
-93
lines changed

planning/obstacle_cruise_planner/include/obstacle_cruise_planner/common_structs.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,15 @@ struct StopObstacle : public TargetObstacleInterface
113113
{
114114
StopObstacle(
115115
const std::string & arg_uuid, const rclcpp::Time & arg_stamp,
116-
const geometry_msgs::msg::Pose & arg_pose, const Shape & arg_shape,
117-
const double arg_lon_velocity, const double arg_lat_velocity,
116+
const ObjectClassification & object_classification, const geometry_msgs::msg::Pose & arg_pose,
117+
const Shape & arg_shape, const double arg_lon_velocity, const double arg_lat_velocity,
118118
const geometry_msgs::msg::Point arg_collision_point,
119119
const double arg_dist_to_collide_on_decimated_traj)
120120
: TargetObstacleInterface(arg_uuid, arg_stamp, arg_pose, arg_lon_velocity, arg_lat_velocity),
121121
shape(arg_shape),
122122
collision_point(arg_collision_point),
123-
dist_to_collide_on_decimated_traj(arg_dist_to_collide_on_decimated_traj)
123+
dist_to_collide_on_decimated_traj(arg_dist_to_collide_on_decimated_traj),
124+
classification(object_classification)
124125
{
125126
}
126127
Shape shape;
@@ -129,6 +130,7 @@ struct StopObstacle : public TargetObstacleInterface
129130
// calculateMarginFromObstacleOnCurve() and should be removed as it can be
130131
// replaced by ”dist_to_collide_on_decimated_traj”
131132
double dist_to_collide_on_decimated_traj;
133+
ObjectClassification classification;
132134
};
133135

134136
struct CruiseObstacle : public TargetObstacleInterface

planning/obstacle_cruise_planner/include/obstacle_cruise_planner/planner_interface.hpp

+40-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class PlannerInterface
4242
vehicle_info_(vehicle_info),
4343
ego_nearest_param_(ego_nearest_param),
4444
debug_data_ptr_(debug_data_ptr),
45-
slow_down_param_(SlowDownParam(node))
45+
slow_down_param_(SlowDownParam(node)),
46+
stop_param_(StopParam(node, longitudinal_info))
4647
{
4748
stop_reasons_pub_ = node.create_publisher<StopReasonArray>("~/output/stop_reasons", 1);
4849
velocity_factors_pub_ =
@@ -333,6 +334,44 @@ class PlannerInterface
333334
double lpf_gain_dist_to_slow_down;
334335
};
335336
SlowDownParam slow_down_param_;
337+
struct StopParam
338+
{
339+
struct ObstacleSpecificParams
340+
{
341+
double limit_min_acc;
342+
bool abandon_to_stop;
343+
};
344+
const std::unordered_map<uint8_t, std::string> types_maps = {
345+
{ObjectClassification::UNKNOWN, "unknown"}, {ObjectClassification::CAR, "car"},
346+
{ObjectClassification::TRUCK, "truck"}, {ObjectClassification::BUS, "bus"},
347+
{ObjectClassification::TRAILER, "trailer"}, {ObjectClassification::MOTORCYCLE, "motorcycle"},
348+
{ObjectClassification::BICYCLE, "bicycle"}, {ObjectClassification::PEDESTRIAN, "pedestrian"}};
349+
std::unordered_map<std::string, ObstacleSpecificParams> type_specified_param_list;
350+
explicit StopParam(rclcpp::Node & node, const LongitudinalInfo & longitudinal_info)
351+
{
352+
const std::string param_prefix = "stop.type_specified_params.";
353+
const ObstacleSpecificParams default_param{longitudinal_info.limit_min_accel, false};
354+
type_specified_param_list.emplace("default", default_param);
355+
for (const auto & type_map : types_maps) {
356+
if (node.declare_parameter<bool>(
357+
param_prefix + "use_type_specified_params." + type_map.second)) {
358+
const ObstacleSpecificParams param{
359+
node.declare_parameter<double>(param_prefix + "limit_min_acc." + type_map.second),
360+
node.declare_parameter<bool>(param_prefix + "abandon_to_stop." + type_map.second)};
361+
type_specified_param_list.emplace(type_map.second, param);
362+
}
363+
}
364+
}
365+
std::string getParamType(ObjectClassification label)
366+
{
367+
const auto type_str = types_maps.at(label.label);
368+
if (type_specified_param_list.count(type_str) != 0) {
369+
return type_str;
370+
}
371+
return "default";
372+
}
373+
};
374+
StopParam stop_param_;
336375
double moving_object_speed_threshold;
337376
double moving_object_hysteresis_range;
338377
std::vector<SlowDownOutput> prev_slow_down_output_;

planning/obstacle_cruise_planner/src/node.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,12 @@ ObstacleCruisePlannerNode::determineEgoBehaviorAgainstObstacles(
815815
}
816816
slow_down_condition_counter_.removeCounterUnlessUpdated();
817817

818+
std::sort(
819+
stop_obstacles.begin(), stop_obstacles.end(),
820+
[](const StopObstacle & o1, const StopObstacle & o2) {
821+
return o1.dist_to_collide_on_decimated_traj < o2.dist_to_collide_on_decimated_traj;
822+
});
823+
818824
// Check target obstacles' consistency
819825
checkConsistency(objects.header.stamp, objects, stop_obstacles);
820826

@@ -1242,9 +1248,9 @@ std::optional<StopObstacle> ObstacleCruisePlannerNode::createStopObstacle(
12421248
}
12431249

12441250
const auto [tangent_vel, normal_vel] = projectObstacleVelocityToTrajectory(traj_points, obstacle);
1245-
return StopObstacle{
1246-
obstacle.uuid, obstacle.stamp, obstacle.pose, obstacle.shape,
1247-
tangent_vel, normal_vel, collision_point->first, collision_point->second};
1251+
return StopObstacle{obstacle.uuid, obstacle.stamp, obstacle.classification,
1252+
obstacle.pose, obstacle.shape, tangent_vel,
1253+
normal_vel, collision_point->first, collision_point->second};
12481254
}
12491255

12501256
std::optional<SlowDownObstacle> ObstacleCruisePlannerNode::createSlowDownObstacle(

planning/obstacle_cruise_planner/src/planner_interface.cpp

+113-86
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,78 @@ std::vector<TrajectoryPoint> PlannerInterface::generateStopTrajectory(
259259
rclcpp::get_logger("ObstacleCruisePlanner::PIDBasedPlanner"), enable_debug_info_,
260260
"stop planning");
261261

262-
// Get Closest Stop Obstacle
263-
const auto closest_stop_obstacle = obstacle_cruise_utils::getClosestStopObstacle(stop_obstacles);
264-
if (!closest_stop_obstacle) {
262+
std::optional<StopObstacle> determined_stop_obstacle{};
263+
std::optional<double> determined_zero_vel_dist{};
264+
std::optional<double> determined_desired_margin{};
265+
// std::optional<bool> will_collide_with_obstacle{};
266+
for (const auto & type_specified_param : stop_param_.type_specified_param_list) {
267+
// stop_obstacles had been sorted by dist_to_collide_on_decimated_traj
268+
for (const auto & stop_obstacle : stop_obstacles) {
269+
if (stop_param_.getParamType(stop_obstacle.classification) != type_specified_param.first) {
270+
continue;
271+
}
272+
const auto ego_segment_idx =
273+
ego_nearest_param_.findSegmentIndex(planner_data.traj_points, planner_data.ego_pose);
274+
const double dist_to_collide_on_ref_traj =
275+
motion_utils::calcSignedArcLength(planner_data.traj_points, 0, ego_segment_idx) +
276+
stop_obstacle.dist_to_collide_on_decimated_traj;
277+
278+
const double desired_margin = [&]() {
279+
const double margin_from_obstacle =
280+
calculateMarginFromObstacleOnCurve(planner_data, stop_obstacle);
281+
// Use terminal margin (terminal_safe_distance_margin) for obstacle stop
282+
const auto ref_traj_length = motion_utils::calcSignedArcLength(
283+
planner_data.traj_points, 0, planner_data.traj_points.size() - 1);
284+
if (dist_to_collide_on_ref_traj > ref_traj_length) {
285+
return longitudinal_info_.terminal_safe_distance_margin;
286+
}
287+
288+
// If behavior stop point is ahead of the closest_obstacle_stop point within a certain
289+
// margin we set closest_obstacle_stop_distance to closest_behavior_stop_distance
290+
const auto closest_behavior_stop_idx =
291+
motion_utils::searchZeroVelocityIndex(planner_data.traj_points, ego_segment_idx + 1);
292+
if (closest_behavior_stop_idx) {
293+
const double closest_behavior_stop_dist_on_ref_traj = motion_utils::calcSignedArcLength(
294+
planner_data.traj_points, 0, *closest_behavior_stop_idx);
295+
const double stop_dist_diff = closest_behavior_stop_dist_on_ref_traj -
296+
(dist_to_collide_on_ref_traj - margin_from_obstacle);
297+
if (0.0 < stop_dist_diff && stop_dist_diff < margin_from_obstacle) {
298+
return min_behavior_stop_margin_;
299+
}
300+
}
301+
return margin_from_obstacle;
302+
}();
303+
304+
// calc stop point against the obstacle
305+
double candidate_zero_vel_dist = std::max(0.0, dist_to_collide_on_ref_traj - desired_margin);
306+
if (suppress_sudden_obstacle_stop_) {
307+
const double acceptable_stop_dist =
308+
calcMinimumDistanceToStop(
309+
planner_data.ego_vel, longitudinal_info_.limit_max_accel,
310+
type_specified_param.second.limit_min_acc) +
311+
motion_utils::calcSignedArcLength(
312+
planner_data.traj_points, 0, planner_data.ego_pose.position);
313+
314+
if (acceptable_stop_dist > candidate_zero_vel_dist) {
315+
if (type_specified_param.second.abandon_to_stop && acceptable_stop_dist > dist_to_collide_on_ref_traj) {
316+
RCLCPP_WARN(
317+
rclcpp::get_logger("ObstacleCruisePlanner::StopPlanner"),
318+
"[Cruise] abandon to stop against %s object", type_specified_param.first.c_str());
319+
continue;
320+
}
321+
candidate_zero_vel_dist = acceptable_stop_dist;
322+
}
323+
}
324+
if (!determined_zero_vel_dist || candidate_zero_vel_dist < determined_zero_vel_dist) {
325+
determined_zero_vel_dist = candidate_zero_vel_dist;
326+
determined_stop_obstacle = stop_obstacle;
327+
determined_desired_margin = desired_margin;
328+
break;
329+
}
330+
}
331+
}
332+
333+
if (!determined_zero_vel_dist) {
265334
// delete marker
266335
const auto markers =
267336
motion_utils::createDeletedStopVirtualWallMarker(planner_data.current_time, 0);
@@ -271,117 +340,75 @@ std::vector<TrajectoryPoint> PlannerInterface::generateStopTrajectory(
271340
return planner_data.traj_points;
272341
}
273342

274-
const auto ego_segment_idx =
275-
ego_nearest_param_.findSegmentIndex(planner_data.traj_points, planner_data.ego_pose);
276-
const double dist_to_collide_on_ref_traj =
277-
motion_utils::calcSignedArcLength(planner_data.traj_points, 0, ego_segment_idx) +
278-
closest_stop_obstacle->dist_to_collide_on_decimated_traj;
279-
280-
const double margin_from_obstacle_considering_behavior_module = [&]() {
281-
const double margin_from_obstacle =
282-
calculateMarginFromObstacleOnCurve(planner_data, *closest_stop_obstacle);
283-
// Use terminal margin (terminal_safe_distance_margin) for obstacle stop
284-
const auto ref_traj_length = motion_utils::calcSignedArcLength(
285-
planner_data.traj_points, 0, planner_data.traj_points.size() - 1);
286-
if (dist_to_collide_on_ref_traj > ref_traj_length) {
287-
return longitudinal_info_.terminal_safe_distance_margin;
288-
}
289-
290-
// If behavior stop point is ahead of the closest_obstacle_stop point within a certain margin
291-
// we set closest_obstacle_stop_distance to closest_behavior_stop_distance
292-
const auto closest_behavior_stop_idx =
293-
motion_utils::searchZeroVelocityIndex(planner_data.traj_points, ego_segment_idx + 1);
294-
if (closest_behavior_stop_idx) {
295-
const double closest_behavior_stop_dist_on_ref_traj =
296-
motion_utils::calcSignedArcLength(planner_data.traj_points, 0, *closest_behavior_stop_idx);
297-
const double stop_dist_diff = closest_behavior_stop_dist_on_ref_traj -
298-
(dist_to_collide_on_ref_traj - margin_from_obstacle);
299-
if (0.0 < stop_dist_diff && stop_dist_diff < margin_from_obstacle) {
300-
return min_behavior_stop_margin_;
301-
}
302-
}
303-
return margin_from_obstacle;
304-
}();
305-
306-
// Generate Output Trajectory
307-
const auto [zero_vel_dist, will_collide_with_obstacle] = [&]() {
308-
double candidate_zero_vel_dist =
309-
std::max(0.0, dist_to_collide_on_ref_traj - margin_from_obstacle_considering_behavior_module);
310-
311-
// Check feasibility to stop
312-
if (suppress_sudden_obstacle_stop_) {
313-
// Calculate feasible stop margin (Check the feasibility)
314-
const double feasible_stop_dist =
315-
calcMinimumDistanceToStop(
316-
planner_data.ego_vel, longitudinal_info_.limit_max_accel,
317-
longitudinal_info_.limit_min_accel) +
318-
motion_utils::calcSignedArcLength(
319-
planner_data.traj_points, 0, planner_data.ego_pose.position);
320-
321-
if (candidate_zero_vel_dist < feasible_stop_dist) {
322-
candidate_zero_vel_dist = feasible_stop_dist;
323-
return std::make_pair(candidate_zero_vel_dist, true);
324-
}
325-
}
326-
327-
// Hold previous stop distance if necessary
343+
// Hold previous stop distance if necessary
344+
if (
345+
std::abs(planner_data.ego_vel) < longitudinal_info_.hold_stop_velocity_threshold &&
346+
prev_stop_distance_info_) {
347+
// NOTE: We assume that the current trajectory's front point is ahead of the previous
348+
// trajectory's front point.
349+
const size_t traj_front_point_prev_seg_idx =
350+
motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
351+
prev_stop_distance_info_->first, planner_data.traj_points.front().pose);
352+
const double diff_dist_front_points = motion_utils::calcSignedArcLength(
353+
prev_stop_distance_info_->first, 0, planner_data.traj_points.front().pose.position,
354+
traj_front_point_prev_seg_idx);
355+
356+
const double prev_zero_vel_dist = prev_stop_distance_info_->second - diff_dist_front_points;
328357
if (
329-
std::abs(planner_data.ego_vel) < longitudinal_info_.hold_stop_velocity_threshold &&
330-
prev_stop_distance_info_) {
331-
// NOTE: We assume that the current trajectory's front point is ahead of the previous
332-
// trajectory's front point.
333-
const size_t traj_front_point_prev_seg_idx =
334-
motion_utils::findFirstNearestSegmentIndexWithSoftConstraints(
335-
prev_stop_distance_info_->first, planner_data.traj_points.front().pose);
336-
const double diff_dist_front_points = motion_utils::calcSignedArcLength(
337-
prev_stop_distance_info_->first, 0, planner_data.traj_points.front().pose.position,
338-
traj_front_point_prev_seg_idx);
339-
340-
const double prev_zero_vel_dist = prev_stop_distance_info_->second - diff_dist_front_points;
341-
if (
342-
std::abs(prev_zero_vel_dist - candidate_zero_vel_dist) <
343-
longitudinal_info_.hold_stop_distance_threshold) {
344-
candidate_zero_vel_dist = prev_zero_vel_dist;
345-
}
358+
std::abs(prev_zero_vel_dist - determined_zero_vel_dist.value()) <
359+
longitudinal_info_.hold_stop_distance_threshold) {
360+
determined_zero_vel_dist.value() = prev_zero_vel_dist;
346361
}
347-
return std::make_pair(candidate_zero_vel_dist, false);
348-
}();
362+
}
349363

350364
// Insert stop point
351365
auto output_traj_points = planner_data.traj_points;
352-
const auto zero_vel_idx = motion_utils::insertStopPoint(0, zero_vel_dist, output_traj_points);
366+
const auto zero_vel_idx =
367+
motion_utils::insertStopPoint(0, determined_zero_vel_dist.value(), output_traj_points);
353368
if (zero_vel_idx) {
354369
// virtual wall marker for stop obstacle
355370
const auto markers = motion_utils::createStopVirtualWallMarker(
356371
output_traj_points.at(*zero_vel_idx).pose, "obstacle stop", planner_data.current_time, 0,
357372
abs_ego_offset, "", planner_data.is_driving_forward);
358373
tier4_autoware_utils::appendMarkerArray(markers, &debug_data_ptr_->stop_wall_marker);
359-
debug_data_ptr_->obstacles_to_stop.push_back(*closest_stop_obstacle);
374+
debug_data_ptr_->obstacles_to_stop.push_back(*determined_stop_obstacle);
360375

361376
// Publish Stop Reason
362377
const auto stop_pose = output_traj_points.at(*zero_vel_idx).pose;
363378
const auto stop_reasons_msg =
364-
makeStopReasonArray(planner_data, stop_pose, *closest_stop_obstacle);
379+
makeStopReasonArray(planner_data, stop_pose, *determined_stop_obstacle);
365380
stop_reasons_pub_->publish(stop_reasons_msg);
366381
velocity_factors_pub_->publish(makeVelocityFactorArray(planner_data.current_time, stop_pose));
367382

368-
// Publish if ego vehicle collides with the obstacle with a limit acceleration
383+
// Publish if ego vehicle will over run against the stop point with a limit acceleration
384+
const bool will_over_run = determined_stop_obstacle->dist_to_collide_on_decimated_traj -
385+
determined_zero_vel_dist.value() <
386+
determined_desired_margin.value();
369387
const auto stop_speed_exceeded_msg =
370-
createStopSpeedExceededMsg(planner_data.current_time, will_collide_with_obstacle);
388+
createStopSpeedExceededMsg(planner_data.current_time, will_over_run);
371389
stop_speed_exceeded_pub_->publish(stop_speed_exceeded_msg);
372390

373-
prev_stop_distance_info_ = std::make_pair(output_traj_points, zero_vel_dist);
391+
prev_stop_distance_info_ = std::make_pair(output_traj_points, determined_zero_vel_dist.value());
374392
}
375393

376394
stop_planning_debug_info_.set(
377395
StopPlanningDebugInfo::TYPE::STOP_CURRENT_OBSTACLE_DISTANCE,
378-
closest_stop_obstacle->dist_to_collide_on_decimated_traj);
396+
determined_stop_obstacle->dist_to_collide_on_decimated_traj);
379397
stop_planning_debug_info_.set(
380-
StopPlanningDebugInfo::TYPE::STOP_CURRENT_OBSTACLE_VELOCITY, closest_stop_obstacle->velocity);
398+
StopPlanningDebugInfo::TYPE::STOP_CURRENT_OBSTACLE_VELOCITY,
399+
determined_stop_obstacle->velocity);
381400

401+
// compatible implementation to the exsiting code is the choice 1, but should we change it to the
402+
// choice2?
403+
// choice 1
382404
stop_planning_debug_info_.set(
383-
StopPlanningDebugInfo::TYPE::STOP_TARGET_OBSTACLE_DISTANCE,
384-
margin_from_obstacle_considering_behavior_module);
405+
StopPlanningDebugInfo::TYPE::STOP_TARGET_OBSTACLE_DISTANCE, determined_desired_margin.value());
406+
// choice 2
407+
// stop_planning_debug_info_.set(
408+
// StopPlanningDebugInfo::TYPE::STOP_TARGET_OBSTACLE_DISTANCE,
409+
// determined_stop_obstacle->dist_to_collide_on_decimated_traj -
410+
// determined_zero_vel_dist.value());
411+
385412
stop_planning_debug_info_.set(StopPlanningDebugInfo::TYPE::STOP_TARGET_VELOCITY, 0.0);
386413
stop_planning_debug_info_.set(StopPlanningDebugInfo::TYPE::STOP_TARGET_ACCELERATION, 0.0);
387414

0 commit comments

Comments
 (0)