| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #ifndef _FOC_CMD_H__
- #define _FOC_CMD_H__
- #include "os/os_types.h"
- #include "config.h"
- typedef enum {
- Foc_Start_Motor = 32, //foc_start_stop_t, ready, unread, 014d01
- Foc_Cali_Hall_Phase, //calibrate hall phase, get the angle when motor running 0-360
- Foc_Cali_Hall_Offset,//calibrate hall offset from A phase 0x034d00
- Foc_Set_iDC_Limit, //u32, set the limited current//mA
- Foc_Set_Speed_Limit, //u32, set the limited speed//rpm
- Foc_Set_Speed_Target, //u32, set the target speed, just for test
- Foc_Set_Cruise_Speed, //u32, set the speed for curise riding
- Foc_Set_Cruise_Mode,
- Foc_Set_Phase_CurrLim,
- Foc_Set_Ctrl_Mode,
- Foc_Set_Gear_Limit, //通过设置限速,限相电流,限母线电流上层可以实现任意挡位
- Foc_Set_Open_Dq_Vol, //u32, u32, 114d000000000a000000, 114d0000000000000000
- Foc_Set_EPM_Mode,
- Foc_Start_EPM_Move,
- Foc_Conf_Pid,
- Foc_Start_DQ_Calibrate,
- Foc_Set_IS_Curr_Angle, //设置DQ电流矢量和超前角
- Foc_Set_Plot_Type,
- Foc_Set_Throttle_throld,
- Foc_Set_eBrake_Throld,
- Foc_Lock_Motor,
- Foc_Auto_Hold,
- Foc_Set_Config,
- Foc_Get_Config,
- Foc_Get_Pid,
- Foc_Fan_Duty, //57
- Foc_Get_Gear_Limit,
- Foc_Set_Thro_Ration,
- Foc_Use_SensorLess_Angle,
- Foc_Force_Open_Run,
- Foc_Enc_Zero_Cali_Result,
- Foc_Set_Limiter_Config,
- Foc_Get_Limiter_Config,
- Foc_Write_Config,
- Foc_Read_Config,
- Foc_SN_Write, //66
- Foc_SN_Read,
- Foc_Set_DQ_Current, //0x44
- Foc_Set_Gear_Mode,//0-3, eco, normal, sport, turbo
- Foc_Set_Adrc_Params,
- Foc_Get_Adrc_Params,
- Foc_Get_MC_NV_Err_RT,
- Foc_Get_MC_NV_Crit_Err,
- Foc_Hall_Phase_Cali_Result = 160,
- Foc_Hall_Offset_Cali_Result,
- Foc_Report_Speed,
- Foc_Report_Vbus_Current, //u32
- Foc_Report_Phase_Current, //s32,s32,s32
- Foc_Report_Dq_Current, //s32,s32
- Foc_Report_Vbus_Vol, //u32
- Foc_Report_Phase_Vol, //u32,u32,u32
- Foc_Report_Dq_Vol, //u32, u32
- Foc_Report_Power,
- Foc_Report_Pid,
- Foc_Report_Status,
- Foc_Report_MTPA_DQ_Angle,
- Foc_Report_Plot,
- Foc_Report_Temp,
- Foc_Set_LogLevel,
- Foc_MotPara_Ind,
- Foc_MotPara_Report,
- Foc_Set_Force_Torque,
- Foc_Cmd_Max = 0xDF
- }foc_cmd_t;
- #define CMD_2_CAN_KEY(cmd) ((u16)(((u16)cmd) | (CAN_MY_ADDRESS<<8)))
- typedef enum {
- Foc_Start = 1,
- Foc_Stop,
- }FSwith_t;;
- typedef struct {
- foc_cmd_t cmd;
- u16 ext_key;
- u8 can_src;
- u8 len;
- void *data;
- }foc_cmd_body_t;
- #pragma pack (push,1)
- typedef struct {
- //0-15 bit
- u16 start :2; //1:stop, 2:start, 0&3:ignore
- u16 gear :3; //0-6 gear, 7:ignore
- u16 idc :11;//0-1024A, 0x7FF:ignore
- //16-31 bit
- u16 ebrk_lvl:4; //0-14, 0xF:ignore
- u16 brkpower:2; //1:disable, 2:enable, 3:ignore
- u16 etcs :2; //1:disable, 2:enable, 3:ignore
- u16 epm :2; //1:disable, 2:enable
- u16 epm_dir :2; //0:stop, 1:back, 2 forword
- u16 thro_dec:1; //0:do noting, 1:do throttle auto detect
- //32-47 bit
- u16 cruise :2; //1:disable, 2:enable
- u16 inc :2; //1:dec, 2:inc
- u16 spd_rel :12;
- //48-63 bit
- u16 res; //when response, this is the error code
- }cmd_2A01_t;
- typedef struct {
- //0-15 bit
- union {
- u16 status;
- struct _x{
- u16 start :1;
- u16 gear :2;
- u16 autohold :1;
- u16 hw_brk :1;
- u16 cruise :1;
- u16 epm_mode :1;
- u16 lock_mot :1;
- u16 e_brk :1;
- u16 crit_err :1;
- u16 fan_run :1;
- u16 stall :1;
- u16 idc_lim :1;
- u16 trq_lim :1;
- u16 etcs_run :1;
- u16 thro_err :1;
- }s;
- }ustat;
- //16-31 bit
- u16 vdc :9;
- u16 mot_ll :2; //motor temp limiter level
- u16 mos_ll :2; //mos temp limiter level
- u16 res :3;
- //31-63 bit
- u32 idc :11;// -1024 ~ +1023
- u32 rpm :14;
- u32 thro_e :4 ;//throttle error bit mask
- }indicat_2A02_t;
- typedef struct {
- u8 start_stop; //1: start, 2: stop
- }foc_start_cmd_t;
- typedef struct {
- u32 vq_mvol; //mV
- }hall_phase_cali_cmd_t;
- typedef struct {
- u32 vq_mvol; //mV
- u32 step_inc; //degree
- u32 step_time;//second
- }hall_offset_cali_cmd_t;
- #pragma pack(pop)
- void foc_command_init(void);
- bool foc_send_command(foc_cmd_body_t *command);
- void can_debug(bool enable);
- #endif /*_FOC_CMD_H__ */
|