lift.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /**
  2. *********************************************************************************************************
  3. * xmk guide
  4. *
  5. * (c) Copyright 2016-2020, hualijidian.com
  6. * All Rights Reserved
  7. *
  8. * @file lift.c
  9. * @author eric
  10. * @brief
  11. * @date 2018��2��1��
  12. * @version V0.0.1
  13. *********************************************************************************************************
  14. */
  15. #include "lift.h"
  16. #include "guide.h"
  17. #include "env.h"
  18. #include "screen.h"
  19. #include "systick.h"
  20. #define DBG_SECTION_NAME "lift"
  21. #define DBG_LEVEL DBG_INFO
  22. #include <rtdbg.h>
  23. uint8_t Lift_Init(void) {
  24. LOG_D("LiftInit");
  25. S.LiftStatus = LIFT_STATUS_INIT;
  26. S.DirStatus = DIR_STATUS_INIT;
  27. // Usart_Config(USART8, 57600, USART_Parity_No); //ǰ���ŷ�����
  28. return 1;
  29. }
  30. /**
  31. * @brief ���״̬
  32. * @param
  33. * @retval
  34. */
  35. uint8_t Lift_Process(void) {
  36. if(S.LiftStatus == LIFT_STATUS_UP){
  37. return Lift_Up();
  38. }
  39. if(S.LiftStatus == LIFT_STATUS_DOWN){
  40. return Lift_Down();
  41. }
  42. return 0;
  43. }
  44. /**
  45. * @brief ֹͣ
  46. * @param
  47. * @retval
  48. * @note
  49. */
  50. uint8_t Lift_Motor_Up(void) {
  51. MOTOR1_EN1 = 1;
  52. MOTOR1_BK1 = 0;
  53. MOTOR1_FR1 = 1; //唐山是1
  54. LIFT1_Speed(1);
  55. Set.LiftRpm = 2000;
  56. LIFT1_UP;
  57. return 1;
  58. }
  59. uint8_t Lift_Motor_Down(void) {
  60. MOTOR1_EN1 = 1;
  61. MOTOR1_BK1 = 0;
  62. MOTOR1_FR1 = 0; //唐山是0
  63. LIFT1_Speed(1);
  64. Set.LiftRpm = -2000;
  65. LIFT1_DOWN;
  66. return 1;
  67. }
  68. uint8_t Lift_Stop(void) {
  69. MOTOR1_EN1 = 0;
  70. MOTOR1_BK1 = 1;
  71. MOTOR1_FR1 = 0;
  72. LIFT1_Speed(10);
  73. Set.LiftRpm = 0;
  74. LIFT1_STOP;
  75. return 1;
  76. }
  77. /**
  78. * @brief ����
  79. * @param
  80. * @retval
  81. * @note
  82. */
  83. uint8_t Lift_Up(void) {
  84. static uint32_t intervalTime100ms;
  85. if(intervalTime100ms == Timer100ms){
  86. return 0;
  87. }
  88. intervalTime100ms = Timer100ms;
  89. if(LIFT1_IS_IN_TOP){
  90. Lift_Stop();
  91. Screen_Icon_Lift(Icon_Clear);
  92. S.LiftStatus = LIFT_STATUS_TOP;
  93. LOG_D("Lift in top ");
  94. return 1;
  95. }
  96. Lift_Motor_Up();
  97. Screen_Icon_Lift(Icon_Up);
  98. if(S.LiftStatus != LIFT_STATUS_UP){
  99. LOG_D("S.LiftStatus -> LIFT_STATUS_UP;");
  100. }
  101. S.LiftStatus = LIFT_STATUS_UP;
  102. return 0;
  103. }
  104. uint8_t Lift_ManualUp(void) {
  105. if(LIFT1_IS_IN_TOP){
  106. Lift_Stop();
  107. Screen_Icon_Lift(Icon_Clear);
  108. S.LiftStatus = LIFT_STATUS_TOP;
  109. LOG_D("Lift in top");
  110. return 1;
  111. }
  112. Lift_Motor_Up();
  113. Screen_Icon_Lift(Icon_Up);
  114. S.LiftStatus = LIFT_STATUS_MANUAL_UP;
  115. LOG_D("Lift_ManualUp");
  116. return 0;
  117. }
  118. /**
  119. * @brief �½�
  120. * @param
  121. * @retval
  122. * @note
  123. */
  124. uint8_t Lift_Down(void) {
  125. static volatile uint32_t intervalTime100ms;
  126. if(intervalTime100ms == Timer100ms){
  127. return 0;
  128. }
  129. intervalTime100ms = Timer100ms;
  130. if(LIFT1_IS_IN_BOTTOM){
  131. Lift_Stop();
  132. Screen_Icon_Lift(Icon_Clear);
  133. S.LiftStatus = LIFT_STATUS_BOTTOM;
  134. LOG_D("Lift in bottom");
  135. return 1;
  136. }
  137. if(S.LiftStatus != LIFT_STATUS_DOWN){
  138. LOG_D("S.LiftStatus ->Lift Down");
  139. S.LiftStatus = LIFT_STATUS_DOWN;
  140. }
  141. Lift_Motor_Down();
  142. Screen_Icon_Lift(Icon_Down);
  143. return 0;
  144. }
  145. uint8_t Lift_ManualDown(void) {
  146. if(LIFT1_IS_IN_BOTTOM){
  147. Lift_Stop();
  148. Screen_Icon_Lift(Icon_Clear);
  149. S.LiftStatus = LIFT_STATUS_BOTTOM;
  150. LOG_D("Lift in bottom");
  151. return 1;
  152. }
  153. S.LiftStatus = LIFT_STATUS_MANUAL_DOWN;
  154. Screen_Icon_Lift(Icon_Down);
  155. LOG_D("Lift_ManualDown");
  156. Lift_Motor_Down();
  157. return 0;
  158. }
  159. //*********************˿�ܶ���************************************************************************
  160. uint8_t Lift_Process_Screw(void) {
  161. if(S.LiftStatus == LIFT_STATUS_UP){
  162. return Lift_Up_Screw();
  163. }
  164. if(S.LiftStatus == LIFT_STATUS_DOWN){
  165. return Lift_Down_Screw();
  166. }
  167. return 0;
  168. }
  169. uint8_t Lift_Stop_Screw(void) {
  170. int32_t StopPos;
  171. if (S.LiftStatus == LIFT_STATUS_MANUAL_UP){
  172. StopPos = S.LiftPosL + 250000;
  173. if (StopPos > Set.LiftUpPos){
  174. StopPos = Set.LiftUpPos;
  175. }
  176. Set.LiftPos = StopPos;
  177. }
  178. if (S.LiftStatus == LIFT_STATUS_MANUAL_DOWN){
  179. StopPos = S.LiftPosL - 250000;
  180. if (StopPos < Set.LiftDownPos){
  181. StopPos = Set.LiftDownPos;
  182. }
  183. Set.LiftPos = StopPos;
  184. }
  185. S.LiftStatus = LIFT_STATUS_MANUAL_STOP;
  186. return 0;
  187. }
  188. uint8_t Lift_Up_Screw(void) {
  189. static uint32_t intervalTime100ms;
  190. if(intervalTime100ms == Timer100ms){
  191. return 0;
  192. }
  193. intervalTime100ms = Timer100ms;
  194. if(S.LiftPosL == Set.LiftUpPos && S.LiftPosR == Set.LiftUpPos){
  195. Screen_Icon_Lift(Icon_Clear);
  196. S.LiftStatus = LIFT_STATUS_TOP;
  197. LOG_D("Lift in top ");
  198. return 1;
  199. }
  200. Set.LiftPos = Set.LiftUpPos;
  201. Screen_Icon_Lift(Icon_Up);
  202. if(S.LiftStatus != LIFT_STATUS_UP){
  203. LOG_D("S.LiftStatus -> LIFT_STATUS_UP;");
  204. }
  205. S.LiftStatus = LIFT_STATUS_UP;
  206. return 0;
  207. }
  208. uint8_t Lift_ManualUp_Screw(void) {
  209. if(S.LiftPosL == Set.LiftUpPos && S.LiftPosR == Set.LiftUpPos){
  210. Screen_Icon_Lift(Icon_Clear);
  211. S.LiftStatus = LIFT_STATUS_TOP;
  212. LOG_D("Lift in top");
  213. return 1;
  214. }
  215. Set.LiftPos = Set.LiftUpPos;
  216. Screen_Icon_Lift(Icon_Up);
  217. S.LiftStatus = LIFT_STATUS_MANUAL_UP;
  218. LOG_D("Lift_ManualUp");
  219. return 0;
  220. }
  221. /**
  222. * @brief �½�
  223. * @param
  224. * @retval
  225. * @note
  226. */
  227. uint8_t Lift_Down_Screw(void) {
  228. static volatile uint32_t intervalTime100ms;
  229. if(intervalTime100ms == Timer100ms){
  230. return 0;
  231. }
  232. intervalTime100ms = Timer100ms;
  233. if(S.LiftPosL == Set.LiftDownPos && S.LiftPosR == Set.LiftDownPos){
  234. Screen_Icon_Lift(Icon_Clear);
  235. S.LiftStatus = LIFT_STATUS_BOTTOM;
  236. LOG_D("Lift in bottom");
  237. return 1;
  238. }
  239. if(S.LiftStatus != LIFT_STATUS_DOWN){
  240. LOG_D("S.LiftStatus ->Lift Down");
  241. S.LiftStatus = LIFT_STATUS_DOWN;
  242. }
  243. Set.LiftPos = Set.LiftDownPos;
  244. Screen_Icon_Lift(Icon_Down);
  245. return 0;
  246. }
  247. uint8_t Lift_ManualDown_Screw(void) {
  248. if(S.LiftPosL == Set.LiftDownPos && S.LiftPosR == Set.LiftDownPos){
  249. Screen_Icon_Lift(Icon_Clear);
  250. S.LiftStatus = LIFT_STATUS_BOTTOM;
  251. LOG_D("Lift in bottom");
  252. return 1;
  253. }
  254. S.LiftStatus = LIFT_STATUS_MANUAL_DOWN;
  255. Screen_Icon_Lift(Icon_Down);
  256. LOG_D("Lift_ManualDown");
  257. Set.LiftPos = Set.LiftDownPos;
  258. return 0;
  259. }
  260. //*********************CSCF������************************************************************************
  261. static uint32_t DirValveOffTimer;
  262. uint8_t Dir_Lift_Process(void) {
  263. // LOG_D("S.DirStatus:%d \n\r",S.DirStatus);
  264. switch(S.DirStatus){
  265. case DIR_STATUS_INIT:
  266. if (DIR_LIFT2_IS_IN_FB) //顶升的前后限位,换向。左右限位,轮子左右走
  267. {
  268. S.DirStatus = DIR_STATUS_FB;
  269. //LOG_D("DirStatus in FB");
  270. }
  271. break;
  272. case DIR_STATUS_FB:
  273. if (DIR_LIFT2_IS_IN_LR) {
  274. S.DirStatus = DIR_STATUS_LR;
  275. //LOG_D("DirStatus in LR");
  276. }
  277. // DirValveOff();
  278. break;
  279. case DIR_STATUS_LR:
  280. if (DIR_LIFT2_IS_IN_FB) {
  281. S.DirStatus = DIR_STATUS_FB;
  282. //LOG_D("DirStatus in FB");
  283. }
  284. // DirValveOff();
  285. break;
  286. }
  287. return 0;
  288. }
  289. uint8_t DirValveOff(void){
  290. DirValveOffTimer++;
  291. if(DirValveOffTimer > 3){
  292. }
  293. return 0;
  294. }
  295. uint8_t DirValveOn(void){
  296. DirValveOffTimer = 0;
  297. return 0;
  298. }
  299. uint8_t Dir_Lift_Up(void) {
  300. MOTOR1_EN1 = 1;
  301. MOTOR1_BK1 = 0;
  302. MOTOR1_FR1 = 1; //唐山是1
  303. LIFT1_Speed(1);
  304. Set.LiftRpm = 2000;
  305. DIR_LIFT2_UP;
  306. return 1;
  307. }
  308. uint8_t Dir_Lift_Down(void) {
  309. MOTOR1_EN1 = 1;
  310. MOTOR1_BK1 = 0;
  311. MOTOR1_FR1 = 0;//唐山是0
  312. LIFT1_Speed(1);
  313. Set.LiftRpm = -2000;
  314. DIR_LIFT2_DOWN;
  315. return 1;
  316. }
  317. uint8_t Dir_Lift_Stop(void) {
  318. MOTOR1_EN1 = 0;
  319. MOTOR1_BK1 = 1;
  320. MOTOR1_FR1 = 0;
  321. LIFT1_Speed(10);
  322. Set.LiftRpm = 0;
  323. DIR_LIFT2_STOP;
  324. return 1;
  325. }
  326. uint32_t DirLiftFbTimer = 0;
  327. void Dir_Lift_FB_Timer(void){
  328. if(DIR_LIFT2_IS_IN_FB){
  329. if(DirLiftFbTimer != DIR_LIFT_TIMER){
  330. DirLiftFbTimer++;
  331. }
  332. }else{
  333. DirLiftFbTimer = 0;
  334. }
  335. }
  336. uint8_t Dir_Lift_FB(void) {
  337. static uint32_t intervalTime100ms;
  338. if(intervalTime100ms == Timer100ms){
  339. return 0;
  340. }
  341. intervalTime100ms = Timer100ms;
  342. if(DIR_LIFT2_IS_IN_FB){
  343. if(DirLiftFbTimer == DIR_LIFT_TIMER){
  344. Dir_Lift_Stop();
  345. Screen_Icon_Lift(Icon_Clear);
  346. S.DirStatus = DIR_STATUS_FB;
  347. LOG_D("DirStatus in fb ");
  348. return 1;
  349. }
  350. }
  351. Dir_Lift_Down();
  352. Screen_Icon_Lift(Icon_Up);
  353. if(S.DirLiftStatus != DIR_STATUS_DOWN){
  354. LOG_D("S.DIR_STATUS_FB -> DIR_STATUS_FB;");
  355. }
  356. S.DirLiftStatus = DIR_STATUS_DOWN;
  357. return 0;
  358. }
  359. uint8_t Dir_Lift_ManualFB(void) {
  360. if(S.Status != STATUS_ESTOP)
  361. S.Status = STATUS_REMOTE_MANUAL;
  362. if(DIR_LIFT2_IS_IN_FB){
  363. if(DirLiftFbTimer == DIR_LIFT_TIMER){
  364. Dir_Lift_Stop();
  365. Screen_Icon_Lift(Icon_Clear);
  366. S.DirStatus = DIR_STATUS_FB;
  367. LOG_D("DirStatus in fb ");
  368. return 1;
  369. }
  370. }
  371. Dir_Lift_Down();
  372. Screen_Icon_Lift(Icon_Up);
  373. S.DirLiftStatus = DIR_STATUS_MANUAL_DOWN;
  374. LOG_D("Dir_Lift_ManualDown");
  375. return 0;
  376. }
  377. /**
  378. * @brief 下降
  379. * @param
  380. * @retval
  381. * @note
  382. */
  383. uint32_t DirLiftLrTimer = 0;
  384. void Dir_Lift_LR_Timer(void){
  385. if(DIR_LIFT2_IS_IN_LR){
  386. if(DirLiftLrTimer != DIR_LIFT_TIMER){
  387. DirLiftLrTimer++;
  388. }
  389. }else{
  390. DirLiftLrTimer = 0;
  391. }
  392. }
  393. /**
  394. * @brief �½�
  395. * @param
  396. * @retval
  397. * @note
  398. */
  399. uint8_t Dir_Lift_LR(void) {
  400. static volatile uint32_t intervalTime100ms;
  401. if(intervalTime100ms == Timer100ms){
  402. return 0;
  403. }
  404. intervalTime100ms = Timer100ms;
  405. if(DIR_LIFT2_IS_IN_LR){
  406. if(DirLiftLrTimer == DIR_LIFT_TIMER){
  407. Dir_Lift_Stop();
  408. Screen_Icon_Lift(Icon_Clear);
  409. S.DirStatus = DIR_STATUS_LR;
  410. // LOG_W("Dir in lr");
  411. return 1;
  412. }
  413. }
  414. if(S.DirLiftStatus != DIR_STATUS_UP){
  415. LOG_D("S.DirStatus ->Dir_Lift Up");
  416. S.DirLiftStatus = DIR_STATUS_UP;
  417. }
  418. Dir_Lift_Up();
  419. Screen_Icon_Lift(Icon_Down);
  420. return 0;
  421. }
  422. uint8_t Dir_Lift_ManualLR(void) {
  423. if(S.Status != STATUS_ESTOP)
  424. S.Status = STATUS_REMOTE_MANUAL;
  425. if(DIR_LIFT2_IS_IN_LR){
  426. if(DirLiftLrTimer == DIR_LIFT_TIMER){
  427. Dir_Lift_Stop();
  428. Screen_Icon_Lift(Icon_Clear);
  429. S.DirStatus = DIR_STATUS_LR;
  430. LOG_D("DirStatus in lr");
  431. return 1;
  432. }
  433. }
  434. S.DirLiftStatus = DIR_STATUS_UP;
  435. Screen_Icon_Lift(Icon_Down);
  436. LOG_D("Lift_ManualDown");
  437. Dir_Lift_Up();
  438. return 0;
  439. }
  440. uint8_t Decompression(uint8_t btn){
  441. if(btn == 1){
  442. DEC_PRESS_1;
  443. }
  444. if(btn == 2){
  445. DEC_PRESS_2;
  446. }
  447. if(btn == 0){
  448. DEC_PRESS_STOP;
  449. }
  450. return 0;
  451. }