AP_BattMonitor_Analog.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma once
  2. #include "AP_BattMonitor.h"
  3. #include "AP_BattMonitor_Backend.h"
  4. // default pins and dividers
  5. #if defined(HAL_BATT_VOLT_PIN)
  6. // pins defined in board config (hwdef.dat on ChibiOS)
  7. # define AP_BATT_VOLT_PIN HAL_BATT_VOLT_PIN
  8. # define AP_BATT_CURR_PIN HAL_BATT_CURR_PIN
  9. # define AP_BATT_VOLTDIVIDER_DEFAULT HAL_BATT_VOLT_SCALE
  10. # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT HAL_BATT_CURR_SCALE
  11. #elif CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
  12. # define AP_BATT_VOLT_PIN 4
  13. # define AP_BATT_CURR_PIN 3
  14. # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
  15. # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
  16. #elif CONFIG_HAL_BOARD == HAL_BOARD_SITL
  17. # define AP_BATT_VOLT_PIN 13
  18. # define AP_BATT_CURR_PIN 12
  19. # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
  20. # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
  21. #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXF)
  22. # define AP_BATT_VOLT_PIN 5
  23. # define AP_BATT_CURR_PIN 6
  24. # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
  25. # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
  26. #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI
  27. # define AP_BATT_VOLT_PIN 0
  28. # define AP_BATT_CURR_PIN 1
  29. # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
  30. # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
  31. #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE
  32. # define AP_BATT_VOLT_PIN 0
  33. # define AP_BATT_CURR_PIN 1
  34. # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
  35. # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
  36. #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET
  37. # define AP_BATT_VOLT_PIN 1
  38. # define AP_BATT_CURR_PIN 0
  39. # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
  40. # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
  41. #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2)
  42. # define AP_BATT_VOLT_PIN 2
  43. # define AP_BATT_CURR_PIN 3
  44. # define AP_BATT_VOLTDIVIDER_DEFAULT 11.3f
  45. # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
  46. #elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX && (CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE)
  47. # define AP_BATT_VOLT_PIN 3
  48. # define AP_BATT_CURR_PIN 2
  49. # define AP_BATT_VOLTDIVIDER_DEFAULT 18.62
  50. # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 62.98f
  51. # define AP_BATT2_VOLT_PIN 5
  52. # define AP_BATT2_CURR_PIN 4
  53. # define AP_BATT2_VOLTDIVIDER_DEFAULT 18.62
  54. # define AP_BATT2_CURR_AMP_PERVOLT_DEFAULT 62.98f
  55. #else
  56. # define AP_BATT_VOLT_PIN -1
  57. # define AP_BATT_CURR_PIN -1
  58. # define AP_BATT_VOLTDIVIDER_DEFAULT 10.1f
  59. # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 17.0f
  60. #endif
  61. // Other values normally set directly by mission planner
  62. // # define AP_BATT_VOLTDIVIDER_DEFAULT 15.70 // Volt divider for AttoPilot 50V/90A sensor
  63. // # define AP_BATT_VOLTDIVIDER_DEFAULT 4.127 // Volt divider for AttoPilot 13.6V/45A sensor
  64. // # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 27.32 // Amp/Volt for AttoPilot 50V/90A sensor
  65. // # define AP_BATT_CURR_AMP_PERVOLT_DEFAULT 13.66 // Amp/Volt for AttoPilot 13.6V/45A sensor
  66. class AP_BattMonitor_Analog : public AP_BattMonitor_Backend
  67. {
  68. public:
  69. /// Constructor
  70. AP_BattMonitor_Analog(AP_BattMonitor &mon, AP_BattMonitor::BattMonitor_State &mon_state, AP_BattMonitor_Params &params);
  71. /// Read the battery voltage and current. Should be called at 10hz
  72. void read() override;
  73. /// returns true if battery monitor provides consumed energy info
  74. bool has_consumed_energy() const override { return has_current(); }
  75. /// returns true if battery monitor provides current info
  76. bool has_current() const override;
  77. void init(void) override {}
  78. protected:
  79. AP_HAL::AnalogSource *_volt_pin_analog_source;
  80. AP_HAL::AnalogSource *_curr_pin_analog_source;
  81. };