15 #include "nav2_mppi_controller/critics/constraint_critic.hpp"
17 namespace mppi::critics
23 auto getParentParam = parameters_handler_->
getParamGetter(parent_name_);
25 getParam(power_,
"cost_power", 1);
26 getParam(weight_,
"cost_weight", 4.0);
28 logger_,
"ConstraintCritic instantiated with %d power and %f weight.",
31 float vx_max, vy_max, vx_min;
32 getParentParam(vx_max,
"vx_max", 0.5);
33 getParentParam(vy_max,
"vy_max", 0.0);
34 getParentParam(vx_min,
"vx_min", -0.35);
36 const float min_sgn = vx_min > 0.0 ? 1.0 : -1.0;
37 max_vel_ = sqrtf(vx_max * vx_max + vy_max * vy_max);
38 min_vel_ = min_sgn * sqrtf(vx_min * vx_min + vy_max * vy_max);
43 using xt::evaluation_strategy::immediate;
49 auto sgn = xt::where(data.state.vx > 0.0, 1.0, -1.0);
50 auto vel_total = sgn * xt::sqrt(data.state.vx * data.state.vx + data.state.vy * data.state.vy);
51 auto out_of_max_bounds_motion = xt::maximum(vel_total - max_vel_, 0);
52 auto out_of_min_bounds_motion = xt::maximum(min_vel_ - vel_total, 0);
55 if (acker !=
nullptr) {
56 auto & vx = data.state.vx;
57 auto & wz = data.state.wz;
58 auto out_of_turning_rad_motion = xt::maximum(
59 acker->getMinTurningRadius() - (xt::fabs(vx) / xt::fabs(wz)), 0.0);
61 data.costs += xt::pow(
63 (std::move(out_of_max_bounds_motion) +
64 std::move(out_of_min_bounds_motion) +
65 std::move(out_of_turning_rad_motion)) *
66 data.model_dt, {1}, immediate) * weight_, power_);
70 data.costs += xt::pow(
72 (std::move(out_of_max_bounds_motion) +
73 std::move(out_of_min_bounds_motion)) *
74 data.model_dt, {1}, immediate) * weight_, power_);
79 #include <pluginlib/class_list_macros.hpp>
auto getParamGetter(const std::string &ns)
Get an object to retreive parameters.
Critic objective function for enforcing feasible constraints.
void score(CriticData &data) override
Evaluate cost related to goal following.
void initialize() override
Initialize critic.
Abstract critic objective function to score trajectories.
Data to pass to critics for scoring, including state, trajectories, pruned path, global goal,...