Просмотр исходного кода

变量初始化

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 2 лет назад
Родитель
Сommit
a60ce6bd6e

+ 7 - 1
Applications/foc/core/controller.c

@@ -19,7 +19,8 @@ void mot_contrl_init(mot_contrl_t *ctrl) {
 	ctrl->foc.half_period = FOC_PWM_Half_Period;
 	ctrl->force_angle = INVALID_ANGLE;
 	ctrl->adv_angle = INVALID_ANGLE;
-	foc_init(&ctrl->foc);
+	ctrl->foc.d_ramp_time = CURRENT_LOOP_RAMP_COUNT;
+	ctrl->foc.q_ramp_time = CURRENT_LOOP_RAMP_COUNT;
 	ctrl->hwlim.dc_curr = CONFIG_HW_MAX_DC_CURRENT;
 	ctrl->hwlim.mot_vel = CONFIG_HW_MAX_MOTOR_RPM;
 	ctrl->hwlim.phase_curr = CONFIG_HW_MAX_PHASE_CURR;
@@ -29,6 +30,9 @@ void mot_contrl_init(mot_contrl_t *ctrl) {
 	ctrl->hwlim.fw_id = mc_conf()->m.max_fw_id;  //电池能支持的最大弱磁电流
 	ctrl->protlim.dc_curr = HW_LIMIT_NONE;
 	ctrl->protlim.torque = HW_LIMIT_NONE;
+	ctrl->torque_acc_time = 500;
+	ctrl->torque_dec_time = 500;//will be set after start
+	foc_init(&ctrl->foc);
 }
 bool mot_contrl_enable(mot_contrl_t *ctrl, bool start) {
 	if (ctrl->b_start == start) {
@@ -58,6 +62,8 @@ bool mot_contrl_enable(mot_contrl_t *ctrl, bool start) {
 	ctrl->dc_curr_filted = 0;
 	ctrl->phase_curr_filted[0] = ctrl->phase_curr_filted[1] = 0;
 	ctrl->out_idq_filterd.d = ctrl->out_idq_filterd.q = 0;
+	ctrl->autohold_torque = 0;
+	ctrl->out_current_vec = 0;
 	foc_init(&ctrl->foc);
 	foc_observer_init();
 	ctrl->b_start = start;

+ 4 - 20
Applications/foc/core/foc.c

@@ -9,26 +9,6 @@
 #include "foc/foc_config.h"
 #include "foc/motor/current.h"
 
-static __INLINE void rev_park(foc_t *foc, dq_t *dq, albt_t *alpha_beta) {
-	float c,s;
-
-	s = foc->sin;
-	c = foc->cos;
-
-	alpha_beta->a = dq->d * c - dq->q * s;
-	alpha_beta->b = dq->d * s + dq->q * c;
-}
-
-
-static __INLINE void park(foc_t *foc, albt_t *alpha_beta, dq_t *dq) {
-	float c,s;
-
-	s = foc->sin;
-	c = foc->cos;
-
-	dq->d = alpha_beta->a * c + alpha_beta->b * s;
-	dq->q = -alpha_beta->a * s + alpha_beta->b * c;
-}
 
 void foc_init(foc_t *foc) {
 	PI_Controller_Reset(&foc->daxis, 0);
@@ -42,6 +22,10 @@ void foc_init(foc_t *foc) {
 	foc->qaxis.ki = mc_conf()->c.pid[PID_IQ_ID].ki;
 	foc->qaxis.kd = mc_conf()->c.pid[PID_IQ_ID].kd;
 	foc->qaxis.DT = foc->ts;
+	foc->ramp_curr_dq.d = 0;
+	foc->ramp_curr_dq.q = 0;
+	foc->mot_velocity_filterd = 0;
+	foc->mot_vel_radusPers = 0;
 	memset(&foc->in, 0, sizeof(foc_in_t));
 	memset(&foc->out, 0, sizeof(foc_out_t));
 }

+ 21 - 2
Applications/foc/core/foc.h

@@ -42,8 +42,6 @@ typedef struct {
 	foc_in_t in;
 	foc_out_t out;
 	dq_t    ramp_curr_dq;
-	float 	curr_abc_filter[3];
-	float   curr_abc_dt[3]; //abc phase current for deadtime compesition
 	float   mot_velocity_filterd; //电机滤波后的转速
 	float   mot_vel_radusPers; //电机的电角速度
 	float   d_ramp_time;
@@ -71,5 +69,26 @@ static __INLINE void rev_clark(albt_t *alpha_beta, float *ABC){
 	ABC[2] = -alpha_beta->a * 0.5f - alpha_beta->b * SQRT3_BY_2;
 }
 
+static __INLINE void rev_park(foc_t *foc, dq_t *dq, albt_t *alpha_beta) {
+	float c,s;
+
+	s = foc->sin;
+	c = foc->cos;
+
+	alpha_beta->a = dq->d * c - dq->q * s;
+	alpha_beta->b = dq->d * s + dq->q * c;
+}
+
+
+static __INLINE void park(foc_t *foc, albt_t *alpha_beta, dq_t *dq) {
+	float c,s;
+
+	s = foc->sin;
+	c = foc->cos;
+
+	dq->d = alpha_beta->a * c + alpha_beta->b * s;
+	dq->q = -alpha_beta->a * s + alpha_beta->b * c;
+}
+
 #endif /* _FOC_H__ */
 

+ 4 - 1
Applications/foc/foc_config.h

@@ -41,7 +41,7 @@
 #define CONFIG_RAMP_SECOND_TARGET (5.0F * 1.5F)
 
 /* dq轴电流环指令斜波 */
-#define CURRENT_LOOP_RAMP_COUNT 15 //15个控制周期 完成ramp给定
+#define CURRENT_LOOP_RAMP_COUNT 15.0f //15个控制周期 完成ramp给定
 
 #define CONFIG_CRUISE_ENABLE_ACCL 1 //定速巡航可以加速,油门回退,继续定速巡航
 
@@ -57,6 +57,9 @@
 #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_ENABLE_IAB_REC 1   // for phase current debug
 
 #ifdef CONFIG_SPEED_LADRC