/**************************************************************************** * * Copyright (c) 2023 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name PX4 nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ /** * @file FlightTaskPrecisionLanding.hpp * * Flight task for better precision landing */ #pragma once #include "FlightTask.hpp" #include #include #include // #include #include #include // #include #include #include // TODO: Get the correct define from some header #define SEC2USEC 1000000.0f #define HOVER_SPEED_THRESHOLD 0.20f // If drone has speed under this value it is considered to be hovering in place class FlightTaskPrecisionLanding : public FlightTask { public: FlightTaskPrecisionLanding() = default; virtual ~FlightTaskPrecisionLanding() = default; bool activate(const trajectory_setpoint_s &last_setpoint) override; bool update() override; private: // TODO: Use ModuleParams DEFINE_PARAMETERS_CUSTOM_PARENT(FlightTask, (ParamFloat) _param_mpc_land_speed, ///< velocity for controlled descend (ParamFloat) _param_pld_srch_alt, (ParamFloat) _param_pld_srch_tout, (ParamInt) _param_pld_max_srch, (ParamFloat) _param_pld_hacc_rad, (ParamFloat) _param_pld_btout, (ParamFloat) _param_rtl_return_alt, (ParamFloat) _param_nav_mc_alt_rad ) enum PRECLAND_STATE { AUTORTL_CLIMB, AUTORTL_APPROACH, MOVE_TO_SEARCH_ALTITUDE, SEARCHING_TARGET, MOVING_ABOVE_TARGET, LANDING }; void do_state_transition(PRECLAND_STATE new_state); bool inside_acceptance_radius(); bool precision_target_available(); void generate_setpoints(); void generate_pos_xy_setpoints(); void generate_pos_z_setpoints(); void generate_vel_setpoints(); void generate_acc_setpoints(); void generate_yaw_setpoint(); void check_state_transitions(); PRECLAND_STATE _precland_state; uORB::Subscription _landing_target_pose_sub{ORB_ID(landing_target_pose)}; landing_target_pose_s _landing_target_pose{}; /**< precision landing target position */ uORB::PublicationMulti _precision_landing_status_pub{ORB_ID(precision_landing_status)}; uint64_t _state_start_time{0}; /**< time when entering search state */ int _search_count = 0; float _initial_yaw; float _target_yaw; matrix::Vector3f _initial_position; orb_advert_t _mavlink_log_pub{nullptr}; };