|
|
|
@ -45,6 +45,8 @@ bool ModeAuto::init(bool ignore_checks)
@@ -45,6 +45,8 @@ bool ModeAuto::init(bool ignore_checks)
|
|
|
|
|
|
|
|
|
|
// start/resume the mission (based on MIS_RESTART parameter)
|
|
|
|
|
mission.start_or_resume(); |
|
|
|
|
wp_nav_index = 0; // nav 重新开始计数
|
|
|
|
|
first_wp_dec = false; |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
@ -57,21 +59,6 @@ bool ModeAuto::init(bool ignore_checks)
@@ -57,21 +59,6 @@ bool ModeAuto::init(bool ignore_checks)
|
|
|
|
|
void ModeAuto::run() |
|
|
|
|
{ |
|
|
|
|
// call the correct auto controller
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// float proximity_alt_diff;
|
|
|
|
|
// AP_Proximity *proximity = AP::proximity();
|
|
|
|
|
// if (proximity && proximity->get_horizontal_distance(0,proximity_alt_diff)) {
|
|
|
|
|
|
|
|
|
|
// if(proximity_alt_diff < 30.0)
|
|
|
|
|
// {
|
|
|
|
|
// if(_mode != Auto_Loiter)
|
|
|
|
|
// gcs().send_text(MAV_SEVERITY_INFO, "Dist: %f, stop",proximity_alt_diff);
|
|
|
|
|
|
|
|
|
|
// _mode = Auto_Loiter;
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
switch (_mode) { |
|
|
|
|
|
|
|
|
|
case Auto_TakeOff: |
|
|
|
@ -158,6 +145,8 @@ void ModeAuto::takeoff_start(const Location& dest_loc)
@@ -158,6 +145,8 @@ void ModeAuto::takeoff_start(const Location& dest_loc)
|
|
|
|
|
|
|
|
|
|
Location dest(dest_loc); |
|
|
|
|
|
|
|
|
|
// gcs().send_text(MAV_SEVERITY_INFO, "NOTICE: dl:%d,%d,%d",dest_loc.lat,dest_loc.lng,dest_loc.alt);
|
|
|
|
|
// last_loc = dest_loc;
|
|
|
|
|
if (!copter.current_loc.initialised()) { |
|
|
|
|
// vehicle doesn't know where it is ATM. We should not
|
|
|
|
|
// initialise our takeoff destination without knowing this!
|
|
|
|
@ -334,7 +323,7 @@ void ModeAuto::circle_movetoedge_start(const Location &circle_center, float radi
@@ -334,7 +323,7 @@ void ModeAuto::circle_movetoedge_start(const Location &circle_center, float radi
|
|
|
|
|
void ModeAuto::circle_start() |
|
|
|
|
{ |
|
|
|
|
_mode = Auto_Circle; |
|
|
|
|
|
|
|
|
|
circle_init_yaw = false; // 绕圈转向下一航点初始化
|
|
|
|
|
// initialise circle controller
|
|
|
|
|
copter.circle_nav->init(copter.circle_nav->get_center()); |
|
|
|
|
} |
|
|
|
@ -794,36 +783,36 @@ void ModeAuto::takeoff_run()
@@ -794,36 +783,36 @@ void ModeAuto::takeoff_run()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(g.zr_8_circle){ // 起飞到高度绕8字
|
|
|
|
|
if(g.zr_8_circle == 1){ |
|
|
|
|
const bool reached_wp_dest = copter.wp_nav->reached_wp_destination(); |
|
|
|
|
static uint8_t init_circle = false; |
|
|
|
|
if(reached_wp_dest){ |
|
|
|
|
if(!init_circle){ |
|
|
|
|
float radius = copter.circle_nav->get_radius(); |
|
|
|
|
if(radius < 500.0f){ |
|
|
|
|
copter.circle_nav->set_radius(5 * 100.0f); |
|
|
|
|
}else if(radius > 2500.0f){ |
|
|
|
|
copter.circle_nav->set_radius(2000 * 100.0f); |
|
|
|
|
} |
|
|
|
|
copter.circle_nav->init(); |
|
|
|
|
init_circle = true; |
|
|
|
|
gcs().send_text(MAV_SEVERITY_WARNING,"auto init_circle"); |
|
|
|
|
}else{ |
|
|
|
|
circle_run(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
init_circle = false; |
|
|
|
|
if (copter.circle_nav->run_8_circle(reached_wp_dest)) |
|
|
|
|
{ |
|
|
|
|
circle_run(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
auto_takeoff_run(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// auto_wp_run - runs the auto waypoint controller
|
|
|
|
|
// called by auto_run at 100hz or more
|
|
|
|
|
void ModeAuto::wp_run() |
|
|
|
|
{ |
|
|
|
|
// 到航点绕圈
|
|
|
|
|
if(g.zr_8_circle == 2 && !first_wp_dec){ |
|
|
|
|
const bool reached_wp_dest = copter.wp_nav->reached_wp_destination(); |
|
|
|
|
if(!reached_wp_dest){ |
|
|
|
|
circle_init_yaw = false; |
|
|
|
|
}else{ |
|
|
|
|
if (copter.circle_nav->run_8_circle(reached_wp_dest)){ |
|
|
|
|
circle_run(); |
|
|
|
|
} |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// process pilot's yaw input
|
|
|
|
|
float target_yaw_rate = 0; |
|
|
|
|
if (!copter.failsafe.radio) { |
|
|
|
@ -933,17 +922,36 @@ void ModeAuto::rtl_run()
@@ -933,17 +922,36 @@ void ModeAuto::rtl_run()
|
|
|
|
|
void ModeAuto::circle_run() |
|
|
|
|
{ |
|
|
|
|
// call circle controller
|
|
|
|
|
copter.circle_nav->update(); |
|
|
|
|
|
|
|
|
|
// call z-axis position controller
|
|
|
|
|
pos_control->update_z_controller(); |
|
|
|
|
|
|
|
|
|
if (auto_yaw.mode() == AUTO_YAW_HOLD) { |
|
|
|
|
// roll & pitch from waypoint controller, yaw rate from pilot
|
|
|
|
|
if(g.zr_8_circle > 0){ // 起飞到高度绕8字
|
|
|
|
|
|
|
|
|
|
int32_t initial_armed_bearing = wp_yaw_cd; |
|
|
|
|
if(circle_init_yaw == false){ // 如果需要转向到下一个航点
|
|
|
|
|
if (abs(wrap_180_cd(ahrs.yaw_sensor-initial_armed_bearing)) <= 200) { //转到角度
|
|
|
|
|
circle_init_yaw = true; |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "[%d]init ok:%d -- %d, %d",circle_init_yaw,initial_armed_bearing,ahrs.yaw_sensor,abs(wrap_180_cd(ahrs.yaw_sensor-initial_armed_bearing))); |
|
|
|
|
}else{ // 转向
|
|
|
|
|
attitude_control->input_euler_angle_roll_pitch_yaw(wp_nav->get_roll(), wp_nav->get_pitch(), initial_armed_bearing ,true); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
}else{ // 转向完成后,开始绕8字
|
|
|
|
|
copter.circle_nav->turn_2_circle(); |
|
|
|
|
} |
|
|
|
|
pos_control->update_z_controller(); |
|
|
|
|
// Yaw 由 circle决定
|
|
|
|
|
attitude_control->input_euler_angle_roll_pitch_yaw(copter.circle_nav->get_roll(), copter.circle_nav->get_pitch(), copter.circle_nav->get_yaw(), true); |
|
|
|
|
} else { |
|
|
|
|
// roll, pitch from waypoint controller, yaw heading from auto_heading()
|
|
|
|
|
attitude_control->input_euler_angle_roll_pitch_yaw(copter.circle_nav->get_roll(), copter.circle_nav->get_pitch(), auto_yaw.yaw(), true); |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
copter.circle_nav->update(); |
|
|
|
|
// call z-axis position controller
|
|
|
|
|
pos_control->update_z_controller(); |
|
|
|
|
|
|
|
|
|
if (auto_yaw.mode() == AUTO_YAW_HOLD) { |
|
|
|
|
// roll & pitch from waypoint controller, yaw rate from pilot
|
|
|
|
|
attitude_control->input_euler_angle_roll_pitch_yaw(copter.circle_nav->get_roll(), copter.circle_nav->get_pitch(), copter.circle_nav->get_yaw(), true); |
|
|
|
|
} else { |
|
|
|
|
// roll, pitch from waypoint controller, yaw heading from auto_heading()
|
|
|
|
|
attitude_control->input_euler_angle_roll_pitch_yaw(copter.circle_nav->get_roll(), copter.circle_nav->get_pitch(), auto_yaw.yaw(), true); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1206,7 +1214,7 @@ void ModeAuto::do_nav_wp(const AP_Mission::Mission_Command& cmd)
@@ -1206,7 +1214,7 @@ void ModeAuto::do_nav_wp(const AP_Mission::Mission_Command& cmd)
|
|
|
|
|
loiter_time_max = cmd.p1; |
|
|
|
|
// Set wp navigation target
|
|
|
|
|
wp_start(target_loc); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if no delay as well as not final waypoint set the waypoint as "fast"
|
|
|
|
|
AP_Mission::Mission_Command temp_cmd; |
|
|
|
|
bool fast_waypoint = false; |
|
|
|
@ -1223,6 +1231,34 @@ void ModeAuto::do_nav_wp(const AP_Mission::Mission_Command& cmd)
@@ -1223,6 +1231,34 @@ void ModeAuto::do_nav_wp(const AP_Mission::Mission_Command& cmd)
|
|
|
|
|
// if next command's lat, lon is specified then do not slowdown at this waypoint
|
|
|
|
|
if ((temp_cmd.content.location.lat != 0) || (temp_cmd.content.location.lng != 0)) { |
|
|
|
|
fast_waypoint = true; |
|
|
|
|
AP_Mission::Mission_Command next_2_cmd; |
|
|
|
|
static int32_t last_yaw_cd; |
|
|
|
|
if(mission.get_next_nav_cmd(cmd.index, next_2_cmd)){ |
|
|
|
|
float wp_distance = next_2_cmd.content.location.get_distance(temp_cmd.content.location); |
|
|
|
|
if(wp_distance < 5.0){// 两个航点距离太近,正常是仿地降高度航点,则取再下一个航点
|
|
|
|
|
// gcs().send_text(MAV_SEVERITY_CRITICAL, "-wp too close:%.2f",wp_distance);
|
|
|
|
|
if(mission.get_next_nav_cmd(cmd.index+2, temp_cmd)){ |
|
|
|
|
wp_yaw_cd = next_2_cmd.content.location.get_bearing_to(temp_cmd.content.location); |
|
|
|
|
// gcs().send_text(MAV_SEVERITY_CRITICAL, "-new rad:%d",wp_yaw_cd);
|
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
wp_yaw_cd = next_2_cmd.content.location.get_bearing_to(temp_cmd.content.location); |
|
|
|
|
} |
|
|
|
|
if(copter.wp_nav->get_fast_waypoint() == 2){ |
|
|
|
|
static float last_dist = 0; |
|
|
|
|
int16_t delt_cd = abs(wp_yaw_cd - last_yaw_cd); |
|
|
|
|
// delt_cd = (delt_cd > 0)? delt_cd:360+delt_cd;
|
|
|
|
|
fast_waypoint = (delt_cd > 6000)?false:true; |
|
|
|
|
// gcs().send_text(MAV_SEVERITY_CRITICAL, "%d,a:%d,d:%d,f:%d,p:%.2f",cmd.index,wp_yaw_cd,delt_cd,fast_waypoint,wp_distance);
|
|
|
|
|
if(wp_distance - last_dist > 0 && first_wp_dec){ // P2.5转弯校准用 //TODO P2.5需要修改这里
|
|
|
|
|
// gcs().send_text(MAV_SEVERITY_CRITICAL, "---- First Turn, Do Sth ----");
|
|
|
|
|
} |
|
|
|
|
last_dist = wp_distance; |
|
|
|
|
last_yaw_cd = wp_yaw_cd; |
|
|
|
|
}else{ |
|
|
|
|
fast_waypoint = copter.wp_nav->get_fast_waypoint(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case MAV_CMD_NAV_RETURN_TO_LAUNCH: |
|
|
|
@ -1237,7 +1273,7 @@ void ModeAuto::do_nav_wp(const AP_Mission::Mission_Command& cmd)
@@ -1237,7 +1273,7 @@ void ModeAuto::do_nav_wp(const AP_Mission::Mission_Command& cmd)
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fast_waypoint = copter.wp_nav->get_fast_waypoint(); |
|
|
|
|
// fast_waypoint = copter.wp_nav->get_fast_waypoint();
|
|
|
|
|
copter.wp_nav->set_fast_waypoint(fast_waypoint); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1306,7 +1342,17 @@ void ModeAuto::do_circle(const AP_Mission::Mission_Command& cmd)
@@ -1306,7 +1342,17 @@ void ModeAuto::do_circle(const AP_Mission::Mission_Command& cmd)
|
|
|
|
|
|
|
|
|
|
// calculate radius
|
|
|
|
|
uint8_t circle_radius_m = HIGHBYTE(cmd.p1); // circle radius held in high byte of p1
|
|
|
|
|
// 方向先转向下一个航点
|
|
|
|
|
AP_Mission::Mission_Command next_cmd; |
|
|
|
|
AP_Mission::Mission_Command curr_cmd; |
|
|
|
|
|
|
|
|
|
mission.get_next_nav_cmd(cmd.index+1, next_cmd); |
|
|
|
|
mission.get_next_nav_cmd(cmd.index, curr_cmd); |
|
|
|
|
// 计算下一个航点方向
|
|
|
|
|
wp_yaw_cd = curr_cmd.content.location.get_bearing_to(next_cmd.content.location); |
|
|
|
|
if(g.zr_8_circle > 0){ |
|
|
|
|
circle_radius_m = 0; |
|
|
|
|
} |
|
|
|
|
// move to edge of circle (verify_circle) will ensure we begin circling once we reach the edge
|
|
|
|
|
circle_movetoedge_start(circle_center, circle_radius_m); |
|
|
|
|
} |
|
|
|
@ -1594,10 +1640,11 @@ bool ModeAuto::verify_takeoff()
@@ -1594,10 +1640,11 @@ bool ModeAuto::verify_takeoff()
|
|
|
|
|
if (reached_wp_dest) { |
|
|
|
|
copter.landinggear.set_position(AP_LandingGear::LandingGear_Retract); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(g.zr_8_circle){ // 起飞结束判断,如果绕8字,则增加8字结束判断
|
|
|
|
|
if(g.zr_8_circle == 1){ //如果启用绕8字,并且是起飞到头顶绕8字,增加判断
|
|
|
|
|
return (reached_wp_dest && copter.circle_nav->get_circle_8_finish()); |
|
|
|
|
}else{ |
|
|
|
|
}else{ // 常规起飞判断,增加设置绕圈相关初始设置
|
|
|
|
|
copter.circle_nav->set_circle_8_finish(false); |
|
|
|
|
first_wp_dec = false; |
|
|
|
|
return reached_wp_dest; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1904,8 +1951,25 @@ bool ModeAuto::verify_nav_wp(const AP_Mission::Mission_Command& cmd)
@@ -1904,8 +1951,25 @@ bool ModeAuto::verify_nav_wp(const AP_Mission::Mission_Command& cmd)
|
|
|
|
|
// play a tone
|
|
|
|
|
AP_Notify::events.waypoint_complete = 1; |
|
|
|
|
} |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Reached command #%i",cmd.index); |
|
|
|
|
return true; |
|
|
|
|
wp_nav_index += 1; // nav 计数,用于是否第一个航点绕8字判断
|
|
|
|
|
if(g.zr_8_circle == 2 && !first_wp_dec){ |
|
|
|
|
bool cyc_ret = copter.circle_nav->get_circle_8_finish(); |
|
|
|
|
if(cyc_ret){ |
|
|
|
|
|
|
|
|
|
// calculate stopping point
|
|
|
|
|
Vector3f stopping_point; |
|
|
|
|
wp_nav->get_wp_stopping_point(stopping_point); |
|
|
|
|
// initialise waypoint controller target to stopping point
|
|
|
|
|
wp_nav->set_wp_destination(stopping_point); |
|
|
|
|
|
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Reached command #%i,nav:%d",cmd.index,wp_nav_index); |
|
|
|
|
first_wp_dec = true;
|
|
|
|
|
} |
|
|
|
|
return cyc_ret; |
|
|
|
|
}else{ |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO, "Reached command #%i,nav:%d",cmd.index,wp_nav_index); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -1940,7 +2004,12 @@ bool ModeAuto::verify_circle(const AP_Mission::Mission_Command& cmd)
@@ -1940,7 +2004,12 @@ bool ModeAuto::verify_circle(const AP_Mission::Mission_Command& cmd)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check if we have completed circling
|
|
|
|
|
return fabsf(copter.circle_nav->get_angle_total()/M_2PI) >= LOWBYTE(cmd.p1); |
|
|
|
|
if(g.zr_8_circle > 0){ // 起飞到高度绕8字
|
|
|
|
|
return (copter.circle_nav->get_circle_8_finish()); |
|
|
|
|
}else{ |
|
|
|
|
return fabsf(copter.circle_nav->get_angle_total()/M_2PI) >= LOWBYTE(cmd.p1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// verify_spline_wp - check if we have reached the next way point using spline
|
|
|
|
|