Skip to content

Commit 0ef18f7

Browse files
committed
add rrtstar algorithm
1 parent c3ae35d commit 0ef18f7

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

planning/freespace_planning_algorithms/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ if(BUILD_TESTING)
3535
freespace_planning_algorithms
3636
)
3737
find_package(ament_cmake_ros REQUIRED)
38-
ament_add_ros_isolated_gtest(freespace_planning_algorithms_astar-test
39-
test/src/test_freespace_planning_algorithms_astar.cpp
38+
ament_add_ros_isolated_gtest(freespace_planning_algorithms_no_obstacles-test
39+
test/src/test_freespace_planning_algorithms_no_obstacles.cpp
4040
)
41-
target_link_libraries(freespace_planning_algorithms_astar-test
41+
target_link_libraries(freespace_planning_algorithms_no_obstacles-test
4242
freespace_planning_algorithms
4343
)
4444
find_package(ament_cmake_ros REQUIRED)

planning/freespace_planning_algorithms/test/src/test_freespace_planning_algorithms_astar.cpp planning/freespace_planning_algorithms/test/src/test_freespace_planning_algorithms_no_obstacles.cpp

+61-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 Tier IV, Inc. All rights reserved.
1+
// Copyright 2024 Tier IV, Inc. All rights reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -240,16 +240,35 @@ std::unique_ptr<fpa::AbstractPlanningAlgorithm> configure_astar(bool use_multi,
240240
return algo;
241241
}
242242

243+
std::unique_ptr<fpa::AbstractPlanningAlgorithm> configure_rrtstar(bool informed, bool update)
244+
{
245+
auto planner_common_param = get_default_planner_params();
246+
247+
// configure rrtstar param
248+
const double mu = 12.0;
249+
const double margin = 0.2;
250+
const double max_planning_time = 200;
251+
const auto rrtstar_param = fpa::RRTStarParam{update, informed, max_planning_time, mu, margin};
252+
auto algo = std::make_unique<fpa::RRTStar>(planner_common_param, vehicle_shape, rrtstar_param);
253+
return algo;
254+
}
255+
243256
enum AlgorithmType {
244257
ASTAR_SINGLE,
245258
ASTAR_MULTI,
246259
ASTAR_MULTI_NOCW,
260+
RRTSTAR_FASTEST,
261+
RRTSTAR_UPDATE,
262+
RRTSTAR_INFORMED_UPDATE,
247263
};
248264
// cspell: ignore fpalgos
249265
std::unordered_map<AlgorithmType, std::string> rosbag_dir_prefix_table(
250266
{{ASTAR_SINGLE, "fpalgos-astar_single"},
251267
{ASTAR_MULTI, "fpalgos-astar_multi"},
252268
{ASTAR_MULTI_NOCW, "fpalgos-astar_multi_nocw"},
269+
{RRTSTAR_FASTEST, "fpalgos-rrtstar_fastest"},
270+
{RRTSTAR_UPDATE, "fpalgos-rrtstar_update"},
271+
{RRTSTAR_INFORMED_UPDATE, "fpalgos-rrtstar_informed_update"}
253272
});
254273

255274
bool test_algorithm(enum AlgorithmType algo_type, bool dump_rosbag = false)
@@ -261,6 +280,12 @@ bool test_algorithm(enum AlgorithmType algo_type, bool dump_rosbag = false)
261280
algo = configure_astar(true, true);
262281
} else if (algo_type == AlgorithmType::ASTAR_MULTI_NOCW) {
263282
algo = configure_astar(true, false);
283+
} else if (algo_type == AlgorithmType::RRTSTAR_FASTEST) {
284+
algo = configure_rrtstar(false, false);
285+
} else if (algo_type == AlgorithmType::RRTSTAR_UPDATE) {
286+
algo = configure_rrtstar(false, true);
287+
} else if (algo_type == AlgorithmType::RRTSTAR_INFORMED_UPDATE) {
288+
algo = configure_rrtstar(true, true);
264289
} else {
265290
throw std::runtime_error("invalid algorithm time");
266291
}
@@ -277,7 +302,26 @@ bool test_algorithm(enum AlgorithmType algo_type, bool dump_rosbag = false)
277302
double msec;
278303
double cost;
279304

280-
{
305+
if (algo_type == RRTSTAR_FASTEST || algo_type == RRTSTAR_UPDATE) {
306+
std::cout << "measuring average performance ..." << std::endl;
307+
const size_t N_mc = (algo_type == RRTSTAR_UPDATE ? 5 : 100);
308+
double time_sum = 0.0;
309+
double cost_sum = 0.0;
310+
for (size_t j = 0; j < N_mc; j++) {
311+
const rclcpp::Time begin = clock.now();
312+
if (!algo->makePlan(create_pose_msg(start_pose), create_pose_msg(goal_pose))) {
313+
success_all = false;
314+
std::cout << "plan fail" << std::endl;
315+
continue;
316+
}
317+
const rclcpp::Time now = clock.now();
318+
time_sum += (now - begin).seconds() * 1000.0;
319+
cost_sum += algo->getWaypoints().compute_length();
320+
}
321+
msec = time_sum / N_mc; // average performance
322+
cost = cost_sum / N_mc;
323+
324+
} else {
281325
const rclcpp::Time begin = clock.now();
282326
if (!algo->makePlan(create_pose_msg(start_pose), create_pose_msg(goal_pose))) {
283327
success_all = false;
@@ -352,6 +396,21 @@ TEST(AstarSearchTestSuite, MultiCurvaturenocw)
352396
EXPECT_TRUE(test_algorithm(AlgorithmType::ASTAR_MULTI_NOCW));
353397
}
354398

399+
TEST(RRTStarTestSuite, Fastest)
400+
{
401+
EXPECT_TRUE(test_algorithm(AlgorithmType::RRTSTAR_FASTEST));
402+
}
403+
404+
TEST(RRTStarTestSuite, Update)
405+
{
406+
EXPECT_TRUE(test_algorithm(AlgorithmType::RRTSTAR_UPDATE));
407+
}
408+
409+
TEST(RRTStarTestSuite, InformedUpdate)
410+
{
411+
EXPECT_TRUE(test_algorithm(AlgorithmType::RRTSTAR_INFORMED_UPDATE));
412+
}
413+
355414
int main(int argc, char ** argv)
356415
{
357416
testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)