|
@@ -8,11 +8,9 @@
|
|
|
#include "libs/time_measure.h"
|
|
#include "libs/time_measure.h"
|
|
|
#include "foc/commands.h"
|
|
#include "foc/commands.h"
|
|
|
#include "libs/logger.h"
|
|
#include "libs/logger.h"
|
|
|
-#include "foc/core/e_ctrl.h"
|
|
|
|
|
#include "foc/samples.h"
|
|
#include "foc/samples.h"
|
|
|
#include "foc/motor/motor_param.h"
|
|
#include "foc/motor/motor_param.h"
|
|
|
#include "foc/core/foc_observer.h"
|
|
#include "foc/core/foc_observer.h"
|
|
|
-#include "foc/core/thro_torque.h"
|
|
|
|
|
#include "foc/core/F_Calc.h"
|
|
#include "foc/core/F_Calc.h"
|
|
|
#include "foc/core/etcs.h"
|
|
#include "foc/core/etcs.h"
|
|
|
#include "app/nv_storage.h"
|
|
#include "app/nv_storage.h"
|
|
@@ -38,7 +36,7 @@ static void _encoder_zero_off_timer_handler(shark_timer_t *);
|
|
|
static shark_timer_t _encoder_zero_off_timer = TIMER_INIT(_encoder_zero_off_timer, _encoder_zero_off_timer_handler);
|
|
static shark_timer_t _encoder_zero_off_timer = TIMER_INIT(_encoder_zero_off_timer, _encoder_zero_off_timer_handler);
|
|
|
static void _led_off_timer_handler(shark_timer_t *);
|
|
static void _led_off_timer_handler(shark_timer_t *);
|
|
|
static shark_timer_t _led_off_timer = TIMER_INIT(_led_off_timer, _led_off_timer_handler);
|
|
static shark_timer_t _led_off_timer = TIMER_INIT(_led_off_timer, _led_off_timer_handler);
|
|
|
-static m_contrl_t motor = {
|
|
|
|
|
|
|
+m_contrl_t motor = {
|
|
|
.s_direction = POSITIVE,
|
|
.s_direction = POSITIVE,
|
|
|
.n_gear = 0,
|
|
.n_gear = 0,
|
|
|
.b_is96Mode = false,
|
|
.b_is96Mode = false,
|
|
@@ -222,12 +220,12 @@ static void mc_gear_vmode_changed(void) {
|
|
|
if (gears != &sensorless_gear) {
|
|
if (gears != &sensorless_gear) {
|
|
|
sensorless_gear.max_torque = gears->max_torque;
|
|
sensorless_gear.max_torque = gears->max_torque;
|
|
|
}else { //slowly changed
|
|
}else { //slowly changed
|
|
|
- eRamp_set_time(&(PMSM_FOC_Get()->rtLim.rpmLimRamp), CONFIG_SENSORLESS_RAMP_TIME, CONFIG_SENSORLESS_RAMP_TIME);
|
|
|
|
|
- eRamp_set_time(&(PMSM_FOC_Get()->rtLim.DCCurrLimRamp), CONFIG_SENSORLESS_RAMP_TIME, CONFIG_SENSORLESS_RAMP_TIME);
|
|
|
|
|
|
|
+ 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);
|
|
|
}
|
|
}
|
|
|
- PMSM_FOC_SpeedLimit((float)min(gears->max_speed, motor.u_set.rpm_lim));
|
|
|
|
|
- PMSM_FOC_DCCurrLimit((float)min(gears->max_idc, motor.u_set.idc_lim));
|
|
|
|
|
- PMSM_FOC_TorqueLimit((float)gears->max_torque);
|
|
|
|
|
|
|
+ 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));
|
|
|
|
|
+ mot_contrl_set_torque_limit(&motor.controller, (float)gears->max_torque);
|
|
|
sys_debug("change %d, %d, %d\n", gears->max_idc, gears->max_speed, gears->max_torque);
|
|
sys_debug("change %d, %d, %d\n", gears->max_idc, gears->max_speed, gears->max_torque);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -239,10 +237,8 @@ void mc_init(void) {
|
|
|
motor_encoder_init();
|
|
motor_encoder_init();
|
|
|
foc_command_init();
|
|
foc_command_init();
|
|
|
throttle_init();
|
|
throttle_init();
|
|
|
- thro_torque_init();
|
|
|
|
|
mc_detect_vbus_mode();
|
|
mc_detect_vbus_mode();
|
|
|
- PMSM_FOC_CoreInit();
|
|
|
|
|
- eCtrl_init(mc_get_gear_config()->zero_accl, mc_conf()->c.thro_dec_time);
|
|
|
|
|
|
|
+ mot_contrl_init(&motor.controller);
|
|
|
mc_gpio_init();
|
|
mc_gpio_init();
|
|
|
MC_Check_MosVbusThrottle();
|
|
MC_Check_MosVbusThrottle();
|
|
|
sched_timer_enable(CONFIG_SPD_CTRL_US);
|
|
sched_timer_enable(CONFIG_SPD_CTRL_US);
|
|
@@ -273,6 +269,41 @@ gear_t *mc_get_gear_config(void) {
|
|
|
return mc_get_gear_config_by_gear(motor.n_gear);
|
|
return mc_get_gear_config_by_gear(motor.n_gear);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static __INLINE float gear_rpm_2_torque(u8 torque, s16 max) {
|
|
|
|
|
+ return (float)torque/100.0f * max;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+float mc_get_max_torque_with_gear_vel(s16 vel, u8 gear) {
|
|
|
|
|
+ gear_t *_current_gear = mc_get_gear_config_by_gear(gear);
|
|
|
|
|
+ if (_current_gear == NULL) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (vel > _current_gear->max_speed) {
|
|
|
|
|
+ vel = _current_gear->max_speed;
|
|
|
|
|
+ }
|
|
|
|
|
+ vel = ABS(vel);
|
|
|
|
|
+ if (vel <= 1000) {
|
|
|
|
|
+ return gear_rpm_2_torque(_current_gear->torque[0], _current_gear->max_torque);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 1; i < CONFIG_GEAR_SPEED_TRQ_NUM; i++) {
|
|
|
|
|
+ if (vel <= 1000 * (i + 1)) { //线性插值
|
|
|
|
|
+ float trq1 = gear_rpm_2_torque(_current_gear->torque[i-1], _current_gear->max_torque);
|
|
|
|
|
+ float min_rpm = (i * 1000);
|
|
|
|
|
+ float trq2 = gear_rpm_2_torque(_current_gear->torque[i], _current_gear->max_torque);
|
|
|
|
|
+ float max_rpm = (i + 1) * 1000;
|
|
|
|
|
+ if (trq1 > trq2) {
|
|
|
|
|
+ return f_map_inv((float)vel, min_rpm, max_rpm, trq2, trq1);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return f_map((float)vel, min_rpm, max_rpm, trq1, trq2);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return gear_rpm_2_torque(_current_gear->torque[CONFIG_GEAR_SPEED_TRQ_NUM-1], _current_gear->max_torque);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/* 必须立即停机 */
|
|
/* 必须立即停机 */
|
|
|
bool mc_critical_need_stop(void) {
|
|
bool mc_critical_need_stop(void) {
|
|
|
u32 mask = FOC_Cri_Err_Mask(FOC_CRIT_IDC_OV) | FOC_Cri_Err_Mask(FOC_CRIT_Angle_Err) | FOC_Cri_Err_Mask(FOC_CRIT_Vol_HW_Err);
|
|
u32 mask = FOC_Cri_Err_Mask(FOC_CRIT_IDC_OV) | FOC_Cri_Err_Mask(FOC_CRIT_Angle_Err) | FOC_Cri_Err_Mask(FOC_CRIT_Vol_HW_Err);
|
|
@@ -324,27 +355,27 @@ bool mc_start(u8 mode) {
|
|
|
target_q = 0.0f;
|
|
target_q = 0.0f;
|
|
|
#endif
|
|
#endif
|
|
|
mc_detect_vbus_mode();
|
|
mc_detect_vbus_mode();
|
|
|
- etcs_enable(motor.u_set.b_tcs);
|
|
|
|
|
|
|
+ etcs_enable(&motor.controller.ects, motor.u_set.b_tcs);
|
|
|
if (motor.b_lock_motor) {
|
|
if (motor.b_lock_motor) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NotAllowed);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NotAllowed);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
MC_Check_MosVbusThrottle();
|
|
MC_Check_MosVbusThrottle();
|
|
|
|
|
|
|
|
if (mc_unsafe_critical_error()) {
|
|
if (mc_unsafe_critical_error()) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_Have_CritiCal_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_Have_CritiCal_Err);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (mode > CTRL_MODE_CURRENT) {
|
|
if (mode > CTRL_MODE_CURRENT) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_Param_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_Param_Err);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- if (PMSM_FOC_GetSpeed() > CONFIG_ZERO_SPEED_RPM) {
|
|
|
|
|
- PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
|
|
|
|
|
|
|
+ if (mot_contrl_get_speed(&motor.controller) > CONFIG_ZERO_SPEED_RPM) {
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NowAllowed_With_Speed);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (!mc_throttle_released()) {
|
|
if (!mc_throttle_released()) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_Throttle_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_Throttle_Err);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -352,12 +383,11 @@ bool mc_start(u8 mode) {
|
|
|
|
|
|
|
|
_mc_internal_init(mode, true);
|
|
_mc_internal_init(mode, true);
|
|
|
|
|
|
|
|
- thro_torque_reset();
|
|
|
|
|
|
|
+ throttle_torque_reset();
|
|
|
mc_gear_vmode_changed();
|
|
mc_gear_vmode_changed();
|
|
|
- eCtrl_init(mc_get_gear_config()->zero_accl, mc_conf()->c.thro_dec_time);
|
|
|
|
|
|
|
+ mot_contrl_set_torque_ramp_time(&motor.controller, mc_get_gear_config()->zero_accl, mc_conf()->c.thro_dec_time);
|
|
|
motor_encoder_start(true);
|
|
motor_encoder_start(true);
|
|
|
- PMSM_FOC_Start(mode);
|
|
|
|
|
- PMSM_FOC_RT_LimInit();
|
|
|
|
|
|
|
+ mot_contrl_start(&motor.controller, mode);
|
|
|
pwm_turn_on_low_side();
|
|
pwm_turn_on_low_side();
|
|
|
delay_ms(10);
|
|
delay_ms(10);
|
|
|
phase_current_offset_calibrate();
|
|
phase_current_offset_calibrate();
|
|
@@ -370,12 +400,12 @@ bool mc_start(u8 mode) {
|
|
|
adc_start_convert();
|
|
adc_start_convert();
|
|
|
phase_current_calibrate_wait();
|
|
phase_current_calibrate_wait();
|
|
|
if (phase_curr_offset_check()) {
|
|
if (phase_curr_offset_check()) {
|
|
|
- mc_set_critical_error(FOC_CRIT_CURR_OFF_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_CRIT_CURR_OFF_Err);
|
|
|
mc_stop();
|
|
mc_stop();
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (mc_detect_hwbrake()) {
|
|
if (mc_detect_hwbrake()) {
|
|
|
- PMSM_FOC_Brake(true);
|
|
|
|
|
|
|
+ mot_contrl_set_hw_brake(&motor.controller, true);
|
|
|
}
|
|
}
|
|
|
gpio_beep(200);
|
|
gpio_beep(200);
|
|
|
|
|
|
|
@@ -388,16 +418,16 @@ bool mc_stop(void) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (motor.b_lock_motor) {
|
|
if (motor.b_lock_motor) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NotAllowed);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NotAllowed);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (PMSM_FOC_GetSpeed() > CONFIG_ZERO_SPEED_RPM) {
|
|
|
|
|
- PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
|
|
|
|
|
|
|
+ if (mot_contrl_get_speed(&motor.controller) > CONFIG_ZERO_SPEED_RPM) {
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NowAllowed_With_Speed);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (!mc_throttle_released()) {
|
|
if (!mc_throttle_released()) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_Throttle_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_Throttle_Err);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -405,7 +435,7 @@ bool mc_stop(void) {
|
|
|
_mc_internal_init(CTRL_MODE_OPEN, false);
|
|
_mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
adc_stop_convert();
|
|
adc_stop_convert();
|
|
|
pwm_stop();
|
|
pwm_stop();
|
|
|
- PMSM_FOC_Stop();
|
|
|
|
|
|
|
+ mot_contrl_stop(&motor.controller);
|
|
|
motor_encoder_start(false);
|
|
motor_encoder_start(false);
|
|
|
pwm_up_enable(true);
|
|
pwm_up_enable(true);
|
|
|
cpu_exit_critical(mask);
|
|
cpu_exit_critical(mask);
|
|
@@ -429,7 +459,7 @@ void mc_set_motor_lim_level(u8 l) {
|
|
|
|
|
|
|
|
bool mc_set_gear(u8 gear) {
|
|
bool mc_set_gear(u8 gear) {
|
|
|
if (gear >= CONFIG_MAX_GEARS) {
|
|
if (gear >= CONFIG_MAX_GEARS) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_Param_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_Param_Err);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (motor.n_gear != gear) {
|
|
if (motor.n_gear != gear) {
|
|
@@ -464,7 +494,7 @@ bool mc_enable_cruise(bool enable) {
|
|
|
if (enable == motor.b_cruise) {
|
|
if (enable == motor.b_cruise) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
- if (PMSM_FOC_EnableCruise(enable)) {
|
|
|
|
|
|
|
+ if (mot_contrl_set_cruise(&motor.controller, enable)) {
|
|
|
motor.b_cruise = enable;
|
|
motor.b_cruise = enable;
|
|
|
motor.cruise_time = enable?shark_get_seconds():0;
|
|
motor.cruise_time = enable?shark_get_seconds():0;
|
|
|
motor.cruise_torque = 0.0f;
|
|
motor.cruise_torque = 0.0f;
|
|
@@ -488,9 +518,9 @@ bool mc_is_cruise_enabled(void) {
|
|
|
bool mc_set_cruise_speed(bool rpm_abs, float target_rpm) {
|
|
bool mc_set_cruise_speed(bool rpm_abs, float target_rpm) {
|
|
|
bool ret;
|
|
bool ret;
|
|
|
if (rpm_abs) {
|
|
if (rpm_abs) {
|
|
|
- ret = PMSM_FOC_Set_CruiseSpeed(target_rpm);
|
|
|
|
|
|
|
+ ret = mot_contrl_set_cruise_speed(&motor.controller, target_rpm);
|
|
|
}else {
|
|
}else {
|
|
|
- ret = PMSM_FOC_Set_CruiseSpeed(PMSM_FOC_GetSpeed() + target_rpm);
|
|
|
|
|
|
|
+ ret = mot_contrl_set_cruise_speed(&motor.controller, mot_contrl_get_speed(&motor.controller) + target_rpm);
|
|
|
}
|
|
}
|
|
|
if (ret) {
|
|
if (ret) {
|
|
|
motor.cruise_time = shark_get_seconds();
|
|
motor.cruise_time = shark_get_seconds();
|
|
@@ -519,8 +549,8 @@ void mc_set_rpm_limit(s16 limit) {
|
|
|
bool mc_set_ebrk_level(u8 level) {
|
|
bool mc_set_ebrk_level(u8 level) {
|
|
|
if (level < CONFIG_EBRK_LVL_NUM) {
|
|
if (level < CONFIG_EBRK_LVL_NUM) {
|
|
|
motor.u_set.ebrk_lvl = level;
|
|
motor.u_set.ebrk_lvl = level;
|
|
|
- eCtrl_Set_eBrk_RampTime(mc_get_ebrk_time());
|
|
|
|
|
- PMSM_FOC_SetEbrkTorque(mc_get_ebrk_torque());
|
|
|
|
|
|
|
+ mot_contrl_set_ebrk_time(&motor.controller, mc_get_ebrk_time());
|
|
|
|
|
+ mot_contrl_set_ebrk_torquer(&motor.controller, mc_get_ebrk_torque());
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
@@ -532,7 +562,7 @@ void mc_enable_brkshutpower(u8 shut) {
|
|
|
|
|
|
|
|
void mc_enable_tcs(bool enable) {
|
|
void mc_enable_tcs(bool enable) {
|
|
|
motor.u_set.b_tcs = enable;
|
|
motor.u_set.b_tcs = enable;
|
|
|
- etcs_enable(enable);
|
|
|
|
|
|
|
+ etcs_enable(&motor.controller.ects, enable);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
s16 mc_get_ebrk_torque(void) {
|
|
s16 mc_get_ebrk_torque(void) {
|
|
@@ -559,17 +589,17 @@ bool mc_set_foc_mode(u8 mode) {
|
|
|
if (mc_critical_can_not_run()) {
|
|
if (mc_critical_can_not_run()) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- if ((mode == CTRL_MODE_OPEN) && (ABS(PMSM_FOC_GetSpeed()) > CONFIG_ZERO_SPEED_RPM)) {
|
|
|
|
|
- PMSM_FOC_SetErrCode(FOC_NotAllowed);
|
|
|
|
|
|
|
+ if ((mode == CTRL_MODE_OPEN) && (ABS(mot_contrl_get_speed(&motor.controller)) > CONFIG_ZERO_SPEED_RPM)) {
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NotAllowed);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
u32 mask = cpu_enter_critical();
|
|
u32 mask = cpu_enter_critical();
|
|
|
bool ret = false;
|
|
bool ret = false;
|
|
|
- if (PMSM_FOC_SetCtrlMode(mode)) {
|
|
|
|
|
|
|
+ if (mot_contrl_request_mode(&motor.controller, mode)) {
|
|
|
motor.mode = mode;
|
|
motor.mode = mode;
|
|
|
if (mode == CTRL_MODE_OPEN || mode == CTRL_MODE_CURRENT) {
|
|
if (mode == CTRL_MODE_OPEN || mode == CTRL_MODE_CURRENT) {
|
|
|
- PMSM_FOC_Start(motor.mode);
|
|
|
|
|
|
|
+ mot_contrl_start(&motor.controller, motor.mode);
|
|
|
pwm_enable_channel();
|
|
pwm_enable_channel();
|
|
|
}
|
|
}
|
|
|
ret = true;
|
|
ret = true;
|
|
@@ -583,15 +613,15 @@ bool mc_start_epm(bool epm) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
if (!motor.b_start) {
|
|
if (!motor.b_start) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NotAllowed);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NotAllowed);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (motor_encoder_get_speed() > CONFIG_ZERO_SPEED_RPM) {
|
|
if (motor_encoder_get_speed() > CONFIG_ZERO_SPEED_RPM) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NowAllowed_With_Speed);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (!mc_throttle_released()) {
|
|
if (!mc_throttle_released()) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_Throttle_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_Throttle_Err);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
u32 mask = cpu_enter_critical();
|
|
u32 mask = cpu_enter_critical();
|
|
@@ -600,16 +630,16 @@ bool mc_start_epm(bool epm) {
|
|
|
motor.f_epm_trq = 0.0f;
|
|
motor.f_epm_trq = 0.0f;
|
|
|
motor_encoder_band_epm(epm);
|
|
motor_encoder_band_epm(epm);
|
|
|
if (epm) {
|
|
if (epm) {
|
|
|
- eCtrl_set_TgtSpeed(0);
|
|
|
|
|
|
|
+ mot_contrl_set_target_vel(&motor.controller, 0);
|
|
|
motor.mode = CTRL_MODE_SPD;
|
|
motor.mode = CTRL_MODE_SPD;
|
|
|
motor.epm_dir = EPM_Dir_None;
|
|
motor.epm_dir = EPM_Dir_None;
|
|
|
- PMSM_FOC_TorqueLimit(mc_conf()->c.max_epm_torque);
|
|
|
|
|
- PMSM_FOC_SetCtrlMode(CTRL_MODE_SPD);
|
|
|
|
|
|
|
+ mot_contrl_set_torque_limit(&motor.controller, mc_conf()->c.max_epm_torque);
|
|
|
|
|
+ mot_contrl_request_mode(&motor.controller, CTRL_MODE_SPD);
|
|
|
}else {
|
|
}else {
|
|
|
motor.epm_dir = EPM_Dir_None;
|
|
motor.epm_dir = EPM_Dir_None;
|
|
|
motor.mode = CTRL_MODE_TRQ;
|
|
motor.mode = CTRL_MODE_TRQ;
|
|
|
motor.b_epm_cmd_move = false;
|
|
motor.b_epm_cmd_move = false;
|
|
|
- PMSM_FOC_SetCtrlMode(CTRL_MODE_TRQ);
|
|
|
|
|
|
|
+ mot_contrl_request_mode(&motor.controller, CTRL_MODE_TRQ);
|
|
|
mc_gear_vmode_changed();
|
|
mc_gear_vmode_changed();
|
|
|
}
|
|
}
|
|
|
cpu_exit_critical(mask);
|
|
cpu_exit_critical(mask);
|
|
@@ -622,12 +652,12 @@ bool mc_is_epm(void) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool mc_is_start(void) {
|
|
bool mc_is_start(void) {
|
|
|
- return (motor.b_start || PMSM_FOC_Is_Start());
|
|
|
|
|
|
|
+ return (motor.b_start || mot_contrl_is_start(&motor.controller));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool mc_start_epm_move(EPM_Dir_t dir, bool is_command) {
|
|
|
|
|
|
|
+bool mc_start_epm_move(epm_dir_t dir, bool is_command) {
|
|
|
if (!motor.b_epm || !motor.b_start) {
|
|
if (!motor.b_epm || !motor.b_start) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NotAllowed);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NotAllowed);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if ((dir == motor.epm_dir) && (is_command == motor.b_epm_cmd_move)) {
|
|
if ((dir == motor.epm_dir) && (is_command == motor.b_epm_cmd_move)) {
|
|
@@ -642,35 +672,23 @@ bool mc_start_epm_move(EPM_Dir_t dir, bool is_command) {
|
|
|
if (dir != EPM_Dir_None) {
|
|
if (dir != EPM_Dir_None) {
|
|
|
motor.b_epm_cmd_move = is_command;
|
|
motor.b_epm_cmd_move = is_command;
|
|
|
|
|
|
|
|
- if (!PMSM_FOC_Is_Start()) {
|
|
|
|
|
- PMSM_FOC_Start(motor.mode);
|
|
|
|
|
|
|
+ if (!mot_contrl_is_start(&motor.controller)) {
|
|
|
|
|
+ mot_contrl_start(&motor.controller, motor.mode);
|
|
|
pwm_enable_channel();
|
|
pwm_enable_channel();
|
|
|
- }else if (PMSM_FOC_AutoHoldding()) {
|
|
|
|
|
|
|
+ }else if (mot_contrl_is_auto_holdding(&motor.controller)) {
|
|
|
mc_auto_hold(false);
|
|
mc_auto_hold(false);
|
|
|
}
|
|
}
|
|
|
if (dir == EPM_Dir_Back) {
|
|
if (dir == EPM_Dir_Back) {
|
|
|
-#ifdef CONFIG_SPEED_LADRC
|
|
|
|
|
- PMSM_FOC_Change_VelLoop_Params(CONFIG_LADRC_EPM_Wcv, CONFIG_LADRC_EPMBK_B0);
|
|
|
|
|
-#else
|
|
|
|
|
- PMSM_FOC_Change_VelLoop_Params(0.2f, 7.5f);
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+ mot_contrl_velloop_params(&motor.controller, 0.2f, 7.5f);
|
|
|
}else {
|
|
}else {
|
|
|
-#ifdef CONFIG_SPEED_LADRC
|
|
|
|
|
- PMSM_FOC_Change_VelLoop_Params(CONFIG_LADRC_EPM_Wcv, CONFIG_LADRC_EPM_B0);
|
|
|
|
|
-#else
|
|
|
|
|
- PMSM_FOC_Change_VelLoop_Params(0.2f, 7.5f);
|
|
|
|
|
-#endif
|
|
|
|
|
|
|
+ mot_contrl_velloop_params(&motor.controller, 0.2f, 7.5f);
|
|
|
}
|
|
}
|
|
|
- PMSM_FOC_TorqueLimit(motor.f_epm_trq);
|
|
|
|
|
- PMSM_FOC_Set_TgtSpeed(motor.f_epm_vel);
|
|
|
|
|
|
|
+ mot_contrl_set_torque_limit(&motor.controller, motor.f_epm_trq);
|
|
|
|
|
+ mot_contrl_set_target_vel(&motor.controller, motor.f_epm_vel);
|
|
|
}else {
|
|
}else {
|
|
|
motor.b_epm_cmd_move = false;
|
|
motor.b_epm_cmd_move = false;
|
|
|
-#ifdef CONFIG_SPEED_LADRC
|
|
|
|
|
- PMSM_FOC_Change_VelLoop_Params(nv_get_foc_params()->f_adrc_vel_Wcv, nv_get_foc_params()->f_adrc_vel_B0);
|
|
|
|
|
-#else
|
|
|
|
|
- PMSM_FOC_Change_VelLoop_Params(mc_conf()->c.pid[PID_Vel_ID].kp, mc_conf()->c.pid[PID_Vel_ID].ki);
|
|
|
|
|
-#endif
|
|
|
|
|
- PMSM_FOC_Set_TgtSpeed(0);
|
|
|
|
|
|
|
+ mot_contrl_velloop_params(&motor.controller, mc_conf()->c.pid[PID_Vel_ID].kp, mc_conf()->c.pid[PID_Vel_ID].ki);
|
|
|
|
|
+ mot_contrl_set_target_vel(&motor.controller, 0);
|
|
|
}
|
|
}
|
|
|
cpu_exit_critical(mask);
|
|
cpu_exit_critical(mask);
|
|
|
return true;
|
|
return true;
|
|
@@ -690,11 +708,11 @@ void mc_set_fan_duty(u8 duty) {
|
|
|
fan_set_duty(duty);
|
|
fan_set_duty(duty);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool mc_command_epm_move(EPM_Dir_t dir) {
|
|
|
|
|
|
|
+bool mc_command_epm_move(epm_dir_t dir) {
|
|
|
return mc_start_epm_move(dir, true);
|
|
return mc_start_epm_move(dir, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool mc_throttle_epm_move(EPM_Dir_t dir) {
|
|
|
|
|
|
|
+bool mc_throttle_epm_move(epm_dir_t dir) {
|
|
|
return mc_start_epm_move(dir, false);
|
|
return mc_start_epm_move(dir, false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -713,7 +731,7 @@ void mc_use_throttle(void) {
|
|
|
|
|
|
|
|
void mc_get_running_status(u8 *data) {
|
|
void mc_get_running_status(u8 *data) {
|
|
|
data[0] = motor.mode;
|
|
data[0] = motor.mode;
|
|
|
- data[0] |= (PMSM_FOC_AutoHoldding()?1:0) << 2;
|
|
|
|
|
|
|
+ data[0] |= (mot_contrl_is_auto_holdding(&motor.controller)?1:0) << 2;
|
|
|
data[0] |= (motor.b_break?1:0) << 3;
|
|
data[0] |= (motor.b_break?1:0) << 3;
|
|
|
data[0] |= (motor.b_cruise?1:0) << 4;
|
|
data[0] |= (motor.b_cruise?1:0) << 4;
|
|
|
data[0] |= (motor.b_start?1:0) << 5;
|
|
data[0] |= (motor.b_start?1:0) << 5;
|
|
@@ -725,18 +743,18 @@ u16 mc_get_running_status2(void) {
|
|
|
u16 data = 0;
|
|
u16 data = 0;
|
|
|
data = motor.b_start?1:0;
|
|
data = motor.b_start?1:0;
|
|
|
data |= (motor.n_gear & 0x7) << 1;
|
|
data |= (motor.n_gear & 0x7) << 1;
|
|
|
- data |= (PMSM_FOC_AutoHoldding()?1:0) << 3;
|
|
|
|
|
|
|
+ data |= (mot_contrl_is_auto_holdding(&motor.controller)?1:0) << 3;
|
|
|
data |= (motor.b_break?1:0) << 4;
|
|
data |= (motor.b_break?1:0) << 4;
|
|
|
data |= (motor.b_cruise?1:0) << 5;
|
|
data |= (motor.b_cruise?1:0) << 5;
|
|
|
data |= (mc_is_epm()?1:0) << 6;
|
|
data |= (mc_is_epm()?1:0) << 6;
|
|
|
data |= (motor.b_lock_motor) << 7; //motor locked
|
|
data |= (motor.b_lock_motor) << 7; //motor locked
|
|
|
- data |= (eCtrl_is_eBrk_Running()?1:0) << 8; //能量回收运行标志
|
|
|
|
|
|
|
+ data |= (mot_contrl_ebrk_is_running(&motor.controller)?1:0) << 8; //能量回收运行标志
|
|
|
data |= ((motor.n_CritiCalErrMask != 0)?1:0) << 9;
|
|
data |= ((motor.n_CritiCalErrMask != 0)?1:0) << 9;
|
|
|
data |= (fan_pwm_is_running()?1:0) << 10; //风扇是否运行
|
|
data |= (fan_pwm_is_running()?1:0) << 10; //风扇是否运行
|
|
|
data |= (motor.b_runStall?1:0) << 11; //是否堵转
|
|
data |= (motor.b_runStall?1:0) << 11; //是否堵转
|
|
|
- data |= (PMSM_FOC_iDC_is_Limited()?1:0) << 12; //是否欠压限制母线电流
|
|
|
|
|
- data |= (PMSM_FOC_Torque_is_Limited()?1:0) << 13; //是否高温限扭矩
|
|
|
|
|
- data |= (etcs_is_running()?1:0) << 14; //电子tcs是否正在工作
|
|
|
|
|
|
|
+ data |= (mot_contrl_dccurr_is_protected(&motor.controller)?1:0) << 12; //是否欠压限制母线电流
|
|
|
|
|
+ data |= (mot_contrl_torque_is_protected(&motor.controller)?1:0) << 13; //是否高温限扭矩
|
|
|
|
|
+ data |= (etcs_is_running(&motor.controller.ects)?1:0) << 14; //电子tcs是否正在工作
|
|
|
data |= (throttle_not_released_err()?1:0) << 15;
|
|
data |= (throttle_not_released_err()?1:0) << 15;
|
|
|
return data;
|
|
return data;
|
|
|
}
|
|
}
|
|
@@ -748,12 +766,12 @@ static int _force_wait = 2000;
|
|
|
void mc_force_run_open(s16 vd, s16 vq, bool align) {
|
|
void mc_force_run_open(s16 vd, s16 vq, bool align) {
|
|
|
if (motor.b_start || motor.b_force_run) {
|
|
if (motor.b_start || motor.b_force_run) {
|
|
|
if (vd == 0 && vq == 0) {
|
|
if (vd == 0 && vq == 0) {
|
|
|
- PMSM_FOC_SetOpenVdq(0, 0);
|
|
|
|
|
|
|
+ mot_contrl_set_vdq(&motor.controller, 0, 0);
|
|
|
delay_ms(500);
|
|
delay_ms(500);
|
|
|
wdog_reload();
|
|
wdog_reload();
|
|
|
adc_stop_convert();
|
|
adc_stop_convert();
|
|
|
pwm_stop();
|
|
pwm_stop();
|
|
|
- PMSM_FOC_Stop();
|
|
|
|
|
|
|
+ mot_contrl_stop(&motor.controller);
|
|
|
pwm_up_enable(true);
|
|
pwm_up_enable(true);
|
|
|
motor.b_force_run = false;
|
|
motor.b_force_run = false;
|
|
|
motor.b_ignor_throttle = false;
|
|
motor.b_ignor_throttle = false;
|
|
@@ -766,20 +784,20 @@ void mc_force_run_open(s16 vd, s16 vq, bool align) {
|
|
|
motor.b_ignor_throttle = true;
|
|
motor.b_ignor_throttle = true;
|
|
|
MC_Check_MosVbusThrottle();
|
|
MC_Check_MosVbusThrottle();
|
|
|
if (mc_unsafe_critical_error()) {
|
|
if (mc_unsafe_critical_error()) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_Have_CritiCal_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_Have_CritiCal_Err);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pwm_up_enable(false);
|
|
pwm_up_enable(false);
|
|
|
pwm_turn_on_low_side();
|
|
pwm_turn_on_low_side();
|
|
|
task_udelay(500);
|
|
task_udelay(500);
|
|
|
- PMSM_FOC_Start(CTRL_MODE_OPEN);
|
|
|
|
|
|
|
+ mot_contrl_start(&motor.controller, CTRL_MODE_OPEN);
|
|
|
phase_current_offset_calibrate();
|
|
phase_current_offset_calibrate();
|
|
|
pwm_start();
|
|
pwm_start();
|
|
|
adc_start_convert();
|
|
adc_start_convert();
|
|
|
pwm_enable_channel();
|
|
pwm_enable_channel();
|
|
|
phase_current_calibrate_wait();
|
|
phase_current_calibrate_wait();
|
|
|
- PMSM_FOC_Set_MotAngle(0);
|
|
|
|
|
- PMSM_FOC_SetOpenVdq((float)vd, 0);
|
|
|
|
|
|
|
+ mot_contrl_set_angle(&motor.controller, 0);
|
|
|
|
|
+ mot_contrl_set_vdq(&motor.controller, (float)vd, 0);
|
|
|
if (align) {
|
|
if (align) {
|
|
|
_force_wait = 2000 + 1;
|
|
_force_wait = 2000 + 1;
|
|
|
}else {
|
|
}else {
|
|
@@ -796,30 +814,30 @@ bool mc_ind_motor_start(bool start) {
|
|
|
motor.b_ignor_throttle = true;
|
|
motor.b_ignor_throttle = true;
|
|
|
MC_Check_MosVbusThrottle();
|
|
MC_Check_MosVbusThrottle();
|
|
|
if (mc_unsafe_critical_error() || mot_params_flux_pending()) {
|
|
if (mc_unsafe_critical_error() || mot_params_flux_pending()) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_Have_CritiCal_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_Have_CritiCal_Err);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
pwm_up_enable(false);
|
|
pwm_up_enable(false);
|
|
|
pwm_turn_on_low_side();
|
|
pwm_turn_on_low_side();
|
|
|
task_udelay(500);
|
|
task_udelay(500);
|
|
|
- PMSM_FOC_Start(CTRL_MODE_OPEN);
|
|
|
|
|
|
|
+ mot_contrl_start(&motor.controller, CTRL_MODE_OPEN);
|
|
|
phase_current_offset_calibrate();
|
|
phase_current_offset_calibrate();
|
|
|
pwm_start();
|
|
pwm_start();
|
|
|
adc_start_convert();
|
|
adc_start_convert();
|
|
|
pwm_enable_channel();
|
|
pwm_enable_channel();
|
|
|
phase_current_calibrate_wait();
|
|
phase_current_calibrate_wait();
|
|
|
- PMSM_FOC_SetOpenVdq_Immediate(0, 0);
|
|
|
|
|
|
|
+ mot_contrl_set_vdq_immediate(&motor.controller, 0, 0);
|
|
|
motor.b_ind_start = start;
|
|
motor.b_ind_start = start;
|
|
|
}else {
|
|
}else {
|
|
|
u32 mask = cpu_enter_critical();
|
|
u32 mask = cpu_enter_critical();
|
|
|
motor.b_ind_start = start;
|
|
motor.b_ind_start = start;
|
|
|
- PMSM_FOC_SetOpenVdq(0, 0);
|
|
|
|
|
|
|
+ mot_contrl_set_vdq(&motor.controller, 0, 0);
|
|
|
cpu_exit_critical(mask);
|
|
cpu_exit_critical(mask);
|
|
|
delay_us(500);
|
|
delay_us(500);
|
|
|
wdog_reload();
|
|
wdog_reload();
|
|
|
adc_stop_convert();
|
|
adc_stop_convert();
|
|
|
pwm_stop();
|
|
pwm_stop();
|
|
|
- PMSM_FOC_Stop();
|
|
|
|
|
|
|
+ mot_contrl_stop(&motor.controller);
|
|
|
motor.mode = CTRL_MODE_OPEN;
|
|
motor.mode = CTRL_MODE_OPEN;
|
|
|
pwm_up_enable(true);
|
|
pwm_up_enable(true);
|
|
|
motor.b_ignor_throttle = false;
|
|
motor.b_ignor_throttle = false;
|
|
@@ -834,11 +852,11 @@ static void _encoder_zero_off_timer_handler(shark_timer_t *t){
|
|
|
}
|
|
}
|
|
|
float enc_off = 0.0f;
|
|
float enc_off = 0.0f;
|
|
|
float phase = motor_encoder_zero_phase_detect(&enc_off);
|
|
float phase = motor_encoder_zero_phase_detect(&enc_off);
|
|
|
- PMSM_FOC_SetOpenVdq(0, 0);
|
|
|
|
|
|
|
+ mot_contrl_set_vdq(&motor.controller, 0, 0);
|
|
|
delay_ms(50);
|
|
delay_ms(50);
|
|
|
adc_stop_convert();
|
|
adc_stop_convert();
|
|
|
pwm_stop();
|
|
pwm_stop();
|
|
|
- PMSM_FOC_Stop();
|
|
|
|
|
|
|
+ mot_contrl_stop(&motor.controller);
|
|
|
_mc_internal_init(CTRL_MODE_OPEN, false);
|
|
_mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
motor.b_calibrate = false;
|
|
motor.b_calibrate = false;
|
|
|
}
|
|
}
|
|
@@ -848,11 +866,11 @@ bool mc_encoder_zero_calibrate(s16 vd) {
|
|
|
if (vd == 0) {
|
|
if (vd == 0) {
|
|
|
encoder_clear_cnt_offset();
|
|
encoder_clear_cnt_offset();
|
|
|
shark_timer_cancel(&_encoder_zero_off_timer);
|
|
shark_timer_cancel(&_encoder_zero_off_timer);
|
|
|
- PMSM_FOC_SetOpenVdq(0, 0);
|
|
|
|
|
|
|
+ mot_contrl_set_vdq(&motor.controller, 0, 0);
|
|
|
delay_ms(500);
|
|
delay_ms(500);
|
|
|
adc_stop_convert();
|
|
adc_stop_convert();
|
|
|
pwm_stop();
|
|
pwm_stop();
|
|
|
- PMSM_FOC_Stop();
|
|
|
|
|
|
|
+ mot_contrl_stop(&motor.controller);
|
|
|
_mc_internal_init(CTRL_MODE_OPEN, false);
|
|
_mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
motor.b_calibrate = false;
|
|
motor.b_calibrate = false;
|
|
|
motor.b_ignor_throttle = false;
|
|
motor.b_ignor_throttle = false;
|
|
@@ -863,21 +881,21 @@ bool mc_encoder_zero_calibrate(s16 vd) {
|
|
|
motor.b_ignor_throttle = true;
|
|
motor.b_ignor_throttle = true;
|
|
|
MC_Check_MosVbusThrottle();
|
|
MC_Check_MosVbusThrottle();
|
|
|
if (mc_unsafe_critical_error()) {
|
|
if (mc_unsafe_critical_error()) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_Have_CritiCal_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_Have_CritiCal_Err);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
_mc_internal_init(CTRL_MODE_OPEN, true);
|
|
_mc_internal_init(CTRL_MODE_OPEN, true);
|
|
|
motor.b_calibrate = true;
|
|
motor.b_calibrate = true;
|
|
|
pwm_turn_on_low_side();
|
|
pwm_turn_on_low_side();
|
|
|
task_udelay(500);
|
|
task_udelay(500);
|
|
|
- PMSM_FOC_Start(CTRL_MODE_OPEN);
|
|
|
|
|
|
|
+ mot_contrl_start(&motor.controller, CTRL_MODE_OPEN);
|
|
|
phase_current_offset_calibrate();
|
|
phase_current_offset_calibrate();
|
|
|
pwm_start();
|
|
pwm_start();
|
|
|
adc_start_convert();
|
|
adc_start_convert();
|
|
|
pwm_enable_channel();
|
|
pwm_enable_channel();
|
|
|
phase_current_calibrate_wait();
|
|
phase_current_calibrate_wait();
|
|
|
- PMSM_FOC_Set_MotAngle(0);
|
|
|
|
|
- PMSM_FOC_SetOpenVdq(vd, 0);
|
|
|
|
|
|
|
+ mot_contrl_set_angle(&motor.controller, 0);
|
|
|
|
|
+ mot_contrl_set_vdq(&motor.controller, vd, 0);
|
|
|
|
|
|
|
|
shark_timer_post(&_encoder_zero_off_timer, 6*1000);
|
|
shark_timer_post(&_encoder_zero_off_timer, 6*1000);
|
|
|
|
|
|
|
@@ -901,12 +919,12 @@ bool mc_lock_motor(bool lock) {
|
|
|
int ret = true;
|
|
int ret = true;
|
|
|
u32 mask = cpu_enter_critical();
|
|
u32 mask = cpu_enter_critical();
|
|
|
if (motor.b_start) {
|
|
if (motor.b_start) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NotAllowed);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NotAllowed);
|
|
|
ret = false;
|
|
ret = false;
|
|
|
goto ml_ex_cri;
|
|
goto ml_ex_cri;
|
|
|
}
|
|
}
|
|
|
if (lock && (motor_encoder_get_speed() >= CONFIG_LOCK_MOTOR_MIN_RPM)) {
|
|
if (lock && (motor_encoder_get_speed() >= CONFIG_LOCK_MOTOR_MIN_RPM)) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NowAllowed_With_Speed);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NowAllowed_With_Speed);
|
|
|
ret = false;
|
|
ret = false;
|
|
|
goto ml_ex_cri;
|
|
goto ml_ex_cri;
|
|
|
}
|
|
}
|
|
@@ -928,25 +946,25 @@ bool mc_auto_hold(bool hold) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
if (!mc_conf()->s.auto_hold) {
|
|
if (!mc_conf()->s.auto_hold) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NotAllowed);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NotAllowed);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (!motor.b_start) {
|
|
if (!motor.b_start) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_NotAllowed);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_NotAllowed);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
if (hold && !mc_throttle_released()) {
|
|
if (hold && !mc_throttle_released()) {
|
|
|
- PMSM_FOC_SetErrCode(FOC_Throttle_Err);
|
|
|
|
|
|
|
+ mot_contrl_set_error(&motor.controller, FOC_Throttle_Err);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
u32 mask = cpu_enter_critical();
|
|
u32 mask = cpu_enter_critical();
|
|
|
motor.b_auto_hold = hold;
|
|
motor.b_auto_hold = hold;
|
|
|
- if (!PMSM_FOC_Is_Start()) {
|
|
|
|
|
- PMSM_FOC_Start(motor.mode);
|
|
|
|
|
- PMSM_FOC_AutoHold(hold);
|
|
|
|
|
|
|
+ if (!mot_contrl_is_start(&motor.controller)) {
|
|
|
|
|
+ mot_contrl_start(&motor.controller, motor.mode);
|
|
|
|
|
+ mot_contrl_set_autohold(&motor.controller, hold);
|
|
|
pwm_enable_channel();
|
|
pwm_enable_channel();
|
|
|
}else {
|
|
}else {
|
|
|
- PMSM_FOC_AutoHold(hold);
|
|
|
|
|
|
|
+ mot_contrl_set_autohold(&motor.controller, hold);
|
|
|
}
|
|
}
|
|
|
cpu_exit_critical(mask);
|
|
cpu_exit_critical(mask);
|
|
|
return true;
|
|
return true;
|
|
@@ -1067,9 +1085,9 @@ void MC_Brake_IRQHandler(void) {
|
|
|
}
|
|
}
|
|
|
if (motor.b_break) {
|
|
if (motor.b_break) {
|
|
|
mc_enable_cruise(false);
|
|
mc_enable_cruise(false);
|
|
|
- PMSM_FOC_Brake(true);
|
|
|
|
|
|
|
+ mot_contrl_set_hw_brake(&motor.controller, true);
|
|
|
}else {
|
|
}else {
|
|
|
- PMSM_FOC_Brake(false);
|
|
|
|
|
|
|
+ mot_contrl_set_hw_brake(&motor.controller, false);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1082,14 +1100,14 @@ static void mc_save_err_runtime(void) {
|
|
|
mc_error.vbus_x10 = (s16)(sample_vbus_raw() * 10.0f);
|
|
mc_error.vbus_x10 = (s16)(sample_vbus_raw() * 10.0f);
|
|
|
mc_error.ibus_x10 = (s16)(sample_ibus_raw() * 10.0f);
|
|
mc_error.ibus_x10 = (s16)(sample_ibus_raw() * 10.0f);
|
|
|
mc_error.vacc_x10 = (s16) (sample_acc_vol_raw() * 10.0f);
|
|
mc_error.vacc_x10 = (s16) (sample_acc_vol_raw() * 10.0f);
|
|
|
- mc_error.id_ref_x10 = (s16)(PMSM_FOC_Get()->idq_ctl[0].s_Cp * 10.0f);
|
|
|
|
|
- mc_error.iq_ref_x10 = (s16)(PMSM_FOC_Get()->idq_ctl[1].s_Cp * 10.0f);
|
|
|
|
|
- mc_error.id_x10 = (s16)(PMSM_FOC_Get()->out.s_RealIdq.d * 10.0f);
|
|
|
|
|
- mc_error.iq_x10 = (s16)(PMSM_FOC_Get()->out.s_RealIdq.q * 10.0f);
|
|
|
|
|
- mc_error.vd_x10 = (s16)(PMSM_FOC_Get()->out.s_OutVdq.d * 10.0f);
|
|
|
|
|
- mc_error.vq_x10 = (s16)(PMSM_FOC_Get()->out.s_OutVdq.q * 10.0f);
|
|
|
|
|
- mc_error.torque_ref_x10 = (s16)(PMSM_FOC_Get()->in.s_targetTorque * 10.0f);
|
|
|
|
|
- mc_error.run_mode = PMSM_FOC_Get()->out.n_RunMode;
|
|
|
|
|
|
|
+ mc_error.id_ref_x10 = (s16)(motor.controller.foc.ramp_curr_dq.d * 10.0f);
|
|
|
|
|
+ mc_error.iq_ref_x10 = (s16)(motor.controller.foc.ramp_curr_dq.q * 10.0f);
|
|
|
|
|
+ mc_error.id_x10 = (s16)(motor.controller.foc.out.curr_dq.d * 10.0f);
|
|
|
|
|
+ mc_error.iq_x10 = (s16)(motor.controller.foc.out.curr_dq.q * 10.0f);
|
|
|
|
|
+ mc_error.vd_x10 = (s16)(motor.controller.foc.out.vol_dq.d * 10.0f);
|
|
|
|
|
+ mc_error.vq_x10 = (s16)(motor.controller.foc.out.vol_dq.q * 10.0f);
|
|
|
|
|
+ mc_error.torque_ref_x10 = (s16)(motor.controller.target_torque * 10.0f);
|
|
|
|
|
+ mc_error.run_mode = motor.controller.mode_running;
|
|
|
mc_error.rpm = (s16)motor_encoder_get_speed();
|
|
mc_error.rpm = (s16)motor_encoder_get_speed();
|
|
|
mc_error.b_sensorless = !foc_observer_is_encoder();
|
|
mc_error.b_sensorless = !foc_observer_is_encoder();
|
|
|
mc_error.b_sensorless_stable = foc_observer_sensorless_stable();
|
|
mc_error.b_sensorless_stable = foc_observer_sensorless_stable();
|
|
@@ -1112,7 +1130,7 @@ void MC_Protect_IRQHandler(void){
|
|
|
_mc_internal_init(CTRL_MODE_OPEN, false);
|
|
_mc_internal_init(CTRL_MODE_OPEN, false);
|
|
|
adc_stop_convert();
|
|
adc_stop_convert();
|
|
|
pwm_stop();
|
|
pwm_stop();
|
|
|
- PMSM_FOC_Stop();
|
|
|
|
|
|
|
+ mot_contrl_stop(&motor.controller);
|
|
|
pwm_up_enable(true);
|
|
pwm_up_enable(true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1131,13 +1149,13 @@ static void motor_vbus_crit_low(s16 curr_vbus) {
|
|
|
if (curr_vbus < motor.s_vbus_hw_min) {
|
|
if (curr_vbus < motor.s_vbus_hw_min) {
|
|
|
_vbus_e_count ++;
|
|
_vbus_e_count ++;
|
|
|
if (_vbus_e_count >= 2) {
|
|
if (_vbus_e_count >= 2) {
|
|
|
- if (PMSM_FOC_Is_Start()) {
|
|
|
|
|
|
|
+ if (mot_contrl_is_start(&motor.controller)) {
|
|
|
pwm_disable_channel();
|
|
pwm_disable_channel();
|
|
|
mc_save_err_runtime();
|
|
mc_save_err_runtime();
|
|
|
- PMSM_FOC_Stop();
|
|
|
|
|
|
|
+ mot_contrl_stop(&motor.controller);
|
|
|
}
|
|
}
|
|
|
if (mc_set_critical_error(FOC_CRIT_Vol_HW_Err)) {
|
|
if (mc_set_critical_error(FOC_CRIT_Vol_HW_Err)) {
|
|
|
- if (PMSM_FOC_GetSpeed() > CONFIG_ZERO_SPEED_RPM) {
|
|
|
|
|
|
|
+ if (mot_contrl_get_speed(&motor.controller) > CONFIG_ZERO_SPEED_RPM) {
|
|
|
mc_crit_err_add_s16(FOC_CRIT_Vol_HW_Err, curr_vbus);
|
|
mc_crit_err_add_s16(FOC_CRIT_Vol_HW_Err, curr_vbus);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1148,7 +1166,7 @@ static void motor_vbus_crit_low(s16 curr_vbus) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void TIMER_UP_IRQHandler(void){
|
|
void TIMER_UP_IRQHandler(void){
|
|
|
- if (!motor.b_start && !PMSM_FOC_Is_Start()) {
|
|
|
|
|
|
|
+ if (!motor.b_start && !mot_contrl_is_start(&motor.controller)) {
|
|
|
motor_encoder_update(false);
|
|
motor_encoder_update(false);
|
|
|
motor_vbus_crit_low((s16)get_vbus_int());
|
|
motor_vbus_crit_low((s16)get_vbus_int());
|
|
|
}
|
|
}
|
|
@@ -1178,8 +1196,8 @@ void ADC_IRQHandler(void) {
|
|
|
|
|
|
|
|
#if (CONFIG_ENABLE_IAB_REC==1)
|
|
#if (CONFIG_ENABLE_IAB_REC==1)
|
|
|
if (b_iab_rec && (iab_w_count < CONFIG_IAB_REC_COUNT)) {
|
|
if (b_iab_rec && (iab_w_count < CONFIG_IAB_REC_COUNT)) {
|
|
|
- ia[iab_w_count] = (s16)PMSM_FOC_Get()->in.s_iABC[0];
|
|
|
|
|
- ib[iab_w_count] = (s16)PMSM_FOC_Get()->in.s_iABC[1];
|
|
|
|
|
|
|
+ ia[iab_w_count] = (s16)motor.controller.foc.in.curr_abc[0];
|
|
|
|
|
+ ib[iab_w_count] = (s16)motor.controller.foc.in.curr_abc[1];
|
|
|
iab_w_count ++;
|
|
iab_w_count ++;
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
@@ -1187,17 +1205,17 @@ void ADC_IRQHandler(void) {
|
|
|
float vd, vq;
|
|
float vd, vq;
|
|
|
if (motor.b_ind_start) {
|
|
if (motor.b_ind_start) {
|
|
|
mot_params_high_freq_inject();
|
|
mot_params_high_freq_inject();
|
|
|
- vd = PMSM_FOC_Get()->out.s_OutVdq.d;
|
|
|
|
|
- vq = PMSM_FOC_Get()->out.s_OutVdq.q;
|
|
|
|
|
|
|
+ vd = motor.controller.foc.out.vol_dq.d;
|
|
|
|
|
+ vq = motor.controller.foc.out.vol_dq.q;
|
|
|
}
|
|
}
|
|
|
- if (!PMSM_FOC_Schedule()) {/* FOC 角度错误,立即停机 */
|
|
|
|
|
- if (PMSM_FOC_Is_Start()) {
|
|
|
|
|
|
|
+ if (!mot_contrl_update(&motor.controller)) {/* FOC 角度错误,立即停机 */
|
|
|
|
|
+ if (mot_contrl_is_start(&motor.controller)) {
|
|
|
pwm_disable_channel();
|
|
pwm_disable_channel();
|
|
|
/* 记录错误 */
|
|
/* 记录错误 */
|
|
|
if (!foc_observer_is_force_sensorless()) {
|
|
if (!foc_observer_is_force_sensorless()) {
|
|
|
mc_save_err_runtime();
|
|
mc_save_err_runtime();
|
|
|
}
|
|
}
|
|
|
- PMSM_FOC_Stop();
|
|
|
|
|
|
|
+ mot_contrl_stop(&motor.controller);
|
|
|
g_meas_foc.first = true;
|
|
g_meas_foc.first = true;
|
|
|
if (!foc_observer_is_force_sensorless()) {
|
|
if (!foc_observer_is_force_sensorless()) {
|
|
|
if (mc_set_critical_error(FOC_CRIT_Angle_Err)) {
|
|
if (mc_set_critical_error(FOC_CRIT_Angle_Err)) {
|
|
@@ -1216,8 +1234,8 @@ void ADC_IRQHandler(void) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (motor.b_ind_start) {
|
|
if (motor.b_ind_start) {
|
|
|
- float id = PMSM_FOC_Get()->out.s_RealIdq.d;
|
|
|
|
|
- float iq = PMSM_FOC_Get()->out.s_RealIdq.q;
|
|
|
|
|
|
|
+ float id = motor.controller.foc.out.curr_dq.d;
|
|
|
|
|
+ float iq = motor.controller.foc.out.curr_dq.q;
|
|
|
mot_params_hj_sample_vi(vd, vq, id, iq);
|
|
mot_params_hj_sample_vi(vd, vq, id, iq);
|
|
|
}
|
|
}
|
|
|
TIME_MEATURE_END();
|
|
TIME_MEATURE_END();
|
|
@@ -1251,7 +1269,7 @@ void mc_start_current_rec(bool rec) {
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
static bool mc_run_stall_process(u8 run_mode) {
|
|
static bool mc_run_stall_process(u8 run_mode) {
|
|
|
- if ((run_mode == CTRL_MODE_TRQ || run_mode == CTRL_MODE_SPD) && !PMSM_FOC_AutoHoldding()) {
|
|
|
|
|
|
|
+ if ((run_mode == CTRL_MODE_TRQ || run_mode == CTRL_MODE_SPD) && !mot_contrl_is_auto_holdding(&motor.controller)) {
|
|
|
//堵转判断
|
|
//堵转判断
|
|
|
if (motor.b_runStall) {
|
|
if (motor.b_runStall) {
|
|
|
if (!mc_throttle_released()) {
|
|
if (!mc_throttle_released()) {
|
|
@@ -1259,8 +1277,8 @@ static bool mc_run_stall_process(u8 run_mode) {
|
|
|
}
|
|
}
|
|
|
motor.runStall_time = 0;
|
|
motor.runStall_time = 0;
|
|
|
motor.b_runStall = false; //转把释放,清除堵转标志
|
|
motor.b_runStall = false; //转把释放,清除堵转标志
|
|
|
- }else if (PMSM_FOC_Get_Real_dqVector() >= CONFIG_STALL_MAX_CURRENT){
|
|
|
|
|
- if (ABS(PMSM_FOC_GetSpeed()) < 1.0f && (motor.runStall_time == 0)) {
|
|
|
|
|
|
|
+ }else if (mot_contrl_get_current_vector(&motor.controller) >= CONFIG_STALL_MAX_CURRENT){
|
|
|
|
|
+ if (ABS(mot_contrl_get_speed(&motor.controller)) < 1.0f && (motor.runStall_time == 0)) {
|
|
|
motor.runStall_time = get_tick_ms();
|
|
motor.runStall_time = get_tick_ms();
|
|
|
motor.runStall_pos = motor_encoder_get_position();
|
|
motor.runStall_pos = motor_encoder_get_position();
|
|
|
}
|
|
}
|
|
@@ -1268,8 +1286,8 @@ static bool mc_run_stall_process(u8 run_mode) {
|
|
|
if (get_delta_ms(motor.runStall_time) >= CONFIG_STALL_MAX_TIME) {
|
|
if (get_delta_ms(motor.runStall_time) >= CONFIG_STALL_MAX_TIME) {
|
|
|
motor.b_runStall = true;
|
|
motor.b_runStall = true;
|
|
|
motor.runStall_time = 0;
|
|
motor.runStall_time = 0;
|
|
|
- PMSM_FOC_Set_Torque(0);
|
|
|
|
|
- thro_torque_reset();
|
|
|
|
|
|
|
+ mot_contrl_set_torque(&motor.controller, 0);
|
|
|
|
|
+ throttle_torque_reset();
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
if (ABS(motor.runStall_pos - motor_encoder_get_position()) >= 0.2f) {
|
|
if (ABS(motor.runStall_pos - motor_encoder_get_position()) >= 0.2f) {
|
|
@@ -1285,12 +1303,12 @@ static bool mc_run_stall_process(u8 run_mode) {
|
|
|
|
|
|
|
|
static void mc_autohold_process(void) {
|
|
static void mc_autohold_process(void) {
|
|
|
if (!mc_conf()->s.auto_hold) {
|
|
if (!mc_conf()->s.auto_hold) {
|
|
|
- if (PMSM_FOC_AutoHoldding()) {
|
|
|
|
|
|
|
+ if (mot_contrl_is_auto_holdding(&motor.controller)) {
|
|
|
mc_auto_hold(false);
|
|
mc_auto_hold(false);
|
|
|
}
|
|
}
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (PMSM_FOC_AutoHoldding()) {
|
|
|
|
|
|
|
+ if (mot_contrl_is_auto_holdding(&motor.controller)) {
|
|
|
if (!mc_throttle_released()) {
|
|
if (!mc_throttle_released()) {
|
|
|
mc_auto_hold(false);
|
|
mc_auto_hold(false);
|
|
|
motor.b_wait_brk_release = false;
|
|
motor.b_wait_brk_release = false;
|
|
@@ -1300,7 +1318,7 @@ static void mc_autohold_process(void) {
|
|
|
mc_auto_hold(false);
|
|
mc_auto_hold(false);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (!PMSM_FOC_AutoHoldding() && motor.b_break && (motor_encoder_get_speed() == 0)) {
|
|
|
|
|
|
|
+ if (!mot_contrl_is_auto_holdding(&motor.controller) && motor.b_break && (motor_encoder_get_speed() == 0)) {
|
|
|
if (motor.n_autohold_time == 0) {
|
|
if (motor.n_autohold_time == 0) {
|
|
|
motor.n_autohold_time = get_tick_ms();
|
|
motor.n_autohold_time = get_tick_ms();
|
|
|
}else {
|
|
}else {
|
|
@@ -1336,13 +1354,13 @@ static void mc_process_epm_move(void) {
|
|
|
target_vel = -mc_conf()->c.max_epm_back_rpm;
|
|
target_vel = -mc_conf()->c.max_epm_back_rpm;
|
|
|
target_trq = mc_conf()->c.max_epm_back_torque;
|
|
target_trq = mc_conf()->c.max_epm_back_torque;
|
|
|
}else if (!motor.b_epm_cmd_move) {
|
|
}else if (!motor.b_epm_cmd_move) {
|
|
|
- target_vel = get_throttle_ration(throttle_get_signal()) * 2.0f * (float)target_vel;
|
|
|
|
|
|
|
+ target_vel = throttle_vol_to_open_ration(throttle_get_signal()) * 2.0f * (float)target_vel;
|
|
|
step = 0.07f;
|
|
step = 0.07f;
|
|
|
}
|
|
}
|
|
|
step_towards(&motor.f_epm_vel, target_vel, step);
|
|
step_towards(&motor.f_epm_vel, target_vel, step);
|
|
|
motor.f_epm_trq = target_trq;
|
|
motor.f_epm_trq = target_trq;
|
|
|
- PMSM_FOC_TorqueLimit(motor.f_epm_trq);
|
|
|
|
|
- PMSM_FOC_Set_TgtSpeed(motor.f_epm_vel);
|
|
|
|
|
|
|
+ mot_contrl_set_torque_limit(&motor.controller, motor.f_epm_trq);
|
|
|
|
|
+ mot_contrl_set_target_vel(&motor.controller, motor.f_epm_vel);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static bool mc_process_force_running(void) {
|
|
static bool mc_process_force_running(void) {
|
|
@@ -1353,7 +1371,7 @@ static bool mc_process_force_running(void) {
|
|
|
}else {
|
|
}else {
|
|
|
_force_angle += 1.5f;
|
|
_force_angle += 1.5f;
|
|
|
rand_angle(_force_angle);
|
|
rand_angle(_force_angle);
|
|
|
- PMSM_FOC_Set_MotAngle(_force_angle);
|
|
|
|
|
|
|
+ mot_contrl_set_angle(&motor.controller, _force_angle);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
@@ -1363,7 +1381,7 @@ static bool mc_process_force_running(void) {
|
|
|
|
|
|
|
|
static void mc_process_brake_light(void) {
|
|
static void mc_process_brake_light(void) {
|
|
|
bool can_lighting = false;
|
|
bool can_lighting = false;
|
|
|
- if (motor.b_break || motor.b_auto_hold || eCtrl_is_eBrk_Running() || ((!mc_critical_can_not_run()) && motor_encoder_get_speed() > 2000)) {
|
|
|
|
|
|
|
+ if (motor.b_break || motor.b_auto_hold || mot_contrl_ebrk_is_running(&motor.controller) || ((!mc_critical_can_not_run()) && motor_encoder_get_speed() > 2000)) {
|
|
|
can_lighting = true;
|
|
can_lighting = true;
|
|
|
}
|
|
}
|
|
|
gpio_brk_light_enable(can_lighting);
|
|
gpio_brk_light_enable(can_lighting);
|
|
@@ -1373,8 +1391,8 @@ static void mc_process_brake_light(void) {
|
|
|
static void mc_process_curise(void) {
|
|
static void mc_process_curise(void) {
|
|
|
static bool can_pause_resume = false;
|
|
static bool can_pause_resume = false;
|
|
|
if (motor.b_cruise) {
|
|
if (motor.b_cruise) {
|
|
|
- if (PMSM_FOC_GetSpeed() < CONFIG_CRUISE_EXIT_RPM) {
|
|
|
|
|
- mc_enable_cruise(false);
|
|
|
|
|
|
|
+ if (mot_contrl_get_speed(&motor.controller) < CONFIG_CRUISE_EXIT_RPM) {
|
|
|
|
|
+ mot_contrl_set_cruise(&motor.controller, false);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
/* 定速巡航模式下,必须转把归位后才能开始通过拧动转把加速 */
|
|
/* 定速巡航模式下,必须转把归位后才能开始通过拧动转把加速 */
|
|
@@ -1384,25 +1402,24 @@ static void mc_process_curise(void) {
|
|
|
if (!can_pause_resume) {
|
|
if (!can_pause_resume) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (PMSM_FOC_Is_CruiseEnabled()) {
|
|
|
|
|
|
|
+ if (mot_contrl_is_cruise_enabled(&motor.controller)) {
|
|
|
u32 cruise_time = shark_get_seconds() - motor.cruise_time;
|
|
u32 cruise_time = shark_get_seconds() - motor.cruise_time;
|
|
|
if ((cruise_time >= 3) && motor.cruise_torque == 0.0f) {
|
|
if ((cruise_time >= 3) && motor.cruise_torque == 0.0f) {
|
|
|
- motor.cruise_torque = PMSM_FOC_Get()->in.s_targetTorque;
|
|
|
|
|
|
|
+ motor.cruise_torque = motor.controller.target_torque;
|
|
|
}else if ((cruise_time >= 3) && (motor.cruise_torque > 0.0f)){
|
|
}else if ((cruise_time >= 3) && (motor.cruise_torque > 0.0f)){
|
|
|
float trq_req = get_user_request_torque();
|
|
float trq_req = get_user_request_torque();
|
|
|
if (trq_req > motor.cruise_torque * 1.2f) {
|
|
if (trq_req > motor.cruise_torque * 1.2f) {
|
|
|
- PMSM_FOC_PauseCruise(); //需要加速,暂停定速巡航
|
|
|
|
|
|
|
+ mot_contrl_pause_cruise(&motor.controller); //需要加速,暂停定速巡航
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}else {
|
|
}else {
|
|
|
float trq_req = get_user_request_torque();
|
|
float trq_req = get_user_request_torque();
|
|
|
if (trq_req <= motor.cruise_torque * 1.1f) {
|
|
if (trq_req <= motor.cruise_torque * 1.1f) {
|
|
|
- PMSM_FOC_ResumeCruise(); //重新开始定速巡航,巡航速度还是前一次定速巡航给的速度
|
|
|
|
|
- //motor.cruise_time = shark_get_seconds();
|
|
|
|
|
|
|
+ mot_contrl_resume_cruise(&motor.controller); //重新开始定速巡航,巡航速度还是前一次定速巡航给的速度
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}else {
|
|
}else {
|
|
|
- PMSM_FOC_EnableCruise(false);
|
|
|
|
|
|
|
+ mot_contrl_set_cruise(&motor.controller, false);
|
|
|
can_pause_resume = false;
|
|
can_pause_resume = false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1423,8 +1440,8 @@ static bool mc_can_stop_foc(void) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (mc_throttle_released() && PMSM_FOC_GetSpeed() == 0.0f) {
|
|
|
|
|
- if (!PMSM_FOC_AutoHoldding() && motor.epm_dir == EPM_Dir_None) {
|
|
|
|
|
|
|
+ if (mc_throttle_released() && mot_contrl_get_speed(&motor.controller) == 0.0f) {
|
|
|
|
|
+ if (!mot_contrl_is_auto_holdding(&motor.controller) && motor.epm_dir == EPM_Dir_None) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1450,24 +1467,49 @@ static bool mc_can_restart_foc(void) {
|
|
|
|
|
|
|
|
static void mc_motor_runstop(void) {
|
|
static void mc_motor_runstop(void) {
|
|
|
u32 mask;
|
|
u32 mask;
|
|
|
- if (PMSM_FOC_Is_Start() && mc_can_stop_foc()) {
|
|
|
|
|
|
|
+ if (mot_contrl_is_start(&motor.controller) && mc_can_stop_foc()) {
|
|
|
mask = cpu_enter_critical();
|
|
mask = cpu_enter_critical();
|
|
|
- PMSM_FOC_Stop();
|
|
|
|
|
|
|
+ mot_contrl_stop(&motor.controller);
|
|
|
pwm_disable_channel();
|
|
pwm_disable_channel();
|
|
|
g_meas_foc.first = true;
|
|
g_meas_foc.first = true;
|
|
|
cpu_exit_critical(mask);
|
|
cpu_exit_critical(mask);
|
|
|
}
|
|
}
|
|
|
- if (!PMSM_FOC_Is_Start() && mc_can_restart_foc()) {
|
|
|
|
|
|
|
+ if (!mot_contrl_is_start(&motor.controller) && mc_can_restart_foc()) {
|
|
|
mask = cpu_enter_critical();
|
|
mask = cpu_enter_critical();
|
|
|
- PMSM_FOC_Start(motor.mode);
|
|
|
|
|
|
|
+ mot_contrl_start(&motor.controller, motor.mode);
|
|
|
mc_gear_vmode_changed();
|
|
mc_gear_vmode_changed();
|
|
|
- thro_torque_reset();
|
|
|
|
|
|
|
+ throttle_torque_reset();
|
|
|
pwm_enable_channel();
|
|
pwm_enable_channel();
|
|
|
g_meas_foc.first = true;
|
|
g_meas_foc.first = true;
|
|
|
cpu_exit_critical(mask);
|
|
cpu_exit_critical(mask);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+static void mc_process_throttle_torque(float vol) {
|
|
|
|
|
+ float torque = throttle_get_torque(&motor.controller, vol);
|
|
|
|
|
+ if (motor.controller.mode_running == CTRL_MODE_TRQ) {
|
|
|
|
|
+ throttle_set_torque(&motor.controller, torque);
|
|
|
|
|
+ }else if (motor.controller.mode_running == CTRL_MODE_SPD) {
|
|
|
|
|
+ if (!mc_is_cruise_enabled()) {
|
|
|
|
|
+ float vel_ref = motor.controller.userlim.mot_vel * throttle_get_open_ration_filted();
|
|
|
|
|
+ mot_contrl_set_target_vel(&motor.controller, vel_ref);
|
|
|
|
|
+ }
|
|
|
|
|
+ }else if (motor.controller.mode_running == CTRL_MODE_EBRAKE){
|
|
|
|
|
+ float vel = mot_contrl_get_speed(&motor.controller);
|
|
|
|
|
+ float ebrk_trq = motor_get_ebreak_toruqe(vel);
|
|
|
|
|
+
|
|
|
|
|
+ if (ebrk_trq >= -mot_contrl_get_ebrk_torque(&motor.controller)/2){
|
|
|
|
|
+ mot_contrl_set_ebrk_time(&motor.controller, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ebrk_trq != 0) {
|
|
|
|
|
+ mot_contrl_set_torque(&motor.controller, ebrk_trq);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((mot_contrl_get_final_torque(&motor.controller) < 0.0001f && vel < CONFIG_MIN_RPM_EXIT_EBRAKE) ||
|
|
|
|
|
+ (!mc_throttle_released() || (mc_throttle_released() && (vel == 0.0f)))) {
|
|
|
|
|
+ mot_contrl_energy_recovery(&motor.controller, false);
|
|
|
|
|
+ throttle_torque_reset();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
/*FOC 的部分处理,比如速度环,状态机,转把采集等*/
|
|
/*FOC 的部分处理,比如速度环,状态机,转把采集等*/
|
|
|
measure_time_t g_meas_MCTask;
|
|
measure_time_t g_meas_MCTask;
|
|
|
#define mc_TaskStart time_measure_start(&g_meas_MCTask)
|
|
#define mc_TaskStart time_measure_start(&g_meas_MCTask)
|
|
@@ -1486,14 +1528,14 @@ void Sched_MC_mTask(void) {
|
|
|
#ifdef CONFIG_CRUISE_ENABLE_ACCL
|
|
#ifdef CONFIG_CRUISE_ENABLE_ACCL
|
|
|
mc_process_curise();
|
|
mc_process_curise();
|
|
|
#endif
|
|
#endif
|
|
|
- u8 runMode = PMSM_FOC_CtrlMode();
|
|
|
|
|
|
|
+ u8 runMode = mot_contrl_mode(&motor.controller);
|
|
|
|
|
|
|
|
/*保护功能*/
|
|
/*保护功能*/
|
|
|
- u8 limted = PMSM_FOC_RunTime_Limit();
|
|
|
|
|
|
|
+ u8 limted = mot_contrl_protect(&motor.controller);
|
|
|
/* 母线电流,实际采集的相电流矢量大小的计算 */
|
|
/* 母线电流,实际采集的相电流矢量大小的计算 */
|
|
|
- PMSM_FOC_Calc_Current();
|
|
|
|
|
|
|
+ mot_contrl_calc_current(&motor.controller);
|
|
|
|
|
|
|
|
- if ((PMSM_FOC_GetVbusCurrent() > (CONFIG_HW_MAX_DC_CURRENT * 1.1f)) || (PMSM_FOC_GetVbusCurrent() < CONFIG_HW_MAX_CHRG_CURRENT)) {
|
|
|
|
|
|
|
+ if ((mot_contrl_get_dc_current(&motor.controller) > (CONFIG_HW_MAX_DC_CURRENT * 1.1f)) || (mot_contrl_get_dc_current(&motor.controller) < CONFIG_HW_MAX_CHRG_CURRENT)) {
|
|
|
vbus_err_cnt ++;
|
|
vbus_err_cnt ++;
|
|
|
if (vbus_err_cnt >= 5) {
|
|
if (vbus_err_cnt >= 5) {
|
|
|
if (mc_set_critical_error(FOC_CRIT_IDC_OV)) {
|
|
if (mc_set_critical_error(FOC_CRIT_IDC_OV)) {
|
|
@@ -1534,8 +1576,7 @@ void Sched_MC_mTask(void) {
|
|
|
}
|
|
}
|
|
|
/* 堵转处理 */
|
|
/* 堵转处理 */
|
|
|
if (mc_run_stall_process(runMode) || (motor.mode == CTRL_MODE_CURRENT)) {
|
|
if (mc_run_stall_process(runMode) || (motor.mode == CTRL_MODE_CURRENT)) {
|
|
|
- eCtrl_Running();
|
|
|
|
|
- PMSM_FOC_Slow_Task();
|
|
|
|
|
|
|
+ mot_contrl_slow_task(&motor.controller);
|
|
|
mc_motor_runstop();
|
|
mc_motor_runstop();
|
|
|
if (motor.b_ind_start) {
|
|
if (motor.b_ind_start) {
|
|
|
mot_params_flux_stop();
|
|
mot_params_flux_stop();
|
|
@@ -1553,24 +1594,22 @@ void Sched_MC_mTask(void) {
|
|
|
mc_motor_runstop();
|
|
mc_motor_runstop();
|
|
|
}
|
|
}
|
|
|
if (runMode != CTRL_MODE_OPEN) {
|
|
if (runMode != CTRL_MODE_OPEN) {
|
|
|
- eCtrl_Running();
|
|
|
|
|
if (runMode == CTRL_MODE_SPD) {
|
|
if (runMode == CTRL_MODE_SPD) {
|
|
|
if (mc_is_epm()) {
|
|
if (mc_is_epm()) {
|
|
|
mc_process_throttle_epm();
|
|
mc_process_throttle_epm();
|
|
|
mc_process_epm_move();
|
|
mc_process_epm_move();
|
|
|
}else if (motor.s_target_speed != MAX_S16) {
|
|
}else if (motor.s_target_speed != MAX_S16) {
|
|
|
- PMSM_FOC_Set_TgtSpeed(motor.s_target_speed);
|
|
|
|
|
|
|
+ mot_contrl_set_target_vel(&motor.controller, motor.s_target_speed);
|
|
|
}
|
|
}
|
|
|
}else {
|
|
}else {
|
|
|
float thro = throttle_get_signal();
|
|
float thro = throttle_get_signal();
|
|
|
if (motor.b_ignor_throttle) {
|
|
if (motor.b_ignor_throttle) {
|
|
|
float r = (float)motor.u_throttle_ration/100.0f;
|
|
float r = (float)motor.u_throttle_ration/100.0f;
|
|
|
- thro = thro_ration_to_voltage(r);
|
|
|
|
|
|
|
+ thro = throttle_open_ration_to_vol(r);
|
|
|
}
|
|
}
|
|
|
- thro_torque_process(runMode, thro);
|
|
|
|
|
|
|
+ mc_process_throttle_torque(thro);
|
|
|
}
|
|
}
|
|
|
- etcs_process();
|
|
|
|
|
- PMSM_FOC_Slow_Task();
|
|
|
|
|
|
|
+ mot_contrl_slow_task(&motor.controller);
|
|
|
}
|
|
}
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|