spdctrFSM.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /************************************************************************
  2. Project: Welling Motor Control Paltform
  3. Filename: sysfsm.c
  4. Partner Filename: sysfsm.h
  5. Description: System finite state machine
  6. Complier: IAR Embedded Workbench for ARM 7.80.4
  7. CPU TYPE : GD32F3x0
  8. *************************************************************************
  9. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  10. All rights reserved.
  11. *************************************************************************
  12. *************************************************************************
  13. Revising History (ECL of this file):
  14. ************************************************************************/
  15. /************************************************************************
  16. Beginning of File, do not put anything above here except notes
  17. Compiler Directives:
  18. ************************************************************************/
  19. #ifndef _STARTFSM_C_
  20. #define _STARTFSM_C_
  21. #endif
  22. /************************************************************************
  23. Include File
  24. ************************************************************************/
  25. #include "syspar.h"
  26. #include "user.h"
  27. #include "FSM_1st.h"
  28. #include "FSM_2nd.h"
  29. #include "spdctrFSM.h"
  30. #include "switchhall.h"
  31. #include "spi_master.h"
  32. #include "cmdgennew.h"
  33. #include "power.h"
  34. #include "sys_ctrl.h"
  35. /************************************************************************
  36. Constant Table:
  37. ************************************************************************/
  38. /************************************************************************
  39. Exported Functions:
  40. ************************************************************************/
  41. void InitPosDet_TbcupHook(void)
  42. {
  43. scm_ulStatCt++;
  44. align_stIn.ulStatCt = scm_ulStatCt;
  45. align_voInitPos(&align_stIn, &align_stCoef, &align_stOut);
  46. scm_slIdRefPu = align_stOut.slIdRefPu; // Q29
  47. scm_swIdRefPu = align_stOut.swIdRefPu; // Q14
  48. scm_swIqRefPu = align_stOut.swIqRefPu; // Q14
  49. scm_uwAngRefPu = align_stOut.uwAngRefPu; // Q15
  50. }
  51. void ParDet_TbcupHook(void)
  52. {}
  53. void StartUp_TbcupHook(void)
  54. {
  55. flx_stCtrlOut.swIqLimPu = (SWORD)cof_uwCurMaxPu;
  56. scm_ulStatCt++;
  57. align_stIn.ulStatCt = scm_ulStatCt;
  58. align_stIn.swRotateDir = scm_swRotateDir;
  59. align_voStartUp(&align_stIn, &align_stCoef, &align_stOut);
  60. scm_slDragSpdRefPu = align_stOut.slDragSpdRefPu;
  61. scm_slDragSpdPu = align_stOut.slDragSpdPu;
  62. scm_swIdRefPu = align_stOut.swIdRefPu;
  63. scm_swIqRefPu = align_stOut.swIqRefPu;
  64. scm_slAngManuPu = align_stOut.slAngManuPu;
  65. scm_uwAngRefPu = align_stOut.uwAngRefPu;
  66. scm_StartUpOvrFlg = align_stOut.blStartUpOvrFlg;
  67. }
  68. void Open2Clz_TbcupHook(void)
  69. {
  70. flx_stCtrlOut.swIqLimPu = (SWORD)cof_uwCurMaxPu;
  71. if(cp_stFlg.ThetaGetModelSelect == ANG_OBSERVER)
  72. {
  73. align_stIn.uwObsElecThetaPu = obs_stObsOutPu.uwElecThetaPu;
  74. }
  75. else if(cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER)
  76. {
  77. align_stIn.uwObsElecThetaPu = spi_stResolverOut.uwSpiThetaPu;
  78. }
  79. else if(cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL)
  80. {
  81. align_stIn.uwObsElecThetaPu = switchhall_stOut.uwLowThetaPu;
  82. }
  83. else
  84. {
  85. //do nothing
  86. }
  87. align_stIn.swCurRefrompu = swCurRefrompu; // swCurRefrompu;
  88. align_voOpen2Clz(&align_stIn, &align_stCoef, &align_stOut);
  89. scm_swIdRefPu = align_stOut.swIdRefPu;
  90. scm_swIqRefPu = align_stOut.swIqRefPu;
  91. scm_blCurSwitchOvrFlg = align_stOut.blCurSwitchOvrFlg;
  92. scm_blAngSwitchOvrFlg = align_stOut.blAngSwitchOvrFlg;
  93. scm_slAngManuPu = align_stOut.slAngManuPu;
  94. scm_uwAngManuPu = align_stOut.uwAngManuPu;
  95. scm_uwAngRefPu = align_stOut.uwAngRefPu;
  96. }
  97. void ClzLoop_TbcupHook(void)
  98. {
  99. /*=======================================================================
  100. Flux weakening
  101. =======================================================================*/
  102. flx_stCtrlIn.swUalphaPu = crd_stVltIParkOut.swAlphaPu; // Q14
  103. flx_stCtrlIn.swUbetaPu = crd_stVltIParkOut.swBetaPu; // Q14
  104. flx_stCtrlIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu; // Q14
  105. flx_stCtrlIn.swIqRefPu = swCurRefrompu; // Q14
  106. flx_stCtrlIn.swUqRefPu = scm_swUqRefPu; // Q14
  107. flx_voCtrl(&flx_stCtrlIn, &flx_stCtrlCoef, &flx_stCtrlOut);
  108. /*=======================================================================
  109. Power Limit
  110. =======================================================================*/
  111. // Q15
  112. pwr_stPwrLimIn.swMotorPwrPu = scm_stMotoPwrInLpf.slY.sw.hi; // Q15
  113. pwr_stPwrLimIn.swIqrefPu = swCurRefrompu; // asr_stSpdPIOut.swIqRefPu;
  114. pwr_stPwrLimIn.PCBTemp = adc_stUpOut.PCBTemp;
  115. pwr_voPwrLim2(&pwr_stPwrLimIn, &pwr_stPwrLimCof, &pwr_stPwrLimOut2); // Q14
  116. /*=======================================================================
  117. Set Iq and Id reference for Constant Voltage Break
  118. =======================================================================*/
  119. cvb_stBrakeIn.uwVdcLpfPu = adc_stUpOut.uwVdcLpfPu;
  120. cvb_stBrakeIn.swIdRefPu = scm_swIdRefPu;
  121. cvb_stBrakeIn.swIqRefPu = swCurRefrompu;
  122. cvb_stBrakeIn.swSpdPu = scm_stSpdFbkLpf.slY.sw.hi;
  123. cvb_stBrakeIn.uwAngelPu = scm_uwAngRefPu;
  124. cvb_stBrakeIn.uwSpdLpfAbsPu = scm_uwSpdFbkLpfAbsPu;
  125. cvb_voBrake(&cvb_stBrakeIn,&cvb_stBrakeCoef,&cvb_stBrakeOut);
  126. /** Idref可变范围-3A~0A且未弱磁,暂不做过多处理;Angle在down中更新,暂不改为改为恒压制动角度 **/
  127. if(cvb_stBrakeIn.uwVdcLpfPu >= cvb_stBrakeCoef.uwVdcStartCvbPu)
  128. {
  129. scm_swIdRefPu = cvb_stBrakeOut.swIdRefPu;
  130. }
  131. else
  132. {
  133. scm_swIdRefPu = 0; //flx_stCtrlOut.swIdRefPu;
  134. }
  135. scm_swIqRefPu = cvb_stBrakeOut.swIqRefPu;
  136. }
  137. void Stop_TbcupHook(void)
  138. {}
  139. void InitPosDet_TbcdownHook(void)
  140. {
  141. /* Get angle for park transformation */
  142. scm_uwAngParkPu = scm_uwAngRefPu; // Q15
  143. scm_uwAngIParkPu = scm_uwAngParkPu;
  144. /*=======================================================================
  145. Current decoupling
  146. =======================================================================*/
  147. acr_stUdqDcpOut.swUdPu = 0;
  148. acr_stUdqDcpOut.swUqPu = 0;
  149. }
  150. void ParDet_TbcdownHook(void)
  151. {
  152. /* Get angle for park transformation */
  153. scm_uwAngParkPu = scm_uwAngRefPu; // Q15
  154. scm_uwAngIParkPu = scm_uwAngParkPu;
  155. /*=======================================================================
  156. Current decoupling
  157. =======================================================================*/
  158. acr_stUdqDcpOut.swUdPu = 0;
  159. acr_stUdqDcpOut.swUqPu = 0;
  160. }
  161. void StartUp_TbcdownHook(void)
  162. {
  163. /* Speed feedback LPF */
  164. if(cp_stFlg.ThetaGetModelSelect == ANG_OBSERVER)
  165. {
  166. mth_voLPFilter(obs_stObsOutPu.swElecFreqPu, &scm_stSpdFbkLpf);
  167. obs_stObsCalcIn.swUalphaPu = scm_swUalphaPu; // Q14
  168. obs_stObsCalcIn.swUbetaPu = scm_swUbetaPu; // Q14
  169. obs_stObsCalcIn.swIalphaPu = crd_stCurClarkOut.swAlphaPu; // Q14
  170. obs_stObsCalcIn.swIbetaPu = crd_stCurClarkOut.swBetaPu; // Q14
  171. obs_stObsCalcIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu;
  172. obs_voObsCalc(&obs_stObsCalcIn, &obs_stObsCoefPu, &obs_stObsOutPu);
  173. }
  174. else if(cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER)
  175. {
  176. mth_voLPFilter(spi_stResolverOut.swSpdFbkPu, &scm_stSpdFbkLpf);
  177. }
  178. else if(cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL)
  179. {
  180. scm_stSpdFbkLpf.slY.sw.hi = switchhall_stOut.swLowSpdLpfPu;
  181. }
  182. else
  183. {
  184. //do nothing
  185. }
  186. /* Speed feedback Absolute */
  187. scm_uwSpdFbkLpfAbsPu = (UWORD)ABS(scm_stSpdFbkLpf.slY.sw.hi); // Q15
  188. /* Get angle for park transformation */
  189. scm_uwAngParkPu = scm_uwAngRefPu; // Q15
  190. scm_uwAngIParkPu = scm_uwAngParkPu;
  191. /*=======================================================================
  192. Current decoupling
  193. =======================================================================*/
  194. acr_stUdqDcpOut.swUdPu = 0;
  195. acr_stUdqDcpOut.swUqPu = 0;
  196. }
  197. void Open2Clz_TbcdownHook(void)
  198. {
  199. /* Speed feedback LPF */
  200. if(cp_stFlg.ThetaGetModelSelect == ANG_OBSERVER)
  201. {
  202. obs_stObsCalcIn.swUalphaPu = scm_swUalphaPu; // Q14
  203. obs_stObsCalcIn.swUbetaPu = scm_swUbetaPu; // Q14
  204. obs_stObsCalcIn.swIalphaPu = crd_stCurClarkOut.swAlphaPu; // Q14
  205. obs_stObsCalcIn.swIbetaPu = crd_stCurClarkOut.swBetaPu; // Q14
  206. obs_stObsCalcIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu;
  207. obs_voObsCalc(&obs_stObsCalcIn, &obs_stObsCoefPu, &obs_stObsOutPu);
  208. mth_voLPFilter(obs_stObsOutPu.swElecFreqPu, &scm_stSpdFbkLpf);
  209. }
  210. else if(cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER)
  211. {
  212. mth_voLPFilter(spi_stResolverOut.swSpdFbkPu, &scm_stSpdFbkLpf);
  213. }
  214. else if(cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL)
  215. {
  216. scm_stSpdFbkLpf.slY.sw.hi = switchhall_stOut.swLowSpdLpfPu;
  217. }
  218. else
  219. {
  220. //do nothing
  221. }
  222. /* Speed feedback Absolute */
  223. scm_uwSpdFbkLpfAbsPu = (UWORD)ABS(scm_stSpdFbkLpf.slY.sw.hi); // Q15
  224. /* Get angle for park transformation */
  225. scm_uwAngParkPu = scm_uwAngRefPu; // Q15
  226. scm_uwAngIParkPu = scm_uwAngParkPu;
  227. /*=======================================================================
  228. Current decoupling
  229. =======================================================================*/
  230. acr_stUdqDcpOut.swUdPu = 0;
  231. acr_stUdqDcpOut.swUqPu = 0;
  232. }
  233. void ClzLoop_TbcdownHook(void)
  234. {
  235. ULONG ulTmp1;
  236. SWORD swAngCompPu = 0; // Q15
  237. /* Speed feedback LPF */
  238. if(cp_stFlg.ThetaGetModelSelect == ANG_OBSERVER)
  239. {
  240. obs_stObsCalcIn.swUalphaPu = scm_swUalphaPu; // Q14
  241. obs_stObsCalcIn.swUbetaPu = scm_swUbetaPu; // Q14
  242. obs_stObsCalcIn.swIalphaPu = crd_stCurClarkOut.swAlphaPu; // Q14
  243. obs_stObsCalcIn.swIbetaPu = crd_stCurClarkOut.swBetaPu; // Q14
  244. obs_stObsCalcIn.uwVdcPu = adc_stUpOut.uwVdcLpfPu;
  245. obs_voObsCalc(&obs_stObsCalcIn, &obs_stObsCoefPu, &obs_stObsOutPu);
  246. mth_voLPFilter(obs_stObsOutPu.swElecFreqPu, &scm_stSpdFbkLpf);
  247. scm_uwAngRefPu = obs_stObsOutPu.uwElecThetaPu;
  248. }
  249. else if(cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER)
  250. {
  251. mth_voLPFilter(spi_stResolverOut.swSpdFbkPu, &scm_stSpdFbkLpf);
  252. scm_uwAngRefPu = spi_stResolverOut.uwSpiThetaPu;
  253. }
  254. else if(cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL)
  255. {
  256. mth_voLPFilter(switchhall_stOut.swLowSpdPu, &scm_stSpdFbkLpf);
  257. scm_uwAngRefPu = switchhall_stOut.uwLowThetaPu;
  258. }
  259. else
  260. {
  261. //do nothing
  262. }
  263. /* Speed feedback Absolute */
  264. scm_uwSpdFbkLpfAbsPu = (UWORD)ABS(scm_stSpdFbkLpf.slY.sw.hi); // Q15
  265. /* Get angle for park transformation */
  266. scm_uwAngParkPu = scm_uwAngRefPu; // Q15
  267. if(cp_stFlg.ThetaGetModelSelect == ANG_OBSERVER)
  268. {
  269. swAngCompPu = (SWORD)(((SLONG)obs_stObsOutPu.swElecFreqPu * TBC_TM) >> 10); // Q15
  270. }
  271. else if(cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER)
  272. {
  273. swAngCompPu = (SWORD)(((SLONG)spi_stResolverOut.swSpdFbkPu * TBC_TM) >> 10); // Q15
  274. }
  275. else if(cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL)
  276. {
  277. swAngCompPu = (SWORD)(((SLONG)switchhall_stOut.swLowSpdPu * TBC_TM) >> 10); // Q15
  278. }
  279. else
  280. {
  281. //do nothing
  282. }
  283. ulTmp1 = scm_uwAngParkPu + ((swAngCompPu * 3) >> 1) + cof_sl720DegreePu;
  284. scm_uwAngIParkPu = (UWORD)(ulTmp1 & 0x7FFF);
  285. /*=======================================================================
  286. Current decoupling
  287. =======================================================================*/
  288. if(cp_stFlg.ThetaGetModelSelect == ANG_OBSERVER)
  289. {
  290. acr_stUdqDcpIn.swWsPu = scm_stSpdFbkLpf.slY.sw.hi; // Q15
  291. }
  292. else if(cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER)
  293. {
  294. acr_stUdqDcpIn.swWsPu = spi_stResolverOut.swSpdFbkPu; // Q15 swSpdFbkLpfPu spi_stResolverOut.swSpdFbkPu
  295. }
  296. else
  297. {
  298. //do nothing
  299. }
  300. acr_stUdqDcpIn.swIdRefPu = scm_swIdFdbLpfPu;//scm_swIdRefPu scm_swIdFdbLpfPu // Q14
  301. acr_stUdqDcpIn.swIqRefPu = scm_swIqFdbLpfPu; //scm_swIqRefPu scm_swIqFdbLpfPu // Q14
  302. acr_stUdqDcpIn.swUdqLimPu = scm_swVsDcpLimPu; // Q14
  303. acr_voUdqDcp(&acr_stUdqDcpIn, &acr_stUdqDcpCoef, &acr_stUdqDcpOut);
  304. }
  305. void Stop_TbcdownHook(void)
  306. {
  307. scm_swIdRefPu = 0;
  308. scm_swIqRefPu = 0;
  309. sysctrl_voPwmInit();
  310. cmfsm_stFlg.blMotorStopFlg = TRUE;
  311. }
  312. void InitPosDet_TbsHook(void)
  313. {}
  314. void ParDet_TbsHook(void)
  315. {}
  316. void StartUp_TbsHook(void)
  317. {
  318. /*=======================================================================
  319. Speed PI output limit in "OpenDrg"
  320. =======================================================================*/
  321. if ((curSpeed_state.state == StartUp) && (scm_uwStartMd == START_ALIGN))
  322. {
  323. if (scm_swRotateDir * asr_stSpdPIOut.slIqRefPu < 0)
  324. {
  325. asr_stSpdPIOut.slIqRefPu = 0; // Q30
  326. asr_stSpdPIOut.slIqSumPu = 0; // Q30
  327. asr_stSpdPIOut.slIqiPu = 0;
  328. }
  329. else
  330. {
  331. if (scm_swRotateDir * asr_stSpdPIOut.slIqRefPu > ((SLONG)mn_uwDragCurPu << 16)) // Q30
  332. {
  333. asr_stSpdPIOut.slIqRefPu = scm_swRotateDir * ((SLONG)mn_uwDragCurPu << 16); // Q30
  334. asr_stSpdPIOut.slIqiPu = scm_swRotateDir * ((SLONG)mn_uwDragCurPu << 16); // Q14+Q16=Q30
  335. }
  336. }
  337. }
  338. }
  339. void Open2Clz_TbsHook(void)
  340. {}
  341. void ClzLoop_TbsHook(void)
  342. {}
  343. void Stop_TbsHook(void)
  344. {}
  345. void scm_voSpdCtrMdFSM(void) /* parasoft-suppress METRICS-28 "本项目圈复杂度无法更改,后续避免" */
  346. {
  347. switch (curSpeed_state.state)
  348. {
  349. case Charge:
  350. break;
  351. case InitPosDet:
  352. /* Command run disable */
  353. /* Motor run flag set */
  354. cmfsm_stFlg.blMotorStopFlg = FALSE;
  355. if (!switch_flg.SysRun_Flag || switch_flg.SysFault_Flag || power_stPowStateOut.powerstate == POWER_OFF)
  356. {
  357. Switch_speed_FSM(&Stop_state);
  358. }
  359. if (scm_ulStatCt < mn_ulAlignRampTbcCt)
  360. {}
  361. else if (scm_ulStatCt >= (mn_ulAlignRampTbcCt + mn_ulAlignHoldTbcCt + 10))
  362. {
  363. if(cp_stFlg.SpiOffsetFirstSetFlg == 0)
  364. {
  365. cp_stFlg.SpiOffsetFirstSetFinishFlg = 1;
  366. }
  367. else
  368. {
  369. if(cp_stFlg.ThetaGetModelSelect == ANG_RESOLVER)
  370. {
  371. align_stCoef.uwSPIreadOnceCt = 0;
  372. }
  373. else
  374. {}
  375. if(cp_stFlg.RunModelSelect == InitPos)
  376. {
  377. }
  378. else if(cp_stFlg.RunModelSelect == ClZLOOP)
  379. {
  380. if(cp_stFlg.ThetaGetModelSelect == ANG_OBSERVER)
  381. {
  382. Switch_speed_FSM(&StartUp_state);
  383. }
  384. else
  385. {
  386. Switch_speed_FSM(&ClzLoop_state);
  387. }
  388. }
  389. else
  390. {
  391. Switch_speed_FSM(&StartUp_state);
  392. }
  393. }
  394. }
  395. else
  396. {
  397. //do nothing
  398. }
  399. break;
  400. case StartUp:
  401. if (!switch_flg.SysRun_Flag || switch_flg.SysFault_Flag || power_stPowStateOut.powerstate == POWER_OFF)
  402. {
  403. Switch_speed_FSM(&Stop_state);
  404. }
  405. if (scm_StartUpOvrFlg == TRUE)
  406. {
  407. if(cp_stFlg.ThetaGetModelSelect == ANG_OBSERVER)
  408. {
  409. if(cp_stFlg.RunModelSelect == ClZLOOP || cp_stFlg.RunModelSelect == CityBIKE || cp_stFlg.RunModelSelect == MountainBIKE)
  410. {
  411. if (FSM2nd_Run_state.state == Boost)
  412. {
  413. cmd_stCmdOut.slIntRefPu = ((SLONG)scm_stSpdFbkLpf.slY.sw.hi * 5) << 12; // Q29 5/4
  414. }
  415. else if (FSM2nd_Run_state.state == Assistance)
  416. {
  417. //do nothing
  418. }
  419. else
  420. {
  421. //do nothing
  422. }
  423. Switch_speed_FSM(&Open2Clz_state);
  424. }
  425. }
  426. else
  427. {
  428. }
  429. }
  430. /* Command run disable */
  431. break;
  432. case Open2Clz:
  433. /* Command run disable */
  434. if (!switch_flg.SysRun_Flag || switch_flg.SysFault_Flag || power_stPowStateOut.powerstate == POWER_OFF)
  435. {
  436. Switch_speed_FSM(&Stop_state);
  437. }
  438. /* Switch over */
  439. if (scm_blCurSwitchOvrFlg && scm_blAngSwitchOvrFlg)
  440. {
  441. Switch_speed_FSM(&ClzLoop_state);
  442. }
  443. break;
  444. case ClzLoop:
  445. /* Go to stop */
  446. cmfsm_stFlg.blMotorStopFlg = FALSE;
  447. if (switch_flg.SysFault_Flag == 1 || power_stPowStateOut.powerstate == POWER_OFF)
  448. {
  449. Switch_speed_FSM(&Stop_state);
  450. }
  451. if (!switch_flg.SysRun_Flag)
  452. {
  453. /* Go to stop */
  454. if ((ABS(scm_swSpdRefPu) < mn_swStopSpdRefPu) && (scm_uwSpdFbkLpfAbsPu < mn_swStopSpdRefPu))
  455. {
  456. scm_swIdRefPu = 0;
  457. scm_swIqRefPu = 0;
  458. Switch_speed_FSM(&Stop_state);
  459. }
  460. }
  461. else
  462. {}
  463. break;
  464. case Stop:
  465. if (switch_flg.SysRun_Flag == TRUE && switch_flg.SysFault_Flag == FALSE) //&& power_stPowStateOut.powerstate == POWER_ON_END
  466. {
  467. scm_voSpdCtrMdInit();
  468. if(cp_stFlg.SpiOffsetFirstSetFlg == 0)
  469. {
  470. Switch_speed_FSM(&InitPosDet_state);
  471. }
  472. else
  473. {
  474. if(cp_stFlg.RunModelSelect == CityBIKE || cp_stFlg.RunModelSelect == MountainBIKE)
  475. {
  476. if(cp_stFlg.ThetaGetModelSelect == ANG_OBSERVER)
  477. {
  478. Switch_speed_FSM(&InitPosDet_state);
  479. }
  480. else
  481. {
  482. Switch_speed_FSM(&ClzLoop_state);
  483. }
  484. }
  485. else
  486. {
  487. #ifdef RUN_ARCH_SIM
  488. Switch_speed_FSM(&ClzLoop_state);
  489. #else
  490. Switch_speed_FSM(&InitPosDet_state);
  491. #endif
  492. }
  493. }
  494. }
  495. break;
  496. default:
  497. break;
  498. }
  499. }
  500. void Switch_speed_FSM(const SPD_STATE_HOOK *in)
  501. {
  502. scm_ulStatCt = 0;
  503. curSpeed_state = *in;
  504. }
  505. void Switch_speed_FSMInit(void)
  506. {
  507. scm_ulStatCt = 0;
  508. curSpeed_state = Stop_state;
  509. }
  510. /************************************************************************
  511. Function: void RUN_FSM_Main(void)
  512. Description:
  513. Call by:
  514. Input Variables:
  515. Output/Return Variables:
  516. Subroutine Call:
  517. Reference:
  518. ************************************************************************/
  519. /************************************************************************
  520. Local Functions: N/A
  521. ************************************************************************/
  522. /************************************************************************
  523. Copyright (c) 2018 Welling Motor Technology(Shanghai) Co. Ltd.
  524. All rights reserved.
  525. ************************************************************************/
  526. #ifdef _STARTFSM_C_
  527. #undef _STARTFSM_C_ /* parasoft-suppress MISRA2004-19_6 "本项目中无法更改,后续避免使用" */
  528. #endif
  529. /************************************************************************
  530. End of this File (EOF)!
  531. Do not put anything after this part!
  532. ************************************************************************/