15 #include "nav2_mppi_controller/critics/constraint_critic.hpp"
16 #include "nav2_mppi_controller/motion_models.hpp"
18 namespace mppi::critics
24 auto getParentParam = parameters_handler_->
getParamGetter(parent_name_);
26 getParam(power_,
"cost_power", 1);
27 getParam(weight_,
"cost_weight", 4.0f);
29 logger_,
"ConstraintCritic instantiated with %d power and %f weight.",
32 getParentParam(vx_max_,
"vx_max", 0.5f);
33 getParentParam(vy_max_,
"vy_max", 0.0f);
34 getParentParam(vx_min_,
"vx_min", -0.35f);
45 if (diff !=
nullptr) {
47 data.costs += (((((data.state.vx - vx_max_).max(0.0f) + (vx_min_ - data.state.vx).
48 max(0.0f)) * data.model_dt).rowwise().sum().eval()) * weight_).pow(power_).eval();
50 data.costs += (((((data.state.vx - vx_max_).max(0.0f) + (vx_min_ - data.state.vx).
51 max(0.0f)) * data.model_dt).rowwise().sum().eval()) * weight_).eval();
59 if (omni !=
nullptr) {
60 auto & vx = data.state.vx;
61 auto & vy = data.state.vy;
64 data.costs += (((((vx - vx_max_).max(0.0f) + (vx_min_ - vx).max(0.0f) +
65 (vy.abs() - vy_max_).max(0.0f)) * data.model_dt).rowwise().sum().eval()) *
66 weight_).pow(power_).eval();
68 data.costs += (((((vx - vx_max_).max(0.0f) + (vx_min_ - vx).max(0.0f) +
69 (vy.abs() - vy_max_).max(0.0f)) * data.model_dt).rowwise().sum().eval()) * weight_).eval();
76 if (acker !=
nullptr) {
77 auto & vx = data.state.vx;
78 auto & wz = data.state.wz;
79 const float min_turning_rad = acker->getMinTurningRadius();
81 const float epsilon = 1e-6f;
82 auto wz_safe = wz.abs().max(epsilon);
83 auto out_of_turning_rad_motion = (min_turning_rad - (vx.abs() / wz_safe)).max(0.0f);
86 data.costs += ((((vx - vx_max_).max(0.0f) + (vx_min_ - vx).max(0.0f) +
87 out_of_turning_rad_motion) * data.model_dt).rowwise().sum().eval() *
88 weight_).pow(power_).eval();
90 data.costs += ((((vx - vx_max_).max(0.0f) + (vx_min_ - vx).max(0.0f) +
91 out_of_turning_rad_motion) * data.model_dt).rowwise().sum().eval() * weight_).eval();
99 #include <pluginlib/class_list_macros.hpp>
Differential drive motion model.
Omnidirectional motion model.
auto getParamGetter(const std::string &ns)
Get an object to retrieve 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,...