commands.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 = 1, //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_Current,
  15. Foc_Conf_Pid,
  16. Foc_Hall_Phase_Cali_Result,
  17. Foc_Hall_Offset_Cali_Result,
  18. Foc_Report_Speed,
  19. Foc_Report_Vbus_Current, //u32
  20. Foc_Report_Phase_Current, //s32,s32,s32
  21. Foc_Report_Dq_Current, //s32,s32
  22. Foc_Report_Vbus_Vol, //u32
  23. Foc_Report_Phase_Vol, //u32,u32,u32
  24. Foc_Report_Dq_Vol, //u32, u32
  25. Foc_Set_Open_Dq_Vol, //u32, u32, 114d000000000a000000, 114d0000000000000000
  26. Foc_Start_EPM_Move,
  27. Foc_Cmd_Max
  28. }foc_cmd_t;
  29. #define CMD_2_CAN_KEY(cmd) ((u16)(((u16)cmd) | (CAN_MY_ADDRESS<<8)))
  30. typedef enum {
  31. Foc_Start = 1,
  32. Foc_Stop,
  33. }FSwith_t;;
  34. typedef struct {
  35. foc_cmd_t cmd;
  36. u8 can_src;
  37. void *data;
  38. }foc_cmd_body_t;
  39. #pragma pack (push,1)
  40. typedef struct {
  41. u8 start_stop; //1: start, 2: stop
  42. }foc_start_cmd_t;
  43. typedef struct {
  44. u32 vq_mvol; //mV
  45. }hall_phase_cali_cmd_t;
  46. typedef struct {
  47. u32 vq_mvol; //mV
  48. u32 step_inc; //degree
  49. u32 step_time;//second
  50. }hall_offset_cali_cmd_t;
  51. typedef struct {
  52. float kp;
  53. float ki;
  54. float kb;
  55. }pid_conf_t;
  56. #pragma pack(pop)
  57. void foc_command_init(void);
  58. bool foc_send_command(foc_cmd_body_t *command);
  59. #endif /*_FOC_CMD_H__ */