HVcallback.bad 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef HVCALLBACK_H_
  2. #define HVCALLBACK_H_
  3. #include <uavcan/uavcan.hpp>
  4. #include <AP_HAL/CAN.h>
  5. #include <AP_HAL/Semaphores.h>
  6. #include <AP_Param/AP_Param.h>
  7. #include <uavcan/helpers/heap_based_pool_allocator.hpp>
  8. #include "AP_UAVCAN_Servers.h"
  9. #define Fault_ACK {0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
  10. #define TorqueMax 15000
  11. #define TorqueMin 500
  12. #define HVspeedMax 2200
  13. #define HVspeedMin 250
  14. #define Start 0x18
  15. #define Stop 0x20
  16. #define ELT_IDENTIFIER_POS 6U
  17. #define TYPE_POS 3U
  18. #define TYPE_DATA_8BIT (1U << TYPE_POS)
  19. #define TYPE_DATA_16BIT (2U << TYPE_POS)
  20. #define TYPE_DATA_32BIT (3U << TYPE_POS)
  21. #define TYPE_DATA_RAW (5U << TYPE_POS)
  22. /* TYPE_DATA_8BIT registers definition */
  23. #define MC_REG_STATUS ((1U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT )
  24. #define MC_REG_CONTROL_MODE ((2U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT )
  25. #define MC_REG_RUC_STAGE_NBR ((3U << ELT_IDENTIFIER_POS) | TYPE_DATA_8BIT )
  26. /* TYPE_DATA_16BIT registers definition */
  27. #define MC_REG_SPEED_KP ((2U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  28. #define MC_REG_SPEED_KI ((3U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  29. #define MC_REG_SPEED_KD ((4U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  30. #define MC_REG_I_Q_KP ((6 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  31. #define MC_REG_I_Q_KI ((7 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  32. #define MC_REG_I_Q_KD ((8 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  33. #define MC_REG_I_D_KP ((10 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  34. #define MC_REG_I_D_KI ((11 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  35. #define MC_REG_I_D_KD ((12 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  36. #define MC_REG_STOPLL_C1 ((13 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  37. #define MC_REG_STOPLL_C2 ((14 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  38. #define MC_REG_STOCORDIC_C1 ((15 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  39. #define MC_REG_STOCORDIC_C2 ((16 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  40. #define MC_REG_STOPLL_KI ((17 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  41. #define MC_REG_STOPLL_KP ((18 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  42. #define MC_REG_BUS_VOLTAGE ((22U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  43. #define MC_REG_HEATS_TEMP ((23U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  44. #define MC_REG_MOTOR_POWER ((24U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  45. #define MC_REG_I_A ((31U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  46. #define MC_REG_I_B ((32U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  47. #define MC_REG_I_ALPHA_MEAS ((33U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  48. #define MC_REG_I_BETA_MEAS ((34U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  49. #define MC_REG_I_Q_MEAS ((35U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  50. #define MC_REG_I_D_MEAS ((36U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  51. #define MC_REG_I_Q_REF ((37U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  52. #define MC_REG_I_D_REF ((38U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  53. #define MC_REG_V_Q ((39U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  54. #define MC_REG_V_D ((40U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  55. #define MC_REG_V_ALPHA ((41U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  56. #define MC_REG_V_BETA ((42U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  57. #define MC_REG_STOPLL_EL_ANGLE ((45U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  58. #define MC_REG_STOPLL_ROT_SPEED ((46U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  59. #define MC_REG_STOPLL_I_ALPHA ((47U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  60. #define MC_REG_STOPLL_I_BETA ((48U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  61. #define MC_REG_STOPLL_BEMF_ALPHA ((49U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  62. #define MC_REG_STOPLL_BEMF_BETA ((50U << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  63. #define MC_REG_SPEED_KP_DIV ((81 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  64. #define MC_REG_SPEED_KI_DIV ((82 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  65. #define MC_REG_SPEED_KD_DIV ((83 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  66. #define MC_REG_I_D_KP_DIV ((84 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  67. #define MC_REG_I_D_KI_DIV ((85 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  68. #define MC_REG_I_D_KD_DIV ((86 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  69. #define MC_REG_I_Q_KP_DIV ((87 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  70. #define MC_REG_I_Q_KI_DIV ((88 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  71. #define MC_REG_I_Q_KD_DIV ((89 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  72. #define MC_REG_STOPLL_KI_DIV ((99 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  73. #define MC_REG_STOPLL_KP_DIV ((100 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  74. #define MC_REG_STARTUP_CURRENT_REF ((105 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  75. #define MC_REG_PULSE_VALUE ((106 << ELT_IDENTIFIER_POS) | TYPE_DATA_16BIT )
  76. /* TYPE_DATA_32BIT registers definition */
  77. #define MC_REG_FAULTS_FLAGS ((0 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT )
  78. #define MC_REG_SPEED_MEAS ((1 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT )
  79. #define MC_REG_SPEED_REF ((2 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT )
  80. #define MC_REG_STOPLL_EST_BEMF ((3 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT ) /* To be checked shifted by >> 16*/
  81. #define MC_REG_STOPLL_OBS_BEMF ((4 << ELT_IDENTIFIER_POS) | TYPE_DATA_32BIT ) /* To be checked shifted by >> 16*/
  82. #define MC_REG_SPEED_RAMP ((6U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW )
  83. #define MC_REG_TORQUE_RAMP ((7U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW )
  84. #define MC_REG_REVUP_DATA ((8U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW ) /* Configure all steps*/
  85. #define MC_REG_CURRENT_REF ((13U << ELT_IDENTIFIER_POS) | TYPE_DATA_RAW )
  86. struct HVmes
  87. {
  88. int16_t voltage;
  89. int32_t speed;
  90. uint32_t fault;
  91. uint16_t state;
  92. int16_t power;
  93. int16_t temperature;
  94. };
  95. extern uint8_t hv_motor_cmd_temp ;
  96. extern uint8_t hv_motor_cmd;
  97. extern int16_t hv_motor_speed_32 ;
  98. void HVregs_v5y4(uint8_t _buffer[],int32_t data[]);
  99. void HVcycle(uint8_t _code,uint8_t _buffer[6],HVmes &Thruster);
  100. #endif