@@ -128,7 +128,11 @@ void LocalPlanner::determineStrategy() {
128
128
simulation_limits lims;
129
129
lims.max_z_velocity = px4_.param_mpc_z_vel_max_up ;
130
130
lims.min_z_velocity = -1 .0f * px4_.param_mpc_z_vel_max_dn ;
131
- lims.max_xy_velocity_norm = px4_.param_mpc_xy_cruise ;
131
+ lims.max_xy_velocity_norm =
132
+ std::min (getMaxSpeed (px4_.param_mpc_jerk_max , px4_.param_mpc_acc_hor , max_sensor_range_,
133
+ px4_.param_mpc_xy_cruise , mission_item_speed_),
134
+ getMaxSpeed (px4_.param_mpc_jerk_max , px4_.param_mpc_acc_hor , (goal_ - position_).norm (),
135
+ px4_.param_mpc_xy_cruise , mission_item_speed_));
132
136
lims.max_acceleration_norm = px4_.param_mpc_acc_hor ;
133
137
lims.max_jerk_norm = px4_.param_mpc_jerk_max ;
134
138
star_planner_->setParams (cost_params_, lims, px4_.param_nav_acc_rad );
@@ -212,24 +216,32 @@ avoidanceOutput LocalPlanner::getAvoidanceOutput() const {
212
216
out.waypoint_type = waypoint_type_;
213
217
out.obstacle_ahead = !polar_histogram_.isEmpty ();
214
218
215
- // calculate maximum speed given the sensor range and vehicle parameters
216
- // quadratic solve of 0 = u^2 + 2as, with s = u * |a/j| + r
217
- // u = initial velocity, a = max acceleration
218
- // s = stopping distance under constant acceleration
219
- // j = maximum jerk, r = maximum range sensor distance
220
- float accel_ramp_time = px4_.param_mpc_acc_hor / px4_.param_mpc_jerk_max ;
221
- float a = 1 ;
222
- float b = 2 * px4_.param_mpc_acc_hor * accel_ramp_time;
223
- float c = 2 * -px4_.param_mpc_acc_hor * max_sensor_range_;
224
- float limited_speed = (-b + std::sqrt (b * b - 4 * a * c)) / (2 * a);
225
-
226
- float speed = std::isfinite (mission_item_speed_) ? mission_item_speed_ : px4_.param_mpc_xy_cruise ;
227
- float max_speed = std::min (speed, limited_speed);
219
+ float max_speed = getMaxSpeed (px4_.param_mpc_jerk_max , px4_.param_mpc_acc_hor , max_sensor_range_,
220
+ px4_.param_mpc_xy_cruise , mission_item_speed_);
228
221
229
222
out.cruise_velocity = max_speed;
230
223
out.last_path_time = last_path_time_;
231
224
out.tree_node_duration = tree_node_duration_;
232
225
out.path_node_setpoints = star_planner_->path_node_setpoints_ ;
233
226
return out;
234
227
}
228
+
229
+ float LocalPlanner::computeMaxSpeedFromBrakingDistance (const float jerk, const float accel,
230
+ const float braking_distance) const {
231
+ // Calculate maximum speed given the sensor range and vehicle parameters
232
+ // We assume a constant acceleration profile with a delay of 2*accel/jerk (time to reach the desired acceleration from
233
+ // opposite max acceleration)
234
+ // Equation to solve: 0 = vel^2 - 2*acc*(x - vel*2*acc/jerk)
235
+ float b = 4 .f * accel * accel / jerk;
236
+ float c = -2 .f * accel * braking_distance;
237
+
238
+ return 0 .5f * (-b + sqrtf (b * b - 4 .f * c));
239
+ }
240
+
241
+ float LocalPlanner::getMaxSpeed (const float jerk, const float accel, const float braking_distance,
242
+ const float mpc_xy_cruise, const float mission_item_speed) const {
243
+ float limited_speed = computeMaxSpeedFromBrakingDistance (jerk, accel, braking_distance);
244
+ float speed = std::isfinite (mission_item_speed) ? mission_item_speed : mpc_xy_cruise;
245
+ return std::min (speed, limited_speed);
246
+ }
235
247
}
0 commit comments