Skip to content

Commit e39282d

Browse files
danielsanchezarankarishma1911
authored andcommitted
feat(control_evaluator): implement a control evaluator (autowarefoundation#6959)
* add control evaluator module Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * make the evaluator depend on messages from AEB Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * update output msg Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * delete extra new line Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * update/fix details Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * add a package mantainer Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> * Add a timer to maintain a constant rate of msg publishing Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com> --------- Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
1 parent 8ff8c83 commit e39282d

File tree

9 files changed

+236
-0
lines changed

9 files changed

+236
-0
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(control_evaluator)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
find_package(pluginlib REQUIRED)
8+
9+
ament_auto_add_library(${PROJECT_NAME}_node SHARED
10+
src/${PROJECT_NAME}_node.cpp
11+
)
12+
13+
rclcpp_components_register_node(${PROJECT_NAME}_node
14+
PLUGIN "control_diagnostics::controlEvaluatorNode"
15+
EXECUTABLE ${PROJECT_NAME}
16+
)
17+
18+
19+
ament_auto_package(
20+
INSTALL_TO_SHARE
21+
param
22+
launch
23+
)

evaluator/control_evaluator/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Planning Evaluator
2+
3+
## Purpose
4+
5+
This package provides nodes that generate metrics to evaluate the quality of control.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 CONTROL_EVALUATOR__CONTROL_EVALUATOR_NODE_HPP_
16+
#define CONTROL_EVALUATOR__CONTROL_EVALUATOR_NODE_HPP_
17+
18+
#include "rclcpp/rclcpp.hpp"
19+
20+
#include "diagnostic_msgs/msg/diagnostic_array.hpp"
21+
22+
#include <array>
23+
#include <deque>
24+
#include <memory>
25+
#include <string>
26+
#include <vector>
27+
28+
namespace control_diagnostics
29+
{
30+
31+
using diagnostic_msgs::msg::DiagnosticArray;
32+
using diagnostic_msgs::msg::DiagnosticStatus;
33+
34+
/**
35+
* @brief Node for control evaluation
36+
*/
37+
class controlEvaluatorNode : public rclcpp::Node
38+
{
39+
public:
40+
explicit controlEvaluatorNode(const rclcpp::NodeOptions & node_options);
41+
42+
/**
43+
* @brief publish the given metric statistic
44+
*/
45+
DiagnosticStatus generateDiagnosticStatus(const bool is_emergency_brake) const;
46+
void onDiagnostics(const DiagnosticArray::ConstSharedPtr diag_msg);
47+
void onTimer();
48+
49+
private:
50+
rclcpp::Subscription<DiagnosticArray>::SharedPtr control_diag_sub_;
51+
rclcpp::Publisher<DiagnosticArray>::SharedPtr metrics_pub_;
52+
53+
// Calculator
54+
// Metrics
55+
std::deque<rclcpp::Time> stamps_;
56+
DiagnosticArray metrics_msg_;
57+
rclcpp::TimerBase::SharedPtr timer_;
58+
};
59+
} // namespace control_diagnostics
60+
61+
#endif // CONTROL_EVALUATOR__CONTROL_EVALUATOR_NODE_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<launch>
2+
<arg name="input/diagnostics" default="/diagnostics"/>
3+
4+
<!-- control evaluator -->
5+
<group>
6+
<node name="control_evaluator" exec="control_evaluator" pkg="control_evaluator">
7+
<param from="$(find-pkg-share control_evaluator)/param/control_evaluator.defaults.yaml"/>
8+
<remap from="~/input/diagnostics" to="$(var input/diagnostics)"/>
9+
<remap from="~/metrics" to="/diagnostic/control_evaluator/metrics"/>
10+
</node>
11+
</group>
12+
</launch>
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>control_evaluator</name>
5+
<version>0.1.0</version>
6+
<description>ROS 2 node for evaluating control</description>
7+
<maintainer email="daniel.sanchez@tier4.jp">Daniel SANCHEZ</maintainer>
8+
<maintainer email="takayuki.murooka@tier4.jp">takayuki MUROOKA</maintainer>
9+
<license>Apache License 2.0</license>
10+
11+
<author email="daniel.sanchez@tier4.jp">Daniel SANCHEZ</author>
12+
<author email="takayuki.murooka@tier4.jp">takayuki MUROOKA</author>
13+
14+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
15+
<buildtool_depend>autoware_cmake</buildtool_depend>
16+
17+
<depend>diagnostic_msgs</depend>
18+
<depend>pluginlib</depend>
19+
<depend>rclcpp</depend>
20+
<depend>rclcpp_components</depend>
21+
22+
<test_depend>ament_cmake_ros</test_depend>
23+
<test_depend>ament_lint_auto</test_depend>
24+
<test_depend>autoware_lint_common</test_depend>
25+
26+
<export>
27+
<build_type>ament_cmake</build_type>
28+
</export>
29+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/**:
2+
ros__parameters:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
#include "control_evaluator/control_evaluator_node.hpp"
16+
17+
#include <fstream>
18+
#include <iostream>
19+
#include <map>
20+
#include <memory>
21+
#include <string>
22+
#include <utility>
23+
#include <vector>
24+
25+
namespace control_diagnostics
26+
{
27+
controlEvaluatorNode::controlEvaluatorNode(const rclcpp::NodeOptions & node_options)
28+
: Node("control_evaluator", node_options)
29+
{
30+
using std::placeholders::_1;
31+
32+
control_diag_sub_ = create_subscription<DiagnosticArray>(
33+
"~/input/diagnostics", 1, std::bind(&controlEvaluatorNode::onDiagnostics, this, _1));
34+
35+
// Publisher
36+
metrics_pub_ = create_publisher<DiagnosticArray>("~/metrics", 1);
37+
38+
// Timer callback to publish evaluator diagnostics
39+
using namespace std::literals::chrono_literals;
40+
timer_ =
41+
rclcpp::create_timer(this, get_clock(), 100ms, std::bind(&controlEvaluatorNode::onTimer, this));
42+
}
43+
44+
DiagnosticStatus controlEvaluatorNode::generateDiagnosticStatus(const bool is_emergency_brake) const
45+
{
46+
DiagnosticStatus status;
47+
status.level = status.OK;
48+
status.name = "autonomous_emergency_braking";
49+
diagnostic_msgs::msg::KeyValue key_value;
50+
key_value.key = "decision";
51+
key_value.value = (is_emergency_brake) ? "stop" : "none";
52+
status.values.push_back(key_value);
53+
return status;
54+
}
55+
56+
void controlEvaluatorNode::onTimer()
57+
{
58+
if (!metrics_msg_.status.empty()) {
59+
metrics_pub_->publish(metrics_msg_);
60+
metrics_msg_.status.clear();
61+
}
62+
}
63+
64+
void controlEvaluatorNode::onDiagnostics(const DiagnosticArray::ConstSharedPtr diag_msg)
65+
{
66+
const auto start = now();
67+
const auto aeb_status =
68+
std::find_if(diag_msg->status.begin(), diag_msg->status.end(), [](const auto & status) {
69+
const bool aeb_found = status.name.find("autonomous_emergency_braking") != std::string::npos;
70+
return aeb_found;
71+
});
72+
73+
if (aeb_status == diag_msg->status.end()) return;
74+
75+
const bool is_emergency_brake = (aeb_status->level == DiagnosticStatus::ERROR);
76+
metrics_msg_.header.stamp = now();
77+
metrics_msg_.status.emplace_back(generateDiagnosticStatus(is_emergency_brake));
78+
79+
const auto runtime = (now() - start).seconds();
80+
RCLCPP_DEBUG(get_logger(), "control evaluation calculation time: %2.2f ms", runtime * 1e3);
81+
}
82+
83+
} // namespace control_diagnostics
84+
85+
#include "rclcpp_components/register_node_macro.hpp"
86+
RCLCPP_COMPONENTS_REGISTER_NODE(control_diagnostics::controlEvaluatorNode)

launch/tier4_control_launch/launch/control.launch.py

+17
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,22 @@ def launch_setup(context, *args, **kwargs):
343343
],
344344
)
345345

346+
# control evaluator
347+
control_evaluator_component = ComposableNode(
348+
package="control_evaluator",
349+
plugin="control_diagnostics::controlEvaluatorNode",
350+
name="control_evaluator",
351+
remappings=[
352+
("~/input/diagnostics", "/diagnostics"),
353+
("~/output/metrics", "~/metrics"),
354+
],
355+
)
356+
357+
control_evaluator_loader = LoadComposableNodes(
358+
composable_node_descriptions=[control_evaluator_component],
359+
target_container="/control/control_container",
360+
)
361+
346362
# control validator checker
347363
control_validator_component = ComposableNode(
348364
package="control_validator",
@@ -369,6 +385,7 @@ def launch_setup(context, *args, **kwargs):
369385
obstacle_collision_checker_loader,
370386
autonomous_emergency_braking_loader,
371387
predicted_path_checker_loader,
388+
control_evaluator_loader,
372389
]
373390
)
374391

launch/tier4_control_launch/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<buildtool_depend>ament_cmake_auto</buildtool_depend>
1212
<buildtool_depend>autoware_cmake</buildtool_depend>
1313

14+
<exec_depend>control_evaluator</exec_depend>
1415
<exec_depend>external_cmd_converter</exec_depend>
1516
<exec_depend>external_cmd_selector</exec_depend>
1617
<exec_depend>lane_departure_checker</exec_depend>

0 commit comments

Comments
 (0)