Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(system error monitor): use polling subscriber #7736

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c33ccce
fix: replace the subscriber that stores the topic in member variables…
masahiro-kubota Jun 27, 2024
1eb538d
fix: replace takeData() with takeNewData()
masahiro-kubota Jun 27, 2024
151fdc9
refactor: delete the redundant comment
masahiro-kubota Jun 27, 2024
712f90f
refactor: delete the redundant code
masahiro-kubota Jun 27, 2024
4308371
fix; remove const
masahiro-kubota Jun 27, 2024
b7185b4
fix: change the path of polling_subscriber.hpp
masahiro-kubota Jun 27, 2024
a3f059d
fix: modify package.xml
masahiro-kubota Jun 27, 2024
924ecf2
style(pre-commit): autofix
pre-commit-ci[bot] Jun 27, 2024
d7809f8
fix: modify package.xml
masahiro-kubota Jun 27, 2024
c10b7c1
style(pre-commit): autofix
pre-commit-ci[bot] Jun 27, 2024
dc6b36b
fix: modify the include file
masahiro-kubota Jun 27, 2024
95c6886
fix: modify the header file
masahiro-kubota Jun 27, 2024
3aec69e
style(pre-commit): autofix
pre-commit-ci[bot] Jun 27, 2024
345cbc4
fix: modify the namespace
masahiro-kubota Jun 27, 2024
d10b907
Merge branch 'feat/system_error_monitor/subscribe_by_polling' of gith…
masahiro-kubota Jun 27, 2024
9018f44
style(pre-commit): autofix
pre-commit-ci[bot] Jun 27, 2024
1820f87
fix: modify the namespace
masahiro-kubota Jun 27, 2024
2e94095
style(pre-commit): autofix
pre-commit-ci[bot] Jun 27, 2024
6b48c68
refactor : refactor onTimer method to reduce cyclomatic complexity
masahiro-kubota Jun 27, 2024
2844319
style(pre-commit): autofix
pre-commit-ci[bot] Jun 27, 2024
b231a4f
fix: add ";"
masahiro-kubota Jun 27, 2024
af07b3b
fi: add <limits>
masahiro-kubota Jun 27, 2024
4f6ec23
style(pre-commit): autofix
pre-commit-ci[bot] Jun 27, 2024
99cae11
fix: modify qos
masahiro-kubota Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "autoware/universe_utils/ros/logger_level_configure.hpp"

#include <autoware/universe_utils/ros/polling_subscriber.hpp>
#include <rclcpp/create_timer.hpp>
#include <rclcpp/rclcpp.hpp>

Expand All @@ -30,6 +31,7 @@
#include <boost/optional.hpp>

#include <deque>
#include <limits>
#include <map>
#include <memory>
#include <string>
Expand Down Expand Up @@ -98,12 +100,21 @@ class AutowareErrorMonitor : public rclcpp::Node
bool isDataReady();
bool isDataHeartbeatTimeout();
void onTimer();
void handleDiagArray();
void handleAutowareState();
void handleCurrentGateMode();
void handleControlMode();

// Subscriber
rclcpp::Subscription<diagnostic_msgs::msg::DiagnosticArray>::SharedPtr sub_diag_array_;
rclcpp::Subscription<autoware_system_msgs::msg::AutowareState>::SharedPtr sub_autoware_state_;
rclcpp::Subscription<tier4_control_msgs::msg::GateMode>::SharedPtr sub_current_gate_mode_;
rclcpp::Subscription<autoware_vehicle_msgs::msg::ControlModeReport>::SharedPtr sub_control_mode_;
autoware::universe_utils::InterProcessPollingSubscriber<diagnostic_msgs::msg::DiagnosticArray>
sub_diag_array_{this, "~/input/diag_array", rclcpp::QoS(10)};
autoware::universe_utils::InterProcessPollingSubscriber<autoware_system_msgs::msg::AutowareState>
sub_autoware_state_{this, "~/input/current_gate_mode"};
autoware::universe_utils::InterProcessPollingSubscriber<tier4_control_msgs::msg::GateMode>
sub_current_gate_mode_{this, "~/input/autoware_state"};
autoware::universe_utils::InterProcessPollingSubscriber<
autoware_vehicle_msgs::msg::ControlModeReport>
sub_control_mode_{this, "~/input/control_mode"};
void onAutowareState(const autoware_system_msgs::msg::AutowareState::ConstSharedPtr msg);
void onCurrentGateMode(const tier4_control_msgs::msg::GateMode::ConstSharedPtr msg);
void onControlMode(const autoware_vehicle_msgs::msg::ControlModeReport::ConstSharedPtr msg);
Expand Down
1 change: 1 addition & 0 deletions system/system_error_monitor/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<version>0.1.1</version>
<description>The system_error_monitor package in ROS 2</description>
<maintainer email="fumihito.ito@tier4.jp">Fumihito Ito</maintainer>

<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
Expand Down
50 changes: 38 additions & 12 deletions system/system_error_monitor/src/system_error_monitor_core.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tier IV, Inc.

Check notice on line 1 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Overall Code Complexity

The mean cyclomatic complexity in this module is no longer above the threshold
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -229,18 +229,6 @@

using std::placeholders::_1;
using std::placeholders::_2;
// Subscriber
sub_diag_array_ = create_subscription<diagnostic_msgs::msg::DiagnosticArray>(
"input/diag_array", rclcpp::QoS{1}, std::bind(&AutowareErrorMonitor::onDiagArray, this, _1));
sub_current_gate_mode_ = create_subscription<tier4_control_msgs::msg::GateMode>(
"~/input/current_gate_mode", rclcpp::QoS{1},
std::bind(&AutowareErrorMonitor::onCurrentGateMode, this, _1));
sub_autoware_state_ = create_subscription<autoware_system_msgs::msg::AutowareState>(
"~/input/autoware_state", rclcpp::QoS{1},
std::bind(&AutowareErrorMonitor::onAutowareState, this, _1));
sub_control_mode_ = create_subscription<autoware_vehicle_msgs::msg::ControlModeReport>(
"~/input/control_mode", rclcpp::QoS{1},
std::bind(&AutowareErrorMonitor::onControlMode, this, _1));

// Publisher
pub_hazard_status_ = create_publisher<autoware_system_msgs::msg::HazardStatusStamped>(
Expand Down Expand Up @@ -440,6 +428,11 @@

void AutowareErrorMonitor::onTimer()
{
handleDiagArray();
handleAutowareState();
handleCurrentGateMode();
handleControlMode();

Check warning on line 434 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L431-L434

Added lines #L431 - L434 were not covered by tests

if (!isDataReady()) {
if ((this->now() - initialized_time_).seconds() > params_.data_ready_timeout) {
RCLCPP_WARN_THROTTLE(
Expand All @@ -465,6 +458,39 @@
publishHazardStatus(hazard_status_);
}

void AutowareErrorMonitor::handleDiagArray()

Check warning on line 461 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L461

Added line #L461 was not covered by tests
{
auto diag_array_msg = sub_diag_array_.takeNewData();

Check warning on line 463 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L463

Added line #L463 was not covered by tests
while (diag_array_msg) {
onDiagArray(diag_array_msg);
diag_array_msg = sub_diag_array_.takeNewData();

Check warning on line 466 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L465-L466

Added lines #L465 - L466 were not covered by tests
}
}

void AutowareErrorMonitor::handleAutowareState()

Check warning on line 470 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L470

Added line #L470 was not covered by tests
{
auto autoware_state_msg = sub_autoware_state_.takeNewData();

Check warning on line 472 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L472

Added line #L472 was not covered by tests
if (autoware_state_msg) {
onAutowareState(autoware_state_msg);

Check warning on line 474 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L474

Added line #L474 was not covered by tests
}
}

void AutowareErrorMonitor::handleCurrentGateMode()

Check warning on line 478 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L478

Added line #L478 was not covered by tests
{
auto current_gate_msg = sub_current_gate_mode_.takeNewData();

Check warning on line 480 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L480

Added line #L480 was not covered by tests
if (current_gate_msg) {
onCurrentGateMode(current_gate_msg);

Check warning on line 482 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L482

Added line #L482 was not covered by tests
}
}

void AutowareErrorMonitor::handleControlMode()

Check warning on line 486 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L486

Added line #L486 was not covered by tests
{
auto control_mode_msg = sub_control_mode_.takeNewData();

Check warning on line 488 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L488

Added line #L488 was not covered by tests
if (control_mode_msg) {
onControlMode(control_mode_msg);

Check warning on line 490 in system/system_error_monitor/src/system_error_monitor_core.cpp

View check run for this annotation

Codecov / codecov/patch

system/system_error_monitor/src/system_error_monitor_core.cpp#L490

Added line #L490 was not covered by tests
}
}

boost::optional<DiagStamped> AutowareErrorMonitor::getLatestDiag(
const std::string & diag_name) const
{
Expand Down
Loading