Skip to content

Commit 17e16d7

Browse files
tkhmypre-commit-ci[bot]rej55kosuke55zulfaqar-azmi-t4
authored
feat(planning_api_interface): add publish steering factor (#1706)
* add basic planning api interface Signed-off-by: tkhmy <tkh.my.p@gmail.com> * add clean function Signed-off-by: tkhmy <tkh.my.p@gmail.com> * add publish empty steering factor Signed-off-by: tkhmy <tkh.my.p@gmail.com> * add publish lanechange steering factor Signed-off-by: tkhmy <tkh.my.p@gmail.com> * add pull out Signed-off-by: khtan <tkh.my.p@gmail.com> * add pull over Signed-off-by: khtan <tkh.my.p@gmail.com> * add intersection Signed-off-by: khtan <tkh.my.p@gmail.com> * manually add steering factor to prevent conflict Signed-off-by: khtan <tkh.my.p@gmail.com> * ci(pre-commit): autofix * feat(rtc_interface): add_finish_distance Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> * use updated distance Signed-off-by: khtan <tkh.my.p@gmail.com> * ci(pre-commit): autofix * fix cpplint Signed-off-by: khtan <tkh.my.p@gmail.com> * add avoidance Signed-off-by: khtan <tkh.my.p@gmail.com> * ci(pre-commit): autofix * fix avoidance Signed-off-by: khtan <tkh.my.p@gmail.com> * fix avoidance pubish Signed-off-by: khtan <tkh.my.p@gmail.com> * clean up lane change Signed-off-by: khtan <tkh.my.p@gmail.com> * fix pull out Signed-off-by: khtan <tkh.my.p@gmail.com> * clean up Signed-off-by: khtan <tkh.my.p@gmail.com> * remove over commit Signed-off-by: khtan <tkh.my.p@gmail.com> * add back pull out Signed-off-by: khtan <tkh.my.p@gmail.com> * ci(pre-commit): autofix * add sterring api for intersect Signed-off-by: khtan <tkh.my.p@gmail.com> * fix pull out Signed-off-by: khtan <tkh.my.p@gmail.com> * add commend Signed-off-by: khtan <tkh.my.p@gmail.com> * get intersection distance Signed-off-by: khtan <tkh.my.p@gmail.com> * add trying status for intersection Signed-off-by: khtan <tkh.my.p@gmail.com> * change to steering_factor_interface Signed-off-by: khtan <tkh.my.p@gmail.com> * change to unique_ptr Signed-off-by: khtan <tkh.my.p@gmail.com> * fix pose and distance array to 2 Signed-off-by: khtan <tkh.my.p@gmail.com> * change to array Signed-off-by: khtan <tkh.my.p@gmail.com> * make member variable private and add public function to get the variable Signed-off-by: khtan <tkh.my.p@gmail.com> * ci(pre-commit): autofix * change to use modified_goal_pose_ instead of getRefinedGoal() Signed-off-by: khtan <tkh.my.p@gmail.com> * add straight direction, fix pull over and pull out error Signed-off-by: khtan <tkh.my.p@gmail.com> * Update planning/behavior_path_planner/src/scene_module/pull_over/pull_over_module.cpp change to get the signal from getTurnInfo() Signed-off-by: tkhmy <tkh.my.p@gmail.com> Co-authored-by: Kosuke Takeuchi <kosuke.tnp@gmail.com> * Update planning/behavior_path_planner/src/scene_module/lane_change/lane_change_module.cpp encapsulated direction variable in lane change Signed-off-by: tkhmy <tkh.my.p@gmail.com> Co-authored-by: Zulfaqar Azmi <93502286+zulfaqar-azmi-t4@users.noreply.github.com> * Update planning/behavior_path_planner/src/scene_module/lane_change/lane_change_module.cpp encapsulated direction variable in lane change Signed-off-by: tkhmy <tkh.my.p@gmail.com> Co-authored-by: Zulfaqar Azmi <93502286+zulfaqar-azmi-t4@users.noreply.github.com> * encapsulated direction variable Signed-off-by: khtan <tkh.my.p@gmail.com> * functionalize steering factor for intersection Signed-off-by: khtan <tkh.my.p@gmail.com> * change to use autoware_adapi_v1_msgs Signed-off-by: khtan <tkh.my.p@gmail.com> * change topic naming Signed-off-by: khtan <tkh.my.p@gmail.com> Signed-off-by: tkhmy <tkh.my.p@gmail.com> Signed-off-by: khtan <tkh.my.p@gmail.com> Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Fumiya Watanabe <rej55.g@gmail.com> Co-authored-by: Kosuke Takeuchi <kosuke.tnp@gmail.com> Co-authored-by: Zulfaqar Azmi <93502286+zulfaqar-azmi-t4@users.noreply.github.com>
1 parent f1aaa5d commit 17e16d7

15 files changed

+329
-5
lines changed

planning/behavior_path_planner/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ament_auto_add_library(behavior_path_planner_node SHARED
1212
src/utilities.cpp
1313
src/path_utilities.cpp
1414
src/debug_utilities.cpp
15+
src/steering_factor_interface.cpp
1516
src/turn_signal_decider.cpp
1617
src/scene_module/scene_module_bt_node_interface.cpp
1718
src/scene_module/side_shift/side_shift_module.cpp

planning/behavior_path_planner/include/behavior_path_planner/behavior_path_planner_node.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "behavior_path_planner/scene_module/pull_out/pull_out_module.hpp"
2424
#include "behavior_path_planner/scene_module/pull_over/pull_over_module.hpp"
2525
#include "behavior_path_planner/scene_module/side_shift/side_shift_module.hpp"
26+
#include "behavior_path_planner/steering_factor_interface.hpp"
2627
#include "behavior_path_planner/turn_signal_decider.hpp"
2728

2829
#include <tier4_autoware_utils/ros/self_pose_listener.hpp>
@@ -72,6 +73,7 @@ using geometry_msgs::msg::TwistStamped;
7273
using nav_msgs::msg::OccupancyGrid;
7374
using nav_msgs::msg::Odometry;
7475
using rcl_interfaces::msg::SetParametersResult;
76+
using steering_factor_interface::SteeringFactorInterface;
7577
using tier4_planning_msgs::msg::AvoidanceDebugMsgArray;
7678
using tier4_planning_msgs::msg::PathChangeModule;
7779
using tier4_planning_msgs::msg::Scenario;
@@ -98,6 +100,7 @@ class BehaviorPathPlannerNode : public rclcpp::Node
98100

99101
std::shared_ptr<PlannerData> planner_data_;
100102
std::shared_ptr<BehaviorTreeManager> bt_manager_;
103+
std::unique_ptr<SteeringFactorInterface> steering_factor_interface_ptr_;
101104
tier4_autoware_utils::SelfPoseListener self_pose_listener_{this};
102105
Scenario::SharedPtr current_scenario_{nullptr};
103106

@@ -171,6 +174,11 @@ class BehaviorPathPlannerNode : public rclcpp::Node
171174
*/
172175
bool isForcedCandidatePath() const;
173176

177+
/**
178+
* @brief publish the steering factor from intersection
179+
*/
180+
void publish_steering_factor(const TurnIndicatorsCommand & turn_signal);
181+
174182
template <class T>
175183
size_t findEgoIndex(const std::vector<T> & points) const
176184
{

planning/behavior_path_planner/include/behavior_path_planner/scene_module/avoidance/avoidance_module.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ class AvoidanceModule : public SceneModuleInterface
124124
path.points, ego_position, left_shift.finish_pose.position);
125125
rtc_interface_left_.updateCooperateStatus(
126126
left_shift.uuid, true, start_distance, finish_distance, clock_->now());
127+
if (finish_distance > -1.0e-03) {
128+
steering_factor_interface_ptr_->updateSteeringFactor(
129+
{left_shift.start_pose, left_shift.finish_pose}, {start_distance, finish_distance},
130+
SteeringFactor::AVOIDANCE_PATH_CHANGE, SteeringFactor::LEFT, SteeringFactor::TURNING, "");
131+
}
127132
}
128133

129134
for (const auto & right_shift : right_shift_array_) {
@@ -133,6 +138,12 @@ class AvoidanceModule : public SceneModuleInterface
133138
path.points, ego_position, right_shift.finish_pose.position);
134139
rtc_interface_right_.updateCooperateStatus(
135140
right_shift.uuid, true, start_distance, finish_distance, clock_->now());
141+
if (finish_distance > -1.0e-03) {
142+
steering_factor_interface_ptr_->updateSteeringFactor(
143+
{right_shift.start_pose, right_shift.finish_pose}, {start_distance, finish_distance},
144+
SteeringFactor::AVOIDANCE_PATH_CHANGE, SteeringFactor::RIGHT, SteeringFactor::TURNING,
145+
"");
146+
}
136147
}
137148
}
138149

planning/behavior_path_planner/include/behavior_path_planner/scene_module/scene_module_interface.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#include "behavior_path_planner/data_manager.hpp"
1919
#include "behavior_path_planner/utilities.hpp"
2020

21+
#include <behavior_path_planner/steering_factor_interface.hpp>
2122
#include <rclcpp/rclcpp.hpp>
2223
#include <route_handler/route_handler.hpp>
2324
#include <rtc_interface/rtc_interface.hpp>
2425

26+
#include <autoware_adapi_v1_msgs/msg/steering_factor_array.hpp>
2527
#include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>
2628
#include <autoware_auto_vehicle_msgs/msg/hazard_lights_command.hpp>
2729
#include <autoware_auto_vehicle_msgs/msg/turn_indicators_command.hpp>
@@ -40,10 +42,12 @@
4042

4143
namespace behavior_path_planner
4244
{
45+
using autoware_adapi_v1_msgs::msg::SteeringFactor;
4346
using autoware_auto_planning_msgs::msg::PathWithLaneId;
4447
using autoware_auto_vehicle_msgs::msg::HazardLightsCommand;
4548
using autoware_auto_vehicle_msgs::msg::TurnIndicatorsCommand;
4649
using rtc_interface::RTCInterface;
50+
using steering_factor_interface::SteeringFactorInterface;
4751
using tier4_planning_msgs::msg::AvoidanceDebugMsgArray;
4852
using unique_identifier_msgs::msg::UUID;
4953
using visualization_msgs::msg::MarkerArray;
@@ -216,6 +220,14 @@ class SceneModuleInterface
216220
return false;
217221
}
218222

223+
virtual void publishSteeringFactor()
224+
{
225+
if (!steering_factor_interface_ptr_) {
226+
return;
227+
}
228+
steering_factor_interface_ptr_->publishSteeringFactor(clock_->now());
229+
}
230+
219231
/**
220232
* @brief set planner data
221233
*/
@@ -249,6 +261,7 @@ class SceneModuleInterface
249261
mutable MarkerArray debug_marker_;
250262

251263
std::shared_ptr<RTCInterface> rtc_interface_ptr_;
264+
std::unique_ptr<SteeringFactorInterface> steering_factor_interface_ptr_;
252265
UUID uuid_;
253266
bool is_waiting_approval_;
254267

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 BEHAVIOR_PATH_PLANNER__STEERING_FACTOR_INTERFACE_HPP_
16+
#define BEHAVIOR_PATH_PLANNER__STEERING_FACTOR_INTERFACE_HPP_
17+
18+
#include "rclcpp/rclcpp.hpp"
19+
20+
#include "autoware_adapi_v1_msgs/msg/steering_factor_array.hpp"
21+
#include "geometry_msgs/msg/pose.hpp"
22+
#include "unique_identifier_msgs/msg/uuid.hpp"
23+
24+
#include <mutex>
25+
#include <string>
26+
#include <vector>
27+
28+
namespace steering_factor_interface
29+
{
30+
using autoware_adapi_v1_msgs::msg::SteeringFactor;
31+
using autoware_adapi_v1_msgs::msg::SteeringFactorArray;
32+
using geometry_msgs::msg::Pose;
33+
34+
class SteeringFactorInterface
35+
{
36+
public:
37+
SteeringFactorInterface(rclcpp::Node * node, const std::string & name);
38+
void publishSteeringFactor(const rclcpp::Time & stamp);
39+
void updateSteeringFactor(
40+
const std::array<Pose, 2> & pose, const std::array<double, 2> distance, const uint16_t type,
41+
const uint16_t direction, const uint16_t status, const std::string detail);
42+
void clearSteeringFactors();
43+
44+
private:
45+
rclcpp::Logger getLogger() const;
46+
47+
rclcpp::Publisher<SteeringFactorArray>::SharedPtr pub_steering_factors_;
48+
49+
std::mutex mutex_;
50+
rclcpp::Logger logger_;
51+
SteeringFactorArray registered_steering_factors_;
52+
};
53+
54+
} // namespace steering_factor_interface
55+
56+
#endif // BEHAVIOR_PATH_PLANNER__STEERING_FACTOR_INTERFACE_HPP_

planning/behavior_path_planner/include/behavior_path_planner/turn_signal_decider.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <lanelet2_core/LaneletMap.h>
2424

25+
#include <limits>
2526
#include <memory>
2627
#include <utility>
2728

@@ -45,6 +46,9 @@ class TurnSignalDecider
4546
intersection_search_distance_ = intersection_search_distance;
4647
}
4748

49+
std::pair<bool, bool> getIntersectionTurnSignalFlag();
50+
std::pair<Pose, double> getIntersectionPoseAndDistance();
51+
4852
private:
4953
std::pair<TurnIndicatorsCommand, double> getIntersectionTurnSignal(
5054
const PathWithLaneId & path, const Pose & current_pose, const size_t current_seg_idx,
@@ -56,6 +60,10 @@ class TurnSignalDecider
5660
// data
5761
double intersection_search_distance_{0.0};
5862
double base_link2front_{0.0};
63+
mutable bool intersection_turn_signal_ = false;
64+
mutable bool approaching_intersection_turn_signal_ = false;
65+
mutable double intersection_distance_ = std::numeric_limits<double>::max();
66+
mutable Pose intersection_pose_point_ = Pose();
5967
};
6068
} // namespace behavior_path_planner
6169

planning/behavior_path_planner/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
<build_depend>autoware_cmake</build_depend>
4141

42+
<depend>autoware_adapi_v1_msgs</depend>
4243
<depend>autoware_auto_perception_msgs</depend>
4344
<depend>autoware_auto_planning_msgs</depend>
4445
<depend>autoware_auto_vehicle_msgs</depend>

planning/behavior_path_planner/src/behavior_path_planner_node.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ BehaviorPathPlannerNode::BehaviorPathPlannerNode(const rclcpp::NodeOptions & nod
149149
planner_data_->parameters.base_link2front, intersection_search_distance);
150150
}
151151

152+
steering_factor_interface_ptr_ = std::make_unique<SteeringFactorInterface>(this, "intersection");
153+
152154
// Start timer
153155
{
154156
const auto planning_hz = declare_parameter("planning_hz", 10.0);
@@ -614,6 +616,8 @@ void BehaviorPathPlannerNode::run()
614616
hazard_signal.stamp = get_clock()->now();
615617
turn_signal_publisher_->publish(turn_signal);
616618
hazard_signal_publisher_->publish(hazard_signal);
619+
620+
publish_steering_factor(turn_signal);
617621
}
618622

619623
// for debug
@@ -629,6 +633,36 @@ void BehaviorPathPlannerNode::run()
629633
RCLCPP_DEBUG(get_logger(), "----- behavior path planner end -----\n\n");
630634
}
631635

636+
void BehaviorPathPlannerNode::publish_steering_factor(const TurnIndicatorsCommand & turn_signal)
637+
{
638+
const auto [intersection_flag, approaching_intersection_flag] =
639+
turn_signal_decider_.getIntersectionTurnSignalFlag();
640+
if (intersection_flag || approaching_intersection_flag) {
641+
const uint16_t steering_factor_direction = std::invoke([&turn_signal]() {
642+
if (turn_signal.command == TurnIndicatorsCommand::ENABLE_LEFT) {
643+
return SteeringFactor::LEFT;
644+
}
645+
return SteeringFactor::RIGHT;
646+
});
647+
648+
const auto [intersection_pose, intersection_distance] =
649+
turn_signal_decider_.getIntersectionPoseAndDistance();
650+
const uint16_t steering_factor_state = std::invoke([&intersection_flag]() {
651+
if (intersection_flag) {
652+
return SteeringFactor::TURNING;
653+
}
654+
return SteeringFactor::TRYING;
655+
});
656+
657+
steering_factor_interface_ptr_->updateSteeringFactor(
658+
{intersection_pose, intersection_pose}, {intersection_distance, intersection_distance},
659+
SteeringFactor::INTERSECTION, steering_factor_direction, steering_factor_state, "");
660+
} else {
661+
steering_factor_interface_ptr_->clearSteeringFactors();
662+
}
663+
steering_factor_interface_ptr_->publishSteeringFactor(get_clock()->now());
664+
}
665+
632666
PathWithLaneId::SharedPtr BehaviorPathPlannerNode::getPath(
633667
const BehaviorModuleOutput & bt_output, const std::shared_ptr<PlannerData> planner_data)
634668
{

planning/behavior_path_planner/src/behavior_tree_manager.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ BehaviorModuleOutput BehaviorTreeManager::run(const std::shared_ptr<PlannerData>
103103
m->onExit();
104104
}
105105
m->publishRTCStatus();
106+
m->publishSteeringFactor();
106107
});
107108
return output;
108109
}

planning/behavior_path_planner/src/scene_module/avoidance/avoidance_module.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ AvoidanceModule::AvoidanceModule(
5656
uuid_right_{generateUUID()}
5757
{
5858
using std::placeholders::_1;
59+
steering_factor_interface_ptr_ = std::make_unique<SteeringFactorInterface>(&node, "avoidance");
5960
}
6061

6162
bool AvoidanceModule::isExecutionRequested() const
@@ -2082,6 +2083,18 @@ CandidateOutput AvoidanceModule::planCandidate() const
20822083
output.lateral_shift = new_shift_points->at(i).getRelativeLength();
20832084
output.start_distance_to_path_change = new_shift_points->front().start_longitudinal;
20842085
output.finish_distance_to_path_change = new_shift_points->back().end_longitudinal;
2086+
2087+
const uint16_t steering_factor_direction = std::invoke([&output]() {
2088+
if (output.lateral_shift > 0.0) {
2089+
return SteeringFactor::LEFT;
2090+
}
2091+
return SteeringFactor::RIGHT;
2092+
});
2093+
steering_factor_interface_ptr_->updateSteeringFactor(
2094+
{new_shift_points->front().start, new_shift_points->back().end},
2095+
{output.start_distance_to_path_change, output.finish_distance_to_path_change},
2096+
SteeringFactor::AVOIDANCE_PATH_CHANGE, steering_factor_direction, SteeringFactor::APPROACHING,
2097+
"");
20852098
}
20862099

20872100
const size_t ego_idx = findEgoIndex(shifted_path.path.points);
@@ -2488,6 +2501,7 @@ void AvoidanceModule::onExit()
24882501
current_state_ = BT::NodeStatus::IDLE;
24892502
clearWaitingApproval();
24902503
removeRTCStatus();
2504+
steering_factor_interface_ptr_->clearSteeringFactors();
24912505
}
24922506

24932507
void AvoidanceModule::initVariables()

planning/behavior_path_planner/src/scene_module/lane_change/lane_change_module.cpp

+32-5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ LaneChangeModule::LaneChangeModule(
4646
uuid_left_{generateUUID()},
4747
uuid_right_{generateUUID()}
4848
{
49+
steering_factor_interface_ptr_ = std::make_unique<SteeringFactorInterface>(&node, "lane_change");
4950
}
5051

5152
BehaviorModuleOutput LaneChangeModule::run()
@@ -61,11 +62,24 @@ BehaviorModuleOutput LaneChangeModule::run()
6162
status_.lane_change_path.shift_point.start.position);
6263
const double finish_distance = motion_utils::calcSignedArcLength(
6364
output.path->points, current_pose.position, status_.lane_change_path.shift_point.end.position);
64-
if (turn_signal_info.turn_signal.command == TurnIndicatorsCommand::ENABLE_LEFT) {
65-
waitApprovalLeft(start_distance, finish_distance);
66-
} else if (turn_signal_info.turn_signal.command == TurnIndicatorsCommand::ENABLE_RIGHT) {
67-
waitApprovalRight(start_distance, finish_distance);
68-
}
65+
66+
const uint16_t steering_factor_direction =
67+
std::invoke([this, &start_distance, &finish_distance, &turn_signal_info]() {
68+
if (turn_signal_info.turn_signal.command == TurnIndicatorsCommand::ENABLE_LEFT) {
69+
waitApprovalLeft(start_distance, finish_distance);
70+
return SteeringFactor::LEFT;
71+
}
72+
if (turn_signal_info.turn_signal.command == TurnIndicatorsCommand::ENABLE_RIGHT) {
73+
waitApprovalRight(start_distance, finish_distance);
74+
return SteeringFactor::RIGHT;
75+
}
76+
return SteeringFactor::UNKNOWN;
77+
});
78+
// TODO(tkhmy) add handle status TRYING
79+
steering_factor_interface_ptr_->updateSteeringFactor(
80+
{status_.lane_change_path.shift_point.start, status_.lane_change_path.shift_point.end},
81+
{start_distance, finish_distance}, SteeringFactor::LANE_CHANGE, steering_factor_direction,
82+
SteeringFactor::TURNING, "");
6983
return output;
7084
}
7185

@@ -85,6 +99,7 @@ void LaneChangeModule::onExit()
8599
{
86100
clearWaitingApproval();
87101
removeRTCStatus();
102+
steering_factor_interface_ptr_->clearSteeringFactors();
88103
debug_marker_.markers.clear();
89104
current_state_ = BT::NodeStatus::IDLE;
90105
RCLCPP_DEBUG(getLogger(), "LANE_CHANGE onExit");
@@ -209,6 +224,18 @@ CandidateOutput LaneChangeModule::planCandidate() const
209224
selected_path.path.points, planner_data_->self_pose->pose.position,
210225
selected_path.shift_point.end.position);
211226

227+
const uint16_t steering_factor_direction = std::invoke([&output]() {
228+
if (output.lateral_shift > 0.0) {
229+
return SteeringFactor::LEFT;
230+
}
231+
return SteeringFactor::RIGHT;
232+
});
233+
234+
steering_factor_interface_ptr_->updateSteeringFactor(
235+
{selected_path.shift_point.start, selected_path.shift_point.end},
236+
{output.start_distance_to_path_change, output.finish_distance_to_path_change},
237+
SteeringFactor::LANE_CHANGE, steering_factor_direction, SteeringFactor::APPROACHING, "");
238+
212239
return output;
213240
}
214241

0 commit comments

Comments
 (0)