Skip to content

Commit 9f41bf1

Browse files
feat(cruise_planner,planning_evaluator): add cruise and slow down diags (autowarefoundation#7960)
* add cruise and slow down diags to cruise planner Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * add cruise types Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * adjust planning eval Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> --------- Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
1 parent 9aedc68 commit 9f41bf1

File tree

8 files changed

+130
-78
lines changed

8 files changed

+130
-78
lines changed

evaluator/autoware_planning_evaluator/include/autoware/planning_evaluator/planning_evaluator_node.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ class PlanningEvaluatorNode : public rclcpp::Node
181181
rclcpp::TimerBase::SharedPtr timer_;
182182
// queue for diagnostics and time stamp
183183
std::deque<std::pair<DiagnosticStatus, rclcpp::Time>> diag_queue_;
184-
const std::vector<std::string> target_functions_ = {"obstacle_cruise_planner"};
184+
const std::vector<std::string> target_functions_ = {
185+
"obstacle_cruise_planner_stop", "obstacle_cruise_planner_slow_down",
186+
"obstacle_cruise_planner_cruise"};
185187
std::optional<AccelWithCovarianceStamped> prev_acc_stamped_{std::nullopt};
186188
};
187189
} // namespace planning_diagnostics

evaluator/autoware_planning_evaluator/src/planning_evaluator_node.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,21 @@ DiagnosticStatus PlanningEvaluatorNode::generateDiagnosticEvaluationStatus(
122122
});
123123
const bool found = it != diag.values.end();
124124
status.level = (found) ? status.OK : status.ERROR;
125-
status.values.push_back((found) ? *it : diagnostic_msgs::msg::KeyValue{});
125+
126+
auto get_key_value = [&]() {
127+
if (!found) {
128+
return diagnostic_msgs::msg::KeyValue{};
129+
}
130+
if (it->value.find("none") != std::string::npos) {
131+
return *it;
132+
}
133+
diagnostic_msgs::msg::KeyValue key_value;
134+
key_value.key = "decision";
135+
key_value.value = "deceleration";
136+
return key_value;
137+
};
138+
139+
status.values.push_back(get_key_value());
126140
return status;
127141
}
128142

planning/autoware_obstacle_cruise_planner/include/autoware/obstacle_cruise_planner/common_structs.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <rclcpp/rclcpp.hpp>
2727

28+
#include <diagnostic_msgs/msg/diagnostic_array.hpp>
29+
2830
#include <optional>
2931
#include <string>
3032
#include <vector>
@@ -286,6 +288,9 @@ struct DebugData
286288
MarkerArray cruise_wall_marker;
287289
MarkerArray slow_down_wall_marker;
288290
std::vector<autoware::universe_utils::Polygon2d> detection_polygons;
291+
std::optional<diagnostic_msgs::msg::DiagnosticStatus> stop_reason_diag{std::nullopt};
292+
std::optional<diagnostic_msgs::msg::DiagnosticStatus> slow_down_reason_diag{std::nullopt};
293+
std::optional<diagnostic_msgs::msg::DiagnosticStatus> cruise_reason_diag{std::nullopt};
289294
};
290295

291296
struct EgoNearestParam

planning/autoware_obstacle_cruise_planner/include/autoware/obstacle_cruise_planner/planner_interface.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ class PlannerInterface
9595
const std::vector<SlowDownObstacle> & slow_down_obstacles,
9696
std::optional<VelocityLimit> & vel_limit);
9797

98+
DiagnosticStatus makeEmptyDiagnostic(const std::string & reason);
99+
DiagnosticStatus makeDiagnostic(
100+
const std::string & reason, const std::optional<PlannerData> & planner_data = std::nullopt,
101+
const std::optional<geometry_msgs::msg::Pose> & stop_pose = std::nullopt,
102+
const std::optional<StopObstacle> & stop_obstacle = std::nullopt);
103+
void publishDiagnostics(const rclcpp::Time & current_time);
104+
void clearDiagnostics();
105+
98106
void onParam(const std::vector<rclcpp::Parameter> & parameters)
99107
{
100108
updateCommonParam(parameters);

planning/autoware_obstacle_cruise_planner/src/node.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ void ObstacleCruisePlannerNode::onTrajectory(const Trajectory::ConstSharedPtr ms
636636

637637
// 8. Publish debug data
638638
published_time_publisher_->publish_if_subscribed(trajectory_pub_, output_traj.header.stamp);
639+
planner_ptr_->publishDiagnostics(now());
639640
publishDebugMarker();
640641
publishDebugInfo();
641642

planning/autoware_obstacle_cruise_planner/src/optimization_based_planner/optimization_based_planner.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ std::vector<TrajectoryPoint> OptimizationBasedPlanner::generateCruiseTrajectory(
199199
output.at(i).longitudinal_velocity_mps = 0.0;
200200
}
201201
prev_output_ = output;
202+
debug_data_ptr_->cruise_reason_diag = makeDiagnostic("cruise", planner_data);
202203
return output;
203204
} else if (opt_position.size() == 1) {
204205
RCLCPP_DEBUG(
@@ -255,6 +256,7 @@ std::vector<TrajectoryPoint> OptimizationBasedPlanner::generateCruiseTrajectory(
255256
// Insert Closest Stop Point
256257
autoware::motion_utils::insertStopPoint(0, closest_stop_dist, output);
257258

259+
debug_data_ptr_->cruise_reason_diag = makeDiagnostic("cruise", planner_data);
258260
prev_output_ = output;
259261
return output;
260262
}

planning/autoware_obstacle_cruise_planner/src/pid_based_planner/pid_based_planner.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ std::vector<TrajectoryPoint> PIDBasedPlanner::planCruise(
323323

324324
// cruise obstacle
325325
debug_data_ptr_->obstacles_to_cruise.push_back(cruise_obstacle_info->obstacle);
326+
debug_data_ptr_->cruise_reason_diag = makeDiagnostic("cruise", planner_data);
326327
}
327328

328329
// do cruise planning

planning/autoware_obstacle_cruise_planner/src/planner_interface.cpp

+95-76
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <boost/geometry/algorithms/distance.hpp>
2626
#include <boost/geometry/strategies/strategies.hpp>
2727

28+
#include <optional>
2829
#include <string>
2930

3031
namespace
@@ -106,78 +107,6 @@ VelocityFactorArray makeVelocityFactorArray(
106107
return velocity_factor_array;
107108
}
108109

109-
DiagnosticArray makeEmptyStopReasonDiagnosticArray(const rclcpp::Time & current_time)
110-
{
111-
// Create status
112-
DiagnosticStatus status;
113-
status.level = status.OK;
114-
status.name = "obstacle_cruise_planner";
115-
diagnostic_msgs::msg::KeyValue key_value;
116-
{
117-
// Decision
118-
key_value.key = "decision";
119-
key_value.value = "none";
120-
status.values.push_back(key_value);
121-
}
122-
// create array
123-
DiagnosticArray diagnostics;
124-
diagnostics.header.stamp = current_time;
125-
diagnostics.header.frame_id = "map";
126-
diagnostics.status.push_back(status);
127-
return diagnostics;
128-
}
129-
130-
DiagnosticArray makeStopReasonDiagnosticArray(
131-
const PlannerData & planner_data, const geometry_msgs::msg::Pose & stop_pose,
132-
const StopObstacle & stop_obstacle)
133-
{
134-
// Create status
135-
DiagnosticStatus status;
136-
status.level = status.OK;
137-
status.name = "obstacle_cruise_planner";
138-
diagnostic_msgs::msg::KeyValue key_value;
139-
{
140-
// Decision
141-
key_value.key = "decision";
142-
key_value.value = "stop";
143-
status.values.push_back(key_value);
144-
}
145-
146-
{ // Stop info
147-
key_value.key = "stop_position";
148-
const auto & p = stop_pose.position;
149-
key_value.value =
150-
"{" + std::to_string(p.x) + ", " + std::to_string(p.y) + ", " + std::to_string(p.z) + "}";
151-
status.values.push_back(key_value);
152-
key_value.key = "stop_orientation";
153-
const auto & o = stop_pose.orientation;
154-
key_value.value = "{" + std::to_string(o.w) + ", " + std::to_string(o.x) + ", " +
155-
std::to_string(o.y) + ", " + std::to_string(o.z) + "}";
156-
status.values.push_back(key_value);
157-
const auto dist_to_stop_pose = autoware::motion_utils::calcSignedArcLength(
158-
planner_data.traj_points, planner_data.ego_pose.position, stop_pose.position);
159-
key_value.key = "distance_to_stop_pose";
160-
key_value.value = std::to_string(dist_to_stop_pose);
161-
status.values.push_back(key_value);
162-
}
163-
164-
{
165-
// Obstacle info
166-
const auto & p = stop_obstacle.collision_point;
167-
key_value.key = "collision_point";
168-
key_value.value =
169-
"{" + std::to_string(p.x) + ", " + std::to_string(p.y) + ", " + std::to_string(p.z) + "}";
170-
status.values.push_back(key_value);
171-
}
172-
173-
// create array
174-
DiagnosticArray diagnostics;
175-
diagnostics.header.stamp = planner_data.current_time;
176-
diagnostics.header.frame_id = "map";
177-
diagnostics.status.push_back(status);
178-
return diagnostics;
179-
}
180-
181110
double calcMinimumDistanceToStop(
182111
const double initial_vel, const double max_acc, const double min_acc)
183112
{
@@ -319,7 +248,6 @@ std::vector<TrajectoryPoint> PlannerInterface::generateStopTrajectory(
319248
if (stop_obstacles.empty()) {
320249
stop_reasons_pub_->publish(makeEmptyStopReasonArray(planner_data.current_time));
321250
velocity_factors_pub_->publish(makeVelocityFactorArray(planner_data.current_time));
322-
diagnostics_pub_->publish(makeEmptyStopReasonDiagnosticArray(planner_data.current_time));
323251
// delete marker
324252
const auto markers =
325253
autoware::motion_utils::createDeletedStopVirtualWallMarker(planner_data.current_time, 0);
@@ -474,11 +402,11 @@ std::vector<TrajectoryPoint> PlannerInterface::generateStopTrajectory(
474402
const auto stop_pose = output_traj_points.at(*zero_vel_idx).pose;
475403
const auto stop_reasons_msg =
476404
makeStopReasonArray(planner_data, stop_pose, *determined_stop_obstacle);
477-
const auto stop_reason_diagnostic_array =
478-
makeStopReasonDiagnosticArray(planner_data, stop_pose, *determined_stop_obstacle);
479405
stop_reasons_pub_->publish(stop_reasons_msg);
480406
velocity_factors_pub_->publish(makeVelocityFactorArray(planner_data.current_time, stop_pose));
481-
diagnostics_pub_->publish(stop_reason_diagnostic_array);
407+
// Store stop reason debug data
408+
debug_data_ptr_->stop_reason_diag =
409+
makeDiagnostic("stop", planner_data, stop_pose, *determined_stop_obstacle);
482410
// Publish if ego vehicle will over run against the stop point with a limit acceleration
483411

484412
const bool will_over_run = determined_zero_vel_dist.value() >
@@ -747,7 +675,11 @@ std::vector<TrajectoryPoint> PlannerInterface::generateSlowDownTrajectory(
747675
markers, &debug_data_ptr_->slow_down_debug_wall_marker);
748676
}
749677

678+
// Add debug data
750679
debug_data_ptr_->obstacles_to_slow_down.push_back(obstacle);
680+
if (!debug_data_ptr_->slow_down_reason_diag.has_value()) {
681+
debug_data_ptr_->slow_down_reason_diag = makeDiagnostic("slow_down", planner_data);
682+
}
751683

752684
// update prev_slow_down_output_
753685
new_prev_slow_down_output.push_back(SlowDownOutput{
@@ -904,3 +836,90 @@ PlannerInterface::calculateDistanceToSlowDownWithConstraints(
904836
return std::make_tuple(
905837
filtered_dist_to_slow_down_start, filtered_dist_to_slow_down_end, feasible_slow_down_vel);
906838
}
839+
840+
DiagnosticStatus PlannerInterface::makeEmptyDiagnostic(const std::string & reason)
841+
{
842+
// Create status
843+
DiagnosticStatus status;
844+
status.level = status.OK;
845+
status.name = "obstacle_cruise_planner_" + reason;
846+
diagnostic_msgs::msg::KeyValue key_value;
847+
{
848+
// Decision
849+
key_value.key = "decision";
850+
key_value.value = "none";
851+
status.values.push_back(key_value);
852+
}
853+
854+
return status;
855+
}
856+
857+
DiagnosticStatus PlannerInterface::makeDiagnostic(
858+
const std::string & reason, const std::optional<PlannerData> & planner_data,
859+
const std::optional<geometry_msgs::msg::Pose> & stop_pose,
860+
const std::optional<StopObstacle> & stop_obstacle)
861+
{
862+
// Create status
863+
DiagnosticStatus status;
864+
status.level = status.OK;
865+
status.name = "obstacle_cruise_planner_" + reason;
866+
diagnostic_msgs::msg::KeyValue key_value;
867+
{
868+
// Decision
869+
key_value.key = "decision";
870+
key_value.value = reason;
871+
status.values.push_back(key_value);
872+
}
873+
874+
if (stop_pose.has_value() && planner_data.has_value()) { // Stop info
875+
key_value.key = "stop_position";
876+
const auto & p = stop_pose.value().position;
877+
key_value.value =
878+
"{" + std::to_string(p.x) + ", " + std::to_string(p.y) + ", " + std::to_string(p.z) + "}";
879+
status.values.push_back(key_value);
880+
key_value.key = "stop_orientation";
881+
const auto & o = stop_pose.value().orientation;
882+
key_value.value = "{" + std::to_string(o.w) + ", " + std::to_string(o.x) + ", " +
883+
std::to_string(o.y) + ", " + std::to_string(o.z) + "}";
884+
status.values.push_back(key_value);
885+
const auto dist_to_stop_pose = autoware::motion_utils::calcSignedArcLength(
886+
planner_data.value().traj_points, planner_data.value().ego_pose.position,
887+
stop_pose.value().position);
888+
key_value.key = "distance_to_stop_pose";
889+
key_value.value = std::to_string(dist_to_stop_pose);
890+
status.values.push_back(key_value);
891+
}
892+
893+
if (stop_obstacle.has_value()) {
894+
// Obstacle info
895+
const auto & p = stop_obstacle.value().collision_point;
896+
key_value.key = "collision_point";
897+
key_value.value =
898+
"{" + std::to_string(p.x) + ", " + std::to_string(p.y) + ", " + std::to_string(p.z) + "}";
899+
status.values.push_back(key_value);
900+
}
901+
902+
return status;
903+
}
904+
905+
void PlannerInterface::publishDiagnostics(const rclcpp::Time & current_time)
906+
{
907+
// create array
908+
DiagnosticArray diagnostics;
909+
diagnostics.header.stamp = current_time;
910+
diagnostics.header.frame_id = "map";
911+
const auto & d = debug_data_ptr_;
912+
diagnostics.status = {
913+
(d->stop_reason_diag) ? d->stop_reason_diag.value() : makeEmptyDiagnostic("stop"),
914+
(d->slow_down_reason_diag) ? *(d->slow_down_reason_diag) : makeEmptyDiagnostic("slow_down"),
915+
(d->cruise_reason_diag) ? d->cruise_reason_diag.value() : makeEmptyDiagnostic("cruise")};
916+
diagnostics_pub_->publish(diagnostics);
917+
clearDiagnostics();
918+
}
919+
920+
void PlannerInterface::clearDiagnostics()
921+
{
922+
debug_data_ptr_->stop_reason_diag = std::nullopt;
923+
debug_data_ptr_->slow_down_reason_diag = std::nullopt;
924+
debug_data_ptr_->cruise_reason_diag = std::nullopt;
925+
}

0 commit comments

Comments
 (0)