|
|
@@ -12,6 +12,7 @@
|
|
|
static void mot_contrl_pid(mot_contrl_t *ctrl);
|
|
|
static void mot_contrl_ulimit(mot_contrl_t *ctrl);
|
|
|
static void mot_contrl_rtlimit(mot_contrl_t *ctrl);
|
|
|
+static bool is_hw_brake_shutting_power(mot_contrl_t *ctrl);
|
|
|
|
|
|
void mot_contrl_init(mot_contrl_t *ctrl) {
|
|
|
memset(ctrl, 0, sizeof(mot_contrl_t));
|
|
|
@@ -50,20 +51,33 @@ bool mot_contrl_enable(mot_contrl_t *ctrl, bool start) {
|
|
|
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->input_torque, CONFIG_DEFAULT_TORQUE_RAMP_TIME);
|
|
|
+ etcs_init(&ctrl->etcs);
|
|
|
}
|
|
|
- ctrl->mode_req = ctrl->mode_running = CTRL_MODE_OPEN;
|
|
|
- ctrl->force_angle = INVALID_ANGLE;
|
|
|
- ctrl->adv_angle = INVALID_ANGLE;
|
|
|
- ctrl->angle_last = INVALID_ANGLE;
|
|
|
+ ctrl->b_ebrk_running = false;
|
|
|
ctrl->b_AutoHold = false;
|
|
|
ctrl->b_cruiseEna = false;
|
|
|
ctrl->b_mtpa_calibrate = false;
|
|
|
+ ctrl->b_hw_braker = false;
|
|
|
+
|
|
|
+ ctrl->mode_req = CTRL_MODE_OPEN;
|
|
|
+ ctrl->mode_running = CTRL_MODE_OPEN;
|
|
|
+
|
|
|
+ ctrl->force_angle = INVALID_ANGLE;
|
|
|
+ ctrl->adv_angle = INVALID_ANGLE;
|
|
|
+ ctrl->angle_last = INVALID_ANGLE;
|
|
|
+
|
|
|
ctrl->dc_curr_filted = 0;
|
|
|
+ ctrl->dc_curr_calc = 0;
|
|
|
ctrl->phase_curr_filted[0] = ctrl->phase_curr_filted[1] = 0;
|
|
|
ctrl->out_idq_filterd.d = ctrl->out_idq_filterd.q = 0;
|
|
|
ctrl->autohold_torque = 0;
|
|
|
ctrl->out_current_vec = 0;
|
|
|
+ ctrl->target_idq.d = 0;
|
|
|
+ ctrl->target_idq.q = 0;
|
|
|
+ ctrl->target_torque = 0;
|
|
|
+ ctrl->target_torque_raw = 0;
|
|
|
+
|
|
|
foc_init(&ctrl->foc);
|
|
|
foc_observer_init();
|
|
|
ctrl->b_start = start;
|
|
|
@@ -104,10 +118,10 @@ u8 mot_contrl_mode(mot_contrl_t *ctrl) {
|
|
|
line_ramp_update(&ctrl->input_torque);
|
|
|
if (preMode == CTRL_MODE_SPD) {
|
|
|
ctrl->target_torque_raw = ctrl->target_torque;
|
|
|
- PI_Controller_Reset(&ctrl->pi_vel_lim, ctrl->target_torque);
|
|
|
+ PI_Controller_Reset(&ctrl->pi_vel_lim, ctrl->target_torque_raw);
|
|
|
}else if (preMode == CTRL_MODE_CURRENT) {
|
|
|
- ctrl->target_torque_raw = ctrl->target_torque;
|
|
|
- PI_Controller_Reset(&ctrl->pi_vel_lim, ctrl->target_torque);
|
|
|
+ ctrl->target_torque_raw = ctrl->target_current.interpolation;
|
|
|
+ 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);
|
|
|
@@ -234,6 +248,9 @@ bool mot_contrl_update(mot_contrl_t *ctrl) {
|
|
|
foc_update(foc);
|
|
|
|
|
|
float lowpass = foc->mot_vel_radusPers * FOC_CTRL_US * 2;
|
|
|
+ if (lowpass > 1) {
|
|
|
+ lowpass = 1;
|
|
|
+ }
|
|
|
LowPass_Filter(ctrl->out_idq_filterd.d, foc->out.curr_dq.d ,lowpass);
|
|
|
LowPass_Filter(ctrl->out_idq_filterd.q, foc->out.curr_dq.q ,lowpass);
|
|
|
return true;
|
|
|
@@ -275,8 +292,7 @@ static void mot_contrl_dq_assign(mot_contrl_t *ctrl) {
|
|
|
ctrl->target_idq.d = 0;
|
|
|
ctrl->target_idq.q = target_current;
|
|
|
}
|
|
|
- }else if ((ctrl->mode_running == CTRL_MODE_TRQ) || (ctrl->mode_running == CTRL_MODE_SPD) ||
|
|
|
- (ctrl->mode_running == CTRL_MODE_EBRAKE)) {
|
|
|
+ }else if (ctrl->mode_running != CTRL_MODE_OPEN) {
|
|
|
motor_mpta_fw_lookup(ctrl->foc.in.mot_velocity, ctrl->target_torque, &ctrl->target_idq);
|
|
|
}
|
|
|
u32 mask = cpu_enter_critical();
|
|
|
@@ -329,7 +345,7 @@ static void crosszero_step_towards(float *value, float target) {
|
|
|
/*called in media task */
|
|
|
void mot_contrl_dq_calc(mot_contrl_t *ctrl) {
|
|
|
foc_t *foc = &ctrl->foc;
|
|
|
- float etcs_out = etcs_process(&ctrl->ects);
|
|
|
+ float etcs_out = etcs_process(&ctrl->etcs);
|
|
|
if (ctrl->b_AutoHold) {
|
|
|
float hold_torque = min(ctrl->protlim.torque, mc_conf()->c.max_autohold_torque);
|
|
|
ctrl->pi_lock.max = hold_torque;
|
|
|
@@ -618,6 +634,9 @@ void mot_contrl_set_torque_acc_time(mot_contrl_t *ctrl, u32 acc) {
|
|
|
}
|
|
|
|
|
|
bool mot_contrl_set_torque(mot_contrl_t *ctrl, float torque) {
|
|
|
+ if (is_hw_brake_shutting_power(ctrl) && !ctrl->b_ebrk_running){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
torque = fclamp(torque, -ctrl->userlim.torque, ctrl->userlim.torque);
|
|
|
line_ramp_set_target(&ctrl->input_torque, torque);
|
|
|
return true;
|