|
25 | 25 | #include <boost/geometry/algorithms/distance.hpp>
|
26 | 26 | #include <boost/geometry/strategies/strategies.hpp>
|
27 | 27 |
|
| 28 | +#include <optional> |
28 | 29 | #include <string>
|
29 | 30 |
|
30 | 31 | namespace
|
@@ -106,78 +107,6 @@ VelocityFactorArray makeVelocityFactorArray(
|
106 | 107 | return velocity_factor_array;
|
107 | 108 | }
|
108 | 109 |
|
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 |
| - |
181 | 110 | double calcMinimumDistanceToStop(
|
182 | 111 | const double initial_vel, const double max_acc, const double min_acc)
|
183 | 112 | {
|
@@ -319,7 +248,6 @@ std::vector<TrajectoryPoint> PlannerInterface::generateStopTrajectory(
|
319 | 248 | if (stop_obstacles.empty()) {
|
320 | 249 | stop_reasons_pub_->publish(makeEmptyStopReasonArray(planner_data.current_time));
|
321 | 250 | velocity_factors_pub_->publish(makeVelocityFactorArray(planner_data.current_time));
|
322 |
| - diagnostics_pub_->publish(makeEmptyStopReasonDiagnosticArray(planner_data.current_time)); |
323 | 251 | // delete marker
|
324 | 252 | const auto markers =
|
325 | 253 | autoware::motion_utils::createDeletedStopVirtualWallMarker(planner_data.current_time, 0);
|
@@ -474,11 +402,11 @@ std::vector<TrajectoryPoint> PlannerInterface::generateStopTrajectory(
|
474 | 402 | const auto stop_pose = output_traj_points.at(*zero_vel_idx).pose;
|
475 | 403 | const auto stop_reasons_msg =
|
476 | 404 | makeStopReasonArray(planner_data, stop_pose, *determined_stop_obstacle);
|
477 |
| - const auto stop_reason_diagnostic_array = |
478 |
| - makeStopReasonDiagnosticArray(planner_data, stop_pose, *determined_stop_obstacle); |
479 | 405 | stop_reasons_pub_->publish(stop_reasons_msg);
|
480 | 406 | 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); |
482 | 410 | // Publish if ego vehicle will over run against the stop point with a limit acceleration
|
483 | 411 |
|
484 | 412 | const bool will_over_run = determined_zero_vel_dist.value() >
|
@@ -747,7 +675,11 @@ std::vector<TrajectoryPoint> PlannerInterface::generateSlowDownTrajectory(
|
747 | 675 | markers, &debug_data_ptr_->slow_down_debug_wall_marker);
|
748 | 676 | }
|
749 | 677 |
|
| 678 | + // Add debug data |
750 | 679 | 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 | + } |
751 | 683 |
|
752 | 684 | // update prev_slow_down_output_
|
753 | 685 | new_prev_slow_down_output.push_back(SlowDownOutput{
|
@@ -904,3 +836,90 @@ PlannerInterface::calculateDistanceToSlowDownWithConstraints(
|
904 | 836 | return std::make_tuple(
|
905 | 837 | filtered_dist_to_slow_down_start, filtered_dist_to_slow_down_end, feasible_slow_down_vel);
|
906 | 838 | }
|
| 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