Nav2 Navigation Stack - jazzy  jazzy
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 namespace mppi::critics
18 {
19 
21 {
22  auto getParam = parameters_handler_->getParamGetter(name_);
23 
24  getParam(power_, "cost_power", 1);
25  getParam(weight_, "cost_weight", 10.0f);
26 
27  RCLCPP_INFO(
28  logger_, "TwirlingCritic instantiated with %d power and %f weight.", power_, weight_);
29 }
30 
32 {
33  using xt::evaluation_strategy::immediate;
34  if (!enabled_ ||
35  utils::withinPositionGoalTolerance(data.goal_checker, data.state.pose.pose, data.goal))
36  {
37  return;
38  }
39 
40  if (power_ > 1u) {
41  data.costs += xt::pow(xt::mean(xt::fabs(data.state.wz), {1}, immediate) * weight_, power_);
42  } else {
43  data.costs += xt::mean(xt::fabs(data.state.wz), {1}, immediate) * weight_;
44  }
45 }
46 
47 } // namespace mppi::critics
48 
49 #include <pluginlib/class_list_macros.hpp>
50 
51 PLUGINLIB_EXPORT_CLASS(
auto getParamGetter(const std::string &ns)
Get an object to retreive 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:45