LCOV - code coverage report
Current view: top level - AP_OpticalFlow - AP_OpticalFlow_Backend.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 3 8 37.5 %
Date: 2026-09-09 11:02:08 Functions: 3 7 42.9 %

          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             : /*
      18             :   AP_OpticalFlow backend class for ArduPilot
      19             :  */
      20             : 
      21             : #include "AP_OpticalFlow.h"
      22             : 
      23             : #include <AP_HAL/Semaphores.h>
      24             : 
      25             : class OpticalFlow_backend
      26             : {
      27             :     friend class AP_OpticalFlow;
      28             : 
      29             : public:
      30             :     // constructor
      31             :     OpticalFlow_backend(AP_OpticalFlow &_frontend);
      32             :     virtual ~OpticalFlow_backend(void);
      33             : 
      34             :     CLASS_NO_COPY(OpticalFlow_backend);
      35             : 
      36             :     // init - initialise sensor
      37          14 :     virtual void init() {}
      38             : 
      39             :     // read latest values from sensor and fill in x,y and totals.
      40             :     virtual void update() = 0;
      41             : 
      42             :     // handle optical flow mavlink messages
      43           0 :     virtual void handle_msg(const mavlink_message_t &msg) {}
      44             : 
      45             : #if HAL_MSP_OPTICALFLOW_ENABLED
      46             :     // handle optical flow msp messages
      47           0 :     virtual void handle_msp(const MSP::msp_opflow_data_message_t &pkt) {}
      48             : #endif
      49             : 
      50             : protected:
      51             :     // access to frontend
      52             :     AP_OpticalFlow &frontend;
      53             : 
      54             :     // update the frontend
      55             :     void _update_frontend(const struct AP_OpticalFlow::OpticalFlow_state &state);
      56             : 
      57             :     // get the flow scaling parameters
      58       10128 :     Vector2f _flowScaler(void) const { return Vector2f(frontend._flowScalerX, frontend._flowScalerY); }
      59             : 
      60             :     // get the yaw angle in radians
      61       10128 :     float _yawAngleRad(void) const { return cd_to_rad(float(frontend._yawAngle_cd)); }
      62             : 
      63             :     // apply yaw angle to a vector
      64             :     void _applyYaw(Vector2f &v);
      65             : 
      66             :     // get ADDR parameter value
      67           0 :     uint8_t get_address(void) const { return frontend._address; }
      68             : 
      69             :     // options parameter values
      70             :     enum class Option : uint16_t {
      71             :         Stabilised = (1 << 0U)      // sensor is stabilised (e.g. mounted on a gimbal)
      72             :     };
      73             : 
      74             :     // returns true if an option is enabled
      75           0 :     bool option_is_enabled(Option option) const {
      76           0 :         return ((uint8_t)frontend._options.get() & (uint16_t)option) != 0;
      77             :     }
      78             : 
      79             :     // semaphore for access to shared frontend data
      80             :     HAL_Semaphore _sem;
      81             : };

Generated by: LCOV version 1.14