|
|
|
@ -50,26 +50,24 @@ void Copter::userhook_MediumLoop()
@@ -50,26 +50,24 @@ void Copter::userhook_MediumLoop()
|
|
|
|
|
if(current_loc.alt > avoid.get_zr_avd_alt()) |
|
|
|
|
do_avoid_action(); |
|
|
|
|
#else |
|
|
|
|
bool flag_avoid_on = true; |
|
|
|
|
static bool last_avoid_flag = true; |
|
|
|
|
if(avoid.get_zr_mode() > 0 && (control_mode == Mode::Number::AUTO || control_mode == Mode::Number::RTL || control_mode == Mode::Number::GUIDED)){ |
|
|
|
|
bool enable_avoid = false; |
|
|
|
|
static bool last_flag = false; |
|
|
|
|
|
|
|
|
|
if(current_loc.alt < avoid.get_zr_avd_alt()){ // 飞行高度小于避障启用高度
|
|
|
|
|
if(home_distance() < avoid.get_zr_avd_on_dist()){ // 距离Home点小于启用距离
|
|
|
|
|
flag_avoid_on = false; //关闭避障
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(flag_avoid_on){ |
|
|
|
|
do_avoid_action(); |
|
|
|
|
if(avoid.get_zr_mode() > 0 && (control_mode == Mode::Number::AUTO || control_mode == Mode::Number::RTL || control_mode == Mode::Number::GUIDED || control_mode == Mode::Number::CIRCLE)){ |
|
|
|
|
if(far_from_home){ |
|
|
|
|
enable_avoid = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(last_avoid_flag != flag_avoid_on){ |
|
|
|
|
avoid.set_enable_aviod(flag_avoid_on); |
|
|
|
|
if(flag_avoid_on){ |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"NOTICE: 避障开启!"); |
|
|
|
|
if(last_flag != enable_avoid){ |
|
|
|
|
if(enable_avoid){ |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"NOTICE: 开启自动避障!"); |
|
|
|
|
}else{ |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"NOTICE: 避障关闭!"); |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"NOTICE: 关闭自动避障!"); |
|
|
|
|
} |
|
|
|
|
last_flag = enable_avoid; |
|
|
|
|
} |
|
|
|
|
if(enable_avoid){ |
|
|
|
|
do_avoid_action(); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
@ -92,6 +90,26 @@ void Copter::userhook_SuperSlowLoop()
@@ -92,6 +90,26 @@ void Copter::userhook_SuperSlowLoop()
|
|
|
|
|
zr_SuperSlowLoop(); |
|
|
|
|
zr_set_uav_state_to_uavcan(); |
|
|
|
|
zr_camera_mkdir(); |
|
|
|
|
if(current_loc.alt < avoid.get_zr_avd_alt()){ // 飞行高度小于避障启用高度
|
|
|
|
|
if(home_distance() < abs(avoid.get_zr_avd_on_dist())){ // 距离Home点小于启用距离
|
|
|
|
|
far_from_home = false; |
|
|
|
|
}else{ |
|
|
|
|
far_from_home = true; |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
far_from_home = true;
|
|
|
|
|
} |
|
|
|
|
avoid.set_enable_aviod(far_from_home); // 远离Home点才启用避障
|
|
|
|
|
/// 手动避障开启提示
|
|
|
|
|
static bool last_manual_avoid = avoid.get_avoid_action(); |
|
|
|
|
if(last_manual_avoid != avoid.get_avoid_action()){ |
|
|
|
|
if(avoid.get_avoid_action()){ |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"NOTICE: 开启手动避障!"); |
|
|
|
|
}else{ |
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"NOTICE: 关闭手动避障!"); |
|
|
|
|
} |
|
|
|
|
last_manual_avoid = avoid.get_avoid_action(); |
|
|
|
|
} |
|
|
|
|
#if CAM_DEBUG |
|
|
|
|
if(in_debug_mode == 2 || control_mode==Mode::Number::ACRO){
|
|
|
|
|
camera.take_picture(); |
|
|
|
|