-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
163 lines (134 loc) · 4.8 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* main.c
*/
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/pwm.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "driverlib/timer.h"
#include "math.h"
#include "motion.h"
#include "sensors.h"
#include "uartfunc.h"
#include "uartstdio.h"
#include "timers.h"
#include "structs.h"
void FloorLearn(void); //prototype
int value;
int g_ui32SysClock;
struct CABIN left;
struct CABIN right;
//volatile unsigned char floor_switch;
int main(void) {
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
/*********************************************************
* Inits
*********************************************************/
SensorsInit(); //initialize all the sensors
VelocityTimerInit(); // initialize the velocity measure timer
//VelocityControlTimer();
PWMInit0();
PWMInit1();
PWMInit2();
PWMInit3();
UARTInit();
UART1Init();
/*********************************************************
* End of Inits
********************************************************/
FloorLearn(); // this function will get the number of the floors and the distance between them
while(1){
}
return 0;
}
//***********************************************************************
// Learning Cycel
//**********************************************************************
// még meg kell írnia a fügvény kiléptetést, taléna végén?
// struct használata
void FloorLearn(void){
while(1){
switch(floor_switch){
case START_LEFT: UARTprintf("Slow motion...Down\n");
Move(LEFT_LIFT,DOWNWARD,30);
floor_switch = LEFT_POS;
break;
case LEFT_POS: if(GPIOPinRead(GPIO_PORTD_BASE,GPIO_PIN_1) && GPIOPinRead(GPIO_PORTP_BASE,GPIO_PIN_1)){ // ha a reed és a photo szintérzékelő érzékel
StopMotion(LEFT_LIFT);
floor_switch = CYCLE_LEFT;
UARTprintf("switch to the CYCLE\n");
SysCtlDelay(400000);
}
break;
case CYCLE_LEFT: UARTprintf("slow motion up..\n");
left.sign_counter = 0;
Move(LEFT_LIFT, UPWARD, 30);
floor_switch = WAIT_LEFT;
break;
case LEARNING_LEFT: if(GPIOPinRead(GPIO_PORTP_BASE,GPIO_PIN_1)){ // nézi a bal oldali lift szintérzékelőjét
left.floor_distance[left.floor_number] = left.sign_counter; // elmenti az értéket
UARTprintf("%d: %d\n",left.floor_number,left.floor_distance[left.floor_number]);
left.floor_number++; // tovább lép a következő szintre
floor_switch = WAIT_LEFT;
}
left_reed_int_enable = 1;
break;
case WAIT_LEFT: if(!(GPIOPinRead(GPIO_PORTP_BASE,GPIO_PIN_1))){ // vár arra hogy elhagyja a szint jeladót
//counter_left = 0;
floor_switch = LEARNING_LEFT;
}
break;
case END_LEFT: UARTprintf("end, so stop!\n");
StopMotion(LEFT_LIFT);
left_reed_int_enable = 0;
floor_switch = START_RIGHT;
break;
case START_RIGHT: UARTprintf("Slow motion...Down\n");
Move(RIGHT_LIFT,DOWNWARD,400); // this is an ideal slow motion , equal than the 30 at the other side
floor_switch = RIGHT_POS;
break;
case RIGHT_POS: if(GPIOPinRead(GPIO_PORTL_BASE,GPIO_PIN_4) && GPIOPinRead(GPIO_PORTD_BASE,GPIO_PIN_0)){ // ha a reed és a photo szintérzékelő érzékel
StopMotion(RIGHT_LIFT);
floor_switch = CYCLE_RIGHT;
UARTprintf("switch to the CYCLE\n");
SysCtlDelay(400000);
}
break;
case CYCLE_RIGHT: UARTprintf("slow motion up..\n");
Move(RIGHT_LIFT, UPWARD,400);
right.sign_counter = 0;
floor_switch = WAIT_RIGHT;
break;
case LEARNING_RIGHT:if(GPIOPinRead(GPIO_PORTL_BASE,GPIO_PIN_4)){ // nézi a bal oldali lift szintérzékelőjét
right.floor_distance[right.floor_number] = right.sign_counter; // elmenti az értéket
UARTprintf("%d: %d\n",right.floor_number,right.floor_distance[right.floor_number]);
right.floor_number++; // tovább lép a következő szintre
floor_switch = WAIT_RIGHT;
}
right_reed_int_enable = 1;
break;
case WAIT_RIGHT: if(!(GPIOPinRead(GPIO_PORTL_BASE,GPIO_PIN_4))){ // vár arra hogy elhagyja a szint jeladót
//counter_right = 0;
floor_switch = LEARNING_RIGHT;
}
break;
case END_RIGHT: StopMotion(RIGHT_LIFT);
floor_switch == LEARN_END;
return;
} // end of switch-case
} // end of while(1)
}// end of FloorLearn