Speed of intermediate point is initialised and constrained based on
current speed vector vs direction to the next waypoint.
This means the copter does not slow if the previous segment and next
segment are in line and also the intermediate point is not advanced
towards the next waypoint if the copter is moving quickly in the
opposite direction.
// calculate point at which velocity switches from linear to sqrt
floatlinear_velocity=_wp_speed_cms;
floatkP=_pid_pos_lat->kP();
if(kP>=0.0f){// avoid divide by zero
linear_velocity=MAX_LOITER_POS_ACCEL/kP;
}
if(_limited_speed_xy_cms>_wp_speed_cms){
_limited_speed_xy_cms=_wp_speed_cms;
// let the limited_speed_xy_cms be some range above or below current velocity along track
if(speed_along_track<-linear_velocity){
// we are travelling fast in the opposite direction of travel to the waypoint so do not move the intermediate point
_limited_speed_xy_cms=0;
}else{
// increase intermediate target point's velocity if not yet at target speed (we will limit it below)
if(dt>0&&_limited_speed_xy_cms<_wp_speed_cms){
_limited_speed_xy_cms+=WPNAV_WP_ACCELERATION*dt;
}
// do not go over top speed
if(_limited_speed_xy_cms>_wp_speed_cms){
_limited_speed_xy_cms=_wp_speed_cms;
}
// if our current velocity is within the linear velocity range limit the intermediate point's velocity to be no more than the linear_velocity above or below our current velocity