|
|
@ -817,6 +817,7 @@ void ModeAuto::wp_run() |
|
|
|
if(g.zr_8_circle == 2 && wp_nav_index == 0){ |
|
|
|
if(g.zr_8_circle == 2 && wp_nav_index == 0){ |
|
|
|
const bool reached_wp_dest = copter.wp_nav->reached_wp_destination(); |
|
|
|
const bool reached_wp_dest = copter.wp_nav->reached_wp_destination(); |
|
|
|
static uint32_t last_100ms; |
|
|
|
static uint32_t last_100ms; |
|
|
|
|
|
|
|
static uint8_t timeout_cnt; |
|
|
|
uint32_t tnow = AP_HAL::millis(); |
|
|
|
uint32_t tnow = AP_HAL::millis(); |
|
|
|
if (tnow - last_100ms > 100) { |
|
|
|
if (tnow - last_100ms > 100) { |
|
|
|
Vector3f stopping_point; |
|
|
|
Vector3f stopping_point; |
|
|
@ -834,6 +835,9 @@ void ModeAuto::wp_run() |
|
|
|
stopping_point.z ); |
|
|
|
stopping_point.z ); |
|
|
|
} |
|
|
|
} |
|
|
|
if(reached_wp_dest){ |
|
|
|
if(reached_wp_dest){ |
|
|
|
|
|
|
|
if(timeout_cnt == 0){ |
|
|
|
|
|
|
|
timeout_cnt = 1; |
|
|
|
|
|
|
|
} |
|
|
|
static autopilot_yaw_mode last_yaw_mode; |
|
|
|
static autopilot_yaw_mode last_yaw_mode; |
|
|
|
if(circle_init_yaw == false){ // 如果需要转向到下一个航点
|
|
|
|
if(circle_init_yaw == false){ // 如果需要转向到下一个航点
|
|
|
|
if (abs(wrap_180_cd(ahrs.yaw_sensor-wp_yaw_cd)) <= 200) { //转到角度
|
|
|
|
if (abs(wrap_180_cd(ahrs.yaw_sensor-wp_yaw_cd)) <= 200) { //转到角度
|
|
|
@ -842,7 +846,9 @@ void ModeAuto::wp_run() |
|
|
|
copter.circle_nav->init(); |
|
|
|
copter.circle_nav->init(); |
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"Auto run circle"); |
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"Auto run circle"); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
// wp_nav->set_wp_destination(last_loc);// 设置第一个WayPoint点为期望值
|
|
|
|
if(timeout_cnt < 10){ |
|
|
|
|
|
|
|
wp_nav->set_wp_destination(last_loc);// 设置第一个WayPoint点为期望值
|
|
|
|
|
|
|
|
} |
|
|
|
if (auto_yaw.mode() != AUTO_YAW_FIXED) { // 需要转角度,yaw mode使用AUTO_YAW_FIXED
|
|
|
|
if (auto_yaw.mode() != AUTO_YAW_FIXED) { // 需要转角度,yaw mode使用AUTO_YAW_FIXED
|
|
|
|
// wp_nav->set_wp_destination(last_loc);// 设置第一个WayPoint点为期望值
|
|
|
|
// wp_nav->set_wp_destination(last_loc);// 设置第一个WayPoint点为期望值
|
|
|
|
last_yaw_mode = auto_yaw.mode(); |
|
|
|
last_yaw_mode = auto_yaw.mode(); |
|
|
@ -852,9 +858,32 @@ void ModeAuto::wp_run() |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
// get current location
|
|
|
|
|
|
|
|
static uint32_t last_1s; |
|
|
|
|
|
|
|
if (timeout_cnt > 0 &&AP_HAL::millis() - last_1s > 1000) { |
|
|
|
|
|
|
|
const Vector3f &curr_pos = copter.inertial_nav.get_position(); |
|
|
|
|
|
|
|
static Vector3f last_pos = curr_pos; |
|
|
|
|
|
|
|
Vector3f dist_to_dest = (curr_pos - last_pos); |
|
|
|
|
|
|
|
// gcs().send_text(MAV_SEVERITY_INFO,"Circle turn move:%.2f,%d", dist_to_dest.length(),timeout_cnt);
|
|
|
|
|
|
|
|
if( dist_to_dest.length() <= 100 ) { |
|
|
|
|
|
|
|
timeout_cnt+=1; |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
timeout_cnt = 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
last_1s = AP_HAL::millis(); |
|
|
|
|
|
|
|
last_pos = curr_pos; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (timeout_cnt == 10) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
gcs().send_text(MAV_SEVERITY_INFO,"Circle turn yaw timeout"); |
|
|
|
|
|
|
|
// circle_init_yaw = true;
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if(circle_init_yaw) |
|
|
|
if(circle_init_yaw) |
|
|
|
{ // 如果需要转向到下一个航点
|
|
|
|
{ // 如果需要转向到下一个航点
|
|
|
|
|
|
|
|
timeout_cnt = 0; |
|
|
|
copter.circle_nav->turn_2_circle(); |
|
|
|
copter.circle_nav->turn_2_circle(); |
|
|
|
pos_control->update_z_controller(); |
|
|
|
pos_control->update_z_controller(); |
|
|
|
// Yaw 由 circle决定
|
|
|
|
// Yaw 由 circle决定
|
|
|
@ -1341,7 +1370,9 @@ void ModeAuto::do_nav_wp(const AP_Mission::Mission_Command& cmd) |
|
|
|
// for unsupported commands it is safer to stop
|
|
|
|
// for unsupported commands it is safer to stop
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(wp_nav_index == 0){ |
|
|
|
|
|
|
|
fast_waypoint = false; |
|
|
|
|
|
|
|
} |
|
|
|
// fast_waypoint = copter.wp_nav->get_fast_waypoint();
|
|
|
|
// fast_waypoint = copter.wp_nav->get_fast_waypoint();
|
|
|
|
copter.wp_nav->set_fast_waypoint(fast_waypoint); |
|
|
|
copter.wp_nav->set_fast_waypoint(fast_waypoint); |
|
|
|
} |
|
|
|
} |
|
|
|