Skip to content

Commit 5db3bae

Browse files
shmpwkrej55kosuke55
authored
Merge pull request #1583 from tier4/feat/reroute
* feat(mission_planner): reroute in manual driving (autowarefoundation#7842) * feat(mission_planner): reroute in manual driving Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * docs(mission_planner): update document Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * feat(mission_planner): fix operation mode state receiving check Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> --------- Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * feat(mission_planner): add option to prevent rerouting in autonomous driving mode (autowarefoundation#8757) Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> --------- Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> Co-authored-by: Fumiya Watanabe <rej55.g@gmail.com> Co-authored-by: Kosuke Takeuchi <kosuke.tnp@gmail.com>
2 parents 1058f9c + 2a3e90f commit 5db3bae

File tree

5 files changed

+76
-23
lines changed

5 files changed

+76
-23
lines changed

planning/autoware_mission_planner/README.md

+18-15
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ It distributes route requests and planning results according to current MRM oper
1919

2020
### Parameters
2121

22-
| Name | Type | Description |
23-
| ---------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------- |
24-
| `map_frame` | string | The frame name for map |
25-
| `arrival_check_angle_deg` | double | Angle threshold for goal check |
26-
| `arrival_check_distance` | double | Distance threshold for goal check |
27-
| `arrival_check_duration` | double | Duration threshold for goal check |
28-
| `goal_angle_threshold` | double | Max goal pose angle for goal approve |
29-
| `enable_correct_goal_pose` | bool | Enabling correction of goal pose according to the closest lanelet orientation |
30-
| `reroute_time_threshold` | double | If the time to the rerouting point at the current velocity is greater than this threshold, rerouting is possible |
31-
| `minimum_reroute_length` | double | Minimum Length for publishing a new route |
32-
| `consider_no_drivable_lanes` | bool | This flag is for considering no_drivable_lanes in planning or not. |
22+
| Name | Type | Description |
23+
| ---------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------- |
24+
| `map_frame` | string | The frame name for map |
25+
| `arrival_check_angle_deg` | double | Angle threshold for goal check |
26+
| `arrival_check_distance` | double | Distance threshold for goal check |
27+
| `arrival_check_duration` | double | Duration threshold for goal check |
28+
| `goal_angle_threshold` | double | Max goal pose angle for goal approve |
29+
| `enable_correct_goal_pose` | bool | Enabling correction of goal pose according to the closest lanelet orientation |
30+
| `reroute_time_threshold` | double | If the time to the rerouting point at the current velocity is greater than this threshold, rerouting is possible |
31+
| `minimum_reroute_length` | double | Minimum Length for publishing a new route |
32+
| `consider_no_drivable_lanes` | bool | This flag is for considering no_drivable_lanes in planning or not. |
33+
| `allow_reroute_in_autonomous_mode` | bool | This is a flag to allow reroute in autonomous driving mode. If false, reroute fails. If true, only safe reroute is allowed |
3334

3435
### Services
3536

@@ -47,10 +48,11 @@ It distributes route requests and planning results according to current MRM oper
4748

4849
### Subscriptions
4950

50-
| Name | Type | Description |
51-
| --------------------- | ----------------------------------- | ---------------------- |
52-
| `input/vector_map` | autoware_map_msgs/msg/LaneletMapBin | vector map of Lanelet2 |
53-
| `input/modified_goal` | geometry_msgs/PoseWithUuidStamped | modified goal pose |
51+
| Name | Type | Description |
52+
| ---------------------------- | ----------------------------------------- | ---------------------- |
53+
| `input/vector_map` | autoware_map_msgs/msg/LaneletMapBin | vector map of Lanelet2 |
54+
| `input/modified_goal` | geometry_msgs/PoseWithUuidStamped | modified goal pose |
55+
| `input/operation_mode_state` | autoware_adapi_v1_msgs/OperationModeState | operation mode state |
5456

5557
### Publications
5658

@@ -170,6 +172,7 @@ To calculate `route_lanelets`,
170172
### Rerouting
171173

172174
Reroute here means changing the route while driving. Unlike route setting, it is required to keep a certain distance from vehicle to the point where the route is changed.
175+
If the ego vehicle is not on autonomous driving state, the safety checking process will be skipped.
173176

174177
![rerouting_safety](./media/rerouting_safety.svg)
175178

planning/autoware_mission_planner/config/mission_planner.param.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
minimum_reroute_length: 30.0
1111
consider_no_drivable_lanes: false # This flag is for considering no_drivable_lanes in planning or not.
1212
check_footprint_inside_lanes: true
13+
allow_reroute_in_autonomous_mode: true

planning/autoware_mission_planner/launch/mission_planner.launch.xml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<remap from="~/input/modified_goal" to="$(var modified_goal_topic_name)"/>
1111
<remap from="~/input/vector_map" to="$(var map_topic_name)"/>
1212
<remap from="~/input/odometry" to="/localization/kinematic_state"/>
13+
<remap from="~/input/operation_mode_state" to="/system/operation_mode/state"/>
1314
<remap from="~/input/reroute_availability" to="/planning/scenario_planning/lane_driving/behavior_planning/behavior_path_planner/output/is_reroute_available"/>
1415
<remap from="~/route" to="route"/>
1516
<remap from="~/state" to="state"/>

planning/autoware_mission_planner/src/mission_planner/mission_planner.cpp

+48-8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ MissionPlanner::MissionPlanner(const rclcpp::NodeOptions & options)
4747
map_frame_ = declare_parameter<std::string>("map_frame");
4848
reroute_time_threshold_ = declare_parameter<double>("reroute_time_threshold");
4949
minimum_reroute_length_ = declare_parameter<double>("minimum_reroute_length");
50+
allow_reroute_in_autonomous_mode_ = declare_parameter<bool>("allow_reroute_in_autonomous_mode");
5051

5152
planner_ =
5253
plugin_loader_.createSharedInstance("autoware::mission_planner::lanelet2::DefaultPlanner");
@@ -55,6 +56,9 @@ MissionPlanner::MissionPlanner(const rclcpp::NodeOptions & options)
5556
const auto durable_qos = rclcpp::QoS(1).transient_local();
5657
sub_odometry_ = create_subscription<Odometry>(
5758
"~/input/odometry", rclcpp::QoS(1), std::bind(&MissionPlanner::on_odometry, this, _1));
59+
sub_operation_mode_state_ = create_subscription<OperationModeState>(
60+
"~/input/operation_mode_state", rclcpp::QoS(1),
61+
std::bind(&MissionPlanner::on_operation_mode_state, this, _1));
5862
sub_vector_map_ = create_subscription<LaneletMapBin>(
5963
"~/input/vector_map", durable_qos, std::bind(&MissionPlanner::on_map, this, _1));
6064
pub_marker_ = create_publisher<MarkerArray>("~/debug/route_marker", durable_qos);
@@ -130,6 +134,11 @@ void MissionPlanner::on_odometry(const Odometry::ConstSharedPtr msg)
130134
}
131135
}
132136

137+
void MissionPlanner::on_operation_mode_state(const OperationModeState::ConstSharedPtr msg)
138+
{
139+
operation_mode_state_ = msg;
140+
}
141+
133142
void MissionPlanner::on_map(const LaneletMapBin::ConstSharedPtr msg)
134143
{
135144
map_ptr_ = msg;
@@ -222,10 +231,28 @@ void MissionPlanner::on_set_lanelet_route(
222231
throw service_utils::ServiceException(
223232
ResponseCode::ERROR_PLANNER_UNREADY, "The vehicle pose is not received.");
224233
}
225-
const auto reroute_availability = sub_reroute_availability_.takeData();
226-
if (is_reroute && (!reroute_availability || !reroute_availability->availability)) {
234+
if (is_reroute && !operation_mode_state_) {
235+
throw service_utils::ServiceException(
236+
ResponseCode::ERROR_PLANNER_UNREADY, "Operation mode state is not received.");
237+
}
238+
239+
const bool is_autonomous_driving =
240+
operation_mode_state_ ? operation_mode_state_->mode == OperationModeState::AUTONOMOUS &&
241+
operation_mode_state_->is_autoware_control_enabled
242+
: false;
243+
244+
if (is_reroute && !allow_reroute_in_autonomous_mode_ && is_autonomous_driving) {
227245
throw service_utils::ServiceException(
228-
ResponseCode::ERROR_INVALID_STATE, "Cannot reroute as the planner is not in lane following.");
246+
ResponseCode::ERROR_INVALID_STATE, "Reroute is not allowed in autonomous mode.");
247+
}
248+
249+
if (is_reroute && is_autonomous_driving) {
250+
const auto reroute_availability = sub_reroute_availability_.takeData();
251+
if (!reroute_availability || !reroute_availability->availability) {
252+
throw service_utils::ServiceException(
253+
ResponseCode::ERROR_INVALID_STATE,
254+
"Cannot reroute as the planner is not in lane following.");
255+
}
229256
}
230257

231258
change_state(is_reroute ? RouteState::REROUTING : RouteState::ROUTING);
@@ -238,7 +265,7 @@ void MissionPlanner::on_set_lanelet_route(
238265
ResponseCode::ERROR_PLANNER_FAILED, "The planned route is empty.");
239266
}
240267

241-
if (is_reroute && !check_reroute_safety(*current_route_, route)) {
268+
if (is_reroute && is_autonomous_driving && !check_reroute_safety(*current_route_, route)) {
242269
cancel_route();
243270
change_state(RouteState::SET);
244271
throw service_utils::ServiceException(
@@ -271,10 +298,23 @@ void MissionPlanner::on_set_waypoint_route(
271298
throw service_utils::ServiceException(
272299
ResponseCode::ERROR_PLANNER_UNREADY, "The vehicle pose is not received.");
273300
}
274-
const auto reroute_availability = sub_reroute_availability_.takeData();
275-
if (is_reroute && (!reroute_availability || !reroute_availability->availability)) {
301+
if (is_reroute && !operation_mode_state_) {
276302
throw service_utils::ServiceException(
277-
ResponseCode::ERROR_INVALID_STATE, "Cannot reroute as the planner is not in lane following.");
303+
ResponseCode::ERROR_PLANNER_UNREADY, "Operation mode state is not received.");
304+
}
305+
306+
const bool is_autonomous_driving =
307+
operation_mode_state_ ? operation_mode_state_->mode == OperationModeState::AUTONOMOUS &&
308+
operation_mode_state_->is_autoware_control_enabled
309+
: false;
310+
311+
if (is_reroute && is_autonomous_driving) {
312+
const auto reroute_availability = sub_reroute_availability_.takeData();
313+
if (!reroute_availability || !reroute_availability->availability) {
314+
throw service_utils::ServiceException(
315+
ResponseCode::ERROR_INVALID_STATE,
316+
"Cannot reroute as the planner is not in lane following.");
317+
}
278318
}
279319

280320
change_state(is_reroute ? RouteState::REROUTING : RouteState::ROUTING);
@@ -287,7 +327,7 @@ void MissionPlanner::on_set_waypoint_route(
287327
ResponseCode::ERROR_PLANNER_FAILED, "The planned route is empty.");
288328
}
289329

290-
if (is_reroute && !check_reroute_safety(*current_route_, route)) {
330+
if (is_reroute && is_autonomous_driving && !check_reroute_safety(*current_route_, route)) {
291331
cancel_route();
292332
change_state(RouteState::SET);
293333
throw service_utils::ServiceException(

planning/autoware_mission_planner/src/mission_planner/mission_planner.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <pluginlib/class_loader.hpp>
2525
#include <rclcpp/rclcpp.hpp>
2626

27+
#include <autoware_adapi_v1_msgs/msg/operation_mode_state.hpp>
2728
#include <autoware_adapi_v1_msgs/srv/set_route.hpp>
2829
#include <autoware_adapi_v1_msgs/srv/set_route_points.hpp>
2930
#include <autoware_planning_msgs/msg/lanelet_route.hpp>
@@ -45,6 +46,7 @@
4546
namespace autoware::mission_planner
4647
{
4748

49+
using autoware_adapi_v1_msgs::msg::OperationModeState;
4850
using autoware_map_msgs::msg::LaneletMapBin;
4951
using autoware_planning_msgs::msg::LaneletPrimitive;
5052
using autoware_planning_msgs::msg::LaneletRoute;
@@ -85,18 +87,21 @@ class MissionPlanner : public rclcpp::Node
8587

8688
rclcpp::Subscription<PoseWithUuidStamped>::SharedPtr sub_modified_goal_;
8789
rclcpp::Subscription<Odometry>::SharedPtr sub_odometry_;
90+
rclcpp::Subscription<OperationModeState>::SharedPtr sub_operation_mode_state_;
8891
autoware::universe_utils::InterProcessPollingSubscriber<RerouteAvailability>
8992
sub_reroute_availability_{this, "~/input/reroute_availability"};
9093

9194
rclcpp::Subscription<LaneletMapBin>::SharedPtr sub_vector_map_;
9295
rclcpp::Publisher<MarkerArray>::SharedPtr pub_marker_;
9396
Odometry::ConstSharedPtr odometry_;
97+
OperationModeState::ConstSharedPtr operation_mode_state_;
9498
LaneletMapBin::ConstSharedPtr map_ptr_;
9599
RouteState state_;
96100
LaneletRoute::ConstSharedPtr current_route_;
97101
lanelet::LaneletMapPtr lanelet_map_ptr_{nullptr};
98102

99103
void on_odometry(const Odometry::ConstSharedPtr msg);
104+
void on_operation_mode_state(const OperationModeState::ConstSharedPtr msg);
100105
void on_map(const LaneletMapBin::ConstSharedPtr msg);
101106
void on_reroute_availability(const RerouteAvailability::ConstSharedPtr msg);
102107
void on_modified_goal(const PoseWithUuidStamped::ConstSharedPtr msg);
@@ -130,6 +135,9 @@ class MissionPlanner : public rclcpp::Node
130135

131136
double reroute_time_threshold_;
132137
double minimum_reroute_length_;
138+
// flag to allow reroute in autonomous driving mode.
139+
// if false, reroute fails. if true, only safe reroute is allowed.
140+
bool allow_reroute_in_autonomous_mode_;
133141
bool check_reroute_safety(const LaneletRoute & original_route, const LaneletRoute & target_route);
134142

135143
std::unique_ptr<autoware::universe_utils::LoggerLevelConfigure> logger_configure_;

0 commit comments

Comments
 (0)