15 #include "nav2_mppi_controller/critics/path_follow_critic.hpp"
17 #include <Eigen/Dense>
19 namespace mppi::critics
24 auto getParentParam = parameters_handler_->
getParamGetter(parent_name_);
25 getParentParam(enforce_path_inversion_,
"enforce_path_inversion",
false);
30 threshold_to_consider_,
31 "threshold_to_consider", 1.4f);
32 getParam(offset_from_furthest_,
"offset_from_furthest", 6);
33 getParam(power_,
"cost_power", 1);
34 getParam(weight_,
"cost_weight", 5.0f);
43 geometry_msgs::msg::Pose goal = utils::getCriticGoal(data, enforce_path_inversion_);
45 if (data.path.x.size() < 2 ||
46 utils::withinPositionGoalTolerance(
47 threshold_to_consider_, data.state.pose.pose, goal))
52 utils::setPathFurthestPointIfNotSet(data);
53 utils::setPathCostsIfNotSet(data, costmap_ros_);
54 const size_t path_size = data.path.x.size() - 1;
56 auto offsetted_idx = std::min(
57 *data.furthest_reached_path_point + offset_from_furthest_, path_size);
62 while (!valid && offsetted_idx < path_size - 1) {
63 valid = (*data.path_pts_valid)[offsetted_idx];
69 const auto path_x = data.path.x(offsetted_idx);
70 const auto path_y = data.path.y(offsetted_idx);
72 const int && rightmost_idx = data.trajectories.x.cols() - 1;
73 const auto last_x = data.trajectories.x.col(rightmost_idx);
74 const auto last_y = data.trajectories.y.col(rightmost_idx);
76 const auto delta_x = last_x - path_x;
77 const auto delta_y = last_y - path_y;
79 data.costs += (((delta_x.square() + delta_y.square()).sqrt()) * weight_).pow(power_);
81 data.costs += ((delta_x.square() + delta_y.square()).sqrt()) * weight_;
87 #include <pluginlib/class_list_macros.hpp>
89 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,...