123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- /**
- *********************************************************************************************************
- * xmk guide
- *
- * (c) Copyright 2016-2020, hualijidian.com
- * All Rights Reserved
- *
- * @file lift.c
- * @author eric
- * @brief
- * @date 2018��2��1��
- * @version V0.0.1
- *********************************************************************************************************
- */
- #include "lift.h"
- #include "guide.h"
- #include "env.h"
- #include "screen.h"
- #include "systick.h"
- #define DBG_SECTION_NAME "lift"
- #define DBG_LEVEL DBG_INFO
- #include <rtdbg.h>
- uint8_t Lift_Init(void) {
- LOG_D("LiftInit");
- S.LiftStatus = LIFT_STATUS_INIT;
- S.DirStatus = DIR_STATUS_INIT;
- // Usart_Config(USART8, 57600, USART_Parity_No); //ǰ���ŷ�����
- return 1;
- }
- /**
- * @brief ���״̬
- * @param
- * @retval
- */
- uint8_t Lift_Process(void) {
- if(S.LiftStatus == LIFT_STATUS_UP){
- return Lift_Up();
- }
- if(S.LiftStatus == LIFT_STATUS_DOWN){
- return Lift_Down();
- }
- return 0;
- }
- /**
- * @brief ֹͣ
- * @param
- * @retval
- * @note
- */
- uint8_t Lift_Motor_Up(void) {
- MOTOR1_EN1 = 1;
- MOTOR1_BK1 = 0;
- MOTOR1_FR1 = 1; //唐山是1
- LIFT1_Speed(1);
- Set.LiftRpm = 2000;
- LIFT1_UP;
- return 1;
- }
- uint8_t Lift_Motor_Down(void) {
- MOTOR1_EN1 = 1;
- MOTOR1_BK1 = 0;
- MOTOR1_FR1 = 0; //唐山是0
- LIFT1_Speed(1);
- Set.LiftRpm = -2000;
- LIFT1_DOWN;
- return 1;
- }
- uint8_t Lift_Stop(void) {
- MOTOR1_EN1 = 0;
- MOTOR1_BK1 = 1;
- MOTOR1_FR1 = 0;
- LIFT1_Speed(10);
- Set.LiftRpm = 0;
- LIFT1_STOP;
- return 1;
- }
- /**
- * @brief ����
- * @param
- * @retval
- * @note
- */
- uint8_t Lift_Up(void) {
- static uint32_t intervalTime100ms;
- if(intervalTime100ms == Timer100ms){
- return 0;
- }
- intervalTime100ms = Timer100ms;
- if(LIFT1_IS_IN_TOP){
- Lift_Stop();
- Screen_Icon_Lift(Icon_Clear);
- S.LiftStatus = LIFT_STATUS_TOP;
- LOG_D("Lift in top ");
- return 1;
- }
- Lift_Motor_Up();
- Screen_Icon_Lift(Icon_Up);
- if(S.LiftStatus != LIFT_STATUS_UP){
- LOG_D("S.LiftStatus -> LIFT_STATUS_UP;");
- }
- S.LiftStatus = LIFT_STATUS_UP;
- return 0;
- }
- uint8_t Lift_ManualUp(void) {
- if(LIFT1_IS_IN_TOP){
- Lift_Stop();
- Screen_Icon_Lift(Icon_Clear);
- S.LiftStatus = LIFT_STATUS_TOP;
- LOG_D("Lift in top");
- return 1;
- }
- Lift_Motor_Up();
- Screen_Icon_Lift(Icon_Up);
- S.LiftStatus = LIFT_STATUS_MANUAL_UP;
- LOG_D("Lift_ManualUp");
- return 0;
- }
- /**
- * @brief �½�
- * @param
- * @retval
- * @note
- */
- uint8_t Lift_Down(void) {
- static volatile uint32_t intervalTime100ms;
- if(intervalTime100ms == Timer100ms){
- return 0;
- }
- intervalTime100ms = Timer100ms;
- if(LIFT1_IS_IN_BOTTOM){
- Lift_Stop();
- Screen_Icon_Lift(Icon_Clear);
- S.LiftStatus = LIFT_STATUS_BOTTOM;
- LOG_D("Lift in bottom");
- return 1;
- }
- if(S.LiftStatus != LIFT_STATUS_DOWN){
- LOG_D("S.LiftStatus ->Lift Down");
- S.LiftStatus = LIFT_STATUS_DOWN;
- }
- Lift_Motor_Down();
- Screen_Icon_Lift(Icon_Down);
- return 0;
- }
- uint8_t Lift_ManualDown(void) {
- if(LIFT1_IS_IN_BOTTOM){
- Lift_Stop();
- Screen_Icon_Lift(Icon_Clear);
- S.LiftStatus = LIFT_STATUS_BOTTOM;
- LOG_D("Lift in bottom");
- return 1;
- }
- S.LiftStatus = LIFT_STATUS_MANUAL_DOWN;
- Screen_Icon_Lift(Icon_Down);
- LOG_D("Lift_ManualDown");
- Lift_Motor_Down();
- return 0;
- }
- //*********************˿�ܶ���************************************************************************
- uint8_t Lift_Process_Screw(void) {
- if(S.LiftStatus == LIFT_STATUS_UP){
- return Lift_Up_Screw();
- }
- if(S.LiftStatus == LIFT_STATUS_DOWN){
- return Lift_Down_Screw();
- }
- return 0;
- }
- uint8_t Lift_Stop_Screw(void) {
- int32_t StopPos;
- if (S.LiftStatus == LIFT_STATUS_MANUAL_UP){
- StopPos = S.LiftPosL + 250000;
- if (StopPos > Set.LiftUpPos){
- StopPos = Set.LiftUpPos;
- }
- Set.LiftPos = StopPos;
- }
- if (S.LiftStatus == LIFT_STATUS_MANUAL_DOWN){
- StopPos = S.LiftPosL - 250000;
- if (StopPos < Set.LiftDownPos){
- StopPos = Set.LiftDownPos;
- }
- Set.LiftPos = StopPos;
- }
- S.LiftStatus = LIFT_STATUS_MANUAL_STOP;
- return 0;
- }
- uint8_t Lift_Up_Screw(void) {
- static uint32_t intervalTime100ms;
- if(intervalTime100ms == Timer100ms){
- return 0;
- }
- intervalTime100ms = Timer100ms;
- if(S.LiftPosL == Set.LiftUpPos && S.LiftPosR == Set.LiftUpPos){
- Screen_Icon_Lift(Icon_Clear);
- S.LiftStatus = LIFT_STATUS_TOP;
- LOG_D("Lift in top ");
- return 1;
- }
- Set.LiftPos = Set.LiftUpPos;
- Screen_Icon_Lift(Icon_Up);
- if(S.LiftStatus != LIFT_STATUS_UP){
- LOG_D("S.LiftStatus -> LIFT_STATUS_UP;");
- }
- S.LiftStatus = LIFT_STATUS_UP;
- return 0;
- }
- uint8_t Lift_ManualUp_Screw(void) {
- if(S.LiftPosL == Set.LiftUpPos && S.LiftPosR == Set.LiftUpPos){
- Screen_Icon_Lift(Icon_Clear);
- S.LiftStatus = LIFT_STATUS_TOP;
- LOG_D("Lift in top");
- return 1;
- }
- Set.LiftPos = Set.LiftUpPos;
- Screen_Icon_Lift(Icon_Up);
- S.LiftStatus = LIFT_STATUS_MANUAL_UP;
- LOG_D("Lift_ManualUp");
- return 0;
- }
- /**
- * @brief �½�
- * @param
- * @retval
- * @note
- */
- uint8_t Lift_Down_Screw(void) {
- static volatile uint32_t intervalTime100ms;
- if(intervalTime100ms == Timer100ms){
- return 0;
- }
- intervalTime100ms = Timer100ms;
- if(S.LiftPosL == Set.LiftDownPos && S.LiftPosR == Set.LiftDownPos){
- Screen_Icon_Lift(Icon_Clear);
- S.LiftStatus = LIFT_STATUS_BOTTOM;
- LOG_D("Lift in bottom");
- return 1;
- }
- if(S.LiftStatus != LIFT_STATUS_DOWN){
- LOG_D("S.LiftStatus ->Lift Down");
- S.LiftStatus = LIFT_STATUS_DOWN;
- }
- Set.LiftPos = Set.LiftDownPos;
- Screen_Icon_Lift(Icon_Down);
- return 0;
- }
- uint8_t Lift_ManualDown_Screw(void) {
- if(S.LiftPosL == Set.LiftDownPos && S.LiftPosR == Set.LiftDownPos){
- Screen_Icon_Lift(Icon_Clear);
- S.LiftStatus = LIFT_STATUS_BOTTOM;
- LOG_D("Lift in bottom");
- return 1;
- }
- S.LiftStatus = LIFT_STATUS_MANUAL_DOWN;
- Screen_Icon_Lift(Icon_Down);
- LOG_D("Lift_ManualDown");
- Set.LiftPos = Set.LiftDownPos;
- return 0;
- }
- //*********************CSCF������************************************************************************
- static uint32_t DirValveOffTimer;
- uint8_t Dir_Lift_Process(void) {
- // LOG_D("S.DirStatus:%d \n\r",S.DirStatus);
- switch(S.DirStatus){
- case DIR_STATUS_INIT:
- if (DIR_LIFT2_IS_IN_FB) //顶升的前后限位,换向。左右限位,轮子左右走
- {
- S.DirStatus = DIR_STATUS_FB;
- //LOG_D("DirStatus in FB");
- }
- break;
- case DIR_STATUS_FB:
- if (DIR_LIFT2_IS_IN_LR) {
- S.DirStatus = DIR_STATUS_LR;
- //LOG_D("DirStatus in LR");
- }
- // DirValveOff();
- break;
- case DIR_STATUS_LR:
- if (DIR_LIFT2_IS_IN_FB) {
- S.DirStatus = DIR_STATUS_FB;
- //LOG_D("DirStatus in FB");
- }
- // DirValveOff();
- break;
- }
- return 0;
- }
- uint8_t DirValveOff(void){
- DirValveOffTimer++;
- if(DirValveOffTimer > 3){
- }
- return 0;
- }
- uint8_t DirValveOn(void){
- DirValveOffTimer = 0;
- return 0;
- }
- uint8_t Dir_Lift_Up(void) {
- MOTOR1_EN1 = 1;
- MOTOR1_BK1 = 0;
- MOTOR1_FR1 = 1; //唐山是1
- LIFT1_Speed(1);
- Set.LiftRpm = 2000;
- DIR_LIFT2_UP;
- return 1;
- }
- uint8_t Dir_Lift_Down(void) {
- MOTOR1_EN1 = 1;
- MOTOR1_BK1 = 0;
- MOTOR1_FR1 = 0;//唐山是0
- LIFT1_Speed(1);
- Set.LiftRpm = -2000;
- DIR_LIFT2_DOWN;
- return 1;
- }
- uint8_t Dir_Lift_Stop(void) {
- MOTOR1_EN1 = 0;
- MOTOR1_BK1 = 1;
- MOTOR1_FR1 = 0;
- LIFT1_Speed(10);
- Set.LiftRpm = 0;
- DIR_LIFT2_STOP;
- return 1;
- }
- uint32_t DirLiftFbTimer = 0;
- void Dir_Lift_FB_Timer(void){
- if(DIR_LIFT2_IS_IN_FB){
- if(DirLiftFbTimer != DIR_LIFT_TIMER){
- DirLiftFbTimer++;
- }
- }else{
- DirLiftFbTimer = 0;
- }
- }
- uint8_t Dir_Lift_FB(void) {
- static uint32_t intervalTime100ms;
- if(intervalTime100ms == Timer100ms){
- return 0;
- }
- intervalTime100ms = Timer100ms;
- if(DIR_LIFT2_IS_IN_FB){
- if(DirLiftFbTimer == DIR_LIFT_TIMER){
- Dir_Lift_Stop();
- Screen_Icon_Lift(Icon_Clear);
- S.DirStatus = DIR_STATUS_FB;
- LOG_D("DirStatus in fb ");
- return 1;
- }
- }
- Dir_Lift_Down();
- Screen_Icon_Lift(Icon_Up);
- if(S.DirLiftStatus != DIR_STATUS_DOWN){
- LOG_D("S.DIR_STATUS_FB -> DIR_STATUS_FB;");
- }
- S.DirLiftStatus = DIR_STATUS_DOWN;
- return 0;
- }
- uint8_t Dir_Lift_ManualFB(void) {
- if(S.Status != STATUS_ESTOP)
- S.Status = STATUS_REMOTE_MANUAL;
- if(DIR_LIFT2_IS_IN_FB){
- if(DirLiftFbTimer == DIR_LIFT_TIMER){
- Dir_Lift_Stop();
- Screen_Icon_Lift(Icon_Clear);
- S.DirStatus = DIR_STATUS_FB;
- LOG_D("DirStatus in fb ");
- return 1;
- }
- }
- Dir_Lift_Down();
- Screen_Icon_Lift(Icon_Up);
- S.DirLiftStatus = DIR_STATUS_MANUAL_DOWN;
- LOG_D("Dir_Lift_ManualDown");
- return 0;
- }
- /**
- * @brief 下降
- * @param
- * @retval
- * @note
- */
- uint32_t DirLiftLrTimer = 0;
- void Dir_Lift_LR_Timer(void){
- if(DIR_LIFT2_IS_IN_LR){
- if(DirLiftLrTimer != DIR_LIFT_TIMER){
- DirLiftLrTimer++;
- }
- }else{
- DirLiftLrTimer = 0;
- }
- }
- /**
- * @brief �½�
- * @param
- * @retval
- * @note
- */
- uint8_t Dir_Lift_LR(void) {
- static volatile uint32_t intervalTime100ms;
- if(intervalTime100ms == Timer100ms){
- return 0;
- }
- intervalTime100ms = Timer100ms;
- if(DIR_LIFT2_IS_IN_LR){
- if(DirLiftLrTimer == DIR_LIFT_TIMER){
- Dir_Lift_Stop();
- Screen_Icon_Lift(Icon_Clear);
- S.DirStatus = DIR_STATUS_LR;
- // LOG_W("Dir in lr");
- return 1;
- }
- }
- if(S.DirLiftStatus != DIR_STATUS_UP){
- LOG_D("S.DirStatus ->Dir_Lift Up");
- S.DirLiftStatus = DIR_STATUS_UP;
- }
- Dir_Lift_Up();
- Screen_Icon_Lift(Icon_Down);
- return 0;
- }
- uint8_t Dir_Lift_ManualLR(void) {
- if(S.Status != STATUS_ESTOP)
- S.Status = STATUS_REMOTE_MANUAL;
- if(DIR_LIFT2_IS_IN_LR){
- if(DirLiftLrTimer == DIR_LIFT_TIMER){
- Dir_Lift_Stop();
- Screen_Icon_Lift(Icon_Clear);
- S.DirStatus = DIR_STATUS_LR;
- LOG_D("DirStatus in lr");
- return 1;
- }
- }
- S.DirLiftStatus = DIR_STATUS_UP;
- Screen_Icon_Lift(Icon_Down);
- LOG_D("Lift_ManualDown");
- Dir_Lift_Up();
- return 0;
- }
- uint8_t Decompression(uint8_t btn){
- if(btn == 1){
- DEC_PRESS_1;
- }
- if(btn == 2){
- DEC_PRESS_2;
- }
- if(btn == 0){
- DEC_PRESS_STOP;
- }
- return 0;
- }
|