Skip to content

Commit ebb8e63

Browse files
authored
Merge pull request #5 from fmrico/astar_gridmap
A* Planner for gridmaps
2 parents 5ba6b35 + 56696f4 commit ebb8e63

5 files changed

Lines changed: 481 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
project(easynav_gridmap_astar_planner)
3+
4+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5+
add_compile_options(-Wall -Wextra -Wpedantic)
6+
endif()
7+
8+
set(CMAKE_CXX_STANDARD 23)
9+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
set(CMAKE_CXX_EXTENSIONS OFF)
11+
12+
find_package(ament_cmake REQUIRED)
13+
find_package(easynav_common REQUIRED)
14+
find_package(easynav_core REQUIRED)
15+
find_package(pluginlib REQUIRED)
16+
find_package(nav_msgs REQUIRED)
17+
find_package(grid_map_ros REQUIRED)
18+
find_package(grid_map_msgs REQUIRED)
19+
20+
add_library(${PROJECT_NAME} SHARED
21+
src/easynav_gridmap_astar_planner/GridMapAStarPlanner.cpp
22+
)
23+
target_include_directories(${PROJECT_NAME} PUBLIC
24+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
25+
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
26+
)
27+
target_link_libraries(${PROJECT_NAME} PUBLIC
28+
easynav_common::easynav_common
29+
easynav_core::easynav_core
30+
pluginlib::pluginlib
31+
grid_map_ros::grid_map_ros
32+
${nav_msgs_TARGETS}
33+
${grid_map_msgs_TARGETS}
34+
)
35+
36+
install(
37+
DIRECTORY include/
38+
DESTINATION include/${PROJECT_NAME}
39+
)
40+
41+
install(TARGETS
42+
${PROJECT_NAME}
43+
EXPORT export_${PROJECT_NAME}
44+
ARCHIVE DESTINATION lib
45+
LIBRARY DESTINATION lib
46+
RUNTIME DESTINATION lib/${PROJECT_NAME}
47+
)
48+
49+
if(BUILD_TESTING)
50+
find_package(ament_lint_auto REQUIRED)
51+
set(ament_cmake_copyright_FOUND TRUE)
52+
set(ament_cmake_cpplint_FOUND TRUE)
53+
ament_lint_auto_find_test_dependencies()
54+
55+
find_package(ament_cmake_gtest REQUIRED)
56+
# add_subdirectory(tests)
57+
endif()
58+
59+
ament_export_include_directories("include/${PROJECT_NAME}")
60+
ament_export_libraries(${PROJECT_NAME})
61+
ament_export_targets(export_${PROJECT_NAME})
62+
63+
# Register the planning plugins
64+
pluginlib_export_plugin_description_file(easynav_core easynav_gridmap_astar_planner_plugins.xml)
65+
66+
ament_export_dependencies(
67+
easynav_common
68+
easynav_core
69+
easynav_simple_common
70+
pluginlib
71+
nav_msgs
72+
grid_map_ros
73+
grid_map_msgs
74+
)
75+
ament_package()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<class_libraries>
2+
<library path="easynav_gridmap_astar_planner">
3+
<class name="easynav_gridmap_astar_planner/GridMapAStarPlanner" type="easynav::GridMapAStarPlanner" base_class_type="easynav::PlannerMethodBase">
4+
<description>
5+
A default "simple" implementation for the A* path planner.
6+
</description>
7+
</class>
8+
</library>
9+
</class_libraries>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2025 Intelligent Robotics Lab
2+
//
3+
// This file is part of the project Easy Navigation (EasyNav in short)
4+
// licensed under the GNU General Public License v3.0.
5+
// See <http://www.gnu.org/licenses/> for details.
6+
//
7+
// Easy Navigation program is free software: you can redistribute it and/or modify
8+
// it under the terms of the GNU General Public License as published by
9+
// the Free Software Foundation, either version 3 of the License, or
10+
// (at your option) any later version.
11+
//
12+
// This program is distributed in the hope that it will be useful,
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
// GNU General Public License for more details.
16+
//
17+
// You should have received a copy of the GNU General Public License
18+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
/// \file
21+
/// \brief Declaration of the GridMapAStarPlanner class implementing A* path planning using elevation maps.
22+
23+
#ifndef EASYNAV_PLANNER__GRIDMAPASTARPLANNER_HPP_
24+
#define EASYNAV_PLANNER__GRIDMAPASTARPLANNER_HPP_
25+
26+
#include <memory>
27+
#include <vector>
28+
#include <string>
29+
#include <expected>
30+
31+
#include "rclcpp/rclcpp.hpp"
32+
#include "nav_msgs/msg/path.hpp"
33+
#include "geometry_msgs/msg/pose.hpp"
34+
35+
#include "easynav_core/PlannerMethodBase.hpp"
36+
#include "easynav_common/types/NavState.hpp"
37+
38+
#include "grid_map_core/GridMap.hpp"
39+
40+
namespace easynav
41+
{
42+
43+
/// \brief Planner based on A* algorithm using GridMap elevation data
44+
class GridMapAStarPlanner : public PlannerMethodBase
45+
{
46+
public:
47+
/// \brief Default constructor
48+
explicit GridMapAStarPlanner();
49+
50+
/**
51+
* @brief Initializes the planner.
52+
*
53+
* Creates necessary publishers/subscribers and initializes the map instances.
54+
*
55+
* @return std::expected<void, std::string> Success or error string.
56+
*/
57+
virtual std::expected<void, std::string> on_initialize() override;
58+
59+
/// \brief Computes a path using A* algorithm
60+
/// \param nav_state Current navigation state (with odometry and goals)
61+
void update(NavState & nav_state) override;
62+
63+
protected:
64+
double robot_radius_;
65+
double clearance_distance_;
66+
double max_allowed_slope_;
67+
68+
nav_msgs::msg::Path current_path_;
69+
rclcpp::Publisher<nav_msgs::msg::Path>::SharedPtr path_pub_;
70+
71+
/// \brief Internal A* implementation
72+
/// \param map The grid map with elevation layer
73+
/// \param start Pose in world coordinates
74+
/// \param goal Pose in world coordinates
75+
/// \return List of poses representing the path
76+
std::vector<geometry_msgs::msg::Pose> a_star_path(
77+
const grid_map::GridMap & map,
78+
const geometry_msgs::msg::Pose & start,
79+
const geometry_msgs::msg::Pose & goal);
80+
81+
/// \brief Checks if the slope between two cells is below threshold
82+
/// \param map The grid map
83+
/// \param from Index of the first cell
84+
/// \param to Index of the second cell
85+
/// \return true if slope is acceptable, false otherwise
86+
bool isTraversable(
87+
const grid_map::GridMap & map,
88+
const grid_map::Index & from,
89+
const grid_map::Index & to) const;
90+
};
91+
92+
} // namespace easynav
93+
94+
#endif // EASYNAV_PLANNER__GRIDMAPASTARPLANNER_HPP_
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>easynav_gridmap_astar_planner</name>
5+
<version>0.0.1</version>
6+
<description>Easy Navigation: Simple planner package.</description>
7+
<maintainer email="fmrico@gmail.com">fmrico</maintainer>
8+
<license>GPL-3.0-only</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<depend>easynav_common</depend>
13+
<depend>easynav_core</depend>
14+
<depend>pluginlib</depend>
15+
<depend>nav_msgs</depend>
16+
<depend>grid_map_ros</depend>
17+
<depend>grid_map_msgs</depend>
18+
19+
<test_depend>ament_lint_auto</test_depend>
20+
<test_depend>ament_lint_common</test_depend>
21+
<test_depend>ament_cmake_gtest</test_depend>
22+
23+
<export>
24+
<build_type>ament_cmake</build_type>
25+
</export>
26+
</package>

0 commit comments

Comments
 (0)