Skip to content

Commit 6fc1f54

Browse files
authored
feat(emergency_goal_manager, mrm_pull_over_manager): add mrm pull over (#1231)
* feat(emergency_goal_manager, mrm_pull_over_manager): add mrm pull over Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * feat(tier4_system_launch): launch nodes for mrm pull over Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> * chore(mrm_pull_over_manager): change pull over points for shiojiri lv4 Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com> --------- Signed-off-by: Makoto Kurihara <mkuri8m@gmail.com>
1 parent 10a8dce commit 6fc1f54

19 files changed

+1082
-0
lines changed

launch/tier4_system_launch/launch/system.launch.xml

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
<arg name="config_file" value="$(var mrm_emergency_stop_operator_param_path)"/>
106106
</include>
107107
</group>
108+
<group>
109+
<include file="$(find-pkg-share mrm_pull_over_manager)/launch/mrm_pull_over_manager.launch.xml"/>
110+
</group>
111+
<group>
112+
<include file="$(find-pkg-share emergency_goal_manager)/launch/emergency_goal_manager.launch.xml"/>
113+
</group>
108114

109115
<!-- MRM Handler -->
110116
<group if="$(var use_diagnostic_graph)">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(emergency_goal_manager)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
ament_auto_add_executable(emergency_goal_manager
8+
src/emergency_goal_manager_node.cpp
9+
src/emergency_goal_manager_core.cpp
10+
)
11+
12+
ament_auto_package(INSTALL_TO_SHARE
13+
launch
14+
config
15+
)
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# emergency_goal_manager
2+
3+
## Purpose
4+
5+
The Emergency goal manager is responsible for coordinating the goal poses for emergency rerouting and communicating it to the mission planner.
6+
7+
## Inner-workings / Algorithms
8+
9+
TBD.
10+
11+
## Inputs / Outputs
12+
13+
### Input
14+
15+
| Name | Type | Description |
16+
| --------------------------------------- | ---------------------------------------------------- | ----------------------------- |
17+
| `~/input/emergency_goals` | `tier4_system_msgs::msg::EmergencyGoalsStamped` | Candidates for emergency goal |
18+
| `~/input/emergency_goals_clear_command` | `tier4_system_msgs::msg::EmergencyGoalsClearCommand` | Clear command |
19+
20+
### Output
21+
22+
| Name | Type | Description |
23+
| ---------------------------------------------------------------- | --------------------------------------------- | ------------------------ |
24+
| `/planning/mission_planning/mission_planner/srv/set_mrm_route` | `autoware_adapi_v1_msgs::srv::SetRoutePoints` | Set route points for MRM |
25+
| `/planning/mission_planning/mission_planner/srv/clear_mrm_route` | `autoware_adapi_v1_msgs::srv::ClearRoute` | Clear route for MRM |
26+
27+
## Parameters
28+
29+
No parameters.
30+
31+
## Assumptions / Known limits
32+
33+
TBD.

system/emergency_goal_manager/config/emergency_goal_manager.param.yaml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2023 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 EMERGENCY_GOAL_MANAGER_CORE_HPP_
16+
#define EMERGENCY_GOAL_MANAGER_CORE_HPP_
17+
18+
#include <rclcpp/rclcpp.hpp>
19+
20+
#include <autoware_adapi_v1_msgs/srv/clear_route.hpp>
21+
#include <autoware_adapi_v1_msgs/srv/set_route_points.hpp>
22+
#include <geometry_msgs/msg/pose.hpp>
23+
#include <std_srvs/srv/trigger.hpp>
24+
#include <tier4_system_msgs/msg/emergency_goals_clear_command.hpp>
25+
#include <tier4_system_msgs/msg/emergency_goals_stamped.hpp>
26+
27+
#include <queue>
28+
#include <string>
29+
#include <unordered_map>
30+
31+
namespace emergency_goal_manager
32+
{
33+
class EmergencyGoalManager : public rclcpp::Node
34+
{
35+
public:
36+
EmergencyGoalManager();
37+
38+
private:
39+
using SetRoutePoints = autoware_adapi_v1_msgs::srv::SetRoutePoints;
40+
using ClearRoute = autoware_adapi_v1_msgs::srv::ClearRoute;
41+
42+
// Subscriber
43+
rclcpp::Subscription<tier4_system_msgs::msg::EmergencyGoalsStamped>::SharedPtr
44+
sub_emergency_goals_;
45+
rclcpp::Subscription<tier4_system_msgs::msg::EmergencyGoalsClearCommand>::SharedPtr
46+
sub_emergency_goals_clear_command_;
47+
48+
void onEmergencyGoals(const tier4_system_msgs::msg::EmergencyGoalsStamped::SharedPtr msg);
49+
void onEmergencyGoalsClearCommand(
50+
const tier4_system_msgs::msg::EmergencyGoalsClearCommand::SharedPtr msg);
51+
52+
// Client
53+
rclcpp::CallbackGroup::SharedPtr client_set_mrm_route_points_callback_group_;
54+
rclcpp::Client<SetRoutePoints>::SharedPtr client_set_mrm_route_points_;
55+
rclcpp::CallbackGroup::SharedPtr client_clear_mrm_route_callback_group_;
56+
rclcpp::Client<ClearRoute>::SharedPtr client_clear_mrm_route_;
57+
58+
// Variables
59+
std::unordered_map<std::string, std::queue<geometry_msgs::msg::Pose>> emergency_goals_map_;
60+
61+
// Algorithm
62+
void callSetMrmRoutePoints();
63+
void callClearMrmRoute();
64+
};
65+
} // namespace emergency_goal_manager
66+
67+
#endif // EMERGENCY_GOAL_MANAGER_CORE_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<launch>
2+
<arg name="input_emergency_goals" default="/system/mrm/pull_over_manager/emergency_goals"/>
3+
<arg name="input_goals_clear_command" default="/system/mrm/pull_over_manager/goals_clear_command"/>
4+
5+
<node pkg="emergency_goal_manager" exec="emergency_goal_manager" name="emergency_goal_manager" output="screen">
6+
<remap from="~/input/emergency_goals" to="$(var input_emergency_goals)"/>
7+
<remap from="~/input/emergency_goals_clear_command" to="$(var input_goals_clear_command)"/>
8+
</node>
9+
</launch>
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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>emergency_goal_manager</name>
5+
<version>0.1.0</version>
6+
<description>The emergency goal manager package</description>
7+
<maintainer email="makoto.kurihara@tier4.jp">Makoto Kurihara</maintainer>
8+
<maintainer email="tomohito.ando@tier4.jp">Tomohito Ando</maintainer>
9+
<maintainer email="ryuta.kambe@tier4.jp">Ryuta Kambe</maintainer>
10+
<license>Apache License 2.0</license>
11+
12+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
13+
<buildtool_depend>autoware_cmake</buildtool_depend>
14+
15+
<depend>autoware_adapi_v1_msgs</depend>
16+
<depend>rclcpp_components</depend>
17+
<depend>std_srvs</depend>
18+
<depend>tier4_system_msgs</depend>
19+
20+
<test_depend>ament_lint_auto</test_depend>
21+
<test_depend>autoware_lint_common</test_depend>
22+
23+
<export>
24+
<build_type>ament_cmake</build_type>
25+
</export>
26+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// Copyright 2023 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 <emergency_goal_manager_core.hpp>
16+
17+
namespace emergency_goal_manager
18+
{
19+
EmergencyGoalManager::EmergencyGoalManager() : Node("emergency_goal_manager")
20+
{
21+
// Subscriber
22+
sub_emergency_goals_ = create_subscription<tier4_system_msgs::msg::EmergencyGoalsStamped>(
23+
"~/input/emergency_goals", rclcpp::QoS{1},
24+
std::bind(&EmergencyGoalManager::onEmergencyGoals, this, std::placeholders::_1));
25+
sub_emergency_goals_clear_command_ =
26+
create_subscription<tier4_system_msgs::msg::EmergencyGoalsClearCommand>(
27+
"~/input/emergency_goals_clear_command", rclcpp::QoS{1},
28+
std::bind(&EmergencyGoalManager::onEmergencyGoalsClearCommand, this, std::placeholders::_1));
29+
30+
// Client
31+
client_set_mrm_route_points_callback_group_ =
32+
create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
33+
client_set_mrm_route_points_ = create_client<SetRoutePoints>(
34+
"/planning/mission_planning/mission_planner/srv/set_mrm_route",
35+
rmw_qos_profile_services_default, client_set_mrm_route_points_callback_group_);
36+
client_clear_mrm_route_callback_group_ =
37+
create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive);
38+
client_clear_mrm_route_ = create_client<ClearRoute>(
39+
"/planning/mission_planning/mission_planner/srv/clear_mrm_route",
40+
rmw_qos_profile_services_default, client_clear_mrm_route_callback_group_);
41+
42+
// Initialize
43+
while (!client_set_mrm_route_points_->wait_for_service(std::chrono::seconds(1)) && rclcpp::ok()) {
44+
}
45+
while (!client_clear_mrm_route_->wait_for_service(std::chrono::seconds(1)) && rclcpp::ok()) {
46+
}
47+
}
48+
49+
void EmergencyGoalManager::onEmergencyGoals(
50+
const tier4_system_msgs::msg::EmergencyGoalsStamped::SharedPtr msg)
51+
{
52+
std::queue<geometry_msgs::msg::Pose> emergency_goals_queue;
53+
for (const auto & goal : msg->goals) {
54+
emergency_goals_queue.push(goal);
55+
}
56+
emergency_goals_map_.emplace(msg->sender, emergency_goals_queue);
57+
58+
callSetMrmRoutePoints();
59+
}
60+
61+
void EmergencyGoalManager::onEmergencyGoalsClearCommand(
62+
const tier4_system_msgs::msg::EmergencyGoalsClearCommand::SharedPtr msg)
63+
{
64+
if (emergency_goals_map_.count(msg->sender) == 0) {
65+
RCLCPP_WARN(get_logger(), "Emergency goals from %s is empty.", msg->sender.c_str());
66+
}
67+
68+
emergency_goals_map_.erase(msg->sender);
69+
70+
if (emergency_goals_map_.empty()) {
71+
callClearMrmRoute();
72+
} else {
73+
callSetMrmRoutePoints();
74+
}
75+
}
76+
77+
void EmergencyGoalManager::callSetMrmRoutePoints()
78+
{
79+
auto request = std::make_shared<SetRoutePoints::Request>();
80+
request->header.frame_id = "map";
81+
request->header.stamp = this->now();
82+
request->option.allow_goal_modification = true;
83+
84+
while (!emergency_goals_map_.empty()) {
85+
// TODO(Makoto Kurihara): set goals with the highest priority
86+
auto goals = emergency_goals_map_.begin();
87+
88+
auto sender = goals->first;
89+
auto & goal_queue = goals->second;
90+
if (goal_queue.empty()) {
91+
emergency_goals_map_.erase(sender);
92+
continue;
93+
}
94+
95+
request->goal = goal_queue.front();
96+
goal_queue.pop();
97+
98+
auto future = client_set_mrm_route_points_->async_send_request(request);
99+
const auto duration = std::chrono::duration<double, std::ratio<1>>(10);
100+
if (future.wait_for(duration) != std::future_status::ready) {
101+
RCLCPP_WARN(get_logger(), "MRM Route service timeout.");
102+
continue;
103+
} else {
104+
if (future.get()->status.success) {
105+
RCLCPP_INFO(get_logger(), "MRM Route has been successfully sent.");
106+
return;
107+
} else {
108+
RCLCPP_WARN(get_logger(), "MRM Route service has failed.");
109+
std::this_thread::sleep_for(std::chrono::seconds(1));
110+
continue;
111+
}
112+
}
113+
}
114+
115+
callClearMrmRoute();
116+
}
117+
118+
void EmergencyGoalManager::callClearMrmRoute()
119+
{
120+
auto request = std::make_shared<ClearRoute::Request>();
121+
const auto duration = std::chrono::duration<double, std::ratio<1>>(10);
122+
const auto start_time = std::chrono::steady_clock::now();
123+
124+
while (rclcpp::ok()) {
125+
if (std::chrono::steady_clock::now() - start_time > duration) {
126+
RCLCPP_WARN(get_logger(), "Clear MRM Route operation timeout.");
127+
return;
128+
}
129+
130+
auto future = client_clear_mrm_route_->async_send_request(request);
131+
if (future.wait_for(duration) != std::future_status::ready) {
132+
RCLCPP_WARN(get_logger(), "Clear MRM Route service timeout.");
133+
return;
134+
} else {
135+
if (future.get()->status.success) {
136+
RCLCPP_INFO(get_logger(), "Clear MRM Route has been successfully sent.");
137+
return;
138+
} else {
139+
std::this_thread::sleep_for(std::chrono::seconds(1));
140+
RCLCPP_WARN(get_logger(), "Clear MRM Route has failed.");
141+
continue;
142+
}
143+
}
144+
}
145+
}
146+
} // namespace emergency_goal_manager
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2023 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 "emergency_goal_manager_core.hpp"
16+
17+
int main(int argc, char ** argv)
18+
{
19+
rclcpp::init(argc, argv);
20+
rclcpp::executors::MultiThreadedExecutor executor;
21+
auto node = std::make_shared<emergency_goal_manager::EmergencyGoalManager>();
22+
executor.add_node(node);
23+
executor.spin();
24+
executor.remove_node(node);
25+
rclcpp::shutdown();
26+
27+
return 0;
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(mrm_pull_over_manager)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
ament_auto_add_executable(mrm_pull_over_manager
8+
src/mrm_pull_over_manager/mrm_pull_over_manager_node.cpp
9+
src/mrm_pull_over_manager/mrm_pull_over_manager_core.cpp
10+
)
11+
12+
ament_auto_package(INSTALL_TO_SHARE
13+
launch
14+
config
15+
)

0 commit comments

Comments
 (0)