Skip to content

Commit 80930c4

Browse files
committed
feat: add leader election converter
Signed-off-by: TetsuKawa <kawaguchitnon@icloud.com>
1 parent 08bf607 commit 80930c4

16 files changed

+1084
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(leader_election_converter)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
ament_auto_add_library(common_converter SHARED
8+
src/common/converter/availability_converter.cpp
9+
src/common/converter/mrm_converter.cpp
10+
src/common/converter/log_converter.cpp
11+
)
12+
13+
target_include_directories(common_converter PRIVATE
14+
src/common/converter
15+
)
16+
17+
ament_auto_add_library(${PROJECT_NAME} SHARED
18+
src/node/leader_election_converter.cpp
19+
)
20+
target_include_directories(${PROJECT_NAME} PRIVATE src/common/converter)
21+
22+
target_link_libraries(${PROJECT_NAME} common_converter)
23+
24+
rclcpp_components_register_node(${PROJECT_NAME}
25+
PLUGIN "leader_election_converter::LeaderElectionConverter"
26+
EXECUTABLE ${PROJECT_NAME}_node
27+
EXECUTOR MultiThreadedExecutor
28+
)
29+
30+
ament_auto_package(INSTALL_TO_SHARE config launch)
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# leader_election_converter
2+
3+
## Overview
4+
5+
The leader election converter node is responsible for relaying UDP packets and ROS2 topics between the leader_election invoked by systemd and Autoware executed on ROS2.
6+
7+
## availability converter
8+
9+
The availability converter subscribes `/system/operation_mode/availability` and `/vehicle/status/mrm_state`, adds them together into a structure called `Availability` and sends it as a udp packet.
10+
11+
12+
### Interface
13+
14+
| Interface Type | Interface Name | Data Type | Description |
15+
| -------------- | ------------------------------------- | ------------------------------------------------- | ---------------------------------- |
16+
| subscriber | `/system/operation_mode/availability` | `tier4_system_msgs/msg/OperationModeAvailability` | Usable behavior of the ego. |
17+
| subscriber | `/vehicle/status/mrm_state` | `autoware_auto_vehicle_msgs/msg/ControlModeReport`| Ego control mode. |
18+
| udp sender | none | `struct Availability` | Combination of the above two. |
19+
20+
21+
## mrm converte
22+
The mrm converter subscribes `/system/fail_safe/mrm_state` into a structure called `MrmState` and sends it as a UDP packet.
23+
In addition, it receives a udp packet`MrmState` and publish `/system/mrm_request`.
24+
25+
### Interface
26+
27+
| Interface Type | Interface Name | Data Type | Description |
28+
| -------------- | ------------------------------------- | ------------------------------------------------- | ---------------------------------- |
29+
| subscriber | `/system/fail_safe/mrm_state` | `tier4_system_msgs/msg/MrmState` | MRM status of each ECU. |
30+
| udp sender | none | `struct MrmState` | Same as above. |
31+
| publisher | `/system/election/mrm_request` | `tier4_system_msgs/msg/MrmBehavior` | Request of MRM behavior. |
32+
| udp receiver | none | `struct MrmRequest` | Same as above. |
33+
34+
35+
## log converter
36+
The log converter receive udp packets into a structure called `ElectionCommunication` and `ElectionStatus`, and publish `/system/election/communication`,
37+
`/system/election/status`, and `/system/fail_safe/over_all/mrm_state`.
38+
39+
### Interface
40+
41+
| Interface Type | Interface Name | Data Type | Description |
42+
| -------------- | ------------------------------------- | ------------------------------------------------- | ---------------------------------- |
43+
| udp receiver | none | `struct ElectionCommunication` | messages amoung election nodes. |
44+
| udp receiver | none | `struct ElectionStatus` | Leader Election status. |
45+
| publisher | `/system/election/communication` | `tier4_system_msgs/msg/ElectionCommunication` | messages amoung election nodes. |
46+
| publisher | `/system/election/status` | `tier4_system_msgs/msg/MrmState` | Leader Election status. |
47+
| publisher | `/system/fail_safe/over_all/mrm_state`| `autoware_adapi_v1_msgs/msg/mrm_state` | System-wode MRM status. |
48+
49+
## Parameters
50+
51+
{{ json_to_markdown("system/leader_election_converter/schema/leader_election_converter.schema.json") }}
52+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**:
2+
ros__parameters:
3+
availability_dest_ip: "127.0.0.1"
4+
availability_dest_port: "9000"
5+
mrm_state_dest_ip: "127.0.0.1"
6+
mrm_state_dest_port: "9001"
7+
mrm_request_src_ip: "127.0.0.1"
8+
mrm_request_src_port: "9002"
9+
election_communication_src_ip: "127.0.0.1"
10+
election_communication_src_port: "9003"
11+
election_status_src_ip: "127.0.0.1"
12+
election_status_src_port: "9004"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<launch>
2+
<arg name="param_file" default="$(find-pkg-share leader_election_converter)/config/leader_electioin_converter.param.yaml"/>
3+
<arg name="input_control_mode" default="/vehicle/status/control_mode"/>
4+
<arg name="input_operation_mode_availability" default="/system/operation_mode/availability"/>
5+
<arg name="input_mrm_state" default="/system/fail_safe/mrm_state"/>
6+
<arg name="output_mrm_request" default="/system/mrm_request"/>
7+
<arg name="output_over_all_mrm_state" default="/system/fail_safe/over_all/mrm_state"/>
8+
<arg name="output_election_communication" default="/system/election_communication"/>
9+
<arg name="output_election_status" default="/system/election_status"/>
10+
<node pkg="leader_election_converter" exec="leader_election_converter_node">
11+
<param from="$(var param_file)"/>
12+
<remap from="~/input/control_mode" to="$(var input_control_mode)"/>
13+
<remap from="~/input/operation_mode_availability" to="$(var input_operation_mode_availability)"/>
14+
<remap from="~/input/mrm_state" to="$(var input_mrm_state)"/>
15+
<remap from="~/output/mrm_request" to="$(var output_mrm_request)"/>
16+
<remap from="~/output/over_all_mrm_state" to="$(var output_over_all_mrm_state)"/>
17+
<remap from="~/output/election_communication" to="$(var output_election_communication)"/>
18+
<remap from="~/output/election_status" to="$(var output_election_status)"/>
19+
</node>
20+
</launch>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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>leader_election_converter</name>
5+
<version>0.1.0</version>
6+
<description>The leader election converter package</description>
7+
<maintainer email="tetsuhiro.kawaguchi@tier4.jp">TetsuKawa</maintainer>
8+
<license>Apache License 2.0</license>
9+
10+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
11+
<buildtool_depend>autoware_cmake</buildtool_depend>
12+
13+
<depend>rclcpp</depend>
14+
<depend>rclcpp_components</depend>
15+
<depend>tier4_system_msgs</depend>
16+
<depend>autoware_auto_vehicle_msgs</depend>
17+
<depend>autoware_adapi_v1_msgs</depend>
18+
19+
<test_depend>ament_lint_auto</test_depend>
20+
<test_depend>autoware_lint_common</test_depend>
21+
22+
<export>
23+
<build_type>ament_cmake</build_type>
24+
</export>
25+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "Parameters for leader election converter",
4+
"type": "object",
5+
"definitions": {
6+
"leader_election_converter": {
7+
"type": "object",
8+
"properties": {
9+
"availability_dest_ip": {
10+
"type": "string",
11+
"description": "IP address of the destination of avaialability",
12+
"default": "127.0.0.1"
13+
},
14+
"availability_dest_port": {
15+
"type": "string",
16+
"description": "Port of the destination of avaialability",
17+
"default": "9000"
18+
},
19+
"mrm_state_dest_ip": {
20+
"type": "string",
21+
"description": "IP address of the destination of mrm_state",
22+
"default": "127.0.0.1"
23+
},
24+
"mrm_state_dest_port": {
25+
"type": "string",
26+
"description": "Port of the destination of mrm_state",
27+
"default": "9001"
28+
},
29+
"mrm_request_src_ip": {
30+
"type": "string",
31+
"description": "IP address of the source of mrm_request",
32+
"default": "127.0.0.1"
33+
},
34+
"mrm_request_src_port": {
35+
"type": "string",
36+
"description": "Port of the source of mrm_request",
37+
"default": "9002"
38+
},
39+
"election_communication_src_ip": {
40+
"type": "string",
41+
"description": "IP address of the source of electioin_communication",
42+
"default": "127.0.0.1"
43+
},
44+
"election_communication_src_port": {
45+
"type": "string",
46+
"description": "Port of the source of electioin_communication",
47+
"default": "9003"
48+
},
49+
"election_status_src_ip": {
50+
"type": "string",
51+
"description": "IP address of the source of election_status",
52+
"default": "127.0.0.1"
53+
},
54+
"election_status_src_port": {
55+
"type": "string",
56+
"description": "Port of the source of election_status",
57+
"default": "9004"
58+
}
59+
},
60+
"required": [
61+
"availability_dest_ip",
62+
"availability_dest_port",
63+
"mrm_state_dest_ip",
64+
"mrm_state_dest_port",
65+
"mrm_request_src_ip",
66+
"mrm_request_src_port",
67+
"election_communication_src_ip",
68+
"election_communication_src_port",
69+
"election_status_src_ip",
70+
"election_status_src_port"
71+
],
72+
"additionalProperties": false
73+
}
74+
},
75+
"properties": {
76+
"/**": {
77+
"type": "object",
78+
"properties": {
79+
"ros__parameters": {
80+
"$ref": "#/definitions/leader_election_converter"
81+
}
82+
},
83+
"required": ["ros__parameters"],
84+
"additionalProperties": false
85+
}
86+
},
87+
"required": ["/**"],
88+
"additionalProperties": false
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2024 The Autoware Contributors
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+
16+
#include "rclcpp/rclcpp.hpp"
17+
#include "availability_converter.hpp"
18+
19+
namespace leader_election_converter
20+
{
21+
22+
AvailabilityConverter::AvailabilityConverter(rclcpp::Node * node)
23+
: node_(node) {}
24+
25+
void AvailabilityConverter::setUdpSender(const std::string & dest_ip, const std::string & dest_port)
26+
{
27+
udp_availability_sender_ = std::make_unique<UdpSender<Availability>>(dest_ip, dest_port);
28+
}
29+
30+
void AvailabilityConverter::setSubscriber()
31+
{
32+
const auto qos = rclcpp::QoS(1).transient_local();
33+
availability_callback_group_ = node_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
34+
rclcpp::SubscriptionOptions availability_options = rclcpp::SubscriptionOptions();
35+
availability_options.callback_group = availability_callback_group_;
36+
37+
control_mode_callback_group_ = node_->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive, false);
38+
rclcpp::SubscriptionOptions control_mode_options = rclcpp::SubscriptionOptions();
39+
control_mode_options.callback_group = control_mode_callback_group_;
40+
auto not_executed_callback = []([[maybe_unused]] const typename autoware_auto_vehicle_msgs::msg::ControlModeReport::ConstSharedPtr msg) {};
41+
42+
sub_operation_mode_availability_ = node_->create_subscription<tier4_system_msgs::msg::OperationModeAvailability>(
43+
"~/input/operation_mode_availability", qos,
44+
std::bind(&AvailabilityConverter::convertToUdp, this, std::placeholders::_1), availability_options);
45+
46+
sub_control_mode_ = node_->create_subscription<autoware_auto_vehicle_msgs::msg::ControlModeReport>(
47+
"~/input/control_mode", qos, not_executed_callback, control_mode_options);
48+
49+
}
50+
51+
void AvailabilityConverter::convertToUdp(
52+
const tier4_system_msgs::msg::OperationModeAvailability::ConstSharedPtr availability_msg)
53+
{
54+
auto control_mode_report = std::make_shared<autoware_auto_vehicle_msgs::msg::ControlModeReport>();
55+
rclcpp::MessageInfo message_info;
56+
const bool success = sub_control_mode_->take(*control_mode_report, message_info);
57+
if (success) {
58+
Availability availability;
59+
availability.mode = control_mode_report->mode;
60+
availability.stop = availability_msg->stop;
61+
availability.autonomous = availability_msg->autonomous;
62+
availability.local = availability_msg->local;
63+
availability.remote = availability_msg->remote;
64+
availability.emergency_stop = availability_msg->emergency_stop;
65+
availability.comfortable_stop = availability_msg->comfortable_stop;
66+
availability.pull_over = availability_msg->pull_over;
67+
udp_availability_sender_->send(availability);
68+
} else {
69+
RCLCPP_ERROR(node_->get_logger(), "Failed to take control mode report");
70+
}
71+
}
72+
73+
} // namespace leader_election_converter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2024 The Autoware Contributors
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 COMMON__AVAILABILITY_CONVERTER_HPP_
16+
#define COMMON__AVAILABILITY_CONVERTER_HPP_
17+
18+
#include <autoware_auto_vehicle_msgs/msg/control_mode_report.hpp>
19+
#include <tier4_system_msgs/msg/operation_mode_availability.hpp>
20+
21+
#include <rclcpp/rclcpp.hpp>
22+
23+
#include "udp_sender.hpp"
24+
25+
26+
namespace leader_election_converter
27+
{
28+
29+
struct Availability
30+
{
31+
autoware_auto_vehicle_msgs::msg::ControlModeReport::_mode_type mode;
32+
tier4_system_msgs::msg::OperationModeAvailability::_stop_type stop;
33+
tier4_system_msgs::msg::OperationModeAvailability::_autonomous_type autonomous;
34+
tier4_system_msgs::msg::OperationModeAvailability::_local_type local;
35+
tier4_system_msgs::msg::OperationModeAvailability::_remote_type remote;
36+
tier4_system_msgs::msg::OperationModeAvailability::_emergency_stop_type emergency_stop;
37+
tier4_system_msgs::msg::OperationModeAvailability::_comfortable_stop_type comfortable_stop;
38+
tier4_system_msgs::msg::OperationModeAvailability::_pull_over_type pull_over;
39+
// tier4_system_msgs::msg::OperationModeAvailability::_stop_next_bus_stop_type stop_next_bus_stop;
40+
};
41+
42+
class AvailabilityConverter
43+
{
44+
45+
public:
46+
AvailabilityConverter(rclcpp::Node * node);
47+
~AvailabilityConverter() = default;
48+
49+
void setUdpSender(const std::string & dest_ip, const std::string & dest_port);
50+
void setSubscriber();
51+
void convertToUdp(const tier4_system_msgs::msg::OperationModeAvailability::ConstSharedPtr availability_msg);
52+
53+
private:
54+
rclcpp::Node * node_;
55+
std::unique_ptr<UdpSender<Availability>> udp_availability_sender_;
56+
rclcpp::CallbackGroup::SharedPtr availability_callback_group_;
57+
rclcpp::CallbackGroup::SharedPtr control_mode_callback_group_;
58+
rclcpp::Subscription<autoware_auto_vehicle_msgs::msg::ControlModeReport>::SharedPtr sub_control_mode_;
59+
rclcpp::Subscription<tier4_system_msgs::msg::OperationModeAvailability>::SharedPtr sub_operation_mode_availability_;
60+
61+
};
62+
63+
} // namespace leader_election_converter
64+
65+
#endif // COMMON__AVAILABILITY_CONVERTER_HPP_

0 commit comments

Comments
 (0)