AP_RangeFinder_Benewake_TFMiniPlus.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2019 Lucas De Marchi <lucas.de.marchi@gmail.com>
  3. *
  4. * This file is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This file is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. * See the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include "RangeFinder.h"
  19. #include "RangeFinder_Backend.h"
  20. #include <AP_HAL/utility/sparse-endian.h>
  21. #include <AP_HAL/I2CDevice.h>
  22. class AP_RangeFinder_Benewake_TFMiniPlus : public AP_RangeFinder_Backend
  23. {
  24. public:
  25. // static detection function
  26. static AP_RangeFinder_Backend *detect(RangeFinder::RangeFinder_State &_state,
  27. AP_RangeFinder_Params &_params,
  28. AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev);
  29. // update state
  30. void update(void) override;
  31. protected:
  32. virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
  33. return MAV_DISTANCE_SENSOR_LASER;
  34. }
  35. private:
  36. AP_RangeFinder_Benewake_TFMiniPlus(RangeFinder::RangeFinder_State &_state,
  37. AP_RangeFinder_Params &_params,
  38. AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev);
  39. bool init();
  40. void timer();
  41. bool process_raw_measure(le16_t distance_raw, le16_t strength_raw,
  42. uint16_t &output_distance_cm);
  43. bool check_checksum(uint8_t *arr, int pkt_len);
  44. AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;
  45. struct {
  46. uint32_t sum;
  47. uint32_t count;
  48. } accum;
  49. };