Skip to content

Commit c4afab0

Browse files
committed
[mppi] constrain velocity & curvature in predict
1 parent b78c774 commit c4afab0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

nav2_mppi_controller/include/nav2_mppi_controller/motion_models.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ class MotionModel
127127
// state.cwz.col(i - 1) = state.wz.col(i);
128128
// }
129129

130+
// also apply velocity limits constrains
131+
state.vx.col(i) = state.vx.col(i)
132+
.cwiseMax(control_constraints_.vx_min)
133+
.cwiseMin(control_constraints_.vx_max);
134+
135+
state.wz.col(i) = state.wz.col(i)
136+
.cwiseMax(-control_constraints_.wz)
137+
.cwiseMin(control_constraints_.wz);
138+
139+
140+
// also constrain wz base
130141
if (is_holo) {
131142
auto lower_bound_vy = (state.vy.col(i - 1) >
132143
0).select(state.vy.col(i - 1) + min_delta_vy,
@@ -138,8 +149,14 @@ class MotionModel
138149
state.vy.col(i) = state.cvy.col(i - 1)
139150
.cwiseMax(lower_bound_vy)
140151
.cwiseMin(upper_bound_vy);
152+
153+
state.vy.col(i) = state.cvy.col(i - 1)
154+
.cwiseMax(-control_constraints_.vy)
155+
.cwiseMin(control_constraints_.vy);
141156
}
142157
}
158+
159+
applyConstraints(state);
143160
}
144161

145162
/**
@@ -153,6 +170,7 @@ class MotionModel
153170
* @param control_sequence Control sequence to apply constraints to
154171
*/
155172
virtual void applyConstraints(models::ControlSequence & /*control_sequence*/) {}
173+
virtual void applyConstraints(models::State & /*state*/) {}
156174

157175
protected:
158176
float model_dt_{0.0};
@@ -201,6 +219,28 @@ class AckermannMotionModel : public MotionModel
201219
}
202220
}
203221

222+
void applyConstraints(models::State & state) override
223+
{
224+
std::cout << "\n\t wz Before applyConstraints:\n\t\t" << state.wz(Eigen::seq(0,1000,300), Eigen::seq(0, 2)) << std::endl;
225+
// auto tmp_state = state;
226+
// for(unsigned int i = 0; i < state.vx.cols(); i++) {
227+
// auto wz_constrained = state.vx.col(i).abs() / min_turning_r_;
228+
// state.wz.col(i) = state.wz.col(i)
229+
// .cwiseMax(-1 * wz_constrained)
230+
// .cwiseMin(wz_constrained);
231+
// }
232+
233+
std::cout << "\n\t wz with loop:\n\t\t" << state.wz(Eigen::seq(0,1000,300), Eigen::seq(0, 2)) << std::endl;
234+
235+
// vectorized version
236+
const auto wz_constrained = tmp_state.vx.abs() / min_turning_r_;
237+
tmp_state.wz = tmp_state.wz
238+
.max((-wz_constrained))
239+
.min(wz_constrained);
240+
241+
std::cout << "\n\t wz without loop:\n\t\t" << tmp_state.wz(Eigen::seq(0,1000,300), Eigen::seq(0, 2)) << std::endl;
242+
}
243+
204244
/**
205245
* @brief Get minimum turning radius of ackermann drive
206246
* @return Minimum turning radius

0 commit comments

Comments
 (0)