Forráskód Böngészése

鲨湾控制器+中动编码器电机需要编码器反向

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 3 éve
szülő
commit
c3a30f7e38
2 módosított fájl, 17 hozzáadás és 6 törlés
  1. 6 4
      Applications/bsp/board_mc100_v1.h
  2. 11 2
      Applications/foc/motor/encoder.c

+ 6 - 4
Applications/bsp/board_mc100_v1.h

@@ -112,7 +112,7 @@
 #define ADC_TO_CURR_ceof1  (0.32f)
 #define ADC_TO_CURR_ceof2  (0.32f)
 
-//#define CONFIG_PWM_UV_SWAP 1
+#define CONFIG_PWM_UV_SWAP 1
 
 //#define CONFIG_HW_MUTISAMPLE ADC_OVERSAMPLING_RATIO_MUL2
 //#define CONFIG_HW_MUTISAMPLE_SHIFT ADC_OVERSAMPLING_SHIFT_1B
@@ -304,7 +304,9 @@
 #define ENC_MAX_interpolation 4.0F
 
 #define ENC_FILTER_NR          15
-
+#ifdef CONFIG_PWM_UV_SWAP
+#define ENCODER_CC_INVERT 1
+#endif
 /* 编码器参数      */
 #define ENC_MAX_RES  4096.0f
 #define ENC_Duty_2_Pluse_Nr(duty) (duty * ENC_MAX_RES) //通过占空比计算有几个脉冲
@@ -330,9 +332,9 @@
 #define DEBUG_PORT_UART2
 
 //#define MOTOR_BLUESHARK_NEW1  //蓝鲨大功率电机,双E形
-#define MOTOR_BLUESHARK_NEW2  //蓝鲨大功率电机,V形
+//#define MOTOR_BLUESHARK_NEW2  //蓝鲨大功率电机,V形
 //#define MOTOR_BLUESHARK_OLD   //目前量产的电机
-//#define MOTOR_BLUESHARK_ZD_100  //中动100码编码器电机样品
+#define MOTOR_BLUESHARK_ZD_100  //中动100码编码器电机样品
 //#define CONFIG_DQ_STEP_RESPONSE
 
 #endif /*_BOARD_MC_V1_H__ */

+ 11 - 2
Applications/foc/motor/encoder.c

@@ -280,17 +280,22 @@ float encoder_get_position(void) {
 float encoder_zero_phase_detect(void) {
 	float phase = g_encoder.pwm_angle;
 	float total_ph = phase;
+	float prev_offset = g_encoder.enc_offset;
+	g_encoder.enc_offset = 0;
 	int count = 0;
 	for(; count < 10; count++) {
 		delay_ms(ENC_PWM_Min_P * 1000 + 2); //wait time for pwm
 		if ABS(phase - g_encoder.pwm_angle > 2.0f) {
+			g_encoder.enc_offset = prev_offset;
 			return INVALID_ANGLE;
 		}
 		phase = g_encoder.pwm_angle;
 		total_ph += phase;
 	}
-	sys_debug("offset = %f\n", (total_ph/(float)count));
-	return (total_ph/(float)count);
+	float offset_now = total_ph/(float)count;
+	g_encoder.enc_offset = offset_now;
+	sys_debug("offset = %f\n", offset_now);
+	return offset_now;
 }
 
 
@@ -357,6 +362,10 @@ bool ENC_Check_error(void) {
 }
 
 float encoder_get_pwm_angle(void) {
+#ifdef ENCODER_CC_INVERT
+	g_encoder.pwm_angle = 360.0f - (g_encoder.pwm_angle - g_encoder.enc_offset) + g_encoder.enc_offset;
+	rand_angle(g_encoder.pwm_angle);
+#endif
 	return g_encoder.pwm_angle;
 }