spdctrFSM.c 19 KB

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