commands.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #ifndef _FOC_CMD_H__
  2. #define _FOC_CMD_H__
  3. #include "os/os_types.h"
  4. #include "config.h"
  5. typedef enum {
  6. Foc_Start_Motor = 32, //foc_start_stop_t, ready, unread, 014d01
  7. Foc_Cali_Hall_Phase, //calibrate hall phase, get the angle when motor running 0-360
  8. Foc_Cali_Hall_Offset,//calibrate hall offset from A phase 0x034d00
  9. Foc_Set_iDC_Limit, //u32, set the limited current//mA
  10. Foc_Set_Speed_Limit, //u32, set the limited speed//rpm
  11. Foc_Set_Speed_Target, //u32, set the target speed, just for test
  12. Foc_Set_Cruise_Speed, //u32, set the speed for curise riding
  13. Foc_Set_Cruise_Mode,
  14. Foc_Set_Phase_CurrLim,
  15. Foc_Set_Ctrl_Mode,
  16. Foc_Set_Gear_Limit, //通过设置限速,限相电流,限母线电流上层可以实现任意挡位
  17. Foc_Set_Open_Dq_Vol, //u32, u32, 114d000000000a000000, 114d0000000000000000
  18. Foc_Set_EPM_Mode,
  19. Foc_Start_EPM_Move,
  20. Foc_Conf_Pid,
  21. Foc_Start_DQ_Calibrate,
  22. Foc_Set_IS_Curr_Angle, //设置DQ电流矢量和超前角
  23. Foc_Set_Plot_Type,
  24. Foc_Set_Throttle_throld,
  25. Foc_Set_eBrake_Throld,
  26. Foc_Lock_Motor,
  27. Foc_Auto_Hold,
  28. Foc_Set_Config,
  29. Foc_Get_Config,
  30. Foc_Get_Pid,
  31. Foc_Fan_Duty, //57
  32. Foc_Get_Gear_Limit,
  33. Foc_Set_Thro_Ration,
  34. Foc_Use_SensorLess_Angle,
  35. Foc_Force_Open_Run,
  36. Foc_Enc_Zero_Cali_Result,
  37. Foc_Set_Limiter_Config,
  38. Foc_Get_Limiter_Config,
  39. Foc_End_Write_TRQ_Table,
  40. Foc_SN_Write, //66
  41. Foc_SN_Read,
  42. Foc_Set_DQ_Current, //0x44
  43. Foc_Set_Gear_Mode,//0-3, eco, normal, sport, turbo
  44. Foc_Set_Adrc_Params,
  45. Foc_Get_Adrc_Params,
  46. Foc_Get_MC_NV_Err_RT,
  47. Foc_Get_MC_NV_Crit_Err,
  48. Foc_Hall_Phase_Cali_Result = 160,
  49. Foc_Hall_Offset_Cali_Result,
  50. Foc_Report_Speed,
  51. Foc_Report_Vbus_Current, //u32
  52. Foc_Report_Phase_Current, //s32,s32,s32
  53. Foc_Report_Dq_Current, //s32,s32
  54. Foc_Report_Vbus_Vol, //u32
  55. Foc_Report_Phase_Vol, //u32,u32,u32
  56. Foc_Report_Dq_Vol, //u32, u32
  57. Foc_Report_Power,
  58. Foc_Report_Pid,
  59. Foc_Report_Status,
  60. Foc_Report_MTPA_DQ_Angle,
  61. Foc_Report_Plot,
  62. Foc_Report_Temp,
  63. Foc_Set_LogLevel,
  64. Foc_MotPara_Ind,
  65. Foc_MotPara_Report,
  66. Foc_Cmd_Max = 0xDF
  67. }foc_cmd_t;
  68. #define CMD_2_CAN_KEY(cmd) ((u16)(((u16)cmd) | (CAN_MY_ADDRESS<<8)))
  69. typedef enum {
  70. Foc_Start = 1,
  71. Foc_Stop,
  72. }FSwith_t;;
  73. typedef struct {
  74. foc_cmd_t cmd;
  75. u16 ext_key;
  76. u8 can_src;
  77. u8 len;
  78. void *data;
  79. }foc_cmd_body_t;
  80. #pragma pack (push,1)
  81. typedef struct {
  82. //0-15 bit
  83. u16 start :2; //1:stop, 2:start, 0&3:ignore
  84. u16 gear :3; //0-6 gear, 7:ignore
  85. u16 idc :11;//0-1024A, 0x7FF:ignore
  86. //16-31 bit
  87. u16 ebrk_lvl:4; //0-14, 0xF:ignore
  88. u16 brkpower:2; //1:disable, 2:enable, 3:ignore
  89. u16 etcs :2; //1:disable, 2:enable, 3:ignore
  90. u16 epm :2; //1:disable, 2:enable
  91. u16 epm_dir :2; //0:stop, 1:back, 2 forword
  92. //32-47 bit
  93. u16 cruise :2; //1:disable, 2:enable
  94. u16 inc :2; //1:dec, 2:inc
  95. u16 spd_rel :12;
  96. //48-63 bit
  97. u16 res; //when response, this is the error code
  98. }cmd_2A01_t;
  99. typedef struct {
  100. //0-15 bit
  101. u16 status;
  102. //16-31 bit
  103. u16 vdc :9;
  104. u16 mot_ll :2; //motor temp limiter level
  105. u16 mos_ll :2; //mos temp limiter level
  106. u16 res :3;
  107. //31-63 bit
  108. u32 idc :11;// -1024 ~ +1023
  109. u32 rpm :14;
  110. u32 thro_e :4 ;//throttle error bit mask
  111. }indicat_2A02_t;
  112. typedef struct {
  113. u8 start_stop; //1: start, 2: stop
  114. }foc_start_cmd_t;
  115. typedef struct {
  116. u32 vq_mvol; //mV
  117. }hall_phase_cali_cmd_t;
  118. typedef struct {
  119. u32 vq_mvol; //mV
  120. u32 step_inc; //degree
  121. u32 step_time;//second
  122. }hall_offset_cali_cmd_t;
  123. typedef struct {
  124. float kp;
  125. float ki;
  126. float kd;
  127. }pid_conf_t;
  128. #pragma pack(pop)
  129. void foc_command_init(void);
  130. bool foc_send_command(foc_cmd_body_t *command);
  131. void can_debug(bool enable);
  132. #endif /*_FOC_CMD_H__ */