diff --git a/aerial_robot_control/include/aerial_robot_control/flight_navigation.h b/aerial_robot_control/include/aerial_robot_control/flight_navigation.h index 9e9aca157..e030e69f8 100644 --- a/aerial_robot_control/include/aerial_robot_control/flight_navigation.h +++ b/aerial_robot_control/include/aerial_robot_control/flight_navigation.h @@ -270,6 +270,8 @@ namespace aerial_robot_navigation bool lock_teleop_; ros::Time force_landing_start_time_; + double takeoff_xy_pos_tolerance_; + double takeoff_z_pos_tolerance_; double hover_convergent_start_time_; double hover_convergent_duration_; double land_check_start_time_; @@ -365,6 +367,23 @@ namespace aerial_robot_navigation { if(getNaviState() == TAKEOFF_STATE) return; + /* check xy position error in initial state */ + double pos_x_error = getTargetPos().x() - estimator_->getPos(Frame::COG, estimate_mode_).x(); + double pos_y_error = getTargetPos().y() - estimator_->getPos(Frame::COG, estimate_mode_).y(); + double pos_xy_error_dist = std::sqrt(pos_x_error * pos_x_error + pos_y_error * pos_y_error); + if(pos_xy_error_dist > takeoff_xy_pos_tolerance_) + { + ROS_ERROR_STREAM("initial xy error distance: " << pos_xy_error_dist << " is larger than threshold " << takeoff_xy_pos_tolerance_ << ". switch back to ARM_OFF_STATE"); + setNaviState(STOP_STATE); + } + + /* check difference in height between arming and takeoff */ + if(fabs(init_height_ - estimator_->getPos(Frame::COG, estimate_mode_).z()) > takeoff_z_pos_tolerance_) + { + ROS_ERROR_STREAM("difference between init height and current height: " << fabs(init_height_ - estimator_->getPos(Frame::COG, estimate_mode_).z()) << " is larger than threshold " << takeoff_z_pos_tolerance_ << ". switch back to ARM_OFF_STATE"); + setNaviState(STOP_STATE); + } + if(getNaviState() == ARM_ON_STATE) { setNaviState(TAKEOFF_STATE); @@ -407,7 +426,8 @@ namespace aerial_robot_navigation setInitHeight(estimator_->getPos(Frame::COG, estimate_mode_).z()); setTargetYawFromCurrentState(); - ROS_INFO_STREAM("init height for takeoff: " << init_height_); + ROS_INFO_STREAM("init height for takeoff: " << init_height_ << ", target height: " << getTargetPos().z()); + ROS_INFO_STREAM("target xy pos: " << "[" << getTargetPos().x() << ", " << getTargetPos().y() << "]"); ROS_INFO("Start state"); } diff --git a/aerial_robot_control/src/flight_navigation.cpp b/aerial_robot_control/src/flight_navigation.cpp index 3ef37bd67..f39d6aa71 100644 --- a/aerial_robot_control/src/flight_navigation.cpp +++ b/aerial_robot_control/src/flight_navigation.cpp @@ -1065,6 +1065,8 @@ void BaseNavigator::rosParamInit() land_descend_vel_ == -0.3; } + getParam(nh, "takeoff_xy_pos_tolerance", takeoff_xy_pos_tolerance_, 0.3); + getParam(nh, "takeoff_z_pos_tolerance", takeoff_z_pos_tolerance_, 0.3); getParam(nh, "hover_convergent_duration", hover_convergent_duration_, 1.0); getParam(nh, "land_check_duration", land_check_duration_, 0.5); if (land_check_duration_ < 0.5) {