Skip to content

Commit 679d6bd

Browse files
tkimura4wep21HiroIshidaTakaHoribeKenji Miyake
authored
feat: add freespace_planning_algorithms package (autowarefoundation#33)
* Master sync for parking (autowarefoundation#1693) * Reedsshepp distance as a heuristic function in hybrid A star (autowarefoundation#1297) * Use reeds sheep distance * Use average radius * Add standalone toy problem * Cleanup standalone node * Add plotter * Add rostest * Arrange directory * Better test and plot settings * Following PEP & small fix cpp * Avoid repeted heap allocation * Standalone reeds-shepp * Licence notice * Use struct instead of raw array * Update license * Removed comment * Add how to use python visualizer * Remove useless methods * Apply clang-format * Do not fully expose StateXYT * Remove StateXYT->q[3] conversion * Use StateXYZ & remove useless functions * Add license in test * Update planning/scenario_planning/parking/astar_search/include/astar_search/astar_search.h Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Update planning/scenario_planning/parking/astar_search/src/astar_search.cpp Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Install reeds-shepp * Apply markdownlint Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Boost collision checking by pre-caching the collision indexes for all yaw angles (autowarefoundation#1298) * Precompute collision index for all theta to accelearte collision * Add test condition that checks solution's feasibility * Fix in response to the review * Update planning/scenario_planning/parking/astar_search/include/astar_search/astar_search.h Co-authored-by: tkimura4 <tomoya.kimura@tier4.jp> * Use inline (autowarefoundation#1572) * Modular planner (autowarefoundation#1492) * Update * Check working (NOTE somehow 2x faster than the original... why???) * Split header and impl * AstarWaypoint => PlannerWaypoint * AstarParam => PlannerParam * Change package name : astar_search => planning_algorithms * Add override keyword for readability * Apply clang-format & Add License * Remove useless executable * Rearange some functions and members * Add include guard * Remove unused node status * Add virtual destructor * Rename test names * Removed duplicate transformPose * Do not expose transformPose * Compatible planning_algorithms * Pointer to AbstractAlgorithm * Apply clang-format * Removed needless method declaration * Renamed planning_algorithms => parking_planning_algorithms * Add explicit * Apply clang-format * Split parameter into PlannerCommonParam and AstarParam * Tweak * Remove unused line * Split rosparam into common_param and astar_param * Fix package stuff reflect to the chagne of planning_algorithm pkg name * Change class name * Small fix (complied! and check running on Autoware) * Add rosparam : planning_algorithm * Fix comment and ros_info message * Remove useless ; * Add note * Add namespace * Fix typo * Apply clang-format 10 * Remove array3d * Avoid using std * Rename: parking => freespace * Avoid using namespace hoge * Update readme of freesapce planner * Apply clang-format * Update readme for freesplace_planning_algorithms * [freespace_planning_algorithms] apply aedd8626762121ad7 Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * fix inline definition Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * rename directory Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * rename function Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Fix bug yaw => index conversion * modify package.xml: fix license, add author Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * fix license Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Fix bug nearest_index must not be greater than the current target_index_ (autowarefoundation#1571) * Fixbug * Apply clang-format * Compute neareset index in the partial trajectory * extract partial_trajectory from current target trajectory Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * add explicit guard Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Cleanup & modify readme freespace planner (autowarefoundation#1607) * apply clang format Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * align indent Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * rename robot_shape -> vehicle_shape Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * rename step -> distance for TODO Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * modify include guard Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * fix comparison warning Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * update readme Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * add namespace on ros-parameters Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * use autoware_utils Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * align indent Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * fix comparison warning Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Rename files Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Remove boost constants Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Apply lint Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Add missing geometry2 apis Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Porting test code to ros2 Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Apply lint Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Install test script Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Change file mode of test script Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Fix map info data type in test script Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Add namespace and message abbreviation Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Fix typo Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Fix lint Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> * Fix for pre-commit Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix tf initialization Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp> Co-authored-by: Hirokazu Ishida <38597814+HiroIshida@users.noreply.github.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: tkimura4 <tomoya.kimura@tier4.jp> Co-authored-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix compile warnings (autowarefoundation#1852) Fix -Wunused-parameter Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> Fix -Wunused-private-field Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> Fix -Wunused-lambda-capture Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> Fix -Wdelete-non-abstract-non-virtual-dtor Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> Fix -Wrange-loop-construct Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> Ignore lint error Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * fix for createQuaternionFromRPY/Yaw (autowarefoundation#2154) * Change formatter to clang-format and black (autowarefoundation#2332) * Revert "Temporarily comment out pre-commit hooks" This reverts commit 748e9cdb145ce12f8b520bcbd97f5ff899fc28a3. * Replace ament_lint_common with autoware_lint_common Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Remove ament_cmake_uncrustify and ament_clang_format Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Apply Black Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Apply clang-format Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix build errors Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix for cpplint * Fix include double quotes to angle brackets Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Apply clang-format Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Fix build errors Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Add COLCON_IGNORE (autowarefoundation#500) Signed-off-by: Kenji Miyake <kenji.miyake@tier4.jp> * Port parking planner packages from .Auto (autowarefoundation#600) * Copy code of 'vehicle_constants_manager' * Fix vehicle_constants_manager for ROS galactic * Rm .iv costmap_generator freespace_planner freespace_planning_aglorihtms * Add astar_search (from .Auto) * Copy freespace_planner from .Auto * Update freespace_planner for .IV * Copy costmap_generator from .Auto * Copy and update had_map_utils from .Auto * Update costmap_generator * Copy costmap_generator_nodes * Update costmap_generator_nodes * Comment out all tests * Move vehicle_constant_managers to tmp_autoware_auto_dependencies * ignore pre-commit for back-ported packages Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> * ignore testing Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> * Port parking modules (autowarefoundation#738) * Port costmap_generator * Port freespace_planner * fix readme Co-authored-by: Daisuke Nishimatsu <42202095+wep21@users.noreply.github.com> Co-authored-by: Hirokazu Ishida <38597814+HiroIshida@users.noreply.github.com> Co-authored-by: Takamasa Horibe <horibe.takamasa@gmail.com> Co-authored-by: Kenji Miyake <kenji.miyake@tier4.jp> Co-authored-by: Takayuki Murooka <takayuki5168@gmail.com> Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> Co-authored-by: Maxime CLEMENT <78338830+maxime-clem@users.noreply.github.com> Co-authored-by: Fumiya Watanabe <rej55.g@gmail.com> Co-authored-by: Takeshi Miura <57553950+1222-takeshi@users.noreply.github.com>
1 parent b319f8a commit 679d6bd

13 files changed

+2180
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(freespace_planning_algorithms)
3+
4+
if(NOT CMAKE_CXX_STANDARD)
5+
set(CMAKE_CXX_STANDARD 14)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
endif()
9+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
10+
add_compile_options(-Wall -Wextra -Wpedantic)
11+
endif()
12+
13+
find_package(ament_cmake_auto REQUIRED)
14+
ament_auto_find_build_dependencies()
15+
16+
ament_auto_add_library(reeds_shepp SHARED
17+
src/reeds_shepp.cpp
18+
)
19+
20+
ament_auto_add_library(freespace_planning_algorithms SHARED
21+
src/abstract_algorithm.cpp
22+
src/astar_search.cpp
23+
)
24+
25+
target_link_libraries(freespace_planning_algorithms
26+
reeds_shepp
27+
)
28+
29+
if(BUILD_TESTING)
30+
find_package(ament_lint_auto REQUIRED)
31+
ament_lint_auto_find_test_dependencies()
32+
33+
find_package(ament_cmake_gtest REQUIRED)
34+
ament_add_gtest(freespace_planning_algorithms-test
35+
test/src/test_freespace_planning_algorithms.cpp
36+
)
37+
target_link_libraries(freespace_planning_algorithms-test
38+
freespace_planning_algorithms
39+
)
40+
endif()
41+
42+
ament_auto_package(
43+
INSTALL_TO_SHARE
44+
)
45+
46+
install(PROGRAMS
47+
test/debug_plot.py
48+
DESTINATION lib/${PROJECT_NAME}
49+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# `freespace planning algorithms`
2+
3+
## Role
4+
5+
This package is for development of path planning algorithms in free space.
6+
7+
### Implemented algorithms
8+
9+
- Hybrid A\*
10+
11+
## Guide to implement a new algorithm
12+
13+
- All planning algorithm class in this package must inherit `AbstractPlanningAlgorithm`
14+
class. If necessary, please overwrite the virtual functions.
15+
- All algorithms must use `nav_msgs::OccupancyGrid`-typed costmap.
16+
Thus, `AbstractPlanningAlgorithm` class mainly implements the collision checking
17+
using the costmap, grid-based indexing, and coordinate transformation related to
18+
costmap.
19+
- All algorithms must take both `PlannerCommonParam`-typed and algorithm-specific-
20+
type structs as inputs of the constructor. For example, `AstarSearch` class's
21+
constructor takes both `PlannerCommonParam` and `AstarParam`.
22+
23+
## Running the standalone tests and visualization
24+
25+
Building the package with ros-test and run tests:
26+
27+
```sh
28+
colcon build --packages-select freespace_planning_algorithms
29+
colcon test --packages-select freespace_planning_algorithms
30+
```
31+
32+
Inside the test, simulation results are stored in `/tmp/result_*.txt`.
33+
34+
Note that the postfix corresponds to the testing scenario (multiple curvatures and single curvature cases).
35+
Loading these resulting files, by using [test/debug_plot.py](test/debug_plot.py),
36+
one can create plots visualizing the path and obstacles as shown
37+
in the figures below.
38+
39+
The created figures are then again saved in `/tmp` with the name like `/tmp/result_multi0.png`.
40+
41+
![sample output figure](figs/freespace_planning_algorithms_astar_test_results.png)
42+
43+
The black cells, green box, and red box, respectively, indicate obstacles,
44+
start configuration, and goal configuration.
45+
The sequence of the blue boxes indicate the solution path.
46+
47+
## License notice
48+
49+
Files `src/reeds_shepp.cpp` and `include/astar_search/reeds_shepp.h`
50+
are fetched from [pyReedsShepp](https://github.com/ghliu/pyReedsShepp).
51+
Note that the implementation in `pyReedsShepp` is also heavily based on
52+
the code in [ompl](https://github.com/ompl/ompl).
53+
Both `pyReedsShepp` and `ompl` are distributed under 3-clause BSD license.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// Copyright 2021 Tier IV, Inc. All rights reserved.
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 FREESPACE_PLANNING_ALGORITHMS__ABSTRACT_ALGORITHM_HPP_
16+
#define FREESPACE_PLANNING_ALGORITHMS__ABSTRACT_ALGORITHM_HPP_
17+
18+
#include <geometry_msgs/msg/pose_array.hpp>
19+
#include <nav_msgs/msg/occupancy_grid.hpp>
20+
21+
#include <tf2/utils.h>
22+
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
23+
24+
#include <vector>
25+
26+
// TODO(wep21): Remove these apis
27+
// after they are implemented in ros2 geometry2.
28+
namespace tf2
29+
{
30+
inline void fromMsg(const geometry_msgs::msg::Point & in, tf2::Vector3 & out)
31+
{
32+
out = tf2::Vector3(in.x, in.y, in.z);
33+
}
34+
35+
template <>
36+
inline void doTransform(
37+
const geometry_msgs::msg::Pose & t_in, geometry_msgs::msg::Pose & t_out,
38+
const geometry_msgs::msg::TransformStamped & transform)
39+
{
40+
tf2::Vector3 v;
41+
fromMsg(t_in.position, v);
42+
tf2::Quaternion r;
43+
fromMsg(t_in.orientation, r);
44+
45+
tf2::Transform t;
46+
fromMsg(transform.transform, t);
47+
tf2::Transform v_out = t * tf2::Transform(r, v);
48+
toMsg(v_out, t_out);
49+
}
50+
} // namespace tf2
51+
52+
namespace freespace_planning_algorithms
53+
{
54+
int discretizeAngle(const double theta, const int theta_size);
55+
56+
struct IndexXYT
57+
{
58+
int x;
59+
int y;
60+
int theta;
61+
};
62+
63+
struct IndexXY
64+
{
65+
int x;
66+
int y;
67+
};
68+
69+
IndexXYT pose2index(
70+
const nav_msgs::msg::OccupancyGrid & costmap, const geometry_msgs::msg::Pose & pose_local,
71+
const int theta_size);
72+
73+
geometry_msgs::msg::Pose index2pose(
74+
const nav_msgs::msg::OccupancyGrid & costmap, const IndexXYT & index, const int theta_size);
75+
76+
geometry_msgs::msg::Pose global2local(
77+
const nav_msgs::msg::OccupancyGrid & costmap, const geometry_msgs::msg::Pose & pose_global);
78+
79+
geometry_msgs::msg::Pose local2global(
80+
const nav_msgs::msg::OccupancyGrid & costmap, const geometry_msgs::msg::Pose & pose_local);
81+
82+
struct VehicleShape
83+
{
84+
double length; // X [m]
85+
double width; // Y [m]
86+
double base2back; // base_link to rear [m]
87+
};
88+
89+
struct PlannerCommonParam
90+
{
91+
// base configs
92+
double time_limit; // planning time limit [msec]
93+
94+
// robot configs
95+
VehicleShape vehicle_shape;
96+
double minimum_turning_radius; // [m]
97+
double maximum_turning_radius; // [m]
98+
int turning_radius_size; // discretized turning radius table size [-]
99+
100+
// search configs
101+
int theta_size; // discretized angle table size [-]
102+
double curve_weight; // curve moving cost [-]
103+
double reverse_weight; // backward moving cost [-]
104+
double lateral_goal_range; // reaching threshold, lateral error [m]
105+
double longitudinal_goal_range; // reaching threshold, longitudinal error [m]
106+
double angle_goal_range; // reaching threshold, angle error [deg]
107+
108+
// costmap configs
109+
int obstacle_threshold; // obstacle threshold on grid [-]
110+
};
111+
112+
struct PlannerWaypoint
113+
{
114+
geometry_msgs::msg::PoseStamped pose;
115+
bool is_back = false;
116+
};
117+
118+
struct PlannerWaypoints
119+
{
120+
std_msgs::msg::Header header;
121+
std::vector<PlannerWaypoint> waypoints;
122+
};
123+
124+
class AbstractPlanningAlgorithm
125+
{
126+
public:
127+
explicit AbstractPlanningAlgorithm(const PlannerCommonParam & planner_common_param)
128+
: planner_common_param_(planner_common_param)
129+
{
130+
}
131+
virtual void setMap(const nav_msgs::msg::OccupancyGrid & costmap);
132+
virtual bool makePlan(
133+
const geometry_msgs::msg::Pose & start_pose, const geometry_msgs::msg::Pose & goal_pose) = 0;
134+
virtual bool hasFeasibleSolution() = 0; // currently used only in testing
135+
void setVehicleShape(const VehicleShape & vehicle_shape)
136+
{
137+
planner_common_param_.vehicle_shape = vehicle_shape;
138+
}
139+
bool hasObstacleOnTrajectory(const geometry_msgs::msg::PoseArray & trajectory);
140+
const PlannerWaypoints & getWaypoints() const { return waypoints_; }
141+
virtual ~AbstractPlanningAlgorithm() {}
142+
143+
protected:
144+
void computeCollisionIndexes(int theta_index, std::vector<IndexXY> & indexes);
145+
bool detectCollision(const IndexXYT & base_index);
146+
inline bool isOutOfRange(const IndexXYT & index)
147+
{
148+
if (index.x < 0 || static_cast<int>(costmap_.info.width) <= index.x) {
149+
return true;
150+
}
151+
if (index.y < 0 || static_cast<int>(costmap_.info.height) <= index.y) {
152+
return true;
153+
}
154+
return false;
155+
}
156+
inline bool isObs(const IndexXYT & index)
157+
{
158+
// NOTE: Accessing by .at() instead makes 1.2 times slower here.
159+
// Also, boundary check is already done in isOutOfRange before calling this function.
160+
// So, basically .at() is not necessary.
161+
return is_obstacle_table_[index.y][index.x];
162+
}
163+
164+
PlannerCommonParam planner_common_param_;
165+
166+
// costmap as occupancy grid
167+
nav_msgs::msg::OccupancyGrid costmap_;
168+
169+
// collision indexes cache
170+
std::vector<std::vector<IndexXY>> coll_indexes_table_;
171+
172+
// is_obstacle's table
173+
std::vector<std::vector<bool>> is_obstacle_table_;
174+
175+
// pose in costmap frame
176+
geometry_msgs::msg::Pose start_pose_;
177+
geometry_msgs::msg::Pose goal_pose_;
178+
179+
// result path
180+
PlannerWaypoints waypoints_;
181+
};
182+
183+
} // namespace freespace_planning_algorithms
184+
185+
#endif // FREESPACE_PLANNING_ALGORITHMS__ABSTRACT_ALGORITHM_HPP_

0 commit comments

Comments
 (0)