LCOV - code coverage report
Current view: top level - home/pbarker/rc/ardupilot/ArduPlane - tiltrotor.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 9 9 100.0 %
Date: 2026-09-09 11:02:08 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /*
       2             :    This program is free software: you can redistribute it and/or modify
       3             :    it under the terms of the GNU General Public License as published by
       4             :    the Free Software Foundation, either version 3 of the License, or
       5             :    (at your option) any later version.
       6             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  */
      15             : #pragma once
      16             : 
      17             : #include <AP_Param/AP_Param.h>
      18             : #include "transition.h"
      19             : #include <AP_Logger/LogStructure.h>
      20             : 
      21             : class QuadPlane;
      22             : class AP_MotorsMulticopter;
      23             : class Tiltrotor_Transition;
      24             : class Tiltrotor
      25             : {
      26             : friend class QuadPlane;
      27             : friend class Plane;
      28             : friend class Tiltrotor_Transition;
      29             : public:
      30             : 
      31             :     Tiltrotor(QuadPlane& _quadplane, AP_MotorsMulticopter*& _motors);
      32             : 
      33    13014916 :     bool enabled() const { return (enable > 0) && setup_complete;}
      34             : 
      35             :     void setup();
      36             : 
      37             :     void slew(float tilt);
      38             :     void binary_slew(bool forward);
      39             :     void update();
      40             :     void continuous_update();
      41             :     void binary_update();
      42             :     void vectoring();
      43             :     void bicopter_output();
      44             :     void tilt_compensate_angle(float *thrust, uint8_t num_motors, float non_tilted_mul, float tilted_mul);
      45             :     void tilt_compensate(float *thrust, uint8_t num_motors);
      46             :     bool tilt_over_max_angle(void) const;
      47             : 
      48    11685495 :     bool is_motor_tilting(uint8_t motor) const {
      49    11685495 :         return tilt_mask.get() & (1U<<motor);
      50             :     }
      51             : 
      52             :     bool fully_fwd() const;
      53             :     bool fully_up() const;
      54             :     float tilt_max_change(bool up, bool in_flap_range = false) const;
      55             :     float get_fully_forward_tilt() const;
      56             :     float get_forward_flight_tilt() const;
      57             : 
      58             :     // update yaw target for tiltrotor transition
      59             :     void update_yaw_target();
      60             : 
      61     1495186 :     bool is_vectored() const { return enabled() && _is_vectored; }
      62             : 
      63       26262 :     bool has_fw_motor() const { return _have_fw_motor; }
      64             : 
      65        6127 :     bool has_vtol_motor() const { return _have_vtol_motor; }
      66             : 
      67      450209 :     bool motors_active() const { return enabled() && _motors_active; }
      68             : 
      69             :     // true if the tilts have completed slewing
      70             :     // always return true if not enabled or not a continuous type
      71        6591 :     bool tilt_angle_achieved() const { return !enabled() || (type != TILT_TYPE_CONTINUOUS) || angle_achieved; }
      72             : 
      73             :     // throttle of tilting motors used for forward flight
      74             :     bool get_forward_throttle(float &throttle) const;
      75             : 
      76             :     // Write tiltrotor specific log
      77             :     void write_log();
      78             : 
      79             :     AP_Int8 enable;
      80             :     AP_Int16 tilt_mask;
      81             :     AP_Int16 max_rate_up_dps;
      82             :     AP_Int16 max_rate_down_dps;
      83             :     AP_Int8  max_angle_deg;
      84             :     AP_Int8  type;
      85             :     AP_Float tilt_yaw_angle;
      86             :     AP_Float fixed_angle;
      87             :     AP_Float fixed_gain;
      88             :     AP_Float flap_angle_deg;
      89             : 
      90             :     float current_tilt;
      91             :     float current_throttle;
      92             :     bool _motors_active;
      93             :     float transition_yaw_cd;
      94             :     uint32_t transition_yaw_set_ms;
      95             :     bool _is_vectored;
      96             : 
      97             :     // types of tilt mechanisms
      98             :     enum {TILT_TYPE_CONTINUOUS    =0,
      99             :           TILT_TYPE_BINARY        =1,
     100             :           TILT_TYPE_VECTORED_YAW  =2,
     101             :           TILT_TYPE_BICOPTER      =3
     102             :     };
     103             : 
     104             :     static const struct AP_Param::GroupInfo var_info[];
     105             : 
     106             : private:
     107             : 
     108             :     // Tiltrotor specific log message
     109             :     struct PACKED log_tiltrotor {
     110             :         LOG_PACKET_HEADER;
     111             :         uint64_t time_us;
     112             :         float current_tilt;
     113             :         float front_left_tilt;
     114             :         float front_right_tilt;
     115             :     };
     116             : 
     117             :     bool setup_complete;
     118             : 
     119             :     // true if a fixed forward motor is setup
     120             :     bool _have_fw_motor;
     121             : 
     122             :     // true if all motors tilt with no fixed VTOL motor
     123             :     bool _have_vtol_motor;
     124             : 
     125             :     // true if the current tilt angle is equal to the desired
     126             :     // with slow tilt rates the tilt angle can lag
     127             :     bool angle_achieved;
     128             : 
     129             :     // references for convenience
     130             :     QuadPlane& quadplane;
     131             :     AP_MotorsMulticopter*& motors;
     132             : 
     133             :     Tiltrotor_Transition* transition;
     134             : 
     135             : };
     136             : 
     137             : // Transition for separate left thrust quadplanes
     138             : class Tiltrotor_Transition : public SLT_Transition
     139             : {
     140             : friend class Tiltrotor;
     141             : public:
     142             : 
     143          13 :     Tiltrotor_Transition(QuadPlane& _quadplane, AP_MotorsMulticopter*& _motors, Tiltrotor& _tiltrotor):SLT_Transition(_quadplane, _motors), tiltrotor(_tiltrotor) {};
     144             : 
     145             :     bool update_yaw_target(float& yaw_target_cd) override;
     146             : 
     147             :     bool show_vtol_view() const override;
     148             : 
     149             :     bool use_multirotor_control_in_fwd_transition() const override;
     150             : 
     151             :     // Return true if forward throttle should be allowed for position control, see Q_FWD_THR_USE
     152             :     virtual bool allow_vfwd() const override;
     153             : 
     154             : private:
     155             : 
     156             :     Tiltrotor& tiltrotor;
     157             : 
     158             : };

Generated by: LCOV version 1.14