IRLock.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /*
  14. * IRLock.h - IRLock Base Class for Ardupilot
  15. *
  16. * Created on: Nov 10, 2014
  17. * Author: MLandes
  18. */
  19. #pragma once
  20. #include <AP_Math/AP_Math.h>
  21. class IRLock
  22. {
  23. public:
  24. // init - initialize sensor library
  25. // library won't be useable unless this is first called
  26. virtual void init(int8_t bus) = 0;
  27. // true if irlock sensor is online and healthy
  28. bool healthy() const { return _flags.healthy; }
  29. // timestamp of most recent data read from the sensor
  30. uint32_t last_update_ms() const { return _last_update_ms; }
  31. // returns the number of blocks in the current frame
  32. size_t num_targets() const { return _flags.healthy?1:0; }
  33. // retrieve latest sensor data - returns true if new data is available
  34. virtual bool update() = 0;
  35. // retrieve body frame unit vector in direction of target
  36. // returns true if data is available
  37. bool get_unit_vector_body(Vector3f& ret) const;
  38. protected:
  39. struct AP_IRLock_Flags {
  40. uint8_t healthy : 1; // true if sensor is healthy
  41. } _flags;
  42. // internals
  43. uint32_t _last_update_ms;
  44. // irlock_target_info is a duplicate of the PX4Firmware irlock_s structure
  45. typedef struct {
  46. uint32_t timestamp; // milliseconds since system start
  47. float pos_x; // x-axis distance from center of image to center of target in units of tan(theta)
  48. float pos_y; // y-axis distance from center of image to center of target in units of tan(theta)
  49. float pos_z;
  50. } irlock_target_info;
  51. irlock_target_info _target_info;
  52. };