bf->entry_vmax = 0;
bf->state = BUFFER_RESTART; // Restart the buffer when done
- } else {
+ } else if (HOLD_VELOCITY_TOLERANCE < braking_velocity) {
// Case 2: deceleration exceeds length remaining in buffer
// Replan to minimum (but non-zero) exit velocity
ex.tail_length = available_length;
ex.exit_velocity =
braking_velocity - mp_get_target_velocity(0, available_length, bf);
+
+ } else { // Were're close enough
+ ex.tail_length = available_length;
+ ex.exit_velocity = 0;
}
}
computed_velocity =
mp_get_target_velocity(bf->entry_velocity, bf->head_length, bf);
- } else {
+ } else if (bf->head_length + bf->tail_length) {
bf->tail_length =
(bf->tail_length / (bf->head_length + bf->tail_length)) * bf->length;
computed_velocity =
mp_get_target_velocity(bf->exit_velocity, bf->tail_length, bf);
- }
+
+ } else break;
} while ((fabs(bf->cruise_velocity - computed_velocity) /
computed_velocity) > TRAPEZOID_ITERATION_ERROR_PERCENT);
* PLANNER_VELOCITY_TOLERANCE necessitating the introduction of fabs()
*/
float mp_get_target_length(float Vi, float Vf, float jerk) {
- ASSERT(0 <= Vi && 0 <= Vf);
+ ASSERT(0 <= Vi);
+ ASSERT(0 <= Vf);
ASSERT(isfinite(jerk));
return fp_EQ(Vi, Vf) ? 0 : fabs(Vi - Vf) * invsqrt(jerk / fabs(Vi - Vf));
}
* J'(x) = (2 * Vi * x - Vi^2 + 3 * x^2) / L^2
*/
float mp_get_target_velocity(float Vi, float L, const mp_buffer_t *bf) {
- ASSERT(0 <= Vi && 0 <= L);
- ASSERT(isfinite(bf->cbrt_jerk) && isfinite(bf->jerk));
+ ASSERT(0 <= Vi);
+ ASSERT(0 <= L);
+ ASSERT(isfinite(bf->jerk));
+ ASSERT(isfinite(bf->cbrt_jerk));
if (!L) return Vi;