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

#define CONFIG_DEFAULT_IDC_LIM CONFIG_MAX_VBUS_CURRENT
#define CONFIG_DEFAULT_RPM_LIM CONFIG_MAX_MOT_RPM

#define CONFIG_DEFAULT_EPM_PHASE_CURR 50
#define CONFIG_DEFAULT_EPM_RPM        200
#define CONFIG_DEFAULT_EBRK_TORQUE 0 //0:means disable ebrake
#define CONFIG_DEFAULT_EBRK_IDC_LIM 15
#define CONFIG_SVM_MODULATION       1.0f//(1.0F/SQRT3_BY_2)
#define CONFIG_BRK_SHUT_POWER_ENABLE 1
#define CONFIG_AUTOHOLD_ENABLE 1
#define CONFIG_DEFAULT_FW_ENABLE 1
/* 转把 */
#define CONFIG_THROTTLE_MIN_VALUE 0.4F   /* 转把最小电压，低于这个值，不给启动 */
#define CONFIG_THROTTLE_START_VALUE 1.2f /* 转把启动电压 */
#define CONFIG_THROTTLE_END_VALUE 3.8f /* 转把停止电压 */
#define CONFIG_THROTTLE_MAX_VALUE 4.8F /* 转把最大电压，大于这个值，不给启动 */

#define CONFIG_THROTTLE_MIN_RPM   10   /* 转把对应最小的速度 */
#define CONFIG_THROTTLE_MIN_IDQ   20   /* 转把对应最小的扭矩电流 Q轴 */
#define CONFIG_MIN_CRUISE_RPM 	  1000   /* 能启动定速巡航的最小速度 */

#define CONFIG_MIN_RPM_FOR_EBRAKE 800 //进入电流回收的最小转速
#define CONFIG_MIN_RPM_EXIT_EBRAKE 100 //推出电流回收的最小转速

#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_ZERO_SPEED_RAMP_RMP 100 //从0速启动到结束的速度
/* 电子刹车，动能回收，加速 */
#define CONFIG_eCTRL_STEP_TS CONFIG_SPD_CTRL_MS     /* 斜率给定的step的时间值，单位 ms */
#define CONFIG_eCTRL_Brake_TIME 1500     /* 捏住刹车的时间，超过这个时间启动ebrake，单位 ms */
#define CONFIG_ACC_TIME 50
#define CONFIG_DEC_TIME 50
#define CONFIG_EBRK_RAMP_TIME 500
#define CONFIG_AUTOHOLD_DETECT_TIME 3000

#define CONFIG_CRUISE_RAMP_TIME 5000

#define CONFIG_LIMIT_RAMP_TIME (2 * 1000)

#define CONFIG_MTPA_CALI_RAMP_TIME (10 * 1000)

#define CONFIG_RAMP_SECOND_STEP (0.1F)
#define CONFIG_RAMP_SECOND_TARGET (5.0F)

#define CONFIG_RAMP_CROSS_ZERO_STEP (0.1F)

#define CURRENT_LOOP_RAMP_COUNT 15 //1ms 完成ramp给定

#define CONFIG_TORQUE_MODE_MIN_RPM 600

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

#define CONFIG_MAX_NEG_TORQUE 0.0F
#ifdef CONFIG_SPEED_LADRC
	#define CONFIG_LADRC_Wo  200.0F
	#define CONFIG_LADRC_Wcv 5.0F
	#define CONFIG_LADRC_B0  2500.0F 
#endif
#ifdef CONFIG_SMO_OBSERVER
	#define CONFIG_SMO_MIN_SPEED    1000 //RPM
	//#define CONFIG_SMO_PLL_BANDWITH 2000.0f //计算角度和速度的pll
	#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__ */

