OpticalFlow_backend.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #pragma once
  14. /*
  15. OpticalFlow backend class for ArduPilot
  16. */
  17. #include "OpticalFlow.h"
  18. class OpticalFlow_backend
  19. {
  20. friend class OpticalFlow;
  21. public:
  22. // constructor
  23. OpticalFlow_backend(OpticalFlow &_frontend);
  24. virtual ~OpticalFlow_backend(void);
  25. // init - initialise sensor
  26. virtual void init() = 0;
  27. // read latest values from sensor and fill in x,y and totals.
  28. virtual void update() = 0;
  29. // handle optical flow mavlink messages
  30. virtual void handle_msg(const mavlink_message_t &msg) {}
  31. protected:
  32. // access to frontend
  33. OpticalFlow &frontend;
  34. // update the frontend
  35. void _update_frontend(const struct OpticalFlow::OpticalFlow_state &state);
  36. // get the flow scaling parameters
  37. Vector2f _flowScaler(void) const { return Vector2f(frontend._flowScalerX, frontend._flowScalerY); }
  38. // get the yaw angle in radians
  39. float _yawAngleRad(void) const { return radians(float(frontend._yawAngle_cd) * 0.01f); }
  40. // apply yaw angle to a vector
  41. void _applyYaw(Vector2f &v);
  42. // get ADDR parameter value
  43. uint8_t get_address(void) const { return frontend._address; }
  44. // semaphore for access to shared frontend data
  45. HAL_Semaphore _sem;
  46. };