init_model.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. % Clear workspace
  2. close all
  3. clear
  4. clc
  5. % Load model parameters
  6. Ts = 1e-6; % [s] Model sampling time (200 KHz)
  7. f_ctrl = 20e3; % [Hz] Controller frequency = 1/Ts_ctrl (20 kHz)
  8. Ts_ctrl = 1/f_ctrl; % [s] Controller sampling time (50us)5e-5
  9. f_speed_ctrl = 500; % [Hz] Speed/torque Controller frequency = (500 Hz)
  10. Ts_Spd_ctl = 1/f_speed_ctrl;
  11. n_spdctl_count = f_ctrl/f_speed_ctrl; % [count] Delay for f_speed_ctrl of the FOC controller
  12. i_pwm_count = 3000;
  13. n_hall_count_ps = 1/Ts; % counts of per second
  14. n_ramp_count = f_ctrl/100; %10ms
  15. %Current sample hw parameters
  16. f_adc_curr_ceof = 0.0942;
  17. f_lpf_idq = 0.4; %Phase Current LowPass filter
  18. f_lpf_vdq = 0.01; %DC link current limit LowPass filter
  19. pll_w = 100;
  20. %Simulink provider Motor parameters
  21. n_polePairs = 4; % [-] Number of motor pole pairs
  22. PM = 0.1688; % Permanent magnet flux linkage,
  23. Ld = 0.9262e-3;% d-axis inductance,
  24. Lq = 1.024e-3; % q-axis inductance,
  25. Rs = 0.0918; % Stator resistance,
  26. J = 0.03945; % Moment of inertia,
  27. i_Udc = 300; % DCbus max voltage
  28. i_dqMax = 150; % [A] Maximum allowed motor current (continuous)
  29. n_max = 2500; % [rpm] Maximum motor speed: [-5000, 5000]
  30. %BlueShark Motor parameters
  31. %n_polePairs = 5; % [-] Number of motor pole pairs
  32. %PM = 0.0191471; % Permanent magnet flux linkage,
  33. %Ld = 0.08971e-3; % d-axis inductance,
  34. %Lq = 0.1128e-3; % q-axis inductance,
  35. %Rs = 0.01587; % Stator resistance,
  36. %J = 0.0014837*2; % Moment of inertia,
  37. %i_Udc = 100; % DCbus max voltage
  38. %i_dqMax = 270; % [A] Maximum allowed motor current (continuous)
  39. %n_max = 5000; % [rpm] Maximum motor speed: [-5000, 5000]
  40. %Hall parameters
  41. a_elecPeriod = 360; % [deg] Electrical angle period
  42. a_elecDeltaAngle = 60; % [deg] Electrical angle between two Hall sensor changing events
  43. %%a_mechAngle = a_elecDeltaAngle / n_polePairs; % [deg] Mechanical angle between two Hall sensor changing events
  44. % 3 2 6 4 5 1 -> [7 5 1 0 3 4 2 7]
  45. vec_hallToPos = [7 5 1 0 3 4 2 7]; % [-] Mapping Hall signal to position
  46. i_hall_offset = -30; %60;%-30;
  47. b_angleMeasEna = 0;
  48. % Sine/Cosine wave look-up table
  49. res_elecAngle = 1;
  50. a_elecAngle_XA = 0:res_elecAngle:360; % [deg] Electrical angle grid
  51. r_sin_M1 = sin((a_elecAngle_XA)*(pi/180));
  52. r_cos_M1 = cos((a_elecAngle_XA)*(pi/180));
  53. %% F02_Diagnostics
  54. t_errQual = 0.24 * f_ctrl/3; % [s] Error qualification time
  55. t_errDequal = 1.80 * f_ctrl/3; % [s] Error dequalification time
  56. r_errInpTgtThres = 310; % [-] Error input target threshold (for "Blocked motor" detection)
  57. % Speed Calculation Parameters
  58. cf_speedCoef = (n_hall_count_ps * a_elecDeltaAngle * (pi/180) * (30/pi)); % [-] Speed calculation coefficient (factors are due to conversions rpm <-> rad/s)
  59. z_maxStillSecond = 2; %(second, also as time-out to detect standing still)
  60. n_commDeacvHi = 30; % [rpm] Commutation method deactivation speed high
  61. n_commAcvLo = 15; % [rpm] Commutation method activation speed low
  62. dz_cntTrnsDetHi = 140; % [-] Counter gradient High for transient behavior detection (used for speed estimation)
  63. dz_cntTrnsDetLo = 100; % [-] Counter gradient Low for steady state detection (used for speed estimation)
  64. n_stdStillDet = 3; % [rpm] Speed threshold for Stand still detection
  65. n_SpeedModeLo = 200; % min speed for exit speed ctrl mode
  66. n_SpeedModeHi = 300; % when speed is Hi can into speed ctrl mode
  67. % Control model request
  68. OPEN_MODE = 0; % [-] Open mode
  69. SPD_MODE = 1; % [-] Speed mode
  70. TRQ_MODE = 2; % [-] Torque mode
  71. % open start vq ramp
  72. dz_OpenStepVol = 10;
  73. % MTPA process
  74. b_MTPA_Enable = 0; % MTPA enable flag: 0 = disable, 1 = enable
  75. cf_MTPA_ldqdiff = PM/(Lq - Ld);
  76. % Field_Weakening
  77. b_fieldWeakEna = 1; % [-] Field weakening enable flag: 0 = disable (default), 1 = enable
  78. cf_Fw_Ki = 0.5;
  79. cf_Fw_Kb = 0.1;
  80. id_fieldWeakMax = -50; % [A] Field weakening maximum current
  81. % Voltage Limitations
  82. V_modulation = 0.95; % [-] Voltage margin to make sure that there is a sufficiently wide pulse for a good phase current measurement
  83. Vq_max = i_Udc * V_modulation;
  84. Vd_max = Vq_max;
  85. Qxis_D = 1; %D轴优先
  86. Qxis_Q = 2; %Q轴优先
  87. Qxis_F = 3; %平均分配
  88. % Current loop FeedForward
  89. b_FF_Enable = 0;
  90. % D axis control gains
  91. %https://www.it610.com/article/1282852898983657472.htm
  92. %https://e2echina.ti.com/support/microcontrollers/c2000/f/c2000-microcontrollers-forum/109265/lab05a-fast-pid
  93. cf_iGain = 1.0;
  94. cf_iBand = 2 * pi * f_ctrl / 20 * 3;
  95. cf_idKp = Ld * cf_iBand; % [-] P gain
  96. cf_idKi = Rs/(Ld * f_ctrl) * cf_iGain; % [-] I gain
  97. cf_idKb = cf_idKi;
  98. % Q axis control gains
  99. cf_iqKp = Lq * cf_iBand; % [-] P gain
  100. cf_iqKi = Rs/(Lq * f_ctrl) * cf_iGain; % [-] I gain
  101. cf_iqKb = cf_iqKi;
  102. % Speed control gains
  103. cf_nKp = 0.15; % [-] P gain
  104. cf_nKi = 4.5 / f_speed_ctrl; % [-] I gain
  105. cf_nKb = cf_nKi;
  106. cf_lastIqGain = 0.5; % when swtich toqure to speed mode, use the last iq as the speed PI init value
  107. % Torque iq limit
  108. cf_TrqLimKp = 0.15; % [-] P gain
  109. cf_TrqLimKi = 4.5 / f_speed_ctrl; % [-] I gain
  110. cf_TrqLimKb = 1.0; %cf_TrqLimKi;