Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State Lattice Planner Work Revival #2582

Merged
merged 34 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a1b396c
adding state lattice beginning point
SteveMacenski Oct 6, 2021
42bb3c8
refactoring to remove analytic expansion into its own object
SteveMacenski Oct 6, 2021
e7e28c6
moving smoother and collision checker into cpp files
SteveMacenski Oct 6, 2021
399f0e4
allowing smac planner to work with irregular bin distributions
SteveMacenski Oct 7, 2021
092c1d9
integrating @jwallice42 s work and enabling reverse expansions
SteveMacenski Oct 11, 2021
4119ef3
adding in intermediate collision checking and backtracing
SteveMacenski Oct 13, 2021
461d2fa
adding traversal function
SteveMacenski Oct 14, 2021
1d71992
adding test coverage and passing for node lattice
SteveMacenski Oct 18, 2021
79f8f00
adding updated rosdep key
SteveMacenski Oct 18, 2021
6425699
compiling, generating paths (though bogus)
SteveMacenski Oct 25, 2021
a51790c
adding working base code
SteveMacenski Oct 28, 2021
e6dca9b
adding search info
SteveMacenski Oct 28, 2021
3a89142
fully working for non-lateral lattices
SteveMacenski Oct 28, 2021
0a81707
removing downsampler for lattice, pushing in cost penalty
SteveMacenski Oct 29, 2021
f2f48f6
adding in updated heuristics, tuned gains, and generally working for …
SteveMacenski Nov 12, 2021
460271d
reverse expansion working
SteveMacenski Nov 16, 2021
391be46
adding complete support, refactoring, etc
SteveMacenski Nov 16, 2021
1659f1c
adding forgotten files
SteveMacenski Nov 16, 2021
f62b7ce
adding readme updates
SteveMacenski Nov 16, 2021
f69a49b
Merge branch 'main' into state_lattice_2
SteveMacenski Nov 16, 2021
1610710
adding max planning time to state lattice
SteveMacenski Nov 16, 2021
ac46c02
adding dynamic parameters
SteveMacenski Nov 16, 2021
6bde250
removing extra config file
SteveMacenski Nov 16, 2021
49b059b
fix linting
SteveMacenski Nov 17, 2021
f364aff
updating test
SteveMacenski Nov 17, 2021
be1993b
adding several unit tests
SteveMacenski Nov 17, 2021
d841fc8
adding system test
SteveMacenski Nov 17, 2021
8373365
fixing crash
SteveMacenski Nov 17, 2021
f1ee728
adding default model
SteveMacenski Nov 17, 2021
4c2b5ae
adding corrected exporting of plugins
SteveMacenski Nov 17, 2021
d7b26d7
Merge branch 'main' into state_lattice_2
SteveMacenski Nov 17, 2021
36f32c0
adding more test coverage
SteveMacenski Nov 17, 2021
a4f8ff5
Merge branch 'state_lattice_2' of github.com:ros-planning/navigation2…
SteveMacenski Nov 17, 2021
8da0f29
reorder tests to see if natters
SteveMacenski Nov 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nav2_navfn_planner/src/navfn_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "nav2_costmap_2d/cost_values.hpp"

using namespace std::chrono_literals;
using namespace std::chrono; // NOLINT
using nav2_util::declare_parameter_if_not_declared;
using rcl_interfaces::msg::ParameterType;
using std::placeholders::_1;
Expand Down Expand Up @@ -180,8 +181,7 @@ nav_msgs::msg::Path NavfnPlanner::createPlan(
#ifdef BENCHMARK_TESTING
steady_clock::time_point b = steady_clock::now();
duration<double> time_span = duration_cast<duration<double>>(b - a);
std::cout << "It took " << time_span.count() * 1000 <<
" milliseconds with " << num_iterations << " iterations." << std::endl;
std::cout << "It took " << time_span.count() * 1000 << std::endl;
#endif

return path;
Expand Down
40 changes: 37 additions & 3 deletions nav2_smac_planner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ find_package(nav2_costmap_2d REQUIRED)
find_package(pluginlib REQUIRED)
find_package(eigen3_cmake_module REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(angles REQUIRED)
find_package(ompl REQUIRED)
find_package(OpenMP REQUIRED)

Expand Down Expand Up @@ -66,16 +67,22 @@ set(dependencies
nav2_costmap_2d
nav2_core
pluginlib
angles
eigen3_cmake_module
)

# Hybrid plugin
add_library(${library_name} SHARED
src/smac_planner_hybrid.cpp
src/a_star.cpp
src/collision_checker.cpp
src/smoother.cpp
src/analytic_expansion.cpp
src/node_hybrid.cpp
src/node_lattice.cpp
src/costmap_downsampler.cpp
src/node_2d.cpp
src/node_basic.cpp
)

target_link_libraries(${library_name} ${OMPL_LIBRARIES} ${OpenMP_LIBRARIES} OpenMP::OpenMP_CXX)
Expand All @@ -89,9 +96,14 @@ ament_target_dependencies(${library_name}
add_library(${library_name}_2d SHARED
src/smac_planner_2d.cpp
src/a_star.cpp
src/smoother.cpp
src/collision_checker.cpp
src/analytic_expansion.cpp
src/node_hybrid.cpp
src/node_lattice.cpp
src/costmap_downsampler.cpp
src/node_2d.cpp
src/node_basic.cpp
)

target_link_libraries(${library_name}_2d ${OMPL_LIBRARIES})
Expand All @@ -101,10 +113,32 @@ ament_target_dependencies(${library_name}_2d
${dependencies}
)

pluginlib_export_plugin_description_file(nav2_core smac_plugin.xml)
# Lattice plugin
add_library(${library_name}_lattice SHARED
src/smac_planner_lattice.cpp
src/a_star.cpp
src/smoother.cpp
src/collision_checker.cpp
src/analytic_expansion.cpp
src/node_hybrid.cpp
src/node_lattice.cpp
src/costmap_downsampler.cpp
src/node_2d.cpp
src/node_basic.cpp
)

target_link_libraries(${library_name}_lattice ${OMPL_LIBRARIES})
target_include_directories(${library_name}_lattice PUBLIC ${Eigen3_INCLUDE_DIRS})

ament_target_dependencies(${library_name}_lattice
${dependencies}
)

pluginlib_export_plugin_description_file(nav2_core smac_plugin_hybrid.xml)
pluginlib_export_plugin_description_file(nav2_core smac_plugin_2d.xml)
pluginlib_export_plugin_description_file(nav2_core smac_plugin_lattice.xml)

install(TARGETS ${library_name} ${library_name}_2d
install(TARGETS ${library_name} ${library_name}_2d ${library_name}_lattice
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION lib/${PROJECT_NAME}
Expand All @@ -122,6 +156,6 @@ if(BUILD_TESTING)
endif()

ament_export_include_directories(include)
ament_export_libraries(${library_name} ${library_name}_2d)
ament_export_libraries(${library_name} ${library_name}_2d ${library_name}_lattice)
ament_export_dependencies(${dependencies})
ament_package()
85 changes: 57 additions & 28 deletions nav2_smac_planner/README.md

Large diffs are not rendered by default.

57 changes: 3 additions & 54 deletions nav2_smac_planner/include/nav2_smac_planner/a_star.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@

#include "nav2_costmap_2d/costmap_2d.hpp"

#include "nav2_smac_planner/analytic_expansion.hpp"
#include "nav2_smac_planner/node_2d.hpp"
#include "nav2_smac_planner/node_hybrid.hpp"
#include "nav2_smac_planner/node_lattice.hpp"
#include "nav2_smac_planner/node_basic.hpp"
#include "nav2_smac_planner/types.hpp"
#include "nav2_smac_planner/constants.hpp"
Expand All @@ -52,27 +54,6 @@ class AStarAlgorithm
typedef typename NodeVector::iterator NeighborIterator;
typedef std::function<bool (const unsigned int &, NodeT * &)> NodeGetter;

/**
* @struct nav2_smac_planner::AnalyticExpansionNodes
* @brief Analytic expansion nodes and associated metadata
*/

struct AnalyticExpansionNode
{
AnalyticExpansionNode(
NodePtr & node_in,
Coordinates & initial_coords_in,
Coordinates & proposed_coords_in)
: node(node_in), initial_coords(initial_coords_in), proposed_coords(proposed_coords_in)
{}

NodePtr node;
Coordinates initial_coords;
Coordinates proposed_coords;
};

typedef std::vector<AnalyticExpansionNode> AnalyticExpansionNodes;

/**
* @struct nav2_smac_planner::NodeComparator
* @brief Node comparison for priority queue sorting
Expand Down Expand Up @@ -229,14 +210,6 @@ class AStarAlgorithm
*/
inline bool isGoal(NodePtr & node);

/**
* @brief Set the starting pose for planning, as a node index
* @param node Node pointer to the goal node to backtrace
* @param path Reference to a vector of indicies of generated path
* @return whether the path was able to be backtraced
*/
bool backtracePath(NodePtr node, CoordinateVector & path);

/**
* @brief Get cost of heuristic of node
* @param node Node index current
Expand All @@ -261,31 +234,6 @@ class AStarAlgorithm
*/
inline void clearGraph();

/**
* @brief Attempt an analytic path completion
* @return Node pointer reference to goal node if successful, else
* return nullptr
*/
NodePtr tryAnalyticExpansion(
const NodePtr & current_node,
const NodeGetter & getter, int & iterations, int & best_cost);

/**
* @brief Perform an analytic path expansion to the goal
* @param node The node to start the analytic path from
* @param getter The function object that gets valid nodes from the graph
* @return A set of analytically expanded nodes to the goal from current node, if possible
*/
AnalyticExpansionNodes getAnalyticPath(const NodePtr & node, const NodeGetter & getter);

/**
* @brief Takes final analytic expansion and appends to current expanded node
* @param node The node to start the analytic path from
* @param expanded_nodes Expanded nodes to append to end of current search path
* @return Node pointer to goal node if successful, else return nullptr
*/
NodePtr setAnalyticPath(const NodePtr & node, const AnalyticExpansionNodes & expanded_nodes);

int _timing_interval = 5000;

bool _traverse_unknown;
Expand All @@ -310,6 +258,7 @@ class AStarAlgorithm

GridCollisionChecker * _collision_checker;
nav2_costmap_2d::Costmap2D * _costmap;
std::unique_ptr<AnalyticExpansion<NodeT>> _expander;
};

} // namespace nav2_smac_planner
Expand Down
130 changes: 130 additions & 0 deletions nav2_smac_planner/include/nav2_smac_planner/analytic_expansion.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright (c) 2021, Samsung Research America
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License. Reserved.

#ifndef NAV2_SMAC_PLANNER__ANALYTIC_EXPANSION_HPP_
#define NAV2_SMAC_PLANNER__ANALYTIC_EXPANSION_HPP_

#include <string>
#include <vector>

#include "nav2_smac_planner/node_2d.hpp"
#include "nav2_smac_planner/node_hybrid.hpp"
#include "nav2_smac_planner/node_lattice.hpp"
#include "nav2_smac_planner/types.hpp"
#include "nav2_smac_planner/constants.hpp"

namespace nav2_smac_planner
{

template<typename NodeT>
class AnalyticExpansion
{
public:
typedef NodeT * NodePtr;
typedef typename NodeT::Coordinates Coordinates;
typedef std::function<bool (const unsigned int &, NodeT * &)> NodeGetter;

/**
* @struct nav2_smac_planner::AnalyticExpansion::AnalyticExpansionNodes
* @brief Analytic expansion nodes and associated metadata
*/
struct AnalyticExpansionNode
{
AnalyticExpansionNode(
NodePtr & node_in,
Coordinates & initial_coords_in,
Coordinates & proposed_coords_in)
: node(node_in),
initial_coords(initial_coords_in),
proposed_coords(proposed_coords_in)
{
}

NodePtr node;
Coordinates initial_coords;
Coordinates proposed_coords;
};

typedef std::vector<AnalyticExpansionNode> AnalyticExpansionNodes;

/**
* @brief Constructor for analytic expansion object
*/
AnalyticExpansion(
const MotionModel & motion_model,
const SearchInfo & search_info,
const bool & traverse_unknown,
const unsigned int & dim_3_size);

/**
* @brief Sets the collision checker and costmap to use in expansion validation
* @param collision_checker Collision checker to use
*/
void setCollisionChecker(GridCollisionChecker * collision_checker);

/**
* @brief Attempt an analytic path completion
* @param node The node to start the analytic path from
* @param goal The goal node to plan to
* @param getter Gets a node at a set of coordinates
* @param iterations Iterations to run over
* @param best_cost Best heuristic cost to propertionally expand more closer to the goal
* @return Node pointer reference to goal node if successful, else
* return nullptr
*/
NodePtr tryAnalyticExpansion(
const NodePtr & current_node,
const NodePtr & goal_node,
const NodeGetter & getter, int & iterations, int & best_cost);

/**
* @brief Perform an analytic path expansion to the goal
* @param node The node to start the analytic path from
* @param goal The goal node to plan to
* @param getter The function object that gets valid nodes from the graph
* @return A set of analytically expanded nodes to the goal from current node, if possible
*/
AnalyticExpansionNodes getAnalyticPath(
const NodePtr & node, const NodePtr & goal,
const NodeGetter & getter);

/**
* @brief Takes final analytic expansion and appends to current expanded node
* @param node The node to start the analytic path from
* @param goal The goal node to plan to
* @param expanded_nodes Expanded nodes to append to end of current search path
* @return Node pointer to goal node if successful, else return nullptr
*/
NodePtr setAnalyticPath(
const NodePtr & node, const NodePtr & goal,
const AnalyticExpansionNodes & expanded_nodes);

/**
* @brief Takes an expanded nodes to clean up, if necessary, of any state
* information that may be poluting it from a prior search iteration
* @param expanded_nodes Expanded node to clean up from search
*/
void cleanNode(const NodePtr & nodes);

protected:
MotionModel _motion_model;
SearchInfo _search_info;
bool _traverse_unknown;
unsigned int _dim_3_size;
GridCollisionChecker * _collision_checker;
};

} // namespace nav2_smac_planner

#endif // NAV2_SMAC_PLANNER__ANALYTIC_EXPANSION_HPP_
Loading