|
|
@@ -35,7 +35,7 @@ clc
|
|
|
Ts = 5e-6; % [s] Model sampling time (1 MHz)
|
|
|
f_ctrl = 20e3; % [Hz] Controller frequency = 1/Ts_ctrl (16 kHz)
|
|
|
Ts_ctrl = 1/f_ctrl; % [s] Controller sampling time (~16 kHz)
|
|
|
-Ts_speed = Ts_ctrl * 50;
|
|
|
+speed_ctrl = 20; %delay for f_ctrl
|
|
|
i_pwm_count = f_ctrl/4;
|
|
|
i_dead = 10;
|
|
|
i_adc = 10;
|
|
|
@@ -85,6 +85,10 @@ a_mechAngle = a_elecDeltaAngle / n_polePairs; % [deg] Mechanical angl
|
|
|
r_whl = 6.5 * 2.54 * 1e-2 / 2; % [m] Wheel radius. Diameter = 6.5 inch (1 inch = 2.54 cm): Speed[kph] = rpm*(pi/30)*r_whl*3.6
|
|
|
|
|
|
f_lpf_coeff = 0.4;
|
|
|
+%% F02_Diagnostics
|
|
|
+t_errQual = 0.24 * f_ctrl/3; % [s] Error qualification time
|
|
|
+t_errDequal = 1.80 * f_ctrl/3; % [s] Error dequalification time
|
|
|
+r_errInpTgtThres = 15; % [-] Error input target threshold (for "Blocked motor" detection)
|
|
|
|
|
|
%hall, [4,6,2,3,1,5,4] [ 3,2,6,4,5,1]
|
|
|
vec_hallToPos = [7 5 1 0 3 4 2 7]; % [-] Mapping Hall signal to position
|
|
|
@@ -92,15 +96,16 @@ i_hall_offset = 60;%-30;
|
|
|
|
|
|
% Speed Calculation Parameters
|
|
|
cf_speedCoef = (i_hall_count_max * a_mechAngle * (pi/180) * (30/pi)); % [-] Speed calculation coefficient (factors are due to conversions rpm <-> rad/s)
|
|
|
-z_maxCntRst = i_hall_count_max; % [-] Maximum counter value for reset (works also as time-out to detect standing still)
|
|
|
+z_maxCntRst = i_hall_count_max; % [-] Maximum counter value for reset
|
|
|
+z_maxStillSecond = 2; %(second, also as time-out to detect standing still)
|
|
|
n_commDeacvHi = 30; % [rpm] Commutation method deactivation speed high
|
|
|
n_commAcvLo = 15; % [rpm] Commutation method activation speed low
|
|
|
dz_cntTrnsDetHi = 140; % [-] Counter gradient High for transient behavior detection (used for speed estimation)
|
|
|
dz_cntTrnsDetLo = 100; % [-] Counter gradient Low for steady state detection (used for speed estimation)
|
|
|
n_stdStillDet = 3; % [rpm] Speed threshold for Stand still detection
|
|
|
|
|
|
-n_SpeedModeLo = 400; % min speed for exit speed ctrl mode
|
|
|
-n_SpeedModeHi = 500; % when speed is Hi can into speed ctrl mode
|
|
|
+n_SpeedModeLo = 200; % min speed for exit speed ctrl mode
|
|
|
+n_SpeedModeHi = 300; % when speed is Hi can into speed ctrl mode
|
|
|
% Motor Angle Measurement (e.g. using an encoder)
|
|
|
b_angleMeasEna = 0; % [-] Enable flag for external mechanical motor angle sensor: 0 = estimated (default), 1 = measured
|
|
|
|
|
|
@@ -124,16 +129,6 @@ n_fieldWeakAuthLo = 300; % [rpm] Motor speed Low for field weaken
|
|
|
% FOC method
|
|
|
id_fieldWeakMax = 5; % [A] Field weakening maximum current
|
|
|
|
|
|
-%% F05_Field_Oriented_Control
|
|
|
-z_selPhaCurMeasABC = 0; % [-] Select measured current phases: {iA,iB} = 0; {iB,iC} = 1; {iA,iC} = 2
|
|
|
-
|
|
|
-% Motor Limitations Calibratables
|
|
|
-speed_pi_time = 1e-3;
|
|
|
-speed_pi_count = speed_pi_time/Ts_ctrl;
|
|
|
-cf_iqKiLimProt = 60 / (f_ctrl/3); % [-] Current limit protection integral gain (only used in VLT_MODE and SPD_MODE)
|
|
|
-cf_nKiLimProt = 20 / (f_ctrl/3); % [-] Speed limit protection integral gain (only used in VLT_MODE and TRQ_MODE)
|
|
|
-cf_KbLimProt = 1000 / (f_ctrl/3);% [-] Back calculation gain for integral anti-windup
|
|
|
-
|
|
|
% Voltage Limitations
|
|
|
V_modulation = 0.95; % [-] Voltage margin to make sure that there is a sufficiently wide pulse for a good phase current measurement
|
|
|
Vd_max = i_Udc * V_modulation;
|
|
|
@@ -146,22 +141,21 @@ i_max = i_max * i_sca;
|
|
|
iq_maxSca_XA = 0:0.02:0.99;
|
|
|
iq_maxSca_XA = fixpt_evenspace_cleanup(iq_maxSca_XA, ufix(16), 2^-16); % Make sure the data is evely spaced up to the last bit
|
|
|
iq_maxSca_M1 = sqrt(1 - iq_maxSca_XA.^2); % Current circle limitations map
|
|
|
-
|
|
|
-%% F06_Control_Type_Management
|
|
|
-
|
|
|
-% Commutation method
|
|
|
-z_commutMap_M1 = [1 0 -1 -1 0 1; % Phase A
|
|
|
- 0 1 1 0 -1 -1; % Phase B
|
|
|
- -1 -1 0 1 1 0]; % Phase C [-] Commutation method map
|
|
|
-
|
|
|
-% Q axis control gains
|
|
|
-cf_iqKp = 0.3; % [-] P gain
|
|
|
-cf_iqKi = 100 / (f_ctrl/3); % [-] I gain
|
|
|
-
|
|
|
+
|
|
|
% D axis control gains
|
|
|
-cf_idKp = 0.9; % [-] P gain
|
|
|
-cf_idKi = 1.071; % [-] I gain
|
|
|
+cf_idKp = 4.0; % [-] P gain
|
|
|
+cf_idKi = 0.05; % [-] I gain
|
|
|
+cf_idKb = 1.0;
|
|
|
+% Q axis control gains
|
|
|
+cf_iqKp = 4.0; % [-] P gain
|
|
|
+cf_iqKi = 0.05; % [-] I gain
|
|
|
+cf_iqKb = 1.0;
|
|
|
|
|
|
% Speed control gains
|
|
|
-cf_nKp = 1.18; % [-] P gain
|
|
|
-cf_nKi = 20.4 / (f_ctrl/3);% [-] I gain
|
|
|
+cf_nKp = 3.1; % [-] P gain
|
|
|
+cf_nKi = 0.01;% [-] I gain
|
|
|
+cf_nKb = 0.02;
|
|
|
+
|
|
|
+% Torque iq limit
|
|
|
+cf_torqKLimHi = 0.8;
|
|
|
+cf_torqKLimLo = -0.1;
|