Browse Source

1. 堵转功能
2. 完善配置命令

Signed-off-by: huhui <huhui@sharkgulf.com>

huhui 3 years ago
parent
commit
e85be2d30c

+ 2 - 1
Applications/app/app.c

@@ -97,7 +97,8 @@ static u32 _app_report_task(void *p) {
 	can_report_mpta_values(0x45);
 	if (++loop % 10 == 0) {
 		can_report_pid_value(0x45, PID_TRQ_id);
-		sys_debug("max exec time %d, %d\n", g_meas_foc.exec_max_error_time, g_meas_foc.exec_time);
+		//sys_debug("max exec time %d, %d\n", g_meas_foc.exec_max_error_time, g_meas_foc.exec_time);
+		sys_debug("run stall %d\n", mc_params()->b_runStall);
 		encoder_log();
 		err_code_log();
 	}

+ 2 - 0
Applications/app/nv_storage.c

@@ -54,6 +54,8 @@ static void nv_default_foc_params(void) {
 	foc_params.n_brkShutPower = CONFIG_BRK_SHUT_POWER_ENABLE;
 	foc_params.s_LimitiDC = CONFIG_DEFAULT_IDC_LIM;
 	foc_params.s_iDCeBrkLim = CONFIG_DEFAULT_EBRK_IDC_LIM;
+	foc_params.n_minThroVol = CONFIG_THROTTLE_LOW_VALUE;
+	foc_params.n_maxThroVol = CONFIG_THROTTLE_MAX_VALUE;
 	
 	foc_params.pid_conf[PID_D_id].kp = (CONFIG_CURRENT_BANDWITH * MOTOR_Ld);
 	foc_params.pid_conf[PID_D_id].ki = (MOTOR_R/MOTOR_Ld);

+ 2 - 5
Applications/bsp/board_mc_v1.h

@@ -95,8 +95,6 @@
 #define V_PHASE_I_CHAN  ADC_CHANNEL_5
 #define W_PHASE_I_CHAN  ADC_CHANNEL_6
 
-//#define CONFIG_PWM_UV_SWAP
-
 #define V_PHASE_ADC_GROUP 	GPIOA
 #define V_PHASE_ADC_PIN 	GPIO_PIN_5
 #define V_PHASE_ADC_RCU 	RCU_GPIOA
@@ -180,7 +178,6 @@
 
 /* 是否用编码器 */
 #define USE_ENCODER_ABI
-//#define ENCODER_CC_INVERT //编码器方向和电机反向
 
 /* 编码器 */
 #define ENC_A_GROUP GPIOB
@@ -238,9 +235,9 @@
 
 #define DEBUG_PORT_UART2
 
-#define MOTOR_BLUESHARK_NEW1  //蓝鲨大功率电机,双E形
+//#define MOTOR_BLUESHARK_NEW1  //蓝鲨大功率电机,双E形
 //#define MOTOR_BLUESHARK_NEW2  //蓝鲨大功率电机,V形
-//#define MOTOR_BLUESHARK_OLD   //目前量产的电机
+#define MOTOR_BLUESHARK_OLD   //目前量产的电机
 
 //#define CONFIG_DQ_STEP_RESPONSE
 

+ 14 - 0
Applications/foc/commands.c

@@ -113,6 +113,7 @@ static void process_foc_command(foc_cmd_body_t *command) {
 				PMSM_FOC_SpeedLimit((float)maxRPM);
 				PMSM_FOC_PhaseCurrLim((float)maxPhaseCurr);
 				PMSM_FOC_DCCurrLimit((float)maxiDC);
+				mc_need_update();//重新获取转把相电流和速度
 				encode_u16(response + 3, (u16)PMSM_FOC_GetSpeedLimit());
 				encode_u16(response + 5, (u16)PMSM_FOC_GetPhaseCurrLim());
 				encode_u8(response + 7, (u8)PMSM_FOC_GetDCCurrLimit());
@@ -220,6 +221,19 @@ static void process_foc_command(foc_cmd_body_t *command) {
 				PMSM_FOC_Set_PlotType((Plot_t)plot);
 			}
 			break;
+		}
+		case Foc_Set_Throttle_throld:
+		{
+			u16 min = decode_u16((u8 *)command->data);
+			u16 max = decode_u16((u8 *)command->data + 2);
+			nv_get_foc_params()->n_minThroVol = (float)min/100.0f;
+			nv_get_foc_params()->n_maxThroVol = (float)max/100.0f;
+			nv_save_foc_params();
+			break;
+		}
+		case Foc_Set_eBrake_Throld:
+		{
+			
 		}
 		default:
 		{

+ 2 - 0
Applications/foc/commands.h

@@ -22,6 +22,8 @@ typedef enum {
 	Foc_Start_DQ_Calibrate,
 	Foc_Set_IS_Curr_Angle,  //设置DQ电流矢量和超前角
 	Foc_Set_Plot_Type,
+	Foc_Set_Throttle_throld,
+	Foc_Set_eBrake_Throld,
 	Foc_Hall_Phase_Cali_Result = 160,
 	Foc_Hall_Offset_Cali_Result,
 	Foc_Report_Speed,

+ 2 - 2
Applications/foc/core/PMSM_FOC_Core.c

@@ -230,7 +230,7 @@ void PMSM_FOC_CoreInit(void) {
 }
 
 //#define PHASE_LFP_FIR
-#define PHASE_LFP
+//#define PHASE_LFP
 static __INLINE void PMSM_FOC_Update_Hardware(void) {
 	AB_t vAB;
 #ifdef PHASE_LFP	
@@ -376,7 +376,7 @@ void PMSM_FOC_Schedule(void) {
 	if (gFoc_Ctrl.plot_type != Plot_None) {
 		if (gFoc_Ctrl.ctrl_count % 5 == 0) {
 			if (gFoc_Ctrl.plot_type == Plot_Phase_curr) {
-				plot_3data16(FtoS16(gFoc_Ctrl.in.s_iABCComp[0]), FtoS16(gFoc_Ctrl.in.s_iABCComp[1]), FtoS16(gFoc_Ctrl.in.s_iABCComp[2]));
+				plot_3data16(FtoS16(gFoc_Ctrl.in.s_iABC[0]), FtoS16(gFoc_Ctrl.in.s_iABC[1]), FtoS16(gFoc_Ctrl.in.s_iABC[2]));
 			}else if (gFoc_Ctrl.plot_type == Plot_Phase_vol) {
 				plot_3data16(FtoS16x10(gFoc_Ctrl.in.s_vABC[0]), FtoS16x10(gFoc_Ctrl.in.s_vABC[1]), FtoS16x10(gFoc_Ctrl.in.s_vABC[2]));
 			}

+ 6 - 6
Applications/foc/core/torque.c

@@ -46,23 +46,23 @@ void torque_get_idq(float torque, float rpm, DQ_t *dq_out) {
 
 float speed_target_from_throttle(float f_throttle) {
 
-	if (f_throttle <= (CONFIG_THROTTLE_LOW_VALUE)) {
+	if (f_throttle <= nv_get_foc_params()->n_minThroVol) {
 		return 0;
 	}
-	float delta = f_throttle - (CONFIG_THROTTLE_LOW_VALUE);
+	float delta = f_throttle - (nv_get_foc_params()->n_minThroVol);
 
-	float ration = delta / (CONFIG_THROTTLE_MAX_VALUE - CONFIG_THROTTLE_LOW_VALUE);
+	float ration = delta / (nv_get_foc_params()->n_maxThroVol - nv_get_foc_params()->n_minThroVol);
 
 	return (PMSM_FOC_GetSpeedLimit() * ration);
 }
 
 float torque_target_from_throttle(float f_throttle) {
-	if (f_throttle <= (CONFIG_THROTTLE_LOW_VALUE)) {
+	if (f_throttle <= (nv_get_foc_params()->n_minThroVol)) {
 		return 0;
 	}
-	float delta = f_throttle - (CONFIG_THROTTLE_LOW_VALUE);
+	float delta = f_throttle - (nv_get_foc_params()->n_minThroVol);
 
-	float ration = delta / (CONFIG_THROTTLE_MAX_VALUE - CONFIG_THROTTLE_LOW_VALUE);
+	float ration = delta / (nv_get_foc_params()->n_maxThroVol - nv_get_foc_params()->n_minThroVol);
 
 	return (PMSM_FOC_GetTorqueLimit() * ration);
 }

+ 2 - 2
Applications/foc/foc_config.h

@@ -2,8 +2,8 @@
 #define _FOC_CONFIG_H__
 
 #define CONFIG_DEFAULT_IDC_LIM 200
-#define CONFIG_DEFAULT_PHASE_CURR_LIM 400
-#define CONFIG_DEFAULT_RPM_LIM       8000
+#define CONFIG_DEFAULT_PHASE_CURR_LIM 200
+#define CONFIG_DEFAULT_RPM_LIM       6000
 
 #define CONFIG_DEFAULT_EPM_PHASE_CURR 50
 #define CONFIG_DEFAULT_EPM_RPM        200

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

@@ -91,6 +91,10 @@ motor_t * mc_params(void) {
 	return &motor;
 }
 
+void mc_need_update(void) {
+	motor.b_updated = true;
+}
+
 bool mc_start(u8 mode) {
 	if (motor.b_start) {
 		return true;
@@ -290,14 +294,14 @@ void mc_get_running_status(u8 *data) {
 	data[0] = motor.mode;
 	data[0] |= PMSM_FOC_Get()->out.n_RunMode << 2;
 	data[0] |= (PMSM_FOC_Get()->in.b_cruiseEna?1:0) << 4;
-	data[0] |= (PMSM_FOC_Is_CruiseEnabled()?1:0) << 5;
+	data[0] |= (motor.b_start?1:0) << 5;
 	data[0] |= (mc_is_epm()?1:0) << 6;
 	data[0] |= (0) << 7; //motor locked
 }
 
 
 void mc_encoder_off_calibrate(s16 vd) {
-	if (PMSM_FOC_Is_Start()) {
+	if (motor.b_start) {
 		return;
 	}
 	motor.b_calibrate = true;
@@ -412,7 +416,7 @@ bool mc_lock_motor(bool lock) {
 
 
 bool mc_throttle_released(void) {
-	return get_throttle_float() < CONFIG_THROTTLE_LOW_VALUE;
+	return get_throttle_float() <= nv_get_foc_params()->n_minThroVol;
 }
 
 static bool mc_is_hwbrake(void) {
@@ -473,7 +477,7 @@ void MC_Protect_IRQHandler(void){
 }
 
 void TIMER_UP_IRQHandler(void){
-	if (!motor.b_start || !PMSM_FOC_Is_Start()) {
+	if (!motor.b_start && !PMSM_FOC_Is_Start()) {
 		motor_encoder_update();
 	}
 }
@@ -549,14 +553,12 @@ void Sched_MC_mTask(void) {
 		return;
 	}
 	/* 堵转处理 */
-	if (mc_run_stall_process(runMode)) {
-		return;
-	}
-	if (runMode == CTRL_MODE_CURRENT) {
+	if (mc_run_stall_process(runMode) || (runMode == CTRL_MODE_CURRENT)) {
 		eCtrl_Running();
 		PMSM_FOC_Slow_Task();
 		return;
 	}
+
 	if ((runMode != CTRL_MODE_OPEN) || (motor.mode != CTRL_MODE_OPEN)) {
 #ifndef CONFIG_DQ_STEP_RESPONSE
 		if (motor.mode != CTRL_MODE_OPEN) {
@@ -580,8 +582,9 @@ void Sched_MC_mTask(void) {
 		if (runMode != CTRL_MODE_OPEN) {
 			eCtrl_Running();
 			float f_throttle = get_throttle_float();
-			if (f_throttle != motor.throttle) {
+			if ((f_throttle != motor.throttle) || motor.b_updated) {
 				motor.throttle = f_throttle;
+				motor.b_updated = false;
 				if (!motor.b_epm_cmd_move) {//通过命令前进后退,不处理转把
 					torque_speed_target(runMode, f_throttle);
 				}

+ 3 - 0
Applications/foc/motor/motor.h

@@ -22,8 +22,10 @@ typedef struct {
 	s8     s_direction;
 	u32    n_brake_errors;
 	u8     mode;
+	bool   b_updated;
 }motor_t;
 
+motor_t * mc_params(void);
 void mc_init(void);
 bool mc_start(u8 mode);
 bool mc_stop(void);
@@ -41,6 +43,7 @@ bool mc_start_epm_move(EPM_Dir_t dir, bool is_command);
 void mc_get_running_status(u8 *data);
 bool mc_command_epm_move(EPM_Dir_t dir);
 bool mc_throttle_epm_move(EPM_Dir_t dir);
+void mc_need_update(void);
 
 static __INLINE float motor_encoder_get_angle(void) {
 #ifdef USE_ENCODER_HALL

+ 2 - 0
Applications/foc/samples.c

@@ -137,10 +137,12 @@ void sample_uvw_phase(void) {
 }
 
 void sample_motor_temp(void) {
+#ifndef MOTOR_BLUESHARK_OLD
 	u16 adc = adc_get_motor_temp();
 	u16 r = MOTOR_TEMP_R(adc);
 	motor_temp.value = ntc_get_motor_temp(r);
 	LowPass_Filter(motor_temp.filted_value, motor_temp.value, motor_temp.lowpass);
+#endif
 }
 
 void sample_mos_temp(void) {