Skip to content

Commit 63cfff8

Browse files
authored
test(autoware_behavior_velocity_planner_common): refactor and test autoware_behavior_velocity_planner_common (#9551)
* test(autoware_behavior_velocity_planner_common): refactor and test autoware_behavior_velocity_planner_common Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> * remove nodiscard Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> * update Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> * fix Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> * fix * update Signed-off-by: Y.Hisaki <yhisaki31@gmail.com> --------- Signed-off-by: Y.Hisaki <yhisaki31@gmail.com>
1 parent 8cf0bc9 commit 63cfff8

19 files changed

+680
-200
lines changed

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/CMakeLists.txt

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ autoware_package()
66

77
ament_auto_add_library(${PROJECT_NAME} SHARED
88
src/scene_module_interface.cpp
9+
src/planner_data.cpp
910
src/utilization/path_utilization.cpp
1011
src/utilization/trajectory_utils.cpp
1112
src/utilization/arc_lane_util.cpp
@@ -15,11 +16,8 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
1516
)
1617

1718
if(BUILD_TESTING)
18-
ament_add_ros_isolated_gtest(test_${PROJECT_NAME}
19-
test/src/test_state_machine.cpp
20-
test/src/test_arc_lane_util.cpp
21-
test/src/test_utilization.cpp
22-
)
19+
file(GLOB TEST_SOURCES test/src/*.cpp)
20+
ament_add_ros_isolated_gtest(test_${PROJECT_NAME} ${TEST_SOURCES})
2321
target_link_libraries(test_${PROJECT_NAME}
2422
gtest_main
2523
${PROJECT_NAME}

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/include/autoware/behavior_velocity_planner_common/planner_data.hpp

+8-74
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
#ifndef AUTOWARE__BEHAVIOR_VELOCITY_PLANNER_COMMON__PLANNER_DATA_HPP_
1616
#define AUTOWARE__BEHAVIOR_VELOCITY_PLANNER_COMMON__PLANNER_DATA_HPP_
1717

18+
#include "autoware/behavior_velocity_planner_common/utilization/util.hpp"
1819
#include "autoware/route_handler/route_handler.hpp"
19-
20-
#include <autoware/behavior_velocity_planner_common/utilization/util.hpp>
21-
#include <autoware/velocity_smoother/smoother/smoother_base.hpp>
22-
#include <autoware_vehicle_info_utils/vehicle_info_utils.hpp>
20+
#include "autoware/velocity_smoother/smoother/smoother_base.hpp"
21+
#include "autoware_vehicle_info_utils/vehicle_info_utils.hpp"
2322

2423
#include <autoware_map_msgs/msg/lanelet_map_bin.hpp>
2524
#include <autoware_perception_msgs/msg/predicted_objects.hpp>
@@ -38,118 +37,53 @@
3837
#include <pcl/point_cloud.h>
3938
#include <pcl/point_types.h>
4039

41-
#include <algorithm>
4240
#include <deque>
4341
#include <map>
4442
#include <memory>
4543
#include <optional>
46-
#include <vector>
4744

4845
namespace autoware::behavior_velocity_planner
4946
{
50-
class BehaviorVelocityPlannerNode;
5147
struct PlannerData
5248
{
53-
explicit PlannerData(rclcpp::Node & node)
54-
: clock_(node.get_clock()),
55-
vehicle_info_(autoware::vehicle_info_utils::VehicleInfoUtils(node).getVehicleInfo())
56-
{
57-
max_stop_acceleration_threshold = node.declare_parameter<double>(
58-
"max_accel"); // TODO(someone): read min_acc in velocity_controller.param.yaml?
59-
max_stop_jerk_threshold = node.declare_parameter<double>("max_jerk");
60-
system_delay = node.declare_parameter<double>("system_delay");
61-
delay_response_time = node.declare_parameter<double>("delay_response_time");
62-
}
49+
explicit PlannerData(rclcpp::Node & node);
6350

6451
rclcpp::Clock::SharedPtr clock_;
6552

66-
// msgs from callbacks that are used for data-ready
6753
geometry_msgs::msg::PoseStamped::ConstSharedPtr current_odometry;
6854
geometry_msgs::msg::TwistStamped::ConstSharedPtr current_velocity;
6955
geometry_msgs::msg::AccelWithCovarianceStamped::ConstSharedPtr current_acceleration;
7056
static constexpr double velocity_buffer_time_sec = 10.0;
7157
std::deque<geometry_msgs::msg::TwistStamped> velocity_buffer;
7258
autoware_perception_msgs::msg::PredictedObjects::ConstSharedPtr predicted_objects;
7359
pcl::PointCloud<pcl::PointXYZ>::ConstPtr no_ground_pointcloud;
74-
// occupancy grid
60+
7561
nav_msgs::msg::OccupancyGrid::ConstSharedPtr occupancy_grid;
7662

77-
// nearest search
7863
double ego_nearest_dist_threshold;
7964
double ego_nearest_yaw_threshold;
8065

81-
// other internal data
82-
// traffic_light_id_map_raw is the raw observation, while traffic_light_id_map_keep_last keeps the
83-
// last observed infomation for UNKNOWN
8466
std::map<lanelet::Id, TrafficSignalStamped> traffic_light_id_map_raw_;
8567
std::map<lanelet::Id, TrafficSignalStamped> traffic_light_id_map_last_observed_;
8668
std::optional<tier4_planning_msgs::msg::VelocityLimit> external_velocity_limit;
8769
tier4_v2x_msgs::msg::VirtualTrafficLightStateArray::ConstSharedPtr virtual_traffic_light_states;
8870

89-
// This variable is used when the Autoware's behavior has to depend on whether it's simulation or
90-
// not.
9171
bool is_simulation = false;
9272

93-
// velocity smoother
9473
std::shared_ptr<autoware::velocity_smoother::SmootherBase> velocity_smoother_;
95-
// route handler
9674
std::shared_ptr<autoware::route_handler::RouteHandler> route_handler_;
97-
// parameters
9875
autoware::vehicle_info_utils::VehicleInfo vehicle_info_;
9976

100-
// additional parameters
10177
double max_stop_acceleration_threshold;
10278
double max_stop_jerk_threshold;
10379
double system_delay;
10480
double delay_response_time;
10581
double stop_line_extend_length;
10682

107-
bool isVehicleStopped(const double stop_duration = 0.0) const
108-
{
109-
if (velocity_buffer.empty()) {
110-
return false;
111-
}
112-
113-
// Get velocities within stop_duration
114-
const auto now = clock_->now();
115-
std::vector<double> vs;
116-
for (const auto & velocity : velocity_buffer) {
117-
vs.push_back(velocity.twist.linear.x);
118-
119-
const auto & s = velocity.header.stamp;
120-
const auto time_diff =
121-
now >= s ? now - s : rclcpp::Duration(0, 0); // Note: negative time throws an exception.
122-
if (time_diff.seconds() >= stop_duration) {
123-
break;
124-
}
125-
}
126-
127-
// Check all velocities
128-
constexpr double stop_velocity = 1e-3;
129-
for (const auto & v : vs) {
130-
if (v >= stop_velocity) {
131-
return false;
132-
}
133-
}
134-
135-
return true;
136-
}
137-
138-
/**
139-
*@fn
140-
*@brief queries the traffic signal information of given Id. if keep_last_observation = true,
141-
*recent UNKNOWN observation is overwritten as the last non-UNKNOWN observation
142-
*/
83+
bool isVehicleStopped(const double stop_duration = 0.0) const;
84+
14385
std::optional<TrafficSignalStamped> getTrafficSignal(
144-
const lanelet::Id id, const bool keep_last_observation = false) const
145-
{
146-
const auto & traffic_light_id_map =
147-
keep_last_observation ? traffic_light_id_map_last_observed_ : traffic_light_id_map_raw_;
148-
if (traffic_light_id_map.count(id) == 0) {
149-
return std::nullopt;
150-
}
151-
return std::make_optional<TrafficSignalStamped>(traffic_light_id_map.at(id));
152-
}
86+
const lanelet::Id id, const bool keep_last_observation = false) const;
15387
};
15488
} // namespace autoware::behavior_velocity_planner
15589

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/include/autoware/behavior_velocity_planner_common/scene_module_interface.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <set>
4040
#include <string>
4141
#include <unordered_map>
42+
#include <utility>
4243
#include <vector>
4344

4445
// Debug
@@ -69,9 +70,9 @@ struct ObjectOfInterest
6970
autoware_perception_msgs::msg::Shape shape;
7071
ColorName color;
7172
ObjectOfInterest(
72-
const geometry_msgs::msg::Pose & pose, const autoware_perception_msgs::msg::Shape & shape,
73+
const geometry_msgs::msg::Pose & pose, autoware_perception_msgs::msg::Shape shape,
7374
const ColorName & color_name)
74-
: pose(pose), shape(shape), color(color_name)
75+
: pose(pose), shape(std::move(shape)), color(color_name)
7576
{
7677
}
7778
};
@@ -89,6 +90,7 @@ class SceneModuleInterface
8990
virtual std::vector<autoware::motion_utils::VirtualWall> createVirtualWalls() = 0;
9091

9192
int64_t getModuleId() const { return module_id_; }
93+
9294
void setPlannerData(const std::shared_ptr<const PlannerData> & planner_data)
9395
{
9496
planner_data_ = planner_data;

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/include/autoware/behavior_velocity_planner_common/utilization/arc_lane_util.hpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include <tier4_planning_msgs/msg/path_with_lane_id.hpp>
2222

23-
#include <algorithm>
2423
#include <optional>
2524
#include <utility>
2625

@@ -29,9 +28,8 @@
2928

3029
namespace autoware::behavior_velocity_planner
3130
{
32-
namespace
33-
{
34-
geometry_msgs::msg::Point convertToGeomPoint(const autoware::universe_utils::Point2d & p)
31+
32+
inline geometry_msgs::msg::Point convertToGeomPoint(const autoware::universe_utils::Point2d & p)
3533
{
3634
geometry_msgs::msg::Point geom_p;
3735
geom_p.x = p.x();
@@ -40,8 +38,6 @@ geometry_msgs::msg::Point convertToGeomPoint(const autoware::universe_utils::Poi
4038
return geom_p;
4139
}
4240

43-
} // namespace
44-
4541
namespace arc_lane_utils
4642
{
4743
using PathIndexWithPose = std::pair<size_t, geometry_msgs::msg::Pose>; // front index, pose

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/include/autoware/behavior_velocity_planner_common/utilization/debug.hpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
#include <string>
2727
#include <vector>
2828

29-
namespace autoware::behavior_velocity_planner
30-
{
31-
namespace debug
29+
namespace autoware::behavior_velocity_planner::debug
3230
{
3331
visualization_msgs::msg::MarkerArray createPolygonMarkerArray(
3432
const geometry_msgs::msg::Polygon & polygon, const std::string & ns, const int64_t module_id,
@@ -46,6 +44,6 @@ visualization_msgs::msg::MarkerArray createPointsMarkerArray(
4644
const std::vector<geometry_msgs::msg::Point> & points, const std::string & ns,
4745
const int64_t module_id, const rclcpp::Time & now, const double x, const double y, const double z,
4846
const double r, const double g, const double b);
49-
} // namespace debug
50-
} // namespace autoware::behavior_velocity_planner
47+
} // namespace autoware::behavior_velocity_planner::debug
48+
5149
#endif // AUTOWARE__BEHAVIOR_VELOCITY_PLANNER_COMMON__UTILIZATION__DEBUG_HPP_

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/include/autoware/behavior_velocity_planner_common/utilization/path_utilization.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
#include <autoware_planning_msgs/msg/path.hpp>
2121
#include <tier4_planning_msgs/msg/path_with_lane_id.hpp>
2222

23-
#include <vector>
24-
2523
namespace autoware::behavior_velocity_planner
2624
{
2725
bool splineInterpolate(
2826
const tier4_planning_msgs::msg::PathWithLaneId & input, const double interval,
29-
tier4_planning_msgs::msg::PathWithLaneId & output, const rclcpp::Logger logger);
27+
tier4_planning_msgs::msg::PathWithLaneId & output, const rclcpp::Logger & logger);
3028
autoware_planning_msgs::msg::Path interpolatePath(
3129
const autoware_planning_msgs::msg::Path & path, const double length, const double interval);
3230
autoware_planning_msgs::msg::Path filterLitterPathPoint(

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/include/autoware/behavior_velocity_planner_common/utilization/state_machine.hpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include <memory>
2121
#include <string>
22-
#include <utility>
2322

2423
namespace autoware::behavior_velocity_planner
2524
{
@@ -37,11 +36,11 @@ class StateMachine
3736
{
3837
if (state == State::STOP) {
3938
return "STOP";
40-
} else if (state == State::GO) {
39+
}
40+
if (state == State::GO) {
4141
return "GO";
42-
} else {
43-
return "";
4442
}
43+
return "";
4544
}
4645
StateMachine()
4746
{

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/include/autoware/behavior_velocity_planner_common/utilization/util.hpp

+30-16
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifndef AUTOWARE__BEHAVIOR_VELOCITY_PLANNER_COMMON__UTILIZATION__UTIL_HPP_
1616
#define AUTOWARE__BEHAVIOR_VELOCITY_PLANNER_COMMON__UTILIZATION__UTIL_HPP_
1717

18-
#include <autoware/universe_utils/geometry/boost_geometry.hpp>
18+
#include "autoware/universe_utils/geometry/boost_geometry.hpp"
1919

2020
#include <autoware_perception_msgs/msg/predicted_objects.hpp>
2121
#include <autoware_perception_msgs/msg/traffic_light_group.hpp>
@@ -36,23 +36,29 @@
3636

3737
namespace autoware::behavior_velocity_planner
3838
{
39+
/**
40+
* @brief Represents detection range parameters.
41+
*/
3942
struct DetectionRange
4043
{
41-
bool use_right = true;
42-
bool use_left = true;
43-
double interval;
44-
double min_longitudinal_distance;
45-
double max_longitudinal_distance;
46-
double max_lateral_distance;
47-
double wheel_tread;
48-
double right_overhang;
49-
double left_overhang;
44+
bool use_right = true; ///< Whether to use the right side.
45+
bool use_left = true; ///< Whether to use the left side.
46+
double interval{0.0}; ///< Interval of detection points.
47+
double min_longitudinal_distance{0.0}; ///< Minimum longitudinal detection distance.
48+
double max_longitudinal_distance{0.0}; ///< Maximum longitudinal detection distance.
49+
double max_lateral_distance{0.0}; ///< Maximum lateral detection distance.
50+
double wheel_tread{0.0}; ///< Wheel tread of the vehicle.
51+
double right_overhang{0.0}; ///< Right overhang of the vehicle.
52+
double left_overhang{0.0}; ///< Left overhang of the vehicle.
5053
};
5154

55+
/**
56+
* @brief Represents a traffic signal with a timestamp.
57+
*/
5258
struct TrafficSignalStamped
5359
{
54-
builtin_interfaces::msg::Time stamp;
55-
autoware_perception_msgs::msg::TrafficLightGroup signal;
60+
builtin_interfaces::msg::Time stamp; ///< Timestamp of the signal.
61+
autoware_perception_msgs::msg::TrafficLightGroup signal; ///< Traffic light group.
5662
};
5763

5864
using Pose = geometry_msgs::msg::Pose;
@@ -70,21 +76,27 @@ namespace planning_utils
7076
size_t calcSegmentIndexFromPointIndex(
7177
const std::vector<tier4_planning_msgs::msg::PathPointWithLaneId> & points,
7278
const geometry_msgs::msg::Point & point, const size_t idx);
73-
// create detection area from given range return false if creation failure
79+
7480
bool createDetectionAreaPolygons(
7581
Polygons2d & da_polys, const PathWithLaneId & path, const geometry_msgs::msg::Pose & target_pose,
7682
const size_t target_seg_idx, const DetectionRange & da_range, const double obstacle_vel_mps,
7783
const double min_velocity = 1.0);
84+
7885
Point2d calculateOffsetPoint2d(
7986
const geometry_msgs::msg::Pose & pose, const double offset_x, const double offset_y);
87+
8088
void extractClosePartition(
8189
const geometry_msgs::msg::Point position, const BasicPolygons2d & all_partitions,
8290
BasicPolygons2d & close_partition, const double distance_thresh = 30.0);
83-
void getAllPartitionLanelets(const lanelet::LaneletMapConstPtr ll, BasicPolygons2d & polys);
91+
92+
void getAllPartitionLanelets(const lanelet::LaneletMapConstPtr & ll, BasicPolygons2d & polys);
93+
8494
void setVelocityFromIndex(const size_t begin_idx, const double vel, PathWithLaneId * input);
95+
8596
void insertVelocity(
8697
PathWithLaneId & path, const PathPointWithLaneId & path_point, const double v,
8798
size_t & insert_index, const double min_distance = 0.001);
99+
88100
inline int64_t bitShift(int64_t original_id)
89101
{
90102
return original_id << (sizeof(int32_t) * 8 / 2);
@@ -96,6 +108,7 @@ geometry_msgs::msg::Pose getAheadPose(
96108
const tier4_planning_msgs::msg::PathWithLaneId & path);
97109
Polygon2d generatePathPolygon(
98110
const PathWithLaneId & path, const size_t start_idx, const size_t end_idx, const double width);
111+
99112
double calcJudgeLineDistWithAccLimit(
100113
const double velocity, const double max_stop_acceleration, const double delay_response_time);
101114

@@ -210,6 +223,7 @@ bool isOverLine(
210223

211224
std::optional<geometry_msgs::msg::Pose> insertStopPoint(
212225
const geometry_msgs::msg::Point & stop_point, PathWithLaneId & output);
226+
213227
std::optional<geometry_msgs::msg::Pose> insertStopPoint(
214228
const geometry_msgs::msg::Point & stop_point, const size_t stop_seg_idx, PathWithLaneId & output);
215229

@@ -218,11 +232,11 @@ std::optional<geometry_msgs::msg::Pose> insertStopPoint(
218232
or lane-changeable parent lanes with `lane` and has same turn_direction value.
219233
*/
220234
std::set<lanelet::Id> getAssociativeIntersectionLanelets(
221-
lanelet::ConstLanelet lane, const lanelet::LaneletMapPtr lanelet_map,
235+
const lanelet::ConstLanelet & lane, const lanelet::LaneletMapPtr lanelet_map,
222236
const lanelet::routing::RoutingGraphPtr routing_graph);
223237

224238
lanelet::ConstLanelets getConstLaneletsFromIds(
225-
lanelet::LaneletMapConstPtr map, const std::set<lanelet::Id> & ids);
239+
const lanelet::LaneletMapConstPtr & map, const std::set<lanelet::Id> & ids);
226240

227241
} // namespace planning_utils
228242
} // namespace autoware::behavior_velocity_planner

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<test_depend>ament_cmake_ros</test_depend>
5353
<test_depend>ament_lint_auto</test_depend>
5454
<test_depend>autoware_lint_common</test_depend>
55+
<test_depend>autoware_test_utils</test_depend>
5556

5657
<export>
5758
<build_type>ament_cmake</build_type>

0 commit comments

Comments
 (0)