Browse Source

解决tcs设置问题

Signed-off-by: kevin <huhui@sharkgulf.com>
kevin 2 years ago
parent
commit
bacf5ccd16

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

@@ -32,6 +32,7 @@ void mot_contrl_init(mot_contrl_t *ctrl) {
 	ctrl->torque_acc_time = 500; //will be set after start
 	ctrl->torque_dec_time = 500; //will be set after start
 	ctrl->ebrk_ramp_time = 500;  //will be set after start
+	etcs_init(&ctrl->etcs);
 	foc_init(&ctrl->foc);
 }
 bool mot_contrl_enable(mot_contrl_t *ctrl, bool start) {
@@ -52,7 +53,6 @@ bool mot_contrl_enable(mot_contrl_t *ctrl, bool start) {
 		mot_contrl_pid(ctrl);
 		mot_contrl_ulimit(ctrl);
 		mot_contrl_rtlimit(ctrl);
-		etcs_init(&ctrl->etcs);
 	}
 	ctrl->b_ebrk_running = false;
 	ctrl->b_AutoHold = false;

+ 12 - 3
Applications/foc/motor/motor.c

@@ -47,7 +47,7 @@ motor_t motor = {
 	.u_set.rpm_lim = RPM_USER_LIMIT_NONE,
 	.u_set.ebrk_lvl = 0,
 	.u_set.n_brkShutPower = CONFIG_Settings_BrkShutPower,
-	.u_set.b_tcs = CONFIG_Settings_TcsEnable,
+	.u_set.b_tcs = 0xFF,
 };
 /* 无感运行的挡位,限制速度,母线电流,最大扭矩 */
 static gear_t sensorless_gear = {
@@ -354,7 +354,7 @@ bool mc_start(u8 mode) {
 #endif
 	motor.s_force_torque = MAX_S16;
 	mc_detect_vbus_mode();
-	etcs_enable(&motor.controller.etcs, motor.u_set.b_tcs);
+	etcs_enable(&motor.controller.etcs, mc_tcs_is_enabled());
 	if (motor.b_lock_motor) {
 		mot_contrl_set_error(&motor.controller, FOC_NotAllowed);
 		return false;
@@ -519,6 +519,15 @@ u8 mc_get_internal_gear(void) {
 	return motor.n_gear;
 }
 
+bool mc_tcs_is_enabled(void) {
+	bool tcs_enabled = mc_conf()->s.tcs_enable;
+	if (motor.u_set.b_tcs == 0) {
+		tcs_enabled = false;
+	}else if (motor.u_set.b_tcs == 1) {
+		tcs_enabled = true;
+	}
+	return tcs_enabled;
+}
 
 bool mc_hwbrk_can_shutpower(void) {
 	if (motor.u_set.n_brkShutPower != MAX_U8) {
@@ -610,7 +619,7 @@ void mc_enable_brkshutpower(u8 shut) {
 }
 
 void mc_enable_tcs(bool enable) {
-	motor.u_set.b_tcs = enable;
+	motor.u_set.b_tcs = enable?1:0;
 	etcs_enable(&motor.controller.etcs, enable);
 }
 

+ 2 - 1
Applications/foc/motor/motor.h

@@ -27,7 +27,7 @@ typedef struct {
 	s16 rpm_lim;
 	u8  ebrk_lvl;
 	u8  n_brkShutPower;
-	bool  b_tcs;
+	u8  b_tcs;
 }user_rt_set;
 
 typedef struct {
@@ -131,6 +131,7 @@ void mc_enable_tcs(bool enable);
 bool mc_set_target_vel(s16 vel);
 float mc_gear_max_torque(s16 vel, u8 gear);
 bool mc_set_force_torque(s16 torque);
+bool mc_tcs_is_enabled(void);
 
 static __INLINE mot_contrl_t *mot_contrl(void) {
 	return &motor.controller;