PmsmSimUt.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. //
  2. // File: PmsmSimUt.h
  3. //
  4. // Code generated for Simulink model 'PmsmSimUt'.
  5. //
  6. // Model version : 1.18
  7. // Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. // C/C++ source code generated on : Tue Aug 1 23:42:37 2023
  9. //
  10. // Target selection: ert.tlc
  11. // Embedded hardware selection: Intel->x86-64 (Windows64)
  12. // Code generation objectives: Unspecified
  13. // Validation result: Not run
  14. //
  15. #ifndef RTW_HEADER_PmsmSimUt_h_
  16. #define RTW_HEADER_PmsmSimUt_h_
  17. #include <cfloat>
  18. #include <cmath>
  19. #include "rtwtypes.h"
  20. #include "PmsmSimUt_types.h"
  21. #include "rt_nonfinite.h"
  22. #include "rtGetInf.h"
  23. // Macros for accessing real-time model data structure
  24. #ifndef rtmGetErrorStatus
  25. #define rtmGetErrorStatus(rtm) ((rtm)->errorStatus)
  26. #endif
  27. #ifndef rtmSetErrorStatus
  28. #define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val))
  29. #endif
  30. // Class declaration for model PmsmSimUt
  31. class PmsmSimUtModelClass {
  32. // public data and function members
  33. public:
  34. // Block signals (default storage)
  35. typedef struct {
  36. real_T Fcn; // '<S26>/Fcn'
  37. real_T Fcn1; // '<S26>/Fcn1'
  38. real_T Fcn_a; // '<S25>/Fcn'
  39. real_T Fcn1_p; // '<S25>/Fcn1'
  40. real_T DiscreteTimeIntegrator; // '<S20>/Discrete-Time Integrator'
  41. real_T Iq_ref; // '<S20>/Saturation2'
  42. real_T DiscreteTimeIntegrator1; // '<S19>/Discrete-Time Integrator1'
  43. real_T Fcn_g; // '<S14>/Fcn'
  44. real_T Fcn1_e; // '<S14>/Fcn1'
  45. real_T Fcn_b; // '<S13>/Fcn'
  46. real_T Fcn1_n; // '<S13>/Fcn1'
  47. } B_PmsmSimUt_T;
  48. // Block states (default storage) for system '<Root>'
  49. typedef struct {
  50. real_T DiscreteTimeIntegrator_DSTATE;// '<S18>/Discrete-Time Integrator'
  51. real_T DiscreteTimeIntegrator1_DSTATE;// '<S17>/Discrete-Time Integrator1'
  52. real_T DiscreteTimeIntegrator_DSTATE_c;// '<S17>/Discrete-Time Integrator'
  53. real_T DiscreteTimeIntegrator_DSTATE_j;// '<S16>/Discrete-Time Integrator'
  54. real_T DiscreteTimeIntegrator_DSTATE_g;// '<S15>/Discrete-Time Integrator'
  55. real_T DiscreteTimeIntegrator_DSTATE_n;// '<S20>/Discrete-Time Integrator'
  56. real_T DiscreteTimeIntegrator1_DSTAT_d;// '<S19>/Discrete-Time Integrator1'
  57. real_T Memory_PreviousInput; // '<S7>/Memory'
  58. boolean_T Relay1_Mode; // '<S7>/Relay1'
  59. boolean_T Relay2_Mode; // '<S7>/Relay2'
  60. boolean_T Subsystem_MODE; // '<Root>/Subsystem'
  61. } DW_PmsmSimUt_T;
  62. // External inputs (root inport signals with default storage)
  63. typedef struct {
  64. InputBus CtrlIn; // '<Root>/CtrlIn'
  65. ObsInputBus ObsIn; // '<Root>/ObsIn'
  66. ICtrlInputBus ICtrlIn; // '<Root>/ICtrlIn'
  67. } ExtU_PmsmSimUt_T;
  68. // External outputs (root outports fed by signals with default storage)
  69. typedef struct {
  70. OutputBus Out; // '<Root>/Out'
  71. } ExtY_PmsmSimUt_T;
  72. // Parameters (default storage)
  73. struct P_PmsmSimUt_T {
  74. struct_tYah6PAnMSQyhFn3I8nH0C Params;// Variable: Params
  75. // Referenced by:
  76. // '<Root>/Constant1'
  77. // '<Root>/Constant2'
  78. // '<Root>/Constant3'
  79. // '<Root>/Constant4'
  80. // '<Root>/Gain1'
  81. // '<S2>/Constant4'
  82. // '<S6>/Constant1'
  83. // '<S6>/Constant2'
  84. // '<S6>/Constant3'
  85. // '<S7>/Gain'
  86. // '<S15>/Gain'
  87. // '<S15>/Kp4'
  88. // '<S15>/Kp5'
  89. // '<S16>/Gain'
  90. // '<S16>/Kp4'
  91. // '<S16>/Kp5'
  92. // '<S17>/Constant'
  93. // '<S17>/Constant1'
  94. // '<S17>/Constant2'
  95. // '<S17>/Constant3'
  96. // '<S17>/Discrete-Time Integrator'
  97. // '<S17>/Gain'
  98. // '<S17>/Gain1'
  99. // '<S17>/Gain2'
  100. // '<S18>/Gain'
  101. // '<S18>/Gain1'
  102. // '<S20>/Gain'
  103. // '<S20>/Kp4'
  104. // '<S20>/Kp5'
  105. // '<S19>/Constant1'
  106. // '<S19>/Gain'
  107. // '<S19>/Gain1'
  108. real_T AlphaBetaZerotodq0_Alignment;
  109. // Mask Parameter: AlphaBetaZerotodq0_Alignment
  110. // Referenced by: '<S1>/Constant'
  111. real_T AlphaBetaZerotodq0_Alignment_e;
  112. // Mask Parameter: AlphaBetaZerotodq0_Alignment_e
  113. // Referenced by: '<S21>/Constant'
  114. real_T Subsystem_Init; // Mask Parameter: Subsystem_Init
  115. // Referenced by: '<S20>/Discrete-Time Integrator'
  116. real_T Subsystem1_Init; // Mask Parameter: Subsystem1_Init
  117. // Referenced by: '<S16>/Discrete-Time Integrator'
  118. real_T Subsystem_Init_c; // Mask Parameter: Subsystem_Init_c
  119. // Referenced by: '<S15>/Discrete-Time Integrator'
  120. real_T CompareToConstant_const; // Mask Parameter: CompareToConstant_const
  121. // Referenced by: '<S11>/Constant'
  122. real_T CompareToConstant1_const; // Mask Parameter: CompareToConstant1_const
  123. // Referenced by: '<S12>/Constant'
  124. real_T CompareToConstant_const_a;
  125. // Mask Parameter: CompareToConstant_const_a
  126. // Referenced by: '<S23>/Constant'
  127. real_T CompareToConstant1_const_o;
  128. // Mask Parameter: CompareToConstant1_const_o
  129. // Referenced by: '<S24>/Constant'
  130. real_T dq_Y0[2]; // Expression: [0,0]
  131. // Referenced by: '<S13>/dq'
  132. real_T dq_Y0_e[2]; // Expression: [0,0]
  133. // Referenced by: '<S14>/dq'
  134. real_T Wm_Y0; // Computed Parameter: Wm_Y0
  135. // Referenced by: '<S19>/Wm'
  136. real_T DiscreteTimeIntegrator1_gainval;
  137. // Computed Parameter: DiscreteTimeIntegrator1_gainval
  138. // Referenced by: '<S19>/Discrete-Time Integrator1'
  139. real_T DiscreteTimeIntegrator1_IC; // Expression: 0
  140. // Referenced by: '<S19>/Discrete-Time Integrator1'
  141. real_T Gain3_Gain; // Expression: pi/30
  142. // Referenced by: '<S18>/Gain3'
  143. real_T Iq_ref_Y0; // Computed Parameter: Iq_ref_Y0
  144. // Referenced by: '<S5>/Iq_ref'
  145. real_T DiscreteTimeIntegrator_gainval;
  146. // Computed Parameter: DiscreteTimeIntegrator_gainval
  147. // Referenced by: '<S20>/Discrete-Time Integrator'
  148. real_T DiscreteTimeIntegrator_UpperSat;// Expression: Limits(1)
  149. // Referenced by: '<S20>/Discrete-Time Integrator'
  150. real_T DiscreteTimeIntegrator_LowerSat;// Expression: Limits(2)
  151. // Referenced by: '<S20>/Discrete-Time Integrator'
  152. real_T Saturation2_UpperSat; // Expression: Limits(1)
  153. // Referenced by: '<S20>/Saturation2'
  154. real_T Saturation2_LowerSat; // Expression: Limits(2)
  155. // Referenced by: '<S20>/Saturation2'
  156. real_T Constant5_Value; // Expression: 0
  157. // Referenced by: '<Root>/Constant5'
  158. real_T Constant6_Value; // Expression: 1
  159. // Referenced by: '<Root>/Constant6'
  160. real_T Saturation2_UpperSat_o; // Expression: Limits(1)
  161. // Referenced by: '<S16>/Saturation2'
  162. real_T Saturation2_LowerSat_o; // Expression: Limits(2)
  163. // Referenced by: '<S16>/Saturation2'
  164. real_T Saturation2_UpperSat_b; // Expression: Limits(1)
  165. // Referenced by: '<S15>/Saturation2'
  166. real_T Saturation2_LowerSat_j; // Expression: Limits(2)
  167. // Referenced by: '<S15>/Saturation2'
  168. real_T dq_Y0_l[2]; // Expression: [0,0]
  169. // Referenced by: '<S25>/dq'
  170. real_T dq_Y0_f[2]; // Expression: [0,0]
  171. // Referenced by: '<S26>/dq'
  172. real_T DiscreteTimeIntegrator_gainva_p;
  173. // Computed Parameter: DiscreteTimeIntegrator_gainva_p
  174. // Referenced by: '<S18>/Discrete-Time Integrator'
  175. real_T DiscreteTimeIntegrator_IC; // Expression: 0
  176. // Referenced by: '<S18>/Discrete-Time Integrator'
  177. real_T Constant_Value; // Expression: 2*pi
  178. // Referenced by: '<S18>/Constant'
  179. real_T DiscreteTimeIntegrator1_gainv_b;
  180. // Computed Parameter: DiscreteTimeIntegrator1_gainv_b
  181. // Referenced by: '<S17>/Discrete-Time Integrator1'
  182. real_T DiscreteTimeIntegrator1_IC_a;// Expression: 0
  183. // Referenced by: '<S17>/Discrete-Time Integrator1'
  184. real_T DiscreteTimeIntegrator_gainv_pq;
  185. // Computed Parameter: DiscreteTimeIntegrator_gainv_pq
  186. // Referenced by: '<S17>/Discrete-Time Integrator'
  187. real_T Constant_Value_e; // Expression: 0
  188. // Referenced by: '<S10>/Constant'
  189. real_T K1_Gain; // Expression: K1
  190. // Referenced by: '<S30>/K1'
  191. real_T K2_Gain; // Expression: K2
  192. // Referenced by: '<S30>/K2'
  193. real_T Switch2_Threshold; // Expression: 0
  194. // Referenced by: '<Root>/Switch2'
  195. real_T Switch_Threshold; // Expression: 0
  196. // Referenced by: '<S18>/Switch'
  197. real_T Switch3_Threshold; // Expression: 0
  198. // Referenced by: '<Root>/Switch3'
  199. real_T Gain1_Gain; // Expression: -1
  200. // Referenced by: '<S6>/Gain1'
  201. real_T Switch5_Threshold; // Expression: 0
  202. // Referenced by: '<Root>/Switch5'
  203. real_T Switch4_Threshold; // Expression: 0
  204. // Referenced by: '<Root>/Switch4'
  205. real_T DiscreteTimeIntegrator_gainva_b;
  206. // Computed Parameter: DiscreteTimeIntegrator_gainva_b
  207. // Referenced by: '<S16>/Discrete-Time Integrator'
  208. real_T DiscreteTimeIntegrator_UpperS_b;// Expression: Limits(1)
  209. // Referenced by: '<S16>/Discrete-Time Integrator'
  210. real_T DiscreteTimeIntegrator_LowerS_l;// Expression: Limits(2)
  211. // Referenced by: '<S16>/Discrete-Time Integrator'
  212. real_T Switch1_Threshold; // Expression: 0
  213. // Referenced by: '<Root>/Switch1'
  214. real_T Memory_InitialCondition; // Expression: 0
  215. // Referenced by: '<S7>/Memory'
  216. real_T Saturation2_UpperSat_p; // Expression: 10000
  217. // Referenced by: '<Root>/Saturation2'
  218. real_T Saturation2_LowerSat_f; // Expression: -10000
  219. // Referenced by: '<Root>/Saturation2'
  220. real_T DiscreteTimeIntegrator_gainva_c;
  221. // Computed Parameter: DiscreteTimeIntegrator_gainva_c
  222. // Referenced by: '<S15>/Discrete-Time Integrator'
  223. real_T DiscreteTimeIntegrator_UpperS_k;// Expression: Limits(1)
  224. // Referenced by: '<S15>/Discrete-Time Integrator'
  225. real_T DiscreteTimeIntegrator_LowerS_a;// Expression: Limits(2)
  226. // Referenced by: '<S15>/Discrete-Time Integrator'
  227. real_T Switch6_Threshold; // Expression: 0
  228. // Referenced by: '<Root>/Switch6'
  229. real_T Constant_Value_p; // Expression: 0
  230. // Referenced by: '<S9>/Constant'
  231. real_T K1_Gain_j; // Expression: K1
  232. // Referenced by: '<S28>/K1'
  233. real_T K2_Gain_b; // Expression: K2
  234. // Referenced by: '<S28>/K2'
  235. real_T Gain3_Gain_j[9];
  236. // Expression: [ 1 -1/2 -1/2; 0 sqrt(3)/2 -sqrt(3)/2; 1/2 1/2 1/2 ]
  237. // Referenced by: '<S22>/Gain3'
  238. real_T Gain1_Gain_e; // Expression: 2/3
  239. // Referenced by: '<S22>/Gain1'
  240. real_T Gain2_Gain; // Expression: 30/pi
  241. // Referenced by: '<S18>/Gain2'
  242. real_T DeadZone_Start; // Expression: -0.01
  243. // Referenced by: '<S7>/Dead Zone'
  244. real_T DeadZone_End; // Expression: 0.01
  245. // Referenced by: '<S7>/Dead Zone'
  246. real_T Relay1_OnVal; // Expression: 0.1
  247. // Referenced by: '<S7>/Relay1'
  248. real_T Relay1_OffVal; // Expression: 0
  249. // Referenced by: '<S7>/Relay1'
  250. real_T Relay1_YOn; // Expression: 1000
  251. // Referenced by: '<S7>/Relay1'
  252. real_T Relay1_YOff; // Expression: 0
  253. // Referenced by: '<S7>/Relay1'
  254. real_T Relay2_OnVal; // Expression: 0
  255. // Referenced by: '<S7>/Relay2'
  256. real_T Relay2_OffVal; // Expression: -0.1
  257. // Referenced by: '<S7>/Relay2'
  258. real_T Relay2_YOn; // Expression: 0
  259. // Referenced by: '<S7>/Relay2'
  260. real_T Relay2_YOff; // Expression: -1000
  261. // Referenced by: '<S7>/Relay2'
  262. uint8_T ManualSwitch1_CurrentSetting;
  263. // Computed Parameter: ManualSwitch1_CurrentSetting
  264. // Referenced by: '<Root>/Manual Switch1'
  265. };
  266. // Real-time Model Data Structure
  267. struct RT_MODEL_PmsmSimUt_T {
  268. const char_T * volatile errorStatus;
  269. };
  270. // Tunable parameters
  271. static P_PmsmSimUt_T PmsmSimUt_P;
  272. // External inputs
  273. ExtU_PmsmSimUt_T PmsmSimUt_U;
  274. // External outputs
  275. ExtY_PmsmSimUt_T PmsmSimUt_Y;
  276. // model initialize function
  277. void initialize();
  278. // model event function
  279. void PmsmSimUt_reset();
  280. // model step function
  281. void step();
  282. // model terminate function
  283. void terminate();
  284. // Constructor
  285. PmsmSimUtModelClass();
  286. // Destructor
  287. ~PmsmSimUtModelClass();
  288. // Block parameters get method
  289. const PmsmSimUtModelClass::P_PmsmSimUt_T & getBlockParameters() const
  290. {
  291. return PmsmSimUt_P;
  292. }
  293. // Block parameters set method
  294. void setBlockParameters(const P_PmsmSimUt_T *pPmsmSimUt_P)
  295. {
  296. PmsmSimUt_P = *pPmsmSimUt_P;
  297. }
  298. // Root-level structure-based inputs set method
  299. // Root inports set method
  300. void setExternalInputs(const ExtU_PmsmSimUt_T* pExtU_PmsmSimUt_T)
  301. {
  302. PmsmSimUt_U = *pExtU_PmsmSimUt_T;
  303. }
  304. // Root-level structure-based outputs get method
  305. // Root outports get method
  306. const PmsmSimUtModelClass::ExtY_PmsmSimUt_T & getExternalOutputs() const
  307. {
  308. return PmsmSimUt_Y;
  309. }
  310. // Real-Time Model get method
  311. PmsmSimUtModelClass::RT_MODEL_PmsmSimUt_T * getRTM();
  312. // private data and function members
  313. private:
  314. // Block signals
  315. B_PmsmSimUt_T PmsmSimUt_B;
  316. // Block states
  317. DW_PmsmSimUt_T PmsmSimUt_DW;
  318. // Real-Time Model
  319. RT_MODEL_PmsmSimUt_T PmsmSimUt_M;
  320. };
  321. //-
  322. // These blocks were eliminated from the model due to optimizations:
  323. //
  324. // Block '<Root>/Constant' : Unused code path elimination
  325. // Block '<S17>/Scope' : Unused code path elimination
  326. // Block '<S17>/Scope1' : Unused code path elimination
  327. // Block '<S18>/Scope' : Unused code path elimination
  328. // Block '<Root>/Scope' : Unused code path elimination
  329. // Block '<Root>/Scope1' : Unused code path elimination
  330. // Block '<Root>/Scope3' : Unused code path elimination
  331. // Block '<Root>/Scope4' : Unused code path elimination
  332. // Block '<Root>/Scope5' : Unused code path elimination
  333. //-
  334. // The generated code includes comments that allow you to trace directly
  335. // back to the appropriate location in the model. The basic format
  336. // is <system>/block_name, where system is the system number (uniquely
  337. // assigned by Simulink) and block_name is the name of the block.
  338. //
  339. // Use the MATLAB hilite_system command to trace the generated code back
  340. // to the model. For example,
  341. //
  342. // hilite_system('<S3>') - opens system 3
  343. // hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
  344. //
  345. // Here is the system hierarchy for this model
  346. //
  347. // '<Root>' : 'PmsmSimUt'
  348. // '<S1>' : 'PmsmSimUt/Alpha-Beta-Zero to dq0'
  349. // '<S2>' : 'PmsmSimUt/Initialize Function'
  350. // '<S3>' : 'PmsmSimUt/PI Controller'
  351. // '<S4>' : 'PmsmSimUt/PM_Motor in dq frame '
  352. // '<S5>' : 'PmsmSimUt/Subsystem'
  353. // '<S6>' : 'PmsmSimUt/Subsystem1'
  354. // '<S7>' : 'PmsmSimUt/Subsystem2'
  355. // '<S8>' : 'PmsmSimUt/abc to dq0'
  356. // '<S9>' : 'PmsmSimUt/dq to abc'
  357. // '<S10>' : 'PmsmSimUt/dq to abc1'
  358. // '<S11>' : 'PmsmSimUt/Alpha-Beta-Zero to dq0/Compare To Constant'
  359. // '<S12>' : 'PmsmSimUt/Alpha-Beta-Zero to dq0/Compare To Constant1'
  360. // '<S13>' : 'PmsmSimUt/Alpha-Beta-Zero to dq0/Subsystem - pi//2 delay'
  361. // '<S14>' : 'PmsmSimUt/Alpha-Beta-Zero to dq0/Subsystem1'
  362. // '<S15>' : 'PmsmSimUt/PI Controller/Subsystem'
  363. // '<S16>' : 'PmsmSimUt/PI Controller/Subsystem1'
  364. // '<S17>' : 'PmsmSimUt/PM_Motor in dq frame /Electrical Modelling'
  365. // '<S18>' : 'PmsmSimUt/PM_Motor in dq frame /Mechanical Modelling'
  366. // '<S19>' : 'PmsmSimUt/PM_Motor in dq frame /Mechanical Modelling/Subsystem'
  367. // '<S20>' : 'PmsmSimUt/Subsystem/Subsystem'
  368. // '<S21>' : 'PmsmSimUt/abc to dq0/Alpha-Beta-Zero to dq0'
  369. // '<S22>' : 'PmsmSimUt/abc to dq0/abc to Alpha-Beta-Zero'
  370. // '<S23>' : 'PmsmSimUt/abc to dq0/Alpha-Beta-Zero to dq0/Compare To Constant'
  371. // '<S24>' : 'PmsmSimUt/abc to dq0/Alpha-Beta-Zero to dq0/Compare To Constant1'
  372. // '<S25>' : 'PmsmSimUt/abc to dq0/Alpha-Beta-Zero to dq0/Subsystem - pi//2 delay'
  373. // '<S26>' : 'PmsmSimUt/abc to dq0/Alpha-Beta-Zero to dq0/Subsystem1'
  374. // '<S27>' : 'PmsmSimUt/dq to abc/An_Park'
  375. // '<S28>' : 'PmsmSimUt/dq to abc/Inverse Clarke Transform2'
  376. // '<S29>' : 'PmsmSimUt/dq to abc1/An_Park'
  377. // '<S30>' : 'PmsmSimUt/dq to abc1/Inverse Clarke Transform2'
  378. #endif // RTW_HEADER_PmsmSimUt_h_
  379. //
  380. // File trailer for generated code.
  381. //
  382. // [EOF]
  383. //