commands.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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,
  32. Foc_Hall_Phase_Cali_Result = 160,
  33. Foc_Hall_Offset_Cali_Result,
  34. Foc_Report_Speed,
  35. Foc_Report_Vbus_Current, //u32
  36. Foc_Report_Phase_Current, //s32,s32,s32
  37. Foc_Report_Dq_Current, //s32,s32
  38. Foc_Report_Vbus_Vol, //u32
  39. Foc_Report_Phase_Vol, //u32,u32,u32
  40. Foc_Report_Dq_Vol, //u32, u32
  41. Foc_Report_Power,
  42. Foc_Report_Pid,
  43. Foc_Report_Status,
  44. Foc_Report_MTPA_DQ_Angle,
  45. Foc_Report_Plot,
  46. Foc_Cmd_Max = 0xE0
  47. }foc_cmd_t;
  48. #define CMD_2_CAN_KEY(cmd) ((u16)(((u16)cmd) | (CAN_MY_ADDRESS<<8)))
  49. typedef enum {
  50. Foc_Start = 1,
  51. Foc_Stop,
  52. }FSwith_t;;
  53. typedef struct {
  54. foc_cmd_t cmd;
  55. u16 ext_key;
  56. u8 can_src;
  57. u8 len;
  58. void *data;
  59. }foc_cmd_body_t;
  60. #pragma pack (push,1)
  61. typedef struct {
  62. u8 start_stop; //1: start, 2: stop
  63. }foc_start_cmd_t;
  64. typedef struct {
  65. u32 vq_mvol; //mV
  66. }hall_phase_cali_cmd_t;
  67. typedef struct {
  68. u32 vq_mvol; //mV
  69. u32 step_inc; //degree
  70. u32 step_time;//second
  71. }hall_offset_cali_cmd_t;
  72. typedef struct {
  73. float kp;
  74. float ki;
  75. float kb;
  76. }pid_conf_t;
  77. #pragma pack(pop)
  78. void foc_command_init(void);
  79. bool foc_send_command(foc_cmd_body_t *command);
  80. #endif /*_FOC_CMD_H__ */