mbed2 zad 5b

Dependencies:   LCD_DISCO_F429ZI mbed BSP_DISCO_F429ZI

Committer:
krzysiek99
Date:
Tue Jun 09 12:30:01 2020 +0000
Revision:
5:cafab5a4d1c9
Parent:
4:7855d3ab4c15
mbed2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
krzysiek99 4:7855d3ab4c15 1 #include "Servo.h"
krzysiek99 4:7855d3ab4c15 2
krzysiek99 4:7855d3ab4c15 3 Servo::Servo(unsigned int uiInitialPosition) :MyGui(uiInitialPosition)
krzysiek99 4:7855d3ab4c15 4 {
krzysiek99 4:7855d3ab4c15 5 uiDesiredPosition = uiInitialPosition;
krzysiek99 4:7855d3ab4c15 6 uiCurrentPosition = uiInitialPosition;
krzysiek99 4:7855d3ab4c15 7 }
krzysiek99 4:7855d3ab4c15 8
krzysiek99 4:7855d3ab4c15 9 enum DetectorState Servo::eReadDetector()
krzysiek99 4:7855d3ab4c15 10 {
krzysiek99 4:7855d3ab4c15 11 return MyGui.eDetectorRead();
krzysiek99 4:7855d3ab4c15 12 }
krzysiek99 4:7855d3ab4c15 13
krzysiek99 4:7855d3ab4c15 14 void Servo::Callib()
krzysiek99 4:7855d3ab4c15 15 {
krzysiek99 4:7855d3ab4c15 16 eState = CALLIB;
krzysiek99 4:7855d3ab4c15 17 while(eState != IDLE)
krzysiek99 4:7855d3ab4c15 18 {
krzysiek99 4:7855d3ab4c15 19 if(uiCurrentPosition == 0)
krzysiek99 4:7855d3ab4c15 20 uiCurrentPosition = 359;
krzysiek99 4:7855d3ab4c15 21 else
krzysiek99 4:7855d3ab4c15 22 uiCurrentPosition--;
krzysiek99 4:7855d3ab4c15 23 MyGui.DetectorStepLeft();
krzysiek99 4:7855d3ab4c15 24 wait(0.05);
krzysiek99 4:7855d3ab4c15 25 MyGui.LedStepLeft();
krzysiek99 4:7855d3ab4c15 26 if(eReadDetector() == ACTIVE)
krzysiek99 4:7855d3ab4c15 27 eState = IDLE;
krzysiek99 4:7855d3ab4c15 28 else
krzysiek99 4:7855d3ab4c15 29 eState = CALLIB;
krzysiek99 4:7855d3ab4c15 30 }
krzysiek99 4:7855d3ab4c15 31 }
krzysiek99 4:7855d3ab4c15 32
krzysiek99 4:7855d3ab4c15 33 void Servo::GoTo(unsigned int uiPosition)
krzysiek99 4:7855d3ab4c15 34 {
krzysiek99 4:7855d3ab4c15 35 uiDesiredPosition = uiPosition;
krzysiek99 4:7855d3ab4c15 36 eState = IN_PROGRESS;
krzysiek99 4:7855d3ab4c15 37 while(eState != IDLE)
krzysiek99 4:7855d3ab4c15 38 {
krzysiek99 4:7855d3ab4c15 39 if(uiCurrentPosition < uiDesiredPosition)
krzysiek99 4:7855d3ab4c15 40 {
krzysiek99 4:7855d3ab4c15 41 uiCurrentPosition++;
krzysiek99 4:7855d3ab4c15 42 MyGui.DetectorStepRight();
krzysiek99 4:7855d3ab4c15 43 wait(0.05);
krzysiek99 4:7855d3ab4c15 44 MyGui.LedStepRight();
krzysiek99 4:7855d3ab4c15 45 eState = IN_PROGRESS;
krzysiek99 4:7855d3ab4c15 46 }
krzysiek99 4:7855d3ab4c15 47 else if(uiCurrentPosition > uiDesiredPosition)
krzysiek99 4:7855d3ab4c15 48 {
krzysiek99 4:7855d3ab4c15 49 uiCurrentPosition--;
krzysiek99 4:7855d3ab4c15 50 MyGui.DetectorStepLeft();
krzysiek99 4:7855d3ab4c15 51 wait(0.05);
krzysiek99 4:7855d3ab4c15 52 MyGui.LedStepLeft();
krzysiek99 4:7855d3ab4c15 53 eState = IN_PROGRESS;
krzysiek99 4:7855d3ab4c15 54 }
krzysiek99 4:7855d3ab4c15 55 else
krzysiek99 4:7855d3ab4c15 56 eState = IDLE;
krzysiek99 4:7855d3ab4c15 57 }
krzysiek99 4:7855d3ab4c15 58 }
krzysiek99 4:7855d3ab4c15 59
krzysiek99 4:7855d3ab4c15 60 void Servo::Automat()
krzysiek99 4:7855d3ab4c15 61 {
krzysiek99 4:7855d3ab4c15 62 switch(eState)
krzysiek99 4:7855d3ab4c15 63 {
krzysiek99 4:7855d3ab4c15 64 case CALLIB:
krzysiek99 4:7855d3ab4c15 65 if(eReadDetector() == INACTIVE)
krzysiek99 4:7855d3ab4c15 66 MyGui.LedStepLeft();
krzysiek99 4:7855d3ab4c15 67 else
krzysiek99 4:7855d3ab4c15 68 eState = IDLE;
krzysiek99 4:7855d3ab4c15 69 break;
krzysiek99 4:7855d3ab4c15 70 case IDLE:
krzysiek99 4:7855d3ab4c15 71 if(uiCurrentPosition != uiDesiredPosition)
krzysiek99 4:7855d3ab4c15 72 eState = IN_PROGRESS;
krzysiek99 4:7855d3ab4c15 73 else
krzysiek99 4:7855d3ab4c15 74 eState = IDLE;
krzysiek99 4:7855d3ab4c15 75 break;
krzysiek99 4:7855d3ab4c15 76 case IN_PROGRESS:
krzysiek99 4:7855d3ab4c15 77 if(uiCurrentPosition < uiDesiredPosition)
krzysiek99 4:7855d3ab4c15 78 {
krzysiek99 4:7855d3ab4c15 79 MyGui.LedStepRight();
krzysiek99 4:7855d3ab4c15 80 uiCurrentPosition++;
krzysiek99 4:7855d3ab4c15 81 eState = IN_PROGRESS;
krzysiek99 4:7855d3ab4c15 82 }
krzysiek99 4:7855d3ab4c15 83 else if(uiCurrentPosition > uiDesiredPosition)
krzysiek99 4:7855d3ab4c15 84 {
krzysiek99 4:7855d3ab4c15 85 MyGui.LedStepLeft();
krzysiek99 4:7855d3ab4c15 86 uiCurrentPosition--;
krzysiek99 4:7855d3ab4c15 87 eState = IN_PROGRESS;
krzysiek99 4:7855d3ab4c15 88 }
krzysiek99 4:7855d3ab4c15 89 else
krzysiek99 4:7855d3ab4c15 90 eState = IDLE;
krzysiek99 4:7855d3ab4c15 91 break;
krzysiek99 4:7855d3ab4c15 92 }
krzysiek99 4:7855d3ab4c15 93 }