Compass_PerMotor.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. per-motor compass compensation
  3. */
  4. #include <AP_Math/AP_Math.h>
  5. class Compass;
  6. // per-motor compass compensation class. Currently tied to quadcopters
  7. // only, and single magnetometer
  8. class Compass_PerMotor {
  9. public:
  10. static const struct AP_Param::GroupInfo var_info[];
  11. Compass_PerMotor(Compass &_compass);
  12. bool enabled(void) const {
  13. return enable.get() != 0;
  14. }
  15. void set_voltage(float _voltage) {
  16. // simple low-pass on voltage
  17. voltage = 0.9f * voltage + 0.1f * _voltage;
  18. }
  19. void calibration_start(void);
  20. void calibration_update(void);
  21. void calibration_end(void);
  22. void compensate(Vector3f &offset);
  23. private:
  24. Compass &compass;
  25. AP_Int8 enable;
  26. AP_Float expo;
  27. AP_Vector3f compensation[4];
  28. // base field on test start
  29. Vector3f base_field;
  30. // sum of calibration field samples
  31. Vector3f field_sum[4];
  32. // sum of output (voltage*scaledpwm) in calibration
  33. float output_sum[4];
  34. // count of calibration accumulation
  35. uint16_t count[4];
  36. // time a motor started in milliseconds
  37. uint32_t start_ms[4];
  38. // battery voltage
  39. float voltage;
  40. // is calibration running?
  41. bool running;
  42. // get scaled motor ouput
  43. float scaled_output(uint8_t motor);
  44. // map of motors
  45. bool have_motor_map;
  46. uint8_t motor_map[4];
  47. };