Parcourir la source

编码器角度偏移配置

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui il y a 2 ans
Parent
commit
5f5c362379

+ 1 - 1
Applications/app/app.c

@@ -159,7 +159,7 @@ static u32 _app_report_task(void *p) {
 		//sys_debug("dead time %d\n", get_deadtime());
 		//thro_torque_log();
 		//sys_debug("_>%f, %f, %f\n", ladrc_observer_get()->ld, ladrc_observer_get()->lq, ladrc_observer_get()->poles);
-		//encoder_log();
+		encoder_log();
 		//motor_debug();
 		//sample_log();
 		//PMSM_FOC_LogDebug();

+ 7 - 6
Applications/autogen_config.h

@@ -1,4 +1,4 @@
-/* auto gen 2023/8/30 19:10:01*/
+/* auto gen 2023/9/2 14:57:59*/
 #ifndef _AUTOGEN_CONFIG_H__
 #define _AUTOGEN_CONFIG_H__
 
@@ -16,6 +16,7 @@
 #define CONFIG_Motor_GearRatio  6.25f
 #define CONFIG_Motor_MaxFwDCurr  100
 #define CONFIG_Motor_MaxTorque  200
+#define CONFIG_Motor_EncOffset  0
 #define CONFIG_Foc_MaxDCVol  110
 #define CONFIG_Foc_MinDCVol  70
 #define CONFIG_Foc_MaxPhaseCurr  300
@@ -24,7 +25,7 @@
 #define CONFIG_Foc_MaxEPMTorque  100
 #define CONFIG_Foc_MaxEPMRPMBk  170
 #define CONFIG_Foc_MaxEPMTorqueBk  80
-#define CONFIG_Foc_MaxTorque  300
+#define CONFIG_Foc_MaxTorque  200
 #define CONFIG_Foc_MaxEbrkTorque  40
 #define CONFIG_Foc_MaxIDC  100
 #define CONFIG_Foc_MaxAutoHoldTorque  100
@@ -202,12 +203,12 @@
 #define CONFIG_EnergyRecovery_Level4_Time 200
 #define CONFIG_EnergyRecovery_Level5_Torque 40
 #define CONFIG_EnergyRecovery_Level5_Time 200
-#define CONFIG_EnergyRecovery_Level6_Torque 45
+#define CONFIG_EnergyRecovery_Level6_Torque 40
 #define CONFIG_EnergyRecovery_Level6_Time 200
-#define CONFIG_EnergyRecovery_Level7_Torque 50
+#define CONFIG_EnergyRecovery_Level7_Torque 40
 #define CONFIG_EnergyRecovery_Level7_Time 200
-#define CONFIG_EnergyRecovery_Level8_Torque 55
+#define CONFIG_EnergyRecovery_Level8_Torque 40
 #define CONFIG_EnergyRecovery_Level8_Time 200
-#define CONFIG_EnergyRecovery_Level9_Torque 60
+#define CONFIG_EnergyRecovery_Level9_Torque 40
 #define CONFIG_EnergyRecovery_Level9_Time 200
 #endif /* _AUTOGEN_CONFIG_H__ */ 

+ 4 - 1
Applications/foc/mc_config.c

@@ -187,6 +187,7 @@ void mc_conf_default(void) {
 	conf.m.gear_ratio = CONFIG_Motor_GearRatio;
 	conf.m.max_fw_id = CONFIG_Motor_MaxFwDCurr;
 	conf.m.max_torque = CONFIG_Motor_MaxTorque;
+	conf.m.encoder_offset = CONFIG_Motor_EncOffset;
 	conf.c.max_dc_vol = CONFIG_Foc_MaxDCVol;
 	conf.c.min_dc_vol = CONFIG_Foc_MinDCVol;
 	conf.c.max_phase_curr = CONFIG_Foc_MaxPhaseCurr;
@@ -277,7 +278,7 @@ void mc_conf_init(void) {
 		mc_conf_default();
 		mc_conf_save();
 	}
-	sys_debug("mc conf band %d, pid: %f, %f, %f, %f\n", conf.c.dq_loop_bandwith, conf.c.pid[PID_ID_ID].kp, conf.c.pid[PID_ID_ID].ki, conf.c.pid[PID_IQ_ID].kp, conf.c.pid[PID_IQ_ID].ki);
+	sys_debug("mc conf band %d, pid: %f, %f, %f, %f, %d\n", conf.c.dq_loop_bandwith, conf.c.pid[PID_ID_ID].kp, conf.c.pid[PID_ID_ID].ki, conf.c.pid[PID_IQ_ID].kp, conf.c.pid[PID_IQ_ID].ki, mc_conf()->m.encoder_offset);
 }
 
 int mc_conf_decode_motor(u8 *buff) {
@@ -295,6 +296,7 @@ int mc_conf_decode_motor(u8 *buff) {
 	conf.m.gear_ratio = decode_float(buff);buff += 4;
 	conf.m.max_fw_id = decode_u16(buff); buff += 2;
 	conf.m.max_torque = decode_u16(buff); buff += 2;
+	conf.m.encoder_offset = decode_s16(buff); buff += 2;
 	return buff - ori;
 }
 
@@ -313,6 +315,7 @@ int mc_conf_encode_motor(u8 *buff) {
 	encode_float(buff, conf.m.gear_ratio);buff += 4;
 	encode_u16(buff, conf.m.max_fw_id); buff += 2;
 	encode_u16(buff, conf.m.max_torque); buff += 2;
+	encode_s16(buff, conf.m.encoder_offset); buff += 2;
 	return buff - ori;
 }
 

+ 1 - 0
Applications/foc/mc_config.h

@@ -34,6 +34,7 @@ typedef struct
 	float gear_ratio;
 	u16	max_fw_id;
 	u16 max_torque;
+	s16 encoder_offset;
 }motor_t;
 
 typedef struct {

+ 1 - 1
Applications/foc/motor/encoder.c

@@ -65,7 +65,7 @@ void encoder_set_bandwidth(float bandwidth) {
 
 void encoder_init_clear(void) {
 	g_encoder.cpr = ENC_MAX_RES;
-	g_encoder.enc_offset = 0;//-103.0F;
+	g_encoder.enc_offset = mc_conf()->m.encoder_offset;
 	g_encoder.motor_poles = mc_conf()->m.poles;
 	g_encoder.b_index_found = false;
 	g_encoder.direction = POSITIVE;

+ 1 - 0
mc_config.yml

@@ -15,6 +15,7 @@ Motor:
   GearRatio: 6.25 # 1:6.25
   MaxFwDCurr: 100
   MaxTorque: 200 #根据控制方式不同,可能是相电流,可能是真实扭矩
+  EncOffset: 0
 Foc:
   MaxDCVol: 110
   MinDCVol: 70