Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
twirling_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/twirling_critic.hpp"
16 
17 #include <Eigen/Dense>
18 
19 namespace mppi::critics
20 {
21 
23 {
24  auto getParentParam = parameters_handler_->getParamGetter(parent_name_);
25  auto getParam = parameters_handler_->getParamGetter(name_);
26  getParam(power_, "cost_power", 1);
27  getParam(weight_, "cost_weight", 10.0f);
28 
29  RCLCPP_INFO(
30  logger_, "TwirlingCritic instantiated with %d power and %f weight.", power_, weight_);
31 }
32 
34 {
35  if (!enabled_) {
36  return;
37  }
38 
39  if (data.goal_checker != nullptr) {
40  geometry_msgs::msg::Pose pose_tolerance;
41  geometry_msgs::msg::Twist velocity_tolerance;
42  double path_length_tolerance;
43  data.goal_checker->getTolerances(pose_tolerance, velocity_tolerance, path_length_tolerance);
44 
45  if (data.state.local_path_length < pose_tolerance.position.x) {
46  return;
47  }
48  }
49 
50  if (power_ > 1u) {
51  data.costs += ((data.state.wz.abs().rowwise().mean()) * weight_).pow(power_).eval();
52  } else {
53  data.costs += ((data.state.wz.abs().rowwise().mean()) * weight_).eval();
54  }
55 }
56 
57 } // namespace mppi::critics
58 
59 #include <pluginlib/class_list_macros.hpp>
60 
61 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...
virtual bool getTolerances(geometry_msgs::msg::Pose &pose_tolerance, geometry_msgs::msg::Twist &vel_tolerance, double &path_length_tolerance)=0
Get the maximum possible tolerances used for goal checking in the major types. Any field without a va...
Data to pass to critics for scoring, including state, trajectories, pruned path, global goal,...
Definition: critic_data.hpp:40