16 #include "nav2_mppi_controller/critics/goal_critic.hpp"
18 namespace mppi::critics
21 using xt::evaluation_strategy::immediate;
27 getParam(power_,
"cost_power", 1);
28 getParam(weight_,
"cost_weight", 5.0);
29 getParam(threshold_to_consider_,
"threshold_to_consider", 1.4);
32 logger_,
"GoalCritic instantiated with %d power and %f weight.",
38 if (!enabled_ || !utils::withinPositionGoalTolerance(
39 threshold_to_consider_, data.state.pose.pose, data.goal))
44 const auto & goal_x = data.goal.position.x;
45 const auto & goal_y = data.goal.position.y;
47 const auto traj_x = xt::view(data.trajectories.x, xt::all(), xt::all());
48 const auto traj_y = xt::view(data.trajectories.y, xt::all(), xt::all());
50 auto dists = xt::sqrt(
51 xt::pow(traj_x - goal_x, 2) +
52 xt::pow(traj_y - goal_y, 2));
54 data.costs += xt::pow(xt::mean(dists, {1}, immediate) * weight_, power_);
59 #include <pluginlib/class_list_macros.hpp>
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 goal following.
Data to pass to critics for scoring, including state, trajectories, pruned path, global goal,...