Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
goal_angle_critic.cpp
1 // Copyright (c) 2022 Samsung Research America, @artofnothingness Alexey Budyakov
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 #include "nav2_mppi_controller/critics/goal_angle_critic.hpp"
16 
17 namespace mppi::critics
18 {
19 
21 {
22  auto getParentParam = parameters_handler_->getParamGetter(parent_name_);
23  getParentParam(enforce_path_inversion_, "enforce_path_inversion", false);
24 
25  auto getParam = parameters_handler_->getParamGetter(name_);
26  getParam(power_, "cost_power", 1);
27  getParam(weight_, "cost_weight", 3.0f);
28  getParam(threshold_to_consider_, "threshold_to_consider", 0.5f);
29 
30  RCLCPP_INFO(
31  logger_,
32  "GoalAngleCritic instantiated with %d power, %f weight, and %f "
33  "angular threshold.",
34  power_, weight_, threshold_to_consider_);
35 }
36 
38 {
39  if (!enabled_) {
40  return;
41  }
42 
43  geometry_msgs::msg::Pose goal = utils::getCriticGoal(data, enforce_path_inversion_);
44 
45  if (!utils::withinPositionGoalTolerance(
46  threshold_to_consider_, data.state.pose.pose, goal))
47  {
48  return;
49  }
50 
51  double goal_yaw = tf2::getYaw(goal.orientation);
52 
53  if(power_ > 1u) {
54  data.costs += (((utils::shortest_angular_distance(data.trajectories.yaws, goal_yaw).abs()).
55  rowwise().mean()) * weight_).pow(power_).eval();
56  } else {
57  data.costs += (((utils::shortest_angular_distance(data.trajectories.yaws, goal_yaw).abs()).
58  rowwise().mean()) * weight_).eval();
59  }
60 }
61 
62 } // namespace mppi::critics
63 
64 #include <pluginlib/class_list_macros.hpp>
65 
66 PLUGINLIB_EXPORT_CLASS(
auto getParamGetter(const std::string &ns)
Get an object to retrieve parameters.
Abstract critic objective function to score trajectories.
void initialize() override
Initialize critic.
void score(CriticData &data) override
Evaluate cost related to robot orientation at goal pose (considered only if robot near last goal in c...
Data to pass to critics for scoring, including state, trajectories, pruned path, global goal,...
Definition: critic_data.hpp:40