#ifndef _FOC_CONFIG_H__
#define _FOC_CONFIG_H__
#include "math/fast_math.h"
#include "bsp/bsp.h"

#define CONFIG_ACC_MIN_VOL 30
#define CONFIG_SVM_MODULATION       1.0f
#define CONFIG_MIN_CRUISE_RPM 	  1000   /* 能启动定速巡航的最小速度 */
#define CONFIG_CRUISE_EXIT_RPM    700    /* 自动推出定速巡航的最小速度*/
#define CONFIG_MIN_RPM_FOR_EBRAKE 800 //进入电流回收的最小转速
#define CONFIG_MIN_RPM_EXIT_EBRAKE 250 //推出电流回收的最小转速

#define CONFIG_IDQ_CTRL_TS FOC_PWM_FS
#define CONFIG_SPD_CTRL_TS 1000
#define CONFIG_SPD_CTRL_MS (1000/CONFIG_SPD_CTRL_TS)
#define CONFIG_SPD_CTRL_US (CONFIG_SPD_CTRL_MS * 1000)
#define CONFIG_FOC_VDQ_RAMP_TS 100
#define CONFIG_FOC_VDQ_RAMP_FINAL_TIME 1000
#define CONFIG_ZERO_SPEED_RPM  10
#define CONFIG_LOCK_MOTOR_MIN_RPM 600
#define CONFIG_ZERO_SPEED_RAMP_RMP 60 //从0速启动到结束的速度
/* 电子刹车，动能回收，加速 */
#define CONFIG_eCTRL_STEP_TS CONFIG_SPD_CTRL_MS     /* 斜率给定的step的时间值，单位 ms */
#define CONFIG_eCTRL_Brake_TIME 1500     /* 捏住刹车的时间，超过这个时间启动ebrake，单位 ms */
#define CONFIG_AUTOHOLD_DETECT_TIME 2000

#define CONFIG_CRUISE_RAMP_TIME 4000 /* 定速巡航的时候给定加减速的斜波时间 */

#define CONFIG_CURRENT_RAMP_TIME 5000

#define CONFIG_DEFAULT_TORQUE_RAMP_TIME 1000

#define CONFIG_LIMIT_RAMP_TIME (6 * 1000) /* 过温、欠压保护的给定限流和限速的斜波时间 */

#define CONFIG_SENSORLESS_RAMP_TIME (20 * 1000)

#define CONFIG_MTPA_CALI_RAMP_TIME (10 * 1000)

/* 防止打齿，0扭矩上下的时候需要缓给定参数 */
#define CONFIG_RAMP_FIRST_TARGET (1.0F)
#define CONFIG_RAMP_SECOND_TARGET (5.0F * 1.5F)

/* dq轴电流环指令斜波 */
#define CONFIG_CURRENT_LOOP_RAMP_COUNT 15.0f //15个控制周期 完成ramp给定
#define CONFIG_CURRENT_LOOP_RAMP_STEP_MIN 5.0F//ramp step 不小于step min

#define CONFIG_CRUISE_ENABLE_ACCL 1 //定速巡航可以加速，油门回退，继续定速巡航

/* 限速/速度环等情况下的最大负扭矩，一般给0，不产生拖拽感 */
#define CONFIG_MAX_NEG_TORQUE 0.0F

#define CONFIG_CURRENT_LOOP_DECOUPE    //电流环解耦
#define CONFIG_SENSORLESS_MAX_IDC 30
#define CONFIG_SENSORLESS_MAX_TORQUE 100
#define CONFIG_SENSORLESS_MAX_SPEED 4000

#define CONFIG_PHASE_UNBALANCE_PEAK_CNT 3 //计算经过的电周期内的最大值(peak 峰值)
#define CONFIG_PHASE_UNBALANCE_THROLD 4.0F
#define CONFIG_PHASE_UNBALANCE_R      0.1F

#define CONFIG_Volvec_Delay_Comp /* 电压矢量角度补偿 */
#define CONFIG_Volvec_Delay_Comp_Start_Vel 500 // rpm

#define CONFIG_CONTRL_FW_ENABLE 1
#define CONFIG_CONTRL_FW_START_DUTY 0.9F

#define CONFIG_ENABLE_IAB_REC 1   // for phase current/voltage debug

#define CONFIG_MOT_IND_USE_PHASE_SAMPLE 1 //电机参数离线识别使用采集的相电压

#ifdef CONFIG_SPEED_LADRC
	#define CONFIG_LADRC_Wo  200.0F
	#define CONFIG_LADRC_Wcv 5.0F
	#define CONFIG_LADRC_B0  2500.0F

	#define CONFIG_LADRC_NOLOAD_Wcv 2.5F
	#define CONFIG_LADRC_NOLOAD_B0  3000.0F

	#define CONFIG_LADRC_EPM_Wcv 3.0F
	#define CONFIG_LADRC_EPMBK_B0	 500.0F
	#define CONFIG_LADRC_EPM_B0	     350.0F
#endif
#ifdef CONFIG_SMO_OBSERVER
	#define CONFIG_SMO_MIN_SPEED    1000 //RPM
	#define CONFIG_SMO_PLL_BANDWITH (200.0f * 2 * PI) //计算速度的pll
	#define CONFIG_SMO_LFP_WC        (200.0F * 2* PI)
	#define CONFIG_SMO_GAIN_K        100.0f
	#define CONFIG_SMO_SIGMOID_MAX   120.0F
#endif
#ifdef CONFIG_LADRC_OBSERVER
	#define CONFIG_LADRC_OBSERVER_MIN_SPEED    1000 //RPM
	#define CONFIG_LADRC_OBSERVER_MIN_eVEL 400
	#define CONFIG_LADRC_OBSERVER_MIN_Wo   (200 * 2 * PI)
	#define CONFIG_LADRC_OBSERVER_LPF_FREQ (100 * 2 * PI)
#endif
#endif /* _FOC_CONFIG_H__ */

