16 #include "nav2_mppi_controller/critics/path_angle_critic.hpp"
20 namespace mppi::critics
25 auto getParentParam = parameters_handler_->
getParamGetter(parent_name_);
27 getParentParam(vx_min,
"vx_min", -0.35);
28 if (fabs(vx_min) < 1e-6) {
29 reversing_allowed_ =
false;
30 }
else if (vx_min < 0.0) {
31 reversing_allowed_ =
true;
35 getParam(offset_from_furthest_,
"offset_from_furthest", 4);
36 getParam(power_,
"cost_power", 1);
37 getParam(weight_,
"cost_weight", 2.0);
39 threshold_to_consider_,
40 "threshold_to_consider", 0.5);
42 max_angle_to_furthest_,
43 "max_angle_to_furthest", 1.2);
46 "forward_preference",
true);
48 if (!reversing_allowed_) {
49 forward_preference_ =
true;
54 "PathAngleCritic instantiated with %d power and %f weight. Reversing %s",
55 power_, weight_, reversing_allowed_ ?
"allowed." :
"not allowed.");
60 using xt::evaluation_strategy::immediate;
65 if (utils::withinPositionGoalTolerance(
66 threshold_to_consider_, data.state.pose.pose, data.goal))
71 utils::setPathFurthestPointIfNotSet(data);
73 auto offseted_idx = std::min(
74 *data.furthest_reached_path_point + offset_from_furthest_, data.path.x.shape(0) - 1);
76 const float goal_x = xt::view(data.path.x, offseted_idx);
77 const float goal_y = xt::view(data.path.y, offseted_idx);
79 if (utils::posePointAngle(
80 data.state.pose.pose, goal_x, goal_y, forward_preference_) < max_angle_to_furthest_)
85 auto yaws_between_points = xt::atan2(
86 goal_y - data.trajectories.y,
87 goal_x - data.trajectories.x);
90 xt::abs(utils::shortest_angular_distance(data.trajectories.yaws, yaws_between_points));
92 if (reversing_allowed_ && !forward_preference_) {
93 const auto yaws_between_points_corrected = xt::where(
94 yaws < M_PI_2, yaws_between_points, utils::normalize_angles(yaws_between_points + M_PI));
95 const auto corrected_yaws = xt::abs(
96 utils::shortest_angular_distance(data.trajectories.yaws, yaws_between_points_corrected));
97 data.costs += xt::pow(xt::mean(corrected_yaws, {1}, immediate) * weight_, power_);
99 data.costs += xt::pow(xt::mean(yaws, {1}, immediate) * weight_, power_);
105 #include <pluginlib/class_list_macros.hpp>
107 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,...