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.0f);
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.5f);
33 getParentParam(vy_max,
"vy_max", 0.0f);
34 getParentParam(vx_min,
"vx_min", -0.35f);
36 const float min_sgn = vx_min > 0.0f ? 1.0f : -1.0f;
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);
49 if (diff !=
nullptr) {
51 data.costs += (((((data.state.vx - max_vel_).max(0.0f) + (min_vel_ - data.state.vx).
52 max(0.0f)) * data.model_dt).rowwise().sum().eval()) * weight_).pow(power_).eval();
54 data.costs += (((((data.state.vx - max_vel_).max(0.0f) + (min_vel_ - data.state.vx).
55 max(0.0f)) * data.model_dt).rowwise().sum().eval()) * weight_).eval();
62 if (omni !=
nullptr) {
63 auto & vx = data.state.vx;
64 unsigned int n_rows = data.state.vx.rows();
65 unsigned int n_cols = data.state.vx.cols();
66 Eigen::ArrayXXf sgn(n_rows, n_cols);
67 sgn = vx.unaryExpr([](
const float x){
return copysignf(1.0f, x);});
69 auto vel_total = sgn * (data.state.vx.square() + data.state.vy.square()).sqrt();
71 data.costs += ((((vel_total - max_vel_).max(0.0f) + (min_vel_ - vel_total).
72 max(0.0f)) * data.model_dt).rowwise().sum().eval() * weight_).pow(power_).eval();
74 data.costs += ((((vel_total - max_vel_).max(0.0f) + (min_vel_ - vel_total).
75 max(0.0f)) * data.model_dt).rowwise().sum().eval() * weight_).eval();
82 if (acker !=
nullptr) {
83 auto & vx = data.state.vx;
84 auto & wz = data.state.wz;
85 float min_turning_rad = acker->getMinTurningRadius();
86 auto out_of_turning_rad_motion = (min_turning_rad - (vx.abs() / wz.abs())).max(0.0f);
88 data.costs += ((((vx - max_vel_).max(0.0f) + (min_vel_ - vx).max(0.0f) +
89 out_of_turning_rad_motion) * data.model_dt).rowwise().sum().eval() *
90 weight_).pow(power_).eval();
92 data.costs += ((((vx - max_vel_).max(0.0f) + (min_vel_ - vx).max(0.0f) +
93 out_of_turning_rad_motion) * data.model_dt).rowwise().sum().eval() * weight_).eval();
101 #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,...