PmsmSimUt.h 20 KB

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