|
|
|
@ -31,6 +31,21 @@ const AP_Param::GroupInfo AP_Mission::var_info[] = {
@@ -31,6 +31,21 @@ const AP_Param::GroupInfo AP_Mission::var_info[] = {
|
|
|
|
|
// @User: Advanced
|
|
|
|
|
AP_GROUPINFO("OPTIONS", 2, AP_Mission, _options, AP_MISSION_OPTIONS_DEFAULT), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Param: AUTO_RESUME
|
|
|
|
|
// @DisplayName: Mission auto resume mission
|
|
|
|
|
// @Description: Bitmask of what options to use in missions.
|
|
|
|
|
// @Values: 0:disable, 1:enable
|
|
|
|
|
// @User: Advanced
|
|
|
|
|
AP_GROUPINFO("AUTO_RESUME", 3, AP_Mission, _auto_resume, 1), |
|
|
|
|
|
|
|
|
|
// @Param: TYPE_RESUME
|
|
|
|
|
// @DisplayName: resume mission type,return to last gps pos or camera pos.
|
|
|
|
|
// @Description: Bitmask of what options to use in missions.
|
|
|
|
|
// @Values: 0:gps pos, 1:camera pos
|
|
|
|
|
// @User: Advanced
|
|
|
|
|
AP_GROUPINFO("TYPE_RESUME", 4, AP_Mission, _type_resume, 1), |
|
|
|
|
|
|
|
|
|
AP_GROUPEND |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -1979,3 +1994,146 @@ AP_Mission *mission()
@@ -1979,3 +1994,146 @@ AP_Mission *mission()
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Modify by @Brown |
|
|
|
|
*/
|
|
|
|
|
void AP_Mission::auto_resume_mission(uint8_t f_mode, bool is_arm,int32_t r_lat,int32_t r_lng) |
|
|
|
|
{ |
|
|
|
|
Mission_Command cmd_rtl = {}; // 存储返航点坐标信息
|
|
|
|
|
Mission_Command cmd_temp = {}; |
|
|
|
|
|
|
|
|
|
static uint8_t need_change_cmd = 0; // 判斷是否需要進入航點改寫程序
|
|
|
|
|
|
|
|
|
|
uint16_t cmd_truncate = 0; // 去除剩余的航点
|
|
|
|
|
static uint16_t cmd_total = 0; // 去除剩余的航点
|
|
|
|
|
static uint16_t cmd_rtl_index = 0; // rtl返航点需要改写的航点序号
|
|
|
|
|
|
|
|
|
|
uint16_t cmd_i = 0; |
|
|
|
|
uint16_t new_cmd_i = 0; |
|
|
|
|
uint8_t cmd_step = 0; |
|
|
|
|
int32_t takeoff_alt = 0; |
|
|
|
|
int32_t rtlwp_alt = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// int32_t cam_lat,cam_lng;
|
|
|
|
|
// get_last_trigger_pos(cam_lat,cam_lng);
|
|
|
|
|
|
|
|
|
|
if(f_mode == 3 && need_change_cmd == 0) |
|
|
|
|
{ |
|
|
|
|
need_change_cmd = 1; |
|
|
|
|
// gcs_send_text_fmt(MAV_SEVERITY_DEBUG, "enter resume dec");
|
|
|
|
|
|
|
|
|
|
}else if(need_change_cmd == 1 && _auto_resume && 6 == f_mode) |
|
|
|
|
{ |
|
|
|
|
cmd_rtl_index = _nav_cmd.index; |
|
|
|
|
|
|
|
|
|
cmd_rtl_index -= 1; |
|
|
|
|
// gcs_send_text_fmt(MAV_SEVERITY_DEBUG, "resume %d",cmd_rtl_index);
|
|
|
|
|
if(cmd_rtl_index < 6 || num_commands() - cmd_rtl_index < 4)// 飛行的航點小於6則直接推出,否則讀取當前航點;飞完所有航点,也直接退出
|
|
|
|
|
{ |
|
|
|
|
need_change_cmd = 0; |
|
|
|
|
// gcs_send_text_fmt(MAV_SEVERITY_DEBUG, "[Resume] Need more waypoint,now:%d, need:6",cmd_rtl_index);
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 存储当前的POS到航点命令
|
|
|
|
|
// cmd_rtl.content.location.alt = current_loc.alt * 10, // millimeters above sea level
|
|
|
|
|
|
|
|
|
|
for(int i = cmd_rtl_index; i < cmd_rtl_index+3;i++) |
|
|
|
|
{ |
|
|
|
|
read_cmd_from_storage(i,cmd_rtl); // 读取原本航点
|
|
|
|
|
|
|
|
|
|
// gcs_send_text_fmt(MAV_SEVERITY_DEBUG, "read[%d]: %d",i,cmd_rtl.id);
|
|
|
|
|
if (is_nav_cmd(cmd_rtl)) { // 是否是Waypoint
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// cmd_rtl.content.location.alt = user_cmd_state.content.location.alt; // 獲取經緯度和高度值
|
|
|
|
|
cmd_rtl.content.location.lat = r_lat; |
|
|
|
|
cmd_rtl.content.location.lng = r_lng; |
|
|
|
|
cmd_rtl.id = MAV_CMD_NAV_WAYPOINT; |
|
|
|
|
// cmd_rtl.content.location.options = 0;
|
|
|
|
|
cmd_rtl.p1 = 2; // 到航点后延时2s
|
|
|
|
|
// cmd_rtl.content.location.flags.relative_alt = 1;
|
|
|
|
|
|
|
|
|
|
replace_cmd(cmd_rtl_index, cmd_rtl); |
|
|
|
|
// gcs_send_text_fmt(MAV_SEVERITY_DEBUG, "[Resume] Replace wp: %d",cmd_rtl_index);
|
|
|
|
|
|
|
|
|
|
need_change_cmd = 2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 飞机上锁,则开始改写航点
|
|
|
|
|
if (!is_arm && need_change_cmd == 2) { |
|
|
|
|
cmd_total = num_commands(); |
|
|
|
|
// gcs_send_text_fmt(MAV_SEVERITY_DEBUG, "[Resume] --- Star replace wp ,total:%d ---",cmd_total);
|
|
|
|
|
|
|
|
|
|
for(cmd_i = 1; cmd_i < cmd_total; cmd_i++) |
|
|
|
|
{ |
|
|
|
|
read_cmd_from_storage(cmd_i,cmd_temp); |
|
|
|
|
// gcs_send_text_fmt(MAV_SEVERITY_DEBUG, "[%d] step:%d, id:%d ",cmd_i,cmd_step ,cmd_temp.id);
|
|
|
|
|
switch (cmd_step) |
|
|
|
|
{ |
|
|
|
|
// gcs_send_text_fmt(MAV_SEVERITY_INFO, "[d]t:%d,i:%d \n ",cmd_step,cmd_rtl_i);
|
|
|
|
|
|
|
|
|
|
case 0: |
|
|
|
|
if(cmd_temp.id == MAV_CMD_NAV_TAKEOFF) |
|
|
|
|
{ |
|
|
|
|
cmd_step = 1; |
|
|
|
|
takeoff_alt = cmd_temp.content.location.alt; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
if(cmd_temp.id == MAV_CMD_NAV_WAYPOINT) |
|
|
|
|
{ |
|
|
|
|
read_cmd_from_storage(cmd_rtl_index,cmd_temp); |
|
|
|
|
// cmd_temp.content.location.flags.relative_alt = 1;
|
|
|
|
|
rtlwp_alt = cmd_temp.content.location.alt; |
|
|
|
|
if(rtlwp_alt < takeoff_alt) |
|
|
|
|
{ |
|
|
|
|
cmd_temp.content.location.alt = takeoff_alt;
|
|
|
|
|
cmd_rtl_index-=1;
|
|
|
|
|
}
|
|
|
|
|
replace_cmd(cmd_i, cmd_temp); // 替換 // 獲取第一個航點的序號
|
|
|
|
|
|
|
|
|
|
cmd_step = 2; |
|
|
|
|
new_cmd_i = cmd_i; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
if(cmd_temp.id == MAV_CMD_DO_SET_CAM_TRIGG_DIST) |
|
|
|
|
{ |
|
|
|
|
// cmd_rtl_i = cmd_i;
|
|
|
|
|
cmd_step = 3; |
|
|
|
|
new_cmd_i++; |
|
|
|
|
replace_cmd(new_cmd_i,cmd_temp); |
|
|
|
|
cmd_i = cmd_rtl_index; // 從返航點開始繼續讀取航點
|
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
|
|
|
|
|
// cmd_temp.content.location.flags.relative_alt = 1;
|
|
|
|
|
new_cmd_i++; |
|
|
|
|
replace_cmd(new_cmd_i,cmd_temp); |
|
|
|
|
if( MAV_CMD_NAV_LAND == cmd_temp.id || MAV_CMD_NAV_RETURN_TO_LAUNCH == cmd_temp.id )
|
|
|
|
|
{ |
|
|
|
|
// cmd_rtl_i = cmd_i;
|
|
|
|
|
cmd_i = cmd_total; |
|
|
|
|
// GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_INFO, "[c]c:%d,i:%d \n ",cmd_rtl_i,cmd_i);
|
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// cmd_truncate = cmd_total - cmd_rtl_index + cmd_rtl_i;
|
|
|
|
|
cmd_truncate = new_cmd_i + 1; |
|
|
|
|
// new mission arriving, truncate mission to be the same length
|
|
|
|
|
truncate(cmd_truncate); |
|
|
|
|
// gcs_send_text_fmt(MAV_SEVERITY_INFO, "[d]t:%d,i:%d \n ",total_cmd,cmd_rtl_i);
|
|
|
|
|
need_change_cmd = 0; |
|
|
|
|
// gcs_send_text_fmt(MAV_SEVERITY_DEBUG, "[Resume] --- Finish replace wp,truncate :%d ---",cmd_truncate);
|
|
|
|
|
} |
|
|
|
|
} |