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: add autoware_node and autoware_control_center #73

Closed
wants to merge 131 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
942930a
feat: add autoware_node and autoware_control_center
Feb 3, 2023
1a4f640
fix case
Feb 3, 2023
fd9981e
mark explicit
Feb 3, 2023
4d7a2a9
simple service call
Mar 15, 2023
d67b55d
style(pre-commit): autofix
pre-commit-ci[bot] Mar 15, 2023
4a695cf
add heartbeat and uuid
Sep 10, 2023
692641d
style(pre-commit): autofix
pre-commit-ci[bot] Sep 10, 2023
02350b8
add node registry template
Sep 10, 2023
4457c90
style(pre-commit): autofix
pre-commit-ci[bot] Sep 10, 2023
0089d7f
feat(autoware_control_center): update register_node, add unregister_node
lexavtanke Dec 13, 2023
55e7ebc
feat(autoware_control_center): add test for register/unregister requests
lexavtanke Dec 15, 2023
01afc38
feat(autoware_control_center): rename unregister to deregister
lexavtanke Dec 25, 2023
abcec4a
feat(autoware_node): add register_callback, timer disable after register
lexavtanke Dec 27, 2023
ea61deb
feat(autoware_node): add deregister service
lexavtanke Dec 28, 2023
276ba5b
feat(autoware_control_center): add is_empty method to node_registry
lexavtanke Jan 5, 2024
83a50ae
feat(autoware_control_center): add startup timer with delay and dereg…
lexavtanke Jan 10, 2024
dd23e23
feat(autoware_node): add launch file for testing with multiple nodes
lexavtanke Jan 10, 2024
8fbecb3
feat(autoware_node): add heartbeat publishing
lexavtanke Jan 11, 2024
1547ffb
style(pre-commit): autofix
pre-commit-ci[bot] Jan 15, 2024
4dd205a
feat(autoware_control_center): add heartbeat sub, doesn't work with n…
lexavtanke Jan 16, 2024
76e1c93
style(pre-commit): autofix
pre-commit-ci[bot] Jan 16, 2024
42577fd
feat(autoware_node): add namespace support
lexavtanke Jan 23, 2024
7218c00
feat(autoware_control_center_msgs): Add AutowareNodeReport and Autowa…
lexavtanke Jan 23, 2024
89271bd
feat(autoware_control_center): add autoware_node_reports publishing
lexavtanke Jan 23, 2024
62af543
style(pre-commit): autofix
pre-commit-ci[bot] Jan 23, 2024
48e2d4c
fix(autoware_control_center): fix double deregister srv call
lexavtanke Jan 25, 2024
162a651
style(pre-commit): autofix
pre-commit-ci[bot] Jan 25, 2024
80155fb
feat(autoware_control_center_msgs): rename StatusRegistration to Stat…
lexavtanke Jan 29, 2024
a6c7fab
feat(autoware_control_center_msgs): add AutowareNodeState msg and Aut…
lexavtanke Jan 29, 2024
77f2ead
feat(autoware_control_center): implement AutowareNodeError srv in ACC
lexavtanke Jan 29, 2024
2c89335
style(pre-commit): autofix
pre-commit-ci[bot] Jan 29, 2024
27201e9
feat(autoware_node): add AutowareNodeError client
lexavtanke Feb 5, 2024
fe92f7e
fix(autoware_node): fix autoware_node deregister respond
lexavtanke Feb 5, 2024
721b8e2
style(pre-commit): autofix
pre-commit-ci[bot] Feb 5, 2024
ffaa74a
feat(autoware_node): add create_monitored_subscription, build, produc…
lexavtanke Feb 12, 2024
b2de989
feat(autoware_node): fix runtime error with monitored subscription
lexavtanke Feb 13, 2024
1ff6a01
feat(test_node): add test_publisher with proper qos param
lexavtanke Feb 13, 2024
74edf54
feat(autoware_control_center): update startup callback
lexavtanke Feb 13, 2024
ea0e8e2
style(pre-commit): autofix
pre-commit-ci[bot] Feb 13, 2024
fbe977f
feat(autoware_control_center): remove tier4_autoware_utils dependency
lexavtanke Feb 16, 2024
2fd28c0
feat(autoware_node): remove tier4_autoware_utils dependency
lexavtanke Feb 16, 2024
877544a
style(pre-commit): autofix
pre-commit-ci[bot] Feb 16, 2024
695c256
feat(test_node): remove autowar
lexavtanke Feb 18, 2024
8948da5
feat(autoware_node): fix ci check errors
lexavtanke Feb 18, 2024
cde1362
feat(test_node): fix ci check errors
lexavtanke Feb 18, 2024
dfe82e2
style(pre-commit): autofix
pre-commit-ci[bot] Feb 18, 2024
c383825
fix(autoware_control_center): fix cspell errors
lexavtanke Feb 18, 2024
d97942f
fix test_pub cmakelists
Feb 22, 2024
f977cf8
feat(autoware_control_center_msgs): add new fields to AutowareNodeReport
lexavtanke Feb 29, 2024
5e96d5b
feat(autoware_control_center): add manage relaunch of registered node…
lexavtanke Feb 29, 2024
85058c7
feat(autoware_node): add send normal state after registration
lexavtanke Feb 29, 2024
dbf66d3
style(pre-commit): autofix
pre-commit-ci[bot] Feb 29, 2024
66736fa
feat(autoware_control_center): add test cases to ACC and node_registry
lexavtanke Mar 11, 2024
e0e9a5b
style(pre-commit): autofix
pre-commit-ci[bot] Mar 11, 2024
21cf431
 feat(autoware_contorl_center): add README
lexavtanke Mar 12, 2024
5886294
style(pre-commit): autofix
pre-commit-ci[bot] Mar 12, 2024
3c84ee1
feat(autoware_control_center): update README
lexavtanke Mar 12, 2024
c9b643d
style(pre-commit): autofix
pre-commit-ci[bot] Mar 12, 2024
35d96f9
feat(autoware_node): update README
lexavtanke Mar 14, 2024
ecf6e7c
style(pre-commit): autofix
pre-commit-ci[bot] Mar 14, 2024
1745e06
fix(autoware_node): fix spell-check errors
lexavtanke Mar 14, 2024
d16e74b
style(pre-commit): autofix
pre-commit-ci[bot] Mar 14, 2024
ec21dbb
fix(autoware_node): fix spell-check error
lexavtanke Mar 14, 2024
e3e8220
feat(autoware_control_center): clean up CMakeLists
lexavtanke Mar 18, 2024
2593013
feat(test_node): clean up CMakeLists
lexavtanke Mar 18, 2024
f20393b
feat(autoware_node): clean up source
lexavtanke Mar 18, 2024
d7bb9f0
fix(autoware_control_center): fix uncrustiry errors
lexavtanke Mar 20, 2024
12cac57
fix(autoware_node): fix uncrustify errors
lexavtanke Mar 20, 2024
c43d40a
fix(test_node): fix uncrustify errors
lexavtanke Mar 20, 2024
c73913e
style(pre-commit): autofix
pre-commit-ci[bot] Mar 20, 2024
8ec287d
feat(autoware_node): improve readabilty
lexavtanke Mar 22, 2024
406cbdb
style(pre-commit): autofix
pre-commit-ci[bot] Mar 25, 2024
6c007a3
fix(autoware_node): fix typo
lexavtanke Mar 25, 2024
5c03cbb
feat(autoware_control_center): improve readability, define callbacks …
lexavtanke Mar 25, 2024
529c29e
feat(autoware_control_center): move node_status_map_ insert to regist…
lexavtanke Mar 25, 2024
7895ade
feat(autoware_control_center):  separate filter_deregister_services f…
lexavtanke Mar 25, 2024
5ab56d1
style(pre-commit): autofix
pre-commit-ci[bot] Mar 25, 2024
77b0c56
feat(autoware_control_center): update and parameterize startup_callba…
lexavtanke Mar 27, 2024
a2e8ce1
style(pre-commit): autofix
pre-commit-ci[bot] Mar 27, 2024
248f53a
fix(autoware_control_center): fix cpplint errors
lexavtanke Mar 27, 2024
26ac0bc
feat(autoware_control_center): update README
lexavtanke Mar 27, 2024
65303a7
refactor(autoware_control_center): remove unused dependencies, add p…
lexavtanke Mar 27, 2024
06ac84b
refactor(autoware_node): remove unused dependency, add package descri…
lexavtanke Mar 27, 2024
8646daf
refactor(autoware_node): perameterize register timer period, use SUCC…
lexavtanke Mar 27, 2024
9cfeb2c
style(pre-commit): autofix
pre-commit-ci[bot] Mar 27, 2024
0a28619
refactor(test_node): remove unused dependecy, add package description
lexavtanke Mar 28, 2024
f94e875
refactor(autoware_node): use SUCCESS from Status.msg
lexavtanke Mar 28, 2024
6334bf7
refactor(autoware_control_center): use SUCCESS from Status.msg
lexavtanke Mar 28, 2024
72413c2
refactor(autoware_control_center):rremove cspell exception
lexavtanke Mar 28, 2024
6906458
doc(autoware_control_center): add doxygen commets
lexavtanke Mar 29, 2024
d53e4c2
style(pre-commit): autofix
pre-commit-ci[bot] Mar 29, 2024
76ceb9d
fix(autoware_control_center): fix spell-check errors
lexavtanke Mar 29, 2024
689b0e3
docs(autoware_node): add doxygen comments
lexavtanke Mar 29, 2024
1c1e0be
style(pre-commit): autofix
pre-commit-ci[bot] Mar 29, 2024
e7eb03e
fix(autoware_node): fix spell-check error
lexavtanke Mar 29, 2024
dd20e6f
refactor(autoware_control_center):add const, use assignment  to varia…
lexavtanke Apr 2, 2024
0688a96
docs(autoware_control_center): add parameters explanation
lexavtanke Apr 2, 2024
04fa515
style(autoware_control_center, autoware_node, test_node): update year
lexavtanke Apr 2, 2024
b9d32c0
refactor(autoware_node): move aliases to header file
lexavtanke Apr 2, 2024
da888b0
refactor(autoware_node): add const, remove unnecessary vars
lexavtanke Apr 2, 2024
b5c5be6
style(pre-commit): autofix
pre-commit-ci[bot] Apr 2, 2024
c2e582e
registrate -> register
Apr 15, 2024
de50f2a
fix lint deps
Apr 15, 2024
db4e729
spelling ROS 2
Apr 15, 2024
3203c3a
remove unused aliases
Apr 15, 2024
e4f5fca
small spelling fixes
Apr 15, 2024
4613318
fix(autoware_control_center): fix clang-tidy warnings
lexavtanke Apr 17, 2024
fea1486
fix(autoware_control_center): fix clang-tidy warnings
lexavtanke Apr 17, 2024
a2a1508
fix(autoware_node, test_node): fix clang-tidy warnings
lexavtanke Apr 17, 2024
d834855
style(pre-commit): autofix
pre-commit-ci[bot] Apr 17, 2024
1d9eddf
fix clang-tidy warnings
lexavtanke Apr 17, 2024
16e99b9
style(pre-commit): autofix
pre-commit-ci[bot] Apr 17, 2024
c5161fd
fix(autoware_control_center): fix clang-tidy warnings
lexavtanke Apr 18, 2024
cfabbab
style(pre-commit): autofix
pre-commit-ci[bot] Apr 18, 2024
f07be46
supress clang-tidy performance warn on async_send_request
lexavtanke Apr 19, 2024
0e6d5ec
refactor(autoware_control_center): change startup procedure, remove t…
lexavtanke Apr 21, 2024
5b4d994
refactor, change log level to debug
lexavtanke Apr 21, 2024
e684b54
style(pre-commit): autofix
pre-commit-ci[bot] Apr 21, 2024
a7edbab
test clang-analyzer prefix for no lint
Apr 22, 2024
3641b52
empty nolint for now
Apr 22, 2024
3d6ff2e
add todo
Apr 22, 2024
9879f58
update namespaces, service/topic names
May 16, 2024
6a48e28
style(pre-commit): autofix
pre-commit-ci[bot] May 16, 2024
63a87b4
memory
May 16, 2024
da9470c
add launch
May 16, 2024
9da94d9
single instance, readme
May 17, 2024
588a1d3
style(pre-commit): autofix
pre-commit-ci[bot] May 17, 2024
8d2db52
refactor autoware_node
May 17, 2024
ed2efdb
style(pre-commit): autofix
pre-commit-ci[bot] May 17, 2024
343cbc5
refactor all
May 17, 2024
54d92cb
style(pre-commit): autofix
pre-commit-ci[bot] May 17, 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
37 changes: 37 additions & 0 deletions common/autoware_control_center/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.8)
project(autoware_control_center)

find_package(autoware_cmake REQUIRED)
autoware_package()

ament_auto_add_library(${PROJECT_NAME} SHARED
src/control_center_node.cpp
src/node_registry.cpp
src/include/control_center_node.hpp
src/include/node_registry.hpp
)

#rclcpp_components_register_node(${PROJECT_NAME}
# PLUGIN "autoware::control_center::ControlCenter"
# EXECUTABLE ${PROJECT_NAME}_node
#)

ament_auto_add_executable(${PROJECT_NAME}_node
src/control_center_main.cpp
)

if(BUILD_TESTING)
file(GLOB_RECURSE TEST_SOURCES test/*.cpp)
ament_add_ros_isolated_gtest(test_autoware_control_center ${TEST_SOURCES})
target_include_directories(test_autoware_control_center PRIVATE src/include)
target_link_libraries(test_autoware_control_center ${PROJECT_NAME})
ament_target_dependencies(test_autoware_control_center
rclcpp
rclcpp_lifecycle
autoware_utils
autoware_control_center_msgs)
endif()

ament_auto_package(INSTALL_TO_SHARE
launch
config)
104 changes: 104 additions & 0 deletions common/autoware_control_center/README.md
xmfcx marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Autoware Control Center

## Abbreviations

- **ACC:** Autoware Control Center
- **AN:** Autoware Node

## Overview

The Autoware Control Center (ACC) is a core package within the Autoware system, designed to manage and monitor Autoware
nodes (ANs).

It provides services for the registration, de-registration, and error handling of ANs, as well as publishing reports on
their status.

ACC maintains an internal registry to keep track of registered ANs.

## Interfaces

### Services

#### Register

Registers an Autoware node to the ACC.

- **Topic:** `/autoware/control_center/srv/register`
- **Type:** `autoware_control_center_msgs::srv::Register`

#### Deregister

De-registers an Autoware node from the ACC.

- **Topic:** `/autoware/control_center/srv/deregister`
- **Type:** `autoware_control_center_msgs::srv::Deregister`

#### ReportState

Reports the state of an Autoware node to the ACC.

- **Topic:** `/autoware/control_center/srv/report_state`
- **Type:** `autoware_control_center_msgs::srv::ReportState`

### Subscribers

#### Heartbeat (**Source:** Autoware Node)

Subscribes to the heartbeat topic of an Autoware node after its registration.
ACC controls the liveness of Autoware nodes by monitoring this topic.

- **Topic:** `/autoware_node_name/heartbeat`
- **Type:** `autoware_control_center_msgs::msg::Heartbeat`
- **Source:** An Autoware Node

### Publishers

#### NodeReports

Publishes reports on the current status of registered Autoware nodes.

- **Topic:** `/autoware/control_center/node_reports`
- **Type:** `autoware_control_center_msgs::msg::NodeReport`

## Parameters

| Name | Type | Default Value | Description |
| --------------------- | -------- | ------------- | ----------------------------------------------------------------------------------- |
| `lease_duration_ms` | `double` | `220.0` | If not received another heartbeat within this duration, AN will be considered dead. |
| `report_publish_rate` | `double` | `1.0` | Publish NodeReports rate (hz) |

## Singleton Constraint

To ensure that only one instance of the ACC is running at any given time, two checks are performed in the main function:

### 1. Lockfile Check

This lockfile mechanism is fast and reliable for single-machine scenarios.
It prevents multiple instances of ACC from running concurrently on the same machine.

**Path:** `/tmp/autoware_control_center_node.lock`

### 2. Network-Wide Node Name Check

This involves gathering all node names and comparing them with the ACC node name (`/autoware/control_center`).
While this method is slower and less reliable than the lockfile check,
it is necessary for scenarios where the ACC is run across a network of machines.
This ensures that no other instance of ACC is running on any other machine within the network.

## Usage

`ros2 launch autoware_control_center control_center.launch.xml`

## Workflow

When an Autoware Node starts, it registers itself with the ACC.

The ACC then subscribes to the heartbeat topic of the Autoware node to monitor its liveness.

If the ACC does not receive a heartbeat from the Autoware node within the specified lease duration,
it considers the node to be dead.

## Credits

- Heartbeat functionality is based on ROS 2 [software_watchdogs](https://github.com/ros-safety/software_watchdogs)
package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**:
ros__parameters:
lease_duration_ms: 220.0
report_publish_rate: 1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<launch>
<arg name="param_path" default="$(find-pkg-share autoware_control_center)/config/control_center.param.yaml"/>

<node pkg="autoware_control_center" exec="autoware_control_center_node" name="control_center" output="screen">
<param from="$(var param_path)"/>
</node>
</launch>
32 changes: 32 additions & 0 deletions common/autoware_control_center/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>autoware_control_center</name>
<version>0.0.0</version>
<description>
Autoware Control Center (ACC) is an Autoware.Core package designed to manage
and monitor Autoware nodes within a system.
</description>
<maintainer email="[email protected]">M. Fatih Cırıt</maintainer>
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>autoware_control_center_msgs</depend>
<depend>autoware_utils</depend>
<depend>lifecycle_msgs</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>rclcpp_lifecycle</depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_cmake_ros</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>
<test_depend>autoware_utils</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
93 changes: 93 additions & 0 deletions common/autoware_control_center/src/control_center_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2024 The Autoware Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "include/control_center_node.hpp"

#include <rclcpp/rclcpp.hpp>

#include <fcntl.h>
#include <sys/file.h>
#include <unistd.h>

#include <memory>

const char * LOCK_FILE = "/tmp/autoware_control_center_node.lock";

bool lock_file()
{
int fd = open(LOCK_FILE, O_CREAT | O_RDWR, 0666);
if (fd == -1) {
RCLCPP_FATAL(rclcpp::get_logger(""), "Failed to open lock file");
return false;
}

if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
if (errno == EWOULDBLOCK) {
RCLCPP_FATAL(rclcpp::get_logger(""), "Another instance is already running");
} else {
RCLCPP_FATAL(rclcpp::get_logger(""), "Failed to lock file");
}
close(fd);
return false;
}

// Keep the file descriptor open to maintain the lock
return true;
}

void unlock_file(int fd)
{
if (fd != -1) {
flock(fd, LOCK_UN);
close(fd);
}
}

int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);

// Lock file to prevent multiple instances on the same machine
int lock_fd = open(LOCK_FILE, O_CREAT | O_RDWR, 0666);
if (!lock_file()) {
return 1;
}

// Check if node already exists to prevent multiple instances across the network
// It's a bit slow but better than nothing
const auto node_name_with_namespace = std::string("/autoware/control_center");

auto node_already_exists = [](const std::string & node_name) {
auto temp_node = rclcpp::Node::make_shared("temp_node");
auto all_nodes = temp_node->get_node_names();
return std::find(all_nodes.begin(), all_nodes.end(), node_name) != all_nodes.end();
};

if (node_already_exists(node_name_with_namespace)) {
RCLCPP_FATAL(
rclcpp::get_logger(""), "Node %s already exists", node_name_with_namespace.c_str());
unlock_file(lock_fd);
throw std::runtime_error("Node already exists");
}

// Instantiate the control center node, hopefully the only instance
auto control_center =
std::make_shared<autoware::control_center::ControlCenter>(rclcpp::NodeOptions());
rclcpp::executors::MultiThreadedExecutor exec;
exec.add_node(control_center->get_node_base_interface());
exec.spin();
unlock_file(lock_fd);
rclcpp::shutdown();
return 0;
}
Loading
Loading