Skip to content

Commit 1696c2b

Browse files
feat: add RTC interface (#765)
* feature(rtc_interface): add files Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * feature(rtc_interface): implement functions Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * feature(rtc_interface): reimprement functions to use CooperateCommands and write README.md Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * feature(rtc_interface): fix README Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * feature(rtc_interface): add getModuleType() Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * feature(rtc_interface): fix definition of constructor Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * feature(rtc_interface): fix time stamp Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * feature(rtc_interface): fix README Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * feature(rtc_interface): add isRegistered and clearCooperateStatus Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * ci(pre-commit): autofix Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c7766f5 commit 1696c2b

File tree

5 files changed

+499
-0
lines changed

5 files changed

+499
-0
lines changed

planning/rtc_interface/CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(rtc_interface)
3+
4+
### Compile options
5+
if(NOT CMAKE_CXX_STANDARD)
6+
set(CMAKE_CXX_STANDARD 17)
7+
endif()
8+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
9+
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
10+
endif()
11+
12+
find_package(ament_cmake_auto REQUIRED)
13+
ament_auto_find_build_dependencies()
14+
15+
ament_auto_add_library(rtc_interface SHARED
16+
src/rtc_interface.cpp
17+
)
18+
19+
# Test
20+
if(BUILD_TESTING)
21+
find_package(ament_lint_auto REQUIRED)
22+
ament_lint_auto_find_test_dependencies()
23+
endif()
24+
25+
ament_auto_package()

planning/rtc_interface/README.md

+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# RTC Interface
2+
3+
## Purpose
4+
5+
RTC Interface is an interface to publish the decision status of behavior planning modules and receive execution command from external of an autonomous driving system.
6+
7+
## Inner-workings / Algorithms
8+
9+
### Usage example
10+
11+
```c++
12+
// Generate instance (in this example, "intersection" is selected)
13+
rtc_interface::RTCInterface rtc_interface(node, "intersection");
14+
15+
// Generate UUID
16+
const unique_identifier_msgs::msg::UUID uuid = generateUUID(getModuleId());
17+
18+
// Repeat while module is running
19+
while (...) {
20+
// Get safety status of the module corresponding to the module id
21+
const bool safe = ...
22+
23+
// Get distance to the object corresponding to the module id
24+
const double distance = ...
25+
26+
// Get time stamp
27+
const rclcpp::Time stamp = ...
28+
29+
// Update status
30+
rtc_interface.updateCooperateStatus(uuid, safe, distance, stamp);
31+
32+
if (rtc_interface.isActivated(uuid)) {
33+
// Execute planning
34+
} else {
35+
// Stop planning
36+
}
37+
// Get time stamp
38+
const rclcpp::Time stamp = ...
39+
40+
// Publish status topic
41+
rtc_interface.publishCooperateStatus(stamp);
42+
}
43+
44+
// Remove the status from array
45+
rtc_interface.removeCooperateStatus(uuid);
46+
```
47+
48+
## Inputs / Outputs
49+
50+
### RTCInterface (Constructor)
51+
52+
```c++
53+
rtc_interface::RTCInterface(rclcpp::Node & node, const std::string & name);
54+
```
55+
56+
#### Description
57+
58+
A constructor for `rtc_interface::RTCInterface`.
59+
60+
#### Input
61+
62+
- `node` : Node calling this interface
63+
- `name` : Name of cooperate status array topic and cooperate commands service
64+
- Cooperate status array topic name : `~/{name}/cooperate_status`
65+
- Cooperate commands service name : `~/{name}/cooperate_commands`
66+
67+
#### Output
68+
69+
An instance of `RTCInterface`
70+
71+
### publishCooperateStatus
72+
73+
```c++
74+
rtc_interface::publishCooperateStatus(const rclcpp::Time & stamp)
75+
```
76+
77+
#### Description
78+
79+
Publish registered cooperate status.
80+
81+
#### Input
82+
83+
- `stamp` : Time stamp
84+
85+
#### Output
86+
87+
Nothing
88+
89+
### updateCooperateStatus
90+
91+
```c++
92+
rtc_interface::updateCooperateStatus(const unique_identifier_msgs::msg::UUID & uuid, const bool safe, const double distance, const rclcpp::Time & stamp)
93+
```
94+
95+
#### Description
96+
97+
Update cooperate status corresponding to `uuid`.
98+
If cooperate status corresponding to `uuid` is not registered yet, add new cooperate status.
99+
100+
#### Input
101+
102+
- `uuid` : UUID for requesting module
103+
- `safe` : Safety status of requesting module
104+
- `distance` : Distance to the object from ego vehicle
105+
- `stamp` : Time stamp
106+
107+
#### Output
108+
109+
Nothing
110+
111+
### removeCooperateStatus
112+
113+
```c++
114+
rtc_interface::removeCooperateStatus(const unique_identifier_msgs::msg::UUID & uuid)
115+
```
116+
117+
#### Description
118+
119+
Remove cooperate status corresponding to `uuid` from registered statuses.
120+
121+
#### Input
122+
123+
- `uuid` : UUID for expired module
124+
125+
#### Output
126+
127+
Nothing
128+
129+
### clearCooperateStatus
130+
131+
```c++
132+
rtc_interface::clearCooperateStatus()
133+
```
134+
135+
#### Description
136+
137+
Remove all cooperate statuses.
138+
139+
#### Input
140+
141+
Nothing
142+
143+
#### Output
144+
145+
Nothing
146+
147+
### isActivated
148+
149+
```c++
150+
rtc_interface::isActivated(const unique_identifier_msgs::msg::UUID & uuid)
151+
```
152+
153+
#### Description
154+
155+
Return received command status corresponding to `uuid`.
156+
157+
#### Input
158+
159+
- `uuid` : UUID for checking module
160+
161+
#### Output
162+
163+
If received command is `ACTIVATED`, return `true`.
164+
If not, return `false`.
165+
166+
### isRegistered
167+
168+
```c++
169+
rtc_interface::isRegistered(const unique_identifier_msgs::msg::UUID & uuid)
170+
```
171+
172+
#### Description
173+
174+
Return `true` if `uuid` is registered.
175+
176+
#### Input
177+
178+
- `uuid` : UUID for checking module
179+
180+
#### Output
181+
182+
If `uuid` is registered, return `true`.
183+
If not, return `false`.
184+
185+
## Assumptions / Known limits
186+
187+
## Future extensions / Unimplemented parts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2022 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 RTC_INTERFACE__RTC_INTERFACE_HPP_
16+
#define RTC_INTERFACE__RTC_INTERFACE_HPP_
17+
18+
#include "rclcpp/rclcpp.hpp"
19+
20+
#include "tier4_rtc_msgs/msg/command.hpp"
21+
#include "tier4_rtc_msgs/msg/cooperate_command.hpp"
22+
#include "tier4_rtc_msgs/msg/cooperate_response.hpp"
23+
#include "tier4_rtc_msgs/msg/cooperate_status.hpp"
24+
#include "tier4_rtc_msgs/msg/cooperate_status_array.hpp"
25+
#include "tier4_rtc_msgs/msg/module.hpp"
26+
#include "tier4_rtc_msgs/srv/cooperate_commands.hpp"
27+
#include <unique_identifier_msgs/msg/uuid.hpp>
28+
29+
#include <string>
30+
#include <vector>
31+
32+
namespace rtc_interface
33+
{
34+
using tier4_rtc_msgs::msg::Command;
35+
using tier4_rtc_msgs::msg::CooperateCommand;
36+
using tier4_rtc_msgs::msg::CooperateResponse;
37+
using tier4_rtc_msgs::msg::CooperateStatus;
38+
using tier4_rtc_msgs::msg::CooperateStatusArray;
39+
using tier4_rtc_msgs::msg::Module;
40+
using tier4_rtc_msgs::srv::CooperateCommands;
41+
using unique_identifier_msgs::msg::UUID;
42+
43+
class RTCInterface
44+
{
45+
public:
46+
RTCInterface(rclcpp::Node & node, const std::string & name);
47+
void publishCooperateStatus(const rclcpp::Time & stamp);
48+
void updateCooperateStatus(
49+
const UUID & uuid, const bool safe, const double distance, const rclcpp::Time & stamp);
50+
void removeCooperateStatus(const UUID & uuid);
51+
void clearCooperateStatus();
52+
bool isActivated(const UUID & uuid) const;
53+
bool isRegistered(const UUID & uuid) const;
54+
55+
private:
56+
void onCooperateCommandService(
57+
const CooperateCommands::Request::SharedPtr request,
58+
const CooperateCommands::Response::SharedPtr responses);
59+
rclcpp::Logger getLogger() const;
60+
61+
rclcpp::Publisher<CooperateStatusArray>::SharedPtr pub_statuses_;
62+
rclcpp::Service<CooperateCommands>::SharedPtr srv_commands_;
63+
64+
rclcpp::Logger logger_;
65+
Module module_;
66+
CooperateStatusArray registered_status_;
67+
};
68+
69+
} // namespace rtc_interface
70+
71+
#endif // RTC_INTERFACE__RTC_INTERFACE_HPP_

planning/rtc_interface/package.xml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<package format="3">
3+
<name>rtc_interface</name>
4+
<version>0.1.0</version>
5+
<description>The rtc_interface package</description>
6+
7+
<maintainer email="fumiya.watanabe@tier4.jp">Fumiya Watanabe</maintainer>
8+
9+
<license>Apache License 2.0</license>
10+
11+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
12+
13+
<depend>rclcpp</depend>
14+
<depend>tier4_rtc_msgs</depend>
15+
<depend>unique_identifier_msgs</depend>
16+
17+
<test_depend>ament_lint_auto</test_depend>
18+
<test_depend>autoware_lint_common</test_depend>
19+
20+
<export>
21+
<build_type>ament_cmake</build_type>
22+
</export>
23+
</package>

0 commit comments

Comments
 (0)