|
|
@ -54,6 +54,7 @@ |
|
|
|
#include <drivers/drv_hrt.h> |
|
|
|
#include <drivers/drv_hrt.h> |
|
|
|
#include <uORB/uORB.h> |
|
|
|
#include <uORB/uORB.h> |
|
|
|
#include <uORB/topics/parameter_update.h> |
|
|
|
#include <uORB/topics/parameter_update.h> |
|
|
|
|
|
|
|
#include <uORB/topics/vehicle_status.h> |
|
|
|
#include <uORB/topics/vehicle_control_mode.h> |
|
|
|
#include <uORB/topics/vehicle_control_mode.h> |
|
|
|
#include <uORB/topics/vehicle_attitude.h> |
|
|
|
#include <uORB/topics/vehicle_attitude.h> |
|
|
|
#include <uORB/topics/manual_control_setpoint.h> |
|
|
|
#include <uORB/topics/manual_control_setpoint.h> |
|
|
@ -221,11 +222,12 @@ static int multirotor_pos_control_thread_main(int argc, char *argv[]) |
|
|
|
bool reset_int_xy = true; |
|
|
|
bool reset_int_xy = true; |
|
|
|
bool was_armed = false; |
|
|
|
bool was_armed = false; |
|
|
|
bool reset_integral = true; |
|
|
|
bool reset_integral = true; |
|
|
|
|
|
|
|
bool reset_auto_pos = true; |
|
|
|
|
|
|
|
|
|
|
|
hrt_abstime t_prev = 0; |
|
|
|
hrt_abstime t_prev = 0; |
|
|
|
/* integrate in NED frame to estimate wind but not attitude offset */ |
|
|
|
|
|
|
|
const float alt_ctl_dz = 0.2f; |
|
|
|
const float alt_ctl_dz = 0.2f; |
|
|
|
const float pos_ctl_dz = 0.05f; |
|
|
|
const float pos_ctl_dz = 0.05f; |
|
|
|
|
|
|
|
const float takeoff_alt_default = 10.0f; |
|
|
|
float ref_alt = 0.0f; |
|
|
|
float ref_alt = 0.0f; |
|
|
|
hrt_abstime ref_alt_t = 0; |
|
|
|
hrt_abstime ref_alt_t = 0; |
|
|
|
uint64_t local_ref_timestamp = 0; |
|
|
|
uint64_t local_ref_timestamp = 0; |
|
|
@ -414,6 +416,26 @@ static int multirotor_pos_control_thread_main(int argc, char *argv[]) |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
/* non-manual mode, use global setpoint */ |
|
|
|
/* non-manual mode, use global setpoint */ |
|
|
|
|
|
|
|
if (control_mode.auto_state == NAVIGATION_STATE_AUTO_TAKEOFF) { |
|
|
|
|
|
|
|
if (reset_auto_pos) { |
|
|
|
|
|
|
|
local_pos_sp.x = local_pos.x; |
|
|
|
|
|
|
|
local_pos_sp.y = local_pos.y; |
|
|
|
|
|
|
|
local_pos_sp.z = -takeoff_alt_default; |
|
|
|
|
|
|
|
att_sp.yaw_body = att.yaw; |
|
|
|
|
|
|
|
reset_auto_pos = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (control_mode.auto_state == NAVIGATION_STATE_AUTO_LOITER) { |
|
|
|
|
|
|
|
if (reset_auto_pos) { |
|
|
|
|
|
|
|
local_pos_sp.x = local_pos.x; |
|
|
|
|
|
|
|
local_pos_sp.y = local_pos.y; |
|
|
|
|
|
|
|
local_pos_sp.z = local_pos.z; |
|
|
|
|
|
|
|
att_sp.yaw_body = att.yaw; |
|
|
|
|
|
|
|
reset_auto_pos = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (control_mode.auto_state == NAVIGATION_STATE_AUTO_RTL) { |
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
reset_auto_pos = true; |
|
|
|
|
|
|
|
} else if (control_mode.auto_state == NAVIGATION_STATE_AUTO_MISSION) { |
|
|
|
/* init local projection using local position ref */ |
|
|
|
/* init local projection using local position ref */ |
|
|
|
if (local_pos.ref_timestamp != local_ref_timestamp) { |
|
|
|
if (local_pos.ref_timestamp != local_ref_timestamp) { |
|
|
|
global_pos_sp_reproject = true; |
|
|
|
global_pos_sp_reproject = true; |
|
|
@ -427,7 +449,6 @@ static int multirotor_pos_control_thread_main(int argc, char *argv[]) |
|
|
|
if (global_pos_sp_reproject) { |
|
|
|
if (global_pos_sp_reproject) { |
|
|
|
/* update global setpoint projection */ |
|
|
|
/* update global setpoint projection */ |
|
|
|
global_pos_sp_reproject = false; |
|
|
|
global_pos_sp_reproject = false; |
|
|
|
|
|
|
|
|
|
|
|
if (global_pos_sp_valid) { |
|
|
|
if (global_pos_sp_valid) { |
|
|
|
/* global position setpoint valid, use it */ |
|
|
|
/* global position setpoint valid, use it */ |
|
|
|
double sp_lat = global_pos_sp.lat * 1e-7; |
|
|
|
double sp_lat = global_pos_sp.lat * 1e-7; |
|
|
@ -459,6 +480,13 @@ static int multirotor_pos_control_thread_main(int argc, char *argv[]) |
|
|
|
/* publish local position setpoint as projection of global position setpoint */ |
|
|
|
/* publish local position setpoint as projection of global position setpoint */ |
|
|
|
orb_publish(ORB_ID(vehicle_local_position_setpoint), local_pos_sp_pub, &local_pos_sp); |
|
|
|
orb_publish(ORB_ID(vehicle_local_position_setpoint), local_pos_sp_pub, &local_pos_sp); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
att_sp.yaw_body = global_pos_sp.yaw; |
|
|
|
|
|
|
|
reset_auto_pos = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (control_mode.auto_state != NAVIGATION_STATE_AUTO_MISSION) { |
|
|
|
|
|
|
|
global_pos_sp_reproject = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* reset setpoints after non-manual modes */ |
|
|
|
/* reset setpoints after non-manual modes */ |
|
|
|
reset_sp_xy = true; |
|
|
|
reset_sp_xy = true; |
|
|
@ -575,6 +603,7 @@ static int multirotor_pos_control_thread_main(int argc, char *argv[]) |
|
|
|
reset_int_z = true; |
|
|
|
reset_int_z = true; |
|
|
|
reset_int_xy = true; |
|
|
|
reset_int_xy = true; |
|
|
|
global_pos_sp_reproject = true; |
|
|
|
global_pos_sp_reproject = true; |
|
|
|
|
|
|
|
reset_auto_pos = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* reset altitude controller integral (hovering throttle) to manual throttle after manual throttle control */ |
|
|
|
/* reset altitude controller integral (hovering throttle) to manual throttle after manual throttle control */ |
|
|
|