Browse Source

navigator: extract breaking functionality out

This only moves the breaking functionality out from the reposition
command handling to a function, so that it can get re-used in other
places.
master
Julian Oes 3 years ago committed by Daniel Agar
parent
commit
f88dd28e85
  1. 2
      src/modules/navigator/navigator.h
  2. 36
      src/modules/navigator/navigator_main.cpp

2
src/modules/navigator/navigator.h

@ -320,6 +320,8 @@ public:
void acquire_gimbal_control(); void acquire_gimbal_control();
void release_gimbal_control(); void release_gimbal_control();
void calculate_breaking_stop(double &lat, double &lon, float &yaw);
private: private:
struct traffic_buffer_s { struct traffic_buffer_s {

36
src/modules/navigator/navigator_main.cpp

@ -311,22 +311,7 @@ void Navigator::run()
if (_vstatus.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING if (_vstatus.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING
&& (get_position_setpoint_triplet()->current.type != position_setpoint_s::SETPOINT_TYPE_TAKEOFF)) { && (get_position_setpoint_triplet()->current.type != position_setpoint_s::SETPOINT_TYPE_TAKEOFF)) {
// For multirotors we need to account for the braking distance, otherwise the vehicle will overshoot and go back calculate_breaking_stop(rep->current.lat, rep->current.lon, rep->current.yaw);
double lat, lon;
float course_over_ground = atan2f(_local_pos.vy, _local_pos.vx);
// predict braking distance
const float velocity_hor_abs = sqrtf(_local_pos.vx * _local_pos.vx + _local_pos.vy * _local_pos.vy);
float multirotor_braking_distance = math::trajectory::computeBrakingDistanceFromVelocity(velocity_hor_abs,
_param_mpc_jerk_auto, _param_mpc_acc_hor, 0.6f * _param_mpc_jerk_auto);
waypoint_from_heading_and_distance(get_global_position()->lat, get_global_position()->lon, course_over_ground,
multirotor_braking_distance, &lat, &lon);
rep->current.lat = lat;
rep->current.lon = lon;
rep->current.yaw = get_local_position()->heading;
rep->current.yaw_valid = true; rep->current.yaw_valid = true;
} else { } else {
@ -1578,6 +1563,25 @@ bool Navigator::geofence_allows_position(const vehicle_global_position_s &pos)
return true; return true;
} }
void Navigator::calculate_breaking_stop(double &lat, double &lon, float &yaw)
{
// For multirotors we need to account for the braking distance, otherwise the vehicle will overshoot and go back
float course_over_ground = atan2f(_local_pos.vy, _local_pos.vx);
// predict braking distance
const float velocity_hor_abs = sqrtf(_local_pos.vx * _local_pos.vx + _local_pos.vy * _local_pos.vy);
float multirotor_braking_distance = math::trajectory::computeBrakingDistanceFromVelocity(velocity_hor_abs,
_param_mpc_jerk_auto, _param_mpc_acc_hor, 0.6f * _param_mpc_jerk_auto);
waypoint_from_heading_and_distance(get_global_position()->lat, get_global_position()->lon, course_over_ground,
multirotor_braking_distance, &lat, &lon);
lat = lat;
lon = lon;
yaw = get_local_position()->heading;
}
int Navigator::print_usage(const char *reason) int Navigator::print_usage(const char *reason)
{ {
if (reason) { if (reason) {

Loading…
Cancel
Save