15 #include "nav2_mppi_controller/critics/path_follow_critic.hpp"
17 #include <xtensor/xmath.hpp>
18 #include <xtensor/xsort.hpp>
20 namespace mppi::critics
28 threshold_to_consider_,
29 "threshold_to_consider", 1.4);
30 getParam(offset_from_furthest_,
"offset_from_furthest", 6);
31 getParam(power_,
"cost_power", 1);
32 getParam(weight_,
"cost_weight", 5.0);
37 if (!enabled_ || data.path.x.shape(0) < 2 ||
38 utils::withinPositionGoalTolerance(threshold_to_consider_, data.state.pose.pose, data.goal))
43 utils::setPathFurthestPointIfNotSet(data);
44 utils::setPathCostsIfNotSet(data, costmap_ros_);
45 const size_t path_size = data.path.x.shape(0) - 1;
47 auto offseted_idx = std::min(
48 *data.furthest_reached_path_point + offset_from_furthest_, path_size);
53 while (!valid && offseted_idx < path_size - 1) {
54 valid = (*data.path_pts_valid)[offseted_idx];
60 const auto path_x = data.path.x(offseted_idx);
61 const auto path_y = data.path.y(offseted_idx);
63 const auto last_x = xt::view(data.trajectories.x, xt::all(), -1);
64 const auto last_y = xt::view(data.trajectories.y, xt::all(), -1);
66 auto dists = xt::sqrt(
67 xt::pow(last_x - path_x, 2) +
68 xt::pow(last_y - path_y, 2));
70 data.costs += xt::pow(weight_ * std::move(dists), power_);
75 #include <pluginlib/class_list_macros.hpp>
77 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,...