HVcallback.ssd 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #include <AP_Common/AP_Common.h>
  2. #include <AP_HAL/AP_HAL.h>
  3. #include "AP_UAVCAN.h"
  4. #include "HVcallback.h"
  5. #define REG_MASK 0xFFF8U
  6. #define TYPE_MASK 0x38U
  7. //hight volt HighVoltThrusterSetRegs.hpp
  8. void HVregs_v5y4(uint8_t _buffer[],int32_t data[]){
  9. uint16_t revID = _buffer[0]+(_buffer[1]<<8);
  10. uint16_t regID = revID & REG_MASK;
  11. uint8_t typeID;
  12. typeID = (uint8_t)revID & TYPE_MASK;
  13. switch (typeID)
  14. {
  15. case TYPE_DATA_8BIT:
  16. {
  17. switch (regID)
  18. {
  19. case MC_REG_CONTROL_MODE:
  20. case MC_REG_RUC_STAGE_NBR:
  21. {
  22. data[0] = (int32_t)_buffer[2];
  23. break;
  24. }
  25. default:
  26. {
  27. data[0] = 0;
  28. break;
  29. }
  30. }
  31. break;
  32. }
  33. case TYPE_DATA_16BIT:
  34. {
  35. switch (regID)
  36. {
  37. case MC_REG_SPEED_KP:
  38. case MC_REG_SPEED_KI:
  39. case MC_REG_SPEED_KD:
  40. case MC_REG_I_Q_KP:
  41. case MC_REG_I_Q_KI:
  42. case MC_REG_I_Q_KD:
  43. case MC_REG_I_D_KP:
  44. case MC_REG_I_D_KI:
  45. case MC_REG_I_D_KD:
  46. case MC_REG_I_A:
  47. case MC_REG_I_B:
  48. case MC_REG_I_ALPHA_MEAS:
  49. case MC_REG_I_BETA_MEAS:
  50. case MC_REG_I_Q_MEAS:
  51. case MC_REG_I_D_MEAS:
  52. case MC_REG_I_Q_REF:
  53. case MC_REG_I_D_REF:
  54. case MC_REG_V_Q:
  55. case MC_REG_V_D:
  56. case MC_REG_V_ALPHA:
  57. case MC_REG_V_BETA:
  58. case MC_REG_STOPLL_EL_ANGLE:
  59. case MC_REG_STOPLL_ROT_SPEED:
  60. case MC_REG_STOPLL_I_ALPHA:
  61. case MC_REG_STOPLL_I_BETA:
  62. case MC_REG_STOPLL_BEMF_ALPHA:
  63. case MC_REG_STOPLL_BEMF_BETA:
  64. case MC_REG_STOPLL_C1:
  65. case MC_REG_STOPLL_C2:
  66. case MC_REG_STOPLL_KI:
  67. case MC_REG_STOPLL_KP:
  68. case MC_REG_SPEED_KP_DIV:
  69. case MC_REG_SPEED_KI_DIV:
  70. case MC_REG_SPEED_KD_DIV:
  71. case MC_REG_I_D_KP_DIV:
  72. case MC_REG_I_D_KI_DIV:
  73. case MC_REG_I_D_KD_DIV:
  74. case MC_REG_I_Q_KP_DIV:
  75. case MC_REG_I_Q_KI_DIV:
  76. case MC_REG_I_Q_KD_DIV:
  77. case MC_REG_STOPLL_KI_DIV:
  78. case MC_REG_STOPLL_KP_DIV:
  79. {
  80. data[0] = (int32_t)(_buffer[2] + (_buffer[3]<<8));
  81. break;
  82. }
  83. default:
  84. {
  85. data[0] = 0;
  86. break;
  87. }
  88. }
  89. break;
  90. }
  91. case TYPE_DATA_32BIT:
  92. {
  93. switch (regID)
  94. {
  95. case MC_REG_SPEED_REF:
  96. case MC_REG_STOPLL_EST_BEMF:
  97. case MC_REG_STOPLL_OBS_BEMF:
  98. {
  99. data[0] = (int32_t)(_buffer[2] + (_buffer[3]<<8) + (_buffer[4]<<16) +(_buffer[5]<<24));
  100. break;
  101. }
  102. default:
  103. {
  104. data[0] = 0;
  105. break;
  106. }
  107. }
  108. break;
  109. }
  110. case TYPE_DATA_RAW:
  111. {
  112. /* First 2 bytes of the answer is reserved to the size */
  113. switch (regID)
  114. {
  115. case MC_REG_SPEED_RAMP:
  116. {
  117. if(_buffer[2]==0x5A)
  118. {
  119. data[0] =(int32_t)( _buffer[3] + _buffer[4]*256 +(_buffer[5]<<16) +(_buffer[6]<<24));
  120. }else if(_buffer[2]==0xA5){
  121. data[1] = (int32_t)(_buffer[3] +( _buffer[4]<<8));
  122. }
  123. break;
  124. }
  125. case MC_REG_TORQUE_RAMP:
  126. {
  127. data[0] = (int32_t)(_buffer[2] +( _buffer[3]<<8));
  128. data[1] = (int32_t)(_buffer[4] +( _buffer[5]<<8));
  129. break;
  130. }
  131. case MC_REG_REVUP_DATA:
  132. {
  133. if( _buffer[2] !=0xFF){
  134. data[0] =(int32_t)( _buffer[3] + _buffer[4]*256 +(_buffer[5]<<16) +(_buffer[6]<<24));
  135. }
  136. else if( _buffer[2] ==0xFF){
  137. data[1] = (int32_t)(_buffer[3] +( _buffer[4]<<8));
  138. data[2] = (int32_t)(_buffer[5] +( _buffer[6]<<8));
  139. }
  140. break;
  141. }
  142. case MC_REG_CURRENT_REF:
  143. {
  144. data[0] = (int32_t)(_buffer[2] +( _buffer[3]<<8));
  145. data[1] = (int32_t)(_buffer[4] +( _buffer[5]<<8));
  146. break;
  147. }
  148. default:
  149. {
  150. data[0] = 0;
  151. break;
  152. }
  153. }
  154. break;
  155. }
  156. default:
  157. {
  158. data[0] = 0;
  159. break;
  160. }
  161. }
  162. }
  163. void HVcycle(uint8_t _code,uint8_t _buffer[6],HVmes &Thruster){
  164. switch (_code)
  165. {
  166. case 0x03:
  167. {
  168. Thruster.voltage = _buffer[0]+(_buffer[1]<<8);
  169. Thruster.speed = _buffer[2]+(_buffer[3]<<8) + (_buffer[4]<<16) + (_buffer[5]<<24);
  170. }
  171. break;
  172. case 0x05:
  173. {
  174. Thruster.fault = _buffer[0]+(_buffer[1]<<8) + (_buffer[2]<<16)+(_buffer[3]<<24);
  175. Thruster.state = _buffer[4] + (_buffer[5]<<8);
  176. }
  177. break;
  178. case 0x0A:
  179. {
  180. Thruster.power = _buffer[0]+(_buffer[1]<<8) ;
  181. Thruster.temperature = _buffer[2] + (_buffer[3]<<8);
  182. }
  183. break;
  184. default:
  185. break;
  186. }
  187. }