|
| 1 | +// Copyright 2024 Tier IV, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef AUTOWARE__CONTROL_EVALUATOR__CONTROL_EVALUATOR_NODE_HPP_ |
| 16 | +#define AUTOWARE__CONTROL_EVALUATOR__CONTROL_EVALUATOR_NODE_HPP_ |
| 17 | + |
| 18 | +#include "autoware/control_evaluator/metrics/deviation_metrics.hpp" |
| 19 | + |
| 20 | +#include <rclcpp/rclcpp.hpp> |
| 21 | +#include <route_handler/route_handler.hpp> |
| 22 | +#include <tier4_autoware_utils/tier4_autoware_utils.hpp> |
| 23 | + |
| 24 | +#include "geometry_msgs/msg/accel_with_covariance_stamped.hpp" |
| 25 | +#include <autoware_auto_planning_msgs/msg/route.hpp> |
| 26 | +#include <diagnostic_msgs/msg/diagnostic_array.hpp> |
| 27 | +#include <nav_msgs/msg/odometry.hpp> |
| 28 | +#include <sensor_msgs/msg/imu.hpp> |
| 29 | + |
| 30 | +#include <deque> |
| 31 | +#include <optional> |
| 32 | +#include <string> |
| 33 | +#include <utility> |
| 34 | +#include <vector> |
| 35 | + |
| 36 | +namespace control_diagnostics |
| 37 | +{ |
| 38 | + |
| 39 | +using autoware_auto_planning_msgs::msg::Trajectory; |
| 40 | +using diagnostic_msgs::msg::DiagnosticArray; |
| 41 | +using diagnostic_msgs::msg::DiagnosticStatus; |
| 42 | +using geometry_msgs::msg::Point; |
| 43 | +using geometry_msgs::msg::Pose; |
| 44 | +using nav_msgs::msg::Odometry; |
| 45 | +using LaneletMapBin = autoware_auto_mapping_msgs::msg::HADMapBin; |
| 46 | +using LaneletRoute = autoware_auto_planning_msgs::msg::HADMapRoute; |
| 47 | +using geometry_msgs::msg::AccelWithCovarianceStamped; |
| 48 | +using sensor_msgs::msg::Imu; |
| 49 | + |
| 50 | +/** |
| 51 | + * @brief Node for control evaluation |
| 52 | + */ |
| 53 | +class ControlEvaluatorNode : public rclcpp::Node |
| 54 | +{ |
| 55 | +public: |
| 56 | + explicit ControlEvaluatorNode(const rclcpp::NodeOptions & node_options); |
| 57 | + DiagnosticStatus generateLateralDeviationDiagnosticStatus( |
| 58 | + const Trajectory & traj, const Point & ego_point); |
| 59 | + DiagnosticStatus generateYawDeviationDiagnosticStatus( |
| 60 | + const Trajectory & traj, const Pose & ego_pose); |
| 61 | + std::optional<DiagnosticStatus> generateStopDiagnosticStatus( |
| 62 | + const DiagnosticArray & diag, const std::string & function_name); |
| 63 | + |
| 64 | + DiagnosticStatus generateAEBDiagnosticStatus(const DiagnosticStatus & diag); |
| 65 | + DiagnosticStatus generateLaneletDiagnosticStatus(const Pose & ego_pose) const; |
| 66 | + DiagnosticStatus generateKinematicStateDiagnosticStatus(const Odometry & odom, const Imu & imu); |
| 67 | + |
| 68 | + void onDiagnostics(const DiagnosticArray::ConstSharedPtr diag_msg); |
| 69 | + void onTimer(); |
| 70 | + |
| 71 | +private: |
| 72 | + // The diagnostics cycle is faster than timer, and each node publishes diagnostic separately. |
| 73 | + // takeData() in onTimer() with a polling subscriber will miss a topic, so save all topics with |
| 74 | + // onDiagnostics(). |
| 75 | + rclcpp::Subscription<DiagnosticArray>::SharedPtr control_diag_sub_; |
| 76 | + |
| 77 | + autoware::universe_utils::InterProcessPollingSubscriber<Odometry> odometry_sub_{ |
| 78 | + this, "~/input/odometry"}; |
| 79 | + // autoware::universe_utils::InterProcessPollingSubscriber<AccelWithCovarianceStamped> accel_sub_{ |
| 80 | + // this, "~/input/acceleration"}; |
| 81 | + autoware::universe_utils::InterProcessPollingSubscriber<Imu> imu_sub_{this, "~/input/imu"}; |
| 82 | + autoware::universe_utils::InterProcessPollingSubscriber<Trajectory> traj_sub_{ |
| 83 | + this, "~/input/trajectory"}; |
| 84 | + autoware::universe_utils::InterProcessPollingSubscriber< |
| 85 | + LaneletRoute, autoware::universe_utils::polling_policy::Newest> |
| 86 | + route_subscriber_{this, "~/input/route", rclcpp::QoS{1}.transient_local()}; |
| 87 | + autoware::universe_utils::InterProcessPollingSubscriber< |
| 88 | + LaneletMapBin, autoware::universe_utils::polling_policy::Newest> |
| 89 | + vector_map_subscriber_{this, "~/input/vector_map", rclcpp::QoS{1}.transient_local()}; |
| 90 | + |
| 91 | + rclcpp::Publisher<DiagnosticArray>::SharedPtr metrics_pub_; |
| 92 | + |
| 93 | + // update Route Handler |
| 94 | + void getRouteData(); |
| 95 | + |
| 96 | + // Calculator |
| 97 | + // Metrics |
| 98 | + std::deque<rclcpp::Time> stamps_; |
| 99 | + |
| 100 | + // queue for diagnostics and time stamp |
| 101 | + std::deque<std::pair<DiagnosticStatus, rclcpp::Time>> diag_queue_; |
| 102 | + const std::vector<std::string> target_functions_ = {"autonomous_emergency_braking"}; |
| 103 | + |
| 104 | + route_handler::RouteHandler route_handler_; |
| 105 | + rclcpp::TimerBase::SharedPtr timer_; |
| 106 | + std::optional<Imu> prev_imu_{std::nullopt}; |
| 107 | +}; |
| 108 | +} // namespace control_diagnostics |
| 109 | + |
| 110 | +#endif // AUTOWARE__CONTROL_EVALUATOR__CONTROL_EVALUATOR_NODE_HPP_ |
0 commit comments