|
@@ -223,7 +223,7 @@ static void _led_off_timer_handler(shark_timer_t *t) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-static void mc_gear_mode_set(void) {
|
|
|
|
|
|
|
+static void mc_gear_mode_set(bool set_imd) {
|
|
|
gear_t *gears = mc_gear_conf();
|
|
gear_t *gears = mc_gear_conf();
|
|
|
float max_vel = (float)min(gears->max_speed, motor.u_set.rpm_lim);
|
|
float max_vel = (float)min(gears->max_speed, motor.u_set.rpm_lim);
|
|
|
float max_idc = (float)min(gears->max_idc, motor.u_set.idc_lim);
|
|
float max_idc = (float)min(gears->max_idc, motor.u_set.idc_lim);
|
|
@@ -235,7 +235,15 @@ static void mc_gear_mode_set(void) {
|
|
|
max_idc = min(max_idc, (float)sensorless_gear.max_idc);
|
|
max_idc = min(max_idc, (float)sensorless_gear.max_idc);
|
|
|
max_torque = min(max_torque, (float)sensorless_gear.max_torque);
|
|
max_torque = min(max_torque, (float)sensorless_gear.max_torque);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ if (set_imd) {
|
|
|
|
|
+ line_ramp_set_time(&motor.controller.ramp_vel_lim, gears->accl_time);
|
|
|
|
|
+ line_ramp_set_time(&motor.controller.ramp_dc_curr_lim, gears->accl_time);
|
|
|
|
|
+ line_ramp_set_time(&motor.controller.ramp_torque_lim, gears->accl_time);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ line_ramp_set_time(&motor.controller.ramp_vel_lim, CONFIG_LIMIT_RAMP_TIME);
|
|
|
|
|
+ line_ramp_set_time(&motor.controller.ramp_dc_curr_lim, CONFIG_LIMIT_RAMP_TIME);
|
|
|
|
|
+ line_ramp_set_time(&motor.controller.ramp_torque_lim, CONFIG_LIMIT_RAMP_TIME);
|
|
|
|
|
+ }
|
|
|
mot_contrl_set_vel_limit(&motor.controller, max_vel);
|
|
mot_contrl_set_vel_limit(&motor.controller, max_vel);
|
|
|
mot_contrl_set_dccurr_limit(&motor.controller, max_idc);
|
|
mot_contrl_set_dccurr_limit(&motor.controller, max_idc);
|
|
|
mot_contrl_set_torque_limit(&motor.controller, max_torque);
|
|
mot_contrl_set_torque_limit(&motor.controller, max_torque);
|
|
@@ -392,7 +400,7 @@ bool mc_start(u8 mode) {
|
|
|
mot_contrl_start(&motor.controller, mode);
|
|
mot_contrl_start(&motor.controller, mode);
|
|
|
mot_contrl_set_torque_ramp_time(&motor.controller, mc_gear_conf()->zero_accl, mc_conf()->c.thro_dec_time);
|
|
mot_contrl_set_torque_ramp_time(&motor.controller, mc_gear_conf()->zero_accl, mc_conf()->c.thro_dec_time);
|
|
|
mc_set_ebrk_level(motor.u_set.ebrk_lvl);
|
|
mc_set_ebrk_level(motor.u_set.ebrk_lvl);
|
|
|
- mc_gear_mode_set();
|
|
|
|
|
|
|
+ mc_gear_mode_set(false);
|
|
|
cpu_exit_critical(mask);
|
|
cpu_exit_critical(mask);
|
|
|
|
|
|
|
|
pwm_turn_on_low_side();
|
|
pwm_turn_on_low_side();
|
|
@@ -481,7 +489,7 @@ bool mc_set_gear(u8 gear) {
|
|
|
#endif
|
|
#endif
|
|
|
u32 mask = cpu_enter_critical();
|
|
u32 mask = cpu_enter_critical();
|
|
|
motor.n_gear = gear;
|
|
motor.n_gear = gear;
|
|
|
- mc_gear_mode_set();
|
|
|
|
|
|
|
+ mc_gear_mode_set(false);
|
|
|
cpu_exit_critical(mask);
|
|
cpu_exit_critical(mask);
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
@@ -592,7 +600,7 @@ void mc_set_idc_limit(s16 limit) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
motor.u_set.idc_lim = limit;
|
|
motor.u_set.idc_lim = limit;
|
|
|
- mc_gear_mode_set();
|
|
|
|
|
|
|
+ mc_gear_mode_set(false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void mc_set_rpm_limit(s16 limit) {
|
|
void mc_set_rpm_limit(s16 limit) {
|
|
@@ -600,7 +608,7 @@ void mc_set_rpm_limit(s16 limit) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
motor.u_set.rpm_lim = limit;
|
|
motor.u_set.rpm_lim = limit;
|
|
|
- mc_gear_mode_set();
|
|
|
|
|
|
|
+ mc_gear_mode_set(false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -700,7 +708,7 @@ bool mc_start_epm(bool epm) {
|
|
|
mot_contrl_request_mode(&motor.controller, CTRL_MODE_TRQ);
|
|
mot_contrl_request_mode(&motor.controller, CTRL_MODE_TRQ);
|
|
|
mot_contrl_set_torque_limit_rttime(&motor.controller, CONFIG_LIMIT_RAMP_TIME);
|
|
mot_contrl_set_torque_limit_rttime(&motor.controller, CONFIG_LIMIT_RAMP_TIME);
|
|
|
mot_contrl_set_vel_rttime(&motor.controller, CONFIG_CRUISE_RAMP_TIME);
|
|
mot_contrl_set_vel_rttime(&motor.controller, CONFIG_CRUISE_RAMP_TIME);
|
|
|
- mc_gear_mode_set();
|
|
|
|
|
|
|
+ mc_gear_mode_set(false);
|
|
|
}
|
|
}
|
|
|
cpu_exit_critical(mask);
|
|
cpu_exit_critical(mask);
|
|
|
|
|
|
|
@@ -734,7 +742,7 @@ bool mc_start_epm_move(epm_dir_t dir, bool is_command) {
|
|
|
|
|
|
|
|
if (!mot_contrl_is_start(&motor.controller)) {
|
|
if (!mot_contrl_is_start(&motor.controller)) {
|
|
|
mot_contrl_start(&motor.controller, motor.mode);
|
|
mot_contrl_start(&motor.controller, motor.mode);
|
|
|
- mc_gear_mode_set();
|
|
|
|
|
|
|
+ mc_gear_mode_set(false);
|
|
|
pwm_enable_channel();
|
|
pwm_enable_channel();
|
|
|
}else if (mot_contrl_is_auto_holdding(&motor.controller)) {
|
|
}else if (mot_contrl_is_auto_holdding(&motor.controller)) {
|
|
|
mc_auto_hold(false);
|
|
mc_auto_hold(false);
|
|
@@ -1573,7 +1581,7 @@ static void mc_motor_runstop(void) {
|
|
|
if (!mot_contrl_is_start(&motor.controller) && mc_can_restart_foc()) {
|
|
if (!mot_contrl_is_start(&motor.controller) && mc_can_restart_foc()) {
|
|
|
mask = cpu_enter_critical();
|
|
mask = cpu_enter_critical();
|
|
|
mot_contrl_start(&motor.controller, motor.mode);
|
|
mot_contrl_start(&motor.controller, motor.mode);
|
|
|
- mc_gear_mode_set();
|
|
|
|
|
|
|
+ mc_gear_mode_set(true);
|
|
|
throttle_torque_reset();
|
|
throttle_torque_reset();
|
|
|
pwm_enable_channel();
|
|
pwm_enable_channel();
|
|
|
g_meas_foc.first = true;
|
|
g_meas_foc.first = true;
|
|
@@ -1661,7 +1669,7 @@ void Sched_MC_mTask(void) {
|
|
|
}
|
|
}
|
|
|
bool sensor_less = !foc_observer_is_encoder();
|
|
bool sensor_less = !foc_observer_is_encoder();
|
|
|
if (mc_detect_vbus_mode() || (limted == FOC_LIM_CHANGE_L) || (_sensorless_run != sensor_less)) {
|
|
if (mc_detect_vbus_mode() || (limted == FOC_LIM_CHANGE_L) || (_sensorless_run != sensor_less)) {
|
|
|
- mc_gear_mode_set();
|
|
|
|
|
|
|
+ mc_gear_mode_set(false);
|
|
|
if (sensor_less && foc_observer_sensorless_stable()) {//unstable 记录在ADC中断处理中
|
|
if (sensor_less && foc_observer_sensorless_stable()) {//unstable 记录在ADC中断处理中
|
|
|
if (motor_encoder_may_error() == ENCODER_PWM_ERR) {
|
|
if (motor_encoder_may_error() == ENCODER_PWM_ERR) {
|
|
|
if (mc_set_critical_error(FOC_CRIT_Encoder_Err)) {
|
|
if (mc_set_critical_error(FOC_CRIT_Encoder_Err)) {
|
|
@@ -1682,7 +1690,7 @@ void Sched_MC_mTask(void) {
|
|
|
/* 如果取消高温,欠压等限流需要释放转把后才生效,确保不会突然加速 */
|
|
/* 如果取消高温,欠压等限流需要释放转把后才生效,确保不会突然加速 */
|
|
|
if (motor.b_limit_pending && mc_throttle_released()) {
|
|
if (motor.b_limit_pending && mc_throttle_released()) {
|
|
|
motor.b_limit_pending = false;
|
|
motor.b_limit_pending = false;
|
|
|
- mc_gear_mode_set();
|
|
|
|
|
|
|
+ mc_gear_mode_set(false);
|
|
|
}
|
|
}
|
|
|
/* 堵转处理 */
|
|
/* 堵转处理 */
|
|
|
if (mc_run_stall_process(runMode) || (motor.mode == CTRL_MODE_CURRENT)) {
|
|
if (mc_run_stall_process(runMode) || (motor.mode == CTRL_MODE_CURRENT)) {
|