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

controller的所有ramp的变量都加上ramp_前缀

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

+ 3 - 3
Applications/app/app.c

@@ -63,7 +63,7 @@ static void app_print_log(void) {
 	//motor_debug();
 	//sample_log();
 	//throttle_log();
-	sys_debug("Trq: %f-%f-%f\n", motor.controller.input_torque.target, motor.controller.input_torque.interpolation, motor.controller.input_torque.step);
+	sys_debug("Trq: %f-%f-%f\n", motor.controller.ramp_input_torque.target, motor.controller.ramp_input_torque.interpolation, motor.controller.ramp_input_torque.step);
 	sys_debug("acc vol: %d\n", get_acc_vol());
 	//F_debug();
 	//eCtrl_debug_log();
@@ -123,9 +123,9 @@ static u32 app_plot_task(void * args) {
 		s16 plot_arg2 = (s16)mot_contrl_get_speed(&motor.controller);
 		if (mot_contrl()->mode_running == CTRL_MODE_SPD) {
 			if (mc_is_cruise_enabled()) {
-				plot_arg1 = mot_contrl()->cruise_vel.target;
+				plot_arg1 = mot_contrl()->ramp_cruise_vel.target;
 			}else {
-				plot_arg1 = mot_contrl()->target_vel.target;
+				plot_arg1 = mot_contrl()->ramp_target_vel.target;
 			}
 		}else {
 			can_plot2(plot_arg1, plot_arg2);

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

@@ -39,15 +39,15 @@ bool mot_contrl_enable(mot_contrl_t *ctrl, bool start) {
 		return true;
 	}
 	if (start) {
-		line_ramp_init(&ctrl->torque_lim, CONFIG_LIMIT_RAMP_TIME);
-		line_ramp_init(&ctrl->dc_curr_lim, CONFIG_LIMIT_RAMP_TIME);
-		line_ramp_init(&ctrl->vel_lim, CONFIG_LIMIT_RAMP_TIME);
-		line_ramp_init(&ctrl->cruise_vel, CONFIG_CRUISE_RAMP_TIME);
-		line_ramp_init(&ctrl->target_vd, CONFIG_FOC_VDQ_RAMP_FINAL_TIME);
-		line_ramp_init(&ctrl->target_vq, CONFIG_FOC_VDQ_RAMP_FINAL_TIME);
-		line_ramp_init(&ctrl->target_vel, CONFIG_CRUISE_RAMP_TIME);
-		line_ramp_init(&ctrl->target_current, CONFIG_CURRENT_RAMP_TIME);
-		line_ramp_init(&ctrl->input_torque, CONFIG_DEFAULT_TORQUE_RAMP_TIME);
+		line_ramp_init(&ctrl->ramp_torque_lim, CONFIG_LIMIT_RAMP_TIME);
+		line_ramp_init(&ctrl->ramp_dc_curr_lim, CONFIG_LIMIT_RAMP_TIME);
+		line_ramp_init(&ctrl->ramp_vel_lim, CONFIG_LIMIT_RAMP_TIME);
+		line_ramp_init(&ctrl->ramp_cruise_vel, CONFIG_CRUISE_RAMP_TIME);
+		line_ramp_init(&ctrl->ramp_target_vd, CONFIG_FOC_VDQ_RAMP_FINAL_TIME);
+		line_ramp_init(&ctrl->ramp_target_vq, CONFIG_FOC_VDQ_RAMP_FINAL_TIME);
+		line_ramp_init(&ctrl->ramp_target_vel, CONFIG_CRUISE_RAMP_TIME);
+		line_ramp_init(&ctrl->ramp_target_current, CONFIG_CURRENT_RAMP_TIME);
+		line_ramp_init(&ctrl->ramp_input_torque, CONFIG_DEFAULT_TORQUE_RAMP_TIME);
 		line_ramp_init(&ctrl->ramp_adv_angle, CONFIG_CURRENT_RAMP_TIME);
 		mot_contrl_pid(ctrl);
 		mot_contrl_ulimit(ctrl);
@@ -113,29 +113,29 @@ u8 mot_contrl_mode(mot_contrl_t *ctrl) {
 	}
 	if (preMode != ctrl->mode_running) {
 		if ((preMode != ctrl->mode_running) && (ctrl->mode_running == CTRL_MODE_TRQ)) {
-			line_ramp_set_acctime(&ctrl->input_torque, ctrl->torque_acc_time);
-			line_ramp_set_dectime(&ctrl->input_torque, ctrl->torque_dec_time);
-			line_ramp_update(&ctrl->input_torque);
+			line_ramp_set_acctime(&ctrl->ramp_input_torque, ctrl->torque_acc_time);
+			line_ramp_set_dectime(&ctrl->ramp_input_torque, ctrl->torque_dec_time);
+			line_ramp_update(&ctrl->ramp_input_torque);
 			if (preMode == CTRL_MODE_SPD) {
 				ctrl->target_torque_raw = ctrl->target_torque;
 				PI_Controller_Reset(&ctrl->pi_vel_lim, ctrl->target_torque_raw);
 			}else if (preMode == CTRL_MODE_CURRENT) {
-				ctrl->target_torque_raw = line_ramp_get_interp(&ctrl->target_current);
+				ctrl->target_torque_raw = line_ramp_get_interp(&ctrl->ramp_target_current);
 				PI_Controller_Reset(&ctrl->pi_vel_lim, ctrl->target_torque_raw);
 			}
 		}else if ((preMode == CTRL_MODE_TRQ) && (ctrl->mode_running == CTRL_MODE_SPD)) {
 			PI_Controller_Reset(&ctrl->pi_vel, ctrl->target_torque);
 		}else if ((preMode != ctrl->mode_running) && (ctrl->mode_running == CTRL_MODE_EBRAKE)) {
-			line_ramp_reset(&ctrl->input_torque, ctrl->target_torque);
-			line_ramp_set_time(&ctrl->input_torque, ctrl->ebrk_ramp_time);
-			line_ramp_set_target(&ctrl->input_torque, motor_get_ebreak_toruqe(ctrl->foc.in.mot_velocity));
+			line_ramp_reset(&ctrl->ramp_input_torque, ctrl->target_torque);
+			line_ramp_set_time(&ctrl->ramp_input_torque, ctrl->ebrk_ramp_time);
+			line_ramp_set_target(&ctrl->ramp_input_torque, motor_get_ebreak_toruqe(ctrl->foc.in.mot_velocity));
 		}else if ((preMode == CTRL_MODE_EBRAKE) && (ctrl->mode_running == CTRL_MODE_SPD)) {
 			PI_Controller_Reset(&ctrl->pi_vel, F_get_air());
 		}
 	}
 	if (ctrl->mode_running == CTRL_MODE_OPEN) {
-		line_ramp_step(&ctrl->target_vd);
-		line_ramp_step(&ctrl->target_vq);
+		line_ramp_step(&ctrl->ramp_target_vd);
+		line_ramp_step(&ctrl->ramp_target_vq);
 	}
 	return ctrl->mode_running;
 }
@@ -244,8 +244,8 @@ bool mot_contrl_update(mot_contrl_t *ctrl) {
 	foc->in.b_openloop = ctrl->mode_running == CTRL_MODE_OPEN;
 	phase_curr_unbal_check(ctrl);
 	if (foc->in.b_openloop) {
-		foc->in.target_vol_dq.d = line_ramp_get_interp(&ctrl->target_vd);
-		foc->in.target_vol_dq.q = line_ramp_get_interp(&ctrl->target_vq);
+		foc->in.target_vol_dq.d = line_ramp_get_interp(&ctrl->ramp_target_vd);
+		foc->in.target_vol_dq.q = line_ramp_get_interp(&ctrl->ramp_target_vq);
 	}
 
 	foc_update(foc);
@@ -259,7 +259,7 @@ bool mot_contrl_update(mot_contrl_t *ctrl) {
 
 static __INLINE float mot_contrl_dc_curr_limiter(mot_contrl_t *ctrl, float maxTrq) {
 	ctrl->pi_power.max = maxTrq;
-	float errRef = line_ramp_get_interp(&ctrl->dc_curr_lim) - ctrl->dc_curr_filted;
+	float errRef = line_ramp_get_interp(&ctrl->ramp_dc_curr_lim) - ctrl->dc_curr_filted;
 	return PI_Controller_Run(&ctrl->pi_power, errRef);
 }
 
@@ -267,14 +267,14 @@ static __INLINE float mot_contrl_vel_limiter(mot_contrl_t *ctrl, float maxTrq) {
 	ctrl->pi_vel_lim.max = maxTrq;
 	ctrl->pi_vel_lim.min = 0;
 
-	float err = line_ramp_get_interp(&ctrl->vel_lim) - ctrl->foc.in.mot_velocity;
+	float err = line_ramp_get_interp(&ctrl->ramp_vel_lim) - ctrl->foc.in.mot_velocity;
 	return PI_Controller_RunVel(&ctrl->pi_vel_lim, err);
 }
 
 /* current vector or torque to dq axis current */
 static void mot_contrl_dq_assign(mot_contrl_t *ctrl) {
 	if (ctrl->mode_running == CTRL_MODE_CURRENT) {
-		float target_current = line_ramp_get_interp(&ctrl->target_current);
+		float target_current = line_ramp_get_interp(&ctrl->ramp_target_current);
 		if (ctrl->b_mtpa_calibrate && (ctrl->adv_angle != INVALID_ANGLE)) {
 			float s, c;
 			float angle_step = line_ramp_step(&ctrl->ramp_adv_angle);
@@ -357,16 +357,16 @@ void mot_contrl_dq_calc(mot_contrl_t *ctrl) {
 		return;
 	}
 	if (ctrl->mode_running == CTRL_MODE_CURRENT) {
-		line_ramp_step(&ctrl->target_current);
+		line_ramp_step(&ctrl->ramp_target_current);
 	}else if (ctrl->mode_running == CTRL_MODE_EBRAKE) {
-		float maxTrq = line_ramp_step(&ctrl->input_torque);
-		if (line_ramp_get_target(&ctrl->input_torque) < 0.0001f && foc->in.mot_velocity < CONFIG_MIN_RPM_EXIT_EBRAKE) {
+		float maxTrq = line_ramp_step(&ctrl->ramp_input_torque);
+		if (line_ramp_get_target(&ctrl->ramp_input_torque) < 0.0001f && foc->in.mot_velocity < CONFIG_MIN_RPM_EXIT_EBRAKE) {
 			maxTrq = 0;
 		}
 		crosszero_step_towards(&ctrl->target_torque, maxTrq);
 	}else if (ctrl->mode_running == CTRL_MODE_TRQ) {
-		float refTorque = line_ramp_step(&ctrl->input_torque);
-		refTorque = min(refTorque, line_ramp_get_interp(&ctrl->torque_lim)) * etcs_out;
+		float refTorque = line_ramp_step(&ctrl->ramp_input_torque);
+		refTorque = min(refTorque, line_ramp_get_interp(&ctrl->ramp_torque_lim)) * etcs_out;
 		float maxTrq = mot_contrl_vel_limiter(ctrl, refTorque);
 		ctrl->target_torque_raw = mot_contrl_dc_curr_limiter(ctrl, maxTrq);
 		crosszero_step_towards(&ctrl->target_torque, ctrl->target_torque_raw);
@@ -374,13 +374,13 @@ void mot_contrl_dq_calc(mot_contrl_t *ctrl) {
 		float refSpeed;
 		float maxSpeed;
 		if (ctrl->b_cruiseEna) {
-			refSpeed = line_ramp_step(&ctrl->cruise_vel);
-			maxSpeed = line_ramp_get_target(&ctrl->cruise_vel);
+			refSpeed = line_ramp_step(&ctrl->ramp_cruise_vel);
+			maxSpeed = line_ramp_get_target(&ctrl->ramp_cruise_vel);
 		}else {
-			refSpeed = line_ramp_step(&ctrl->target_vel);
-			maxSpeed = line_ramp_get_target(&ctrl->target_vel);
+			refSpeed = line_ramp_step(&ctrl->ramp_target_vel);
+			maxSpeed = line_ramp_get_target(&ctrl->ramp_target_vel);
 		}
-		float max_input = line_ramp_get_interp(&ctrl->torque_lim) * etcs_out;
+		float max_input = line_ramp_get_interp(&ctrl->ramp_torque_lim) * etcs_out;
 		if (maxSpeed >= 0) {
 			ctrl->pi_vel.max = max_input;
 #ifdef CONFIG_SERVO_MOTOR
@@ -449,15 +449,15 @@ static void mot_contrl_ulimit(mot_contrl_t *ctrl) {
 }
 
 static void mot_contrl_rtlimit(mot_contrl_t *ctrl) {
-	line_ramp_reset(&ctrl->torque_lim, ctrl->userlim.torque);
-	line_ramp_reset(&ctrl->dc_curr_lim, ctrl->userlim.dc_curr);
-	line_ramp_reset(&ctrl->vel_lim, ctrl->userlim.mot_vel);
+	line_ramp_reset(&ctrl->ramp_torque_lim, ctrl->userlim.torque);
+	line_ramp_reset(&ctrl->ramp_dc_curr_lim, ctrl->userlim.dc_curr);
+	line_ramp_reset(&ctrl->ramp_vel_lim, ctrl->userlim.mot_vel);
 }
 
 void mot_contrl_slow_task(mot_contrl_t *ctrl) {
-	line_ramp_step(&ctrl->torque_lim);
-	line_ramp_step(&ctrl->dc_curr_lim);
-	line_ramp_step(&ctrl->vel_lim);
+	line_ramp_step(&ctrl->ramp_torque_lim);
+	line_ramp_step(&ctrl->ramp_dc_curr_lim);
+	line_ramp_step(&ctrl->ramp_vel_lim);
 	mot_contrl_dq_calc(ctrl);
 }
 
@@ -520,9 +520,9 @@ void mot_contrl_set_dccurr_limit(mot_contrl_t *ctrl, float ibusLimit) {
 	}
 	ctrl->userlim.dc_curr = ibusLimit;
 	if (ABS(ctrl->dc_curr_filted) <= ibusLimit){
-		line_ramp_reset(&ctrl->dc_curr_lim, ctrl->userlim.dc_curr);
+		line_ramp_reset(&ctrl->ramp_dc_curr_lim, ctrl->userlim.dc_curr);
 	}else {
-		line_ramp_set_target(&ctrl->dc_curr_lim, ctrl->userlim.dc_curr);
+		line_ramp_set_target(&ctrl->ramp_dc_curr_lim, ctrl->userlim.dc_curr);
 	}
 }
 
@@ -532,15 +532,15 @@ void mot_contrl_set_vel_limit(mot_contrl_t *ctrl, float vel) {
 	}
 	ctrl->userlim.mot_vel = vel;
 	if (ABS(ctrl->foc.in.mot_velocity) <= vel) {
-		line_ramp_reset(&ctrl->vel_lim, ctrl->userlim.mot_vel);
+		line_ramp_reset(&ctrl->ramp_vel_lim, ctrl->userlim.mot_vel);
 	}else {
-		line_ramp_set_target(&ctrl->vel_lim, ctrl->userlim.mot_vel);
+		line_ramp_set_target(&ctrl->ramp_vel_lim, ctrl->userlim.mot_vel);
 	}
 }
 
 void mot_contrl_set_vel_limit_rttime(mot_contrl_t *ctrl, u32 time) {
-	line_ramp_set_time(&ctrl->vel_lim, (float)time);
-	line_ramp_update(&ctrl->vel_lim);
+	line_ramp_set_time(&ctrl->ramp_vel_lim, (float)time);
+	line_ramp_update(&ctrl->ramp_vel_lim);
 }
 
 
@@ -553,15 +553,15 @@ void mot_contrl_set_torque_limit(mot_contrl_t *ctrl, float torque) {
 	}
 	ctrl->userlim.torque = torque;
 	if (ABS(ctrl->target_torque) <= torque){
-		line_ramp_reset(&ctrl->torque_lim, ctrl->userlim.torque);
+		line_ramp_reset(&ctrl->ramp_torque_lim, ctrl->userlim.torque);
 	}else {
-		line_ramp_set_target(&ctrl->torque_lim, ctrl->userlim.torque);
+		line_ramp_set_target(&ctrl->ramp_torque_lim, ctrl->userlim.torque);
 	}
 }
 
 void mot_contrl_set_torque_limit_rttime(mot_contrl_t *ctrl, u32 time) {
-	line_ramp_set_time(&ctrl->torque_lim, (float)time);
-	line_ramp_update(&ctrl->torque_lim);
+	line_ramp_set_time(&ctrl->ramp_torque_lim, (float)time);
+	line_ramp_update(&ctrl->ramp_torque_lim);
 }
 
 float mot_contrl_get_ebrk_torque(mot_contrl_t *ctrl) {
@@ -574,19 +574,19 @@ float mot_contrl_get_ebrk_torque(mot_contrl_t *ctrl) {
 void mot_contrl_set_ebrk_time(mot_contrl_t *ctrl, u32 time) {
 	ctrl->ebrk_ramp_time = time;
 	if (ctrl->mode_running == CTRL_MODE_EBRAKE) {
-		line_ramp_set_time(&ctrl->input_torque, time);
-		line_ramp_update(&ctrl->input_torque);
+		line_ramp_set_time(&ctrl->ramp_input_torque, time);
+		line_ramp_update(&ctrl->ramp_input_torque);
 	}
 }
 
 void mot_contrl_set_vdq(mot_contrl_t *ctrl, float vd, float vq) {
-	line_ramp_set_target(&ctrl->target_vd, vd);
-	line_ramp_set_target(&ctrl->target_vq, vq);
+	line_ramp_set_target(&ctrl->ramp_target_vd, vd);
+	line_ramp_set_target(&ctrl->ramp_target_vq, vq);
 }
 
 void mot_contrl_set_vdq_immediate(mot_contrl_t *ctrl, float vd, float vq) {
-	line_ramp_reset(&ctrl->target_vd, vd);
-	line_ramp_reset(&ctrl->target_vq, vq);
+	line_ramp_reset(&ctrl->ramp_target_vd, vd);
+	line_ramp_reset(&ctrl->ramp_target_vq, vq);
 }
 
 bool mot_contrl_set_cruise(mot_contrl_t *ctrl, bool enable) {
@@ -596,7 +596,7 @@ bool mot_contrl_set_cruise(mot_contrl_t *ctrl, bool enable) {
 			mot_contrl_set_error(ctrl, FOC_NowAllowed_With_Speed);
 			return false;
 		}
-		line_ramp_reset(&ctrl->cruise_vel, motSpd);
+		line_ramp_reset(&ctrl->ramp_cruise_vel, motSpd);
 		ctrl->b_cruiseEna = enable;
 	}
 	return true;
@@ -605,7 +605,7 @@ bool mot_contrl_set_cruise(mot_contrl_t *ctrl, bool enable) {
 
 bool mot_contrl_resume_cruise(mot_contrl_t *ctrl) {
 	ctrl->b_cruiseEna = true;
-	line_ramp_set_time(&ctrl->cruise_vel, CONFIG_CRUISE_RAMP_TIME);
+	line_ramp_set_time(&ctrl->ramp_cruise_vel, CONFIG_CRUISE_RAMP_TIME);
 	return true;
 }
 
@@ -615,7 +615,7 @@ bool mot_contrl_set_cruise_speed(mot_contrl_t *ctrl, float rpm) {
 			rpm = CONFIG_MIN_CRUISE_RPM;
 		}
 		float vel = min(ABS(rpm),ctrl->userlim.mot_vel)*SIGN(rpm);
-		line_ramp_set_target(&ctrl->cruise_vel, vel);
+		line_ramp_set_target(&ctrl->ramp_cruise_vel, vel);
 		return true;
 	}
 	mot_contrl_set_error(ctrl, FOC_NotCruiseMode);
@@ -624,7 +624,7 @@ bool mot_contrl_set_cruise_speed(mot_contrl_t *ctrl, float rpm) {
 
 bool mot_contrl_set_current(mot_contrl_t *ctrl, float is) {
 	is = fclamp(is, -ctrl->userlim.phase_curr, ctrl->userlim.phase_curr);
-	line_ramp_set_target(&ctrl->target_current, is);
+	line_ramp_set_target(&ctrl->ramp_target_current, is);
 	return true;
 }
 
@@ -632,17 +632,17 @@ void mot_contrl_set_torque_ramp_time(mot_contrl_t *ctrl, u32 acc, u32 dec) {
 	ctrl->torque_acc_time = acc;
 	ctrl->torque_dec_time = dec;
 	if (ctrl->mode_running == CTRL_MODE_TRQ) {
-		line_ramp_set_acctime(&ctrl->input_torque, acc);
-		line_ramp_set_dectime(&ctrl->input_torque, dec);
-		line_ramp_update(&ctrl->input_torque);
+		line_ramp_set_acctime(&ctrl->ramp_input_torque, acc);
+		line_ramp_set_dectime(&ctrl->ramp_input_torque, dec);
+		line_ramp_update(&ctrl->ramp_input_torque);
 	}
 }
 
 void mot_contrl_set_torque_acc_time(mot_contrl_t *ctrl, u32 acc) {
 	ctrl->torque_acc_time = acc;
 	if (ctrl->mode_running == CTRL_MODE_TRQ) {
-		line_ramp_set_acctime(&ctrl->input_torque, acc);
-		line_ramp_update(&ctrl->input_torque);
+		line_ramp_set_acctime(&ctrl->ramp_input_torque, acc);
+		line_ramp_update(&ctrl->ramp_input_torque);
 	}
 }
 
@@ -657,7 +657,7 @@ bool mot_contrl_set_torque(mot_contrl_t *ctrl, float torque) {
 		torque_max = 0;
 	}
 	torque = fclamp(torque, torque_min, torque_max);
-	line_ramp_set_target(&ctrl->input_torque, torque);
+	line_ramp_set_target(&ctrl->ramp_input_torque, torque);
 	return true;
 }
 
@@ -673,7 +673,7 @@ bool mot_contrl_set_force_torque(mot_contrl_t *ctrl, float torque) {
 		torque_max = 0;
 	}
 	torque = fclamp(torque, torque_min, torque_max);
-	line_ramp_set_target(&ctrl->input_torque, torque);
+	line_ramp_set_target(&ctrl->ramp_input_torque, torque);
 	return true;
 }
 
@@ -700,7 +700,7 @@ void mot_contrl_set_autohold(mot_contrl_t *ctrl, bool lock) {
 			}else if (ctrl->mode_running == CTRL_MODE_SPD) {
 				PI_Controller_Reset(&ctrl->pi_vel, hold_torque);
 			}
-			line_ramp_reset(&ctrl->input_torque, hold_torque);
+			line_ramp_reset(&ctrl->ramp_input_torque, hold_torque);
 			ctrl->autohold_torque = hold_torque;
 		}else {
 			ctrl->autohold_torque = 0;
@@ -740,7 +740,7 @@ void mot_contrl_set_hw_brake(mot_contrl_t *ctrl, bool hw_brake) {
 	}
 	if (is_hw_brake_shutting_power(ctrl)) {
 		if (!ctrl->b_ebrk_running && !mot_contrl_energy_recovery(ctrl, true)) {
-			line_ramp_reset(&ctrl->input_torque, 0);
+			line_ramp_reset(&ctrl->ramp_input_torque, 0);
 		}
 	}
 	cpu_exit_critical(mask);

+ 14 - 14
Applications/foc/core/controller.h

@@ -149,15 +149,15 @@ typedef struct{
 	user_limit 		userlim;
 	hw_limit   		hwlim;
 	prot_limit 		protlim;
-	lineramp_t   	target_current;
-	lineramp_t 		cruise_vel;
-	lineramp_t 		target_vd;
-	lineramp_t 		target_vq;
-	lineramp_t		target_vel;
-	lineramp_t 		vel_lim;
-	lineramp_t 		torque_lim;
-	lineramp_t 		dc_curr_lim;
-	lineramp_t		input_torque;
+	lineramp_t   	ramp_target_current;
+	lineramp_t 		ramp_cruise_vel;
+	lineramp_t 		ramp_target_vd;
+	lineramp_t 		ramp_target_vq;
+	lineramp_t		ramp_target_vel;
+	lineramp_t 		ramp_vel_lim;
+	lineramp_t 		ramp_torque_lim;
+	lineramp_t 		ramp_dc_curr_lim;
+	lineramp_t		ramp_input_torque;
 	lineramp_t		ramp_adv_angle;
 	float 			phase_a_max;
 	float 			phase_b_max;
@@ -245,13 +245,13 @@ static __INLINE bool mot_contrl_set_target_vel(mot_contrl_t *ctrl, float vel) {
 	if (ctrl->b_cruiseEna) {
 		return false;
 	}
-	line_ramp_set_target(&ctrl->target_vel ,min(ABS(vel), ctrl->userlim.mot_vel)*SIGN(vel));
+	line_ramp_set_target(&ctrl->ramp_target_vel ,min(ABS(vel), ctrl->userlim.mot_vel)*SIGN(vel));
 	return true;
 }
 
 static __INLINE void mot_contrl_set_vel_rttime(mot_contrl_t *ctrl, u32 time) {
-	line_ramp_set_time(&ctrl->target_vel, (float)time);
-	line_ramp_update(&ctrl->target_vel);
+	line_ramp_set_time(&ctrl->ramp_target_vel, (float)time);
+	line_ramp_update(&ctrl->ramp_target_vel);
 }
 
 
@@ -285,11 +285,11 @@ static __INLINE bool mot_contrl_ebrk_is_running(mot_contrl_t *ctrl) {
 }
 
 static __INLINE float mot_contrl_get_final_torque(mot_contrl_t *ctrl) {
-	return ctrl->input_torque.target;
+	return ctrl->ramp_input_torque.target;
 }
 
 static __INLINE u32 mot_contrl_get_torque_acc_time(mot_contrl_t *ctrl) {
-	return ctrl->input_torque.time;
+	return ctrl->ramp_input_torque.time;
 }
 
 #endif /* _CONTROLLER_H__ */

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

@@ -227,8 +227,8 @@ static void mc_gear_mode_set(void) {
 	if (gears != &sensorless_gear) {
 		sensorless_gear.max_torque = gears->max_torque;
 	}else { //slowly changed
-		line_ramp_set_time(&motor.controller.vel_lim, CONFIG_SENSORLESS_RAMP_TIME);
-		line_ramp_set_time(&motor.controller.dc_curr_lim, CONFIG_SENSORLESS_RAMP_TIME);
+		line_ramp_set_time(&motor.controller.ramp_vel_lim, CONFIG_SENSORLESS_RAMP_TIME);
+		line_ramp_set_time(&motor.controller.ramp_dc_curr_lim, CONFIG_SENSORLESS_RAMP_TIME);
 	}
 	mot_contrl_set_vel_limit(&motor.controller, (float)min(gears->max_speed, motor.u_set.rpm_lim));
 	mot_contrl_set_dccurr_limit(&motor.controller, (float)min(gears->max_idc, motor.u_set.idc_lim));

+ 2 - 2
Applications/foc/motor/throttle.c

@@ -272,7 +272,7 @@ float throttle_get_torque(mot_contrl_t * ctrl, float vol) {
 			_throttle.throttle_opening_last = _throttle.throttle_opening;
 			_throttle.torque_real = ctrl->target_torque_raw;
 			/* 如果扭矩给定的ramp没有结束,使用原始扭矩请求作为减扭矩的起始点 */
-			if (_throttle.torque_req - line_ramp_get_interp(&ctrl->input_torque) >= 10.0f ) {
+			if (_throttle.torque_req - line_ramp_get_interp(&ctrl->ramp_input_torque) >= 10.0f ) {
 				_throttle.torque_real = _throttle.torque_req;
 			}
 			if (_throttle.torque_real < 0) { //电子刹车的时候,扭矩可能为负
@@ -301,7 +301,7 @@ void throttle_set_torque(mot_contrl_t * ctrl, float torque) {
 		if (curr_vel <= CONFIG_ZERO_SPEED_RPM) {//从静止开始加速
 			if (_throttle.torque_req < hold_torque) {
 				_throttle.torque_req = hold_torque;
-				line_ramp_reset(&ctrl->input_torque, hold_torque);
+				line_ramp_reset(&ctrl->ramp_input_torque, hold_torque);
 			}
 		}else {
 			ctrl->autohold_torque = 0;