-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Smac Planner] Enable goal orientation non-specificity #4019
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,39 +179,98 @@ template<> | |
void AStarAlgorithm<Node2D>::setGoal( | ||
const unsigned int & mx, | ||
const unsigned int & my, | ||
const unsigned int & dim_3) | ||
const unsigned int & dim_3, | ||
const GoalHeading & goal_heading) | ||
{ | ||
if (dim_3 != 0) { | ||
throw std::runtime_error("Node type Node2D cannot be given non-zero goal dim 3."); | ||
} | ||
|
||
_goal = addToGraph(Node2D::getIndex(mx, my, getSizeX())); | ||
_goal_coordinates = Node2D::Coordinates(mx, my); | ||
_goal.clear(); | ||
_goal_coordinates.clear(); | ||
_goals.push_back(addToGraph(Node2D::getIndex(mx, my, getSizeX()))); | ||
_goals_coordinates.push_back(Node2D::Coordinates(mx, my)); | ||
} | ||
|
||
template<typename NodeT> | ||
void AStarAlgorithm<NodeT>::setGoal( | ||
const unsigned int & mx, | ||
const unsigned int & my, | ||
const unsigned int & dim_3) | ||
const unsigned int & dim_3, | ||
const GoalHeading & goal_heading) | ||
{ | ||
_goal = addToGraph(NodeT::getIndex(mx, my, dim_3)); | ||
_goals.clear(); | ||
// _goals_coordinates.clear(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this line? |
||
std::vector<Coordinates> goal_coordinates; | ||
unsigned int number_of_bins = NodeT::motion_table.getNumOfBins(); | ||
if(goal_heading == GoalHeading::DEFAULT){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could do this with a |
||
_goals.push_back(addToGraph(NodeT::getIndex(mx, my, dim_3))); | ||
goal_coordinates.push_back(typename NodeT::Coordinates( | ||
static_cast<float>(mx), | ||
static_cast<float>(my), | ||
static_cast<float>(dim_3))); | ||
}else if(goal_heading == GoalHeading::BIDIRECTIONAL) | ||
{ | ||
_goals.push_back(addToGraph(NodeT::getIndex(mx, my, dim_3))); | ||
// add angle -180 | ||
_goals.push_back(addToGraph(NodeT::getIndex(mx, my, dim_3 + number_of_bins/2))); | ||
goal_coordinates.push_back(typename NodeT::Coordinates( | ||
static_cast<float>(mx), | ||
static_cast<float>(my), | ||
static_cast<float>(dim_3))); | ||
goal_coordinates.push_back(typename NodeT::Coordinates( | ||
static_cast<float>(mx), | ||
static_cast<float>(my), | ||
static_cast<float>(dim_3 + number_of_bins/2))); | ||
|
||
}else if (goal_heading == GoalHeading::ANY_HEADING) | ||
{ | ||
for (unsigned int i = 0; i < number_of_bins; i++) | ||
{ | ||
_goals.push_back(addToGraph(NodeT::getIndex(mx, my, i))); | ||
goal_coordinates.push_back(typename NodeT::Coordinates( | ||
static_cast<float>(mx), | ||
static_cast<float>(my), | ||
static_cast<float>(i))); | ||
} | ||
} | ||
else | ||
{ | ||
throw std::runtime_error("Goal Heading not supported"); | ||
} | ||
|
||
typename NodeT::Coordinates goal_coords( | ||
static_cast<float>(mx), | ||
static_cast<float>(my), | ||
static_cast<float>(dim_3)); | ||
auto has_goals_changed = [](const std::vector<Coordinates> & current_goal_coordinates,const std::vector<Coordinates> & previous_goal_coordinates) -> bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this lambda. Why not simply do |
||
{ | ||
if(current_goal_coordinates.size() != previous_goal_coordinates.size()) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
for(unsigned int i = 0; i < goal_coordinates.size() - 1; i++) | ||
{ | ||
if(goal_coordinates[i] != goal_coordinates[i+1]) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (!_search_info.cache_obstacle_heuristic || goal_coords != _goal_coordinates) { | ||
if (!_search_info.cache_obstacle_heuristic || has_goals_changed(goal_coordinates)) { | ||
if (!_start) { | ||
throw std::runtime_error("Start must be set before goal."); | ||
} | ||
|
||
NodeT::resetObstacleHeuristic(_costmap, _start->pose.x, _start->pose.y, mx, my); | ||
} | ||
|
||
_goal_coordinates = goal_coords; | ||
_goal->setPose(_goal_coordinates); | ||
_goals_coordinates.clear(); | ||
_goals_coordinates = goal_coordinates; | ||
for(int i = 0; i < _goals_coordinates.size(); i++) | ||
{ | ||
_goals[i]->setPose(_goals_coordinates[i]); | ||
} | ||
} | ||
|
||
template<typename NodeT> | ||
|
@@ -368,6 +427,7 @@ bool AStarAlgorithm<NodeT>::isGoal(NodePtr & node) | |
return node == getGoal(); | ||
} | ||
|
||
|
||
template<typename NodeT> | ||
typename AStarAlgorithm<NodeT>::NodePtr & AStarAlgorithm<NodeT>::getStart() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,6 +337,11 @@ float HybridMotionTable::getAngleFromBin(const unsigned int & bin_idx) | |
return bin_idx * bin_size; | ||
} | ||
|
||
unsigned int getNumOfBins() | ||
{ | ||
return num_angle_quantization; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could just use |
||
} | ||
|
||
NodeHybrid::NodeHybrid(const unsigned int index) | ||
: parent(nullptr), | ||
pose(0.0f, 0.0f, 0.0f), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,20 @@ void SmacPlannerHybrid::configure( | |
nav2_util::declare_parameter_if_not_declared( | ||
node, name + ".motion_model_for_search", rclcpp::ParameterValue(std::string("DUBIN"))); | ||
node->get_parameter(name + ".motion_model_for_search", _motion_model_for_search); | ||
|
||
nav2_util::declare_parameter_if_not_declared( | ||
node, name + ".goal_heading", rclcpp::ParameterValue("DEFAULT")); | ||
node->get_parameter(name + ".goal_heading", _goal_heading_type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to store the string type if you're storing the enum class |
||
|
||
_goal_heading = fromStringToGH(_goal_heading_type); | ||
if(_goal_heading == GoalHeading::UNKNOWN) | ||
{ | ||
RCLCPP_WARN( | ||
_logger, | ||
"Unable to get GoalHeader type. Given '%s', " | ||
"Valid options are DEFAULT, BIDIRECTIONAL, ANY_HEADING. ", | ||
_goal_heading_type.c_str()); | ||
} | ||
_motion_model = fromString(_motion_model_for_search); | ||
if (_motion_model == MotionModel::UNKNOWN) { | ||
RCLCPP_WARN( | ||
|
@@ -359,7 +373,7 @@ nav_msgs::msg::Path SmacPlannerHybrid::createPlan( | |
orientation_bin -= static_cast<float>(_angle_quantizations); | ||
} | ||
orientation_bin_id = static_cast<unsigned int>(floor(orientation_bin)); | ||
_a_star->setGoal(mx, my, orientation_bin_id); | ||
_a_star->setGoal(mx, my, orientation_bin_id, _goal_heading); | ||
|
||
// Setup message | ||
nav_msgs::msg::Path plan; | ||
|
@@ -600,6 +614,17 @@ SmacPlannerHybrid::dynamicParametersCallback(std::vector<rclcpp::Parameter> para | |
"valid options are MOORE, VON_NEUMANN, DUBIN, REEDS_SHEPP.", | ||
_motion_model_for_search.c_str()); | ||
} | ||
}else if (name == _name + ".goal_heading") { | ||
_goal_heading_type = parameter.as_string(); | ||
_goal_heading = fromStringToGH(_goal_heading_type); | ||
if(_goal_heading == GoalHeading::UNKNOWN) | ||
{ | ||
RCLCPP_WARN( | ||
_logger, | ||
"Unable to get GoalHeader type. Given '%s', " | ||
"Valid options are DEFAULT, BIDIRECTIONAL, ANY_HEADING. ", | ||
_goal_heading_type.c_str()); | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the concern? I think this works fine, anything more you want to expand on here?