mt6701_sensor.h 948 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <SimpleFOC.h>
  3. #include "driver/spi_master.h"
  4. struct MT6701Error {
  5. bool error;
  6. uint8_t received_crc;
  7. uint8_t calculated_crc;
  8. };
  9. class MT6701Sensor : public Sensor {
  10. public:
  11. MT6701Sensor();
  12. // initialize the sensor hardware
  13. void init();
  14. // Get current shaft angle from the sensor hardware, and
  15. // return it as a float in radians, in the range 0 to 2PI.
  16. // - This method is pure virtual and must be implemented in subclasses.
  17. // Calling this method directly does not update the base-class internal fields.
  18. // Use update() when calling from outside code.
  19. float getSensorAngle();
  20. MT6701Error getAndClearError();
  21. private:
  22. spi_device_handle_t spi_device_;
  23. spi_transaction_t spi_transaction_ = {};
  24. float x_;
  25. float y_;
  26. uint32_t last_update_;
  27. MT6701Error error_ = {};
  28. };