-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcpu_code.cpp
More file actions
306 lines (263 loc) · 4.73 KB
/
cpu_code.cpp
File metadata and controls
306 lines (263 loc) · 4.73 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
void init(void);
void poll(char,char);
void agv(char);
char distance(char, char, char, char);
void clock(void);
void anti(void);
//defines start
#define NUL 0x7E
#define SOH 0x01
#define SOD 0x02
//defines end
#define EM 0xFE
#define ET 0xFF
//defines CRC
#define PRESET 0Xff
#define POLY 0x1D
//defines addresses
#define LC1 0x01
#define LC2 0x02
#define SC 0x03
#define A1 0x04
#define A2 0x05
#define A3 0x06
//define directions
#define BW 0x00
#define HR 0x01
#define HL 0x02
#define FW 0x03
#define STOP 0x04
//define crane instructions
#define REQ 0x00
#define REQ_FF 0x01
#define NO_REQ 0x02
#define AGV_LOADED 0x03
#define AGV_UNLOADED 0x04
#define STATUS 0x05
// current AGV directions
#define W 3
#define S 2
#define E 1
#define N 0
enum t
{
ocq,free
};
struct node
{
enum t i;
};
struct node n[4][4];
struct agv
{
char next_dir,current_dir;
char x,y,gx,gy;
enum t p;
};
struct agv a[3];
void init()
{
// set all nodes as free
// set all agvs as free
//set current dir as North
}
void poll(char add,char data)
{
crane_comm(add,data);
if (szBuff[3]==REQ)
{
//check free AGV
//if free then assign new goal to AGV
//notify crane
}
else if(szBuff[3]==NO_REQ)
{
//take no action
}
else if(szBuff[3]==AGV_LOADED)
{
//assign new goal as SC
//change the tag as busy
}
else if(szBuff[3]==AGV_UNLOADED)
{
//change the tag as free
//if no req is there then send the agv to buffer area
// else assign new goal
}
}
agv(char add)
{
char cx,cy,g[3],h[3],f[3],t;
cx=a[add]->x;
cy=a[add]->y
/////////////////for NORTH direction//////////////////
if(a[add]->current_dir==N)
{
if ( cx+1 <=3 && cx+1 >=0 && n[cx+1][cy]->i==free)
{
h[0]=distance(cx+1,cy,a[add]->gx,a[add].gy);
g[0]=5;
f[0]=g[0]+h[0];
}
else
{
f[0]=0xff;
}
if ( cx-1 <=3 && cx-1 >=0 && n[cx-1][cy]->i==free)
{
h[1]=distance(cx-1,cy,a[add]->gx,a[add].gy);
g[1]=5;
f[1]=g[1]+h[1];
}
else
{
f[1]=0xff;
}
if ( cy+1 <=3 && cy+1 >=0 && n[cx][cy+1]->i==free)
{
h[2]=distance(cx,cy+1,a[add]->gx,a[add].gy);
g[2]=0;
f[2]=g[2]+h[2];
}
else
{
f[2]=0xff;
}
}
/////////////////for EAST direction//////////////////
else if(a[add]->current_dir==E)
{
if ( cx+1 <=3 && cx+1 >=0 && n[cx+1][cy]->i==free)
{
h[0]=distance(cx+1,cy,a[add]->gx,a[add].gy);
g[0]=0;
f[0]=g[0]+h[0];
}
else
{
f[0]=0xff;
}
if ( cy+1 <=3 && cy+1 >=0 && n[cx][cy+1]->i==free)
{
h[1]=distance(cx,cy+1,a[add]->gx,a[add].gy);
g[1]=5;
f[1]=g[1]+h[1];
}
else
{
f[1]=0xff;
}
if ( cy-1 <=3 && cy-1 >=0 && n[cx][cy-1]->i==free)
{
h[2]=distance(cx,cy-1,a[add]->gx,a[add].gy);
g[2]=5;
f[2]=g[2]+h[2];
}
else
{
f[2]=0xff;
}
}
/////////////////for SOUTH direction//////////////////
else if(a[add]->current_dir==S)
{
if ( cx-1 <=3 && cx-1 >=0 && n[cx-1][cy]->i==free)
{
h[0]=distance(cx-1,cy,a[add]->gx,a[add].gy);
g[0]=5;
f[0]=g[0]+h[0];
}
else
{
f[0]=0xff;
}
if ( cx+1 <=3 && cx+1 >=0 && n[cx+1][cy]->i==free)
{
h[1]=distance(cx+1,cy,a[add]->gx,a[add].gy);
g[1]=5;
f[1]=g[1]+h[1];
}
else
{
f[1]=0xff;
}
if ( cy-1 <=3 && cy-1 >=0 && n[cx][cy-1]->i==free)
{
h[2]=distance(cx,cy-1,a[add]->gx,a[add].gy);
g[2]=0;
f[2]=g[2]+h[2];
}
else
{
f[2]=0xff;
}
}
/////////////////for WEST direction//////////////////
else if(a[add]->current_dir==W)
{
if ( cx-1 <=3 && cx-1 >=0 && n[cx-1][cy]->i==free)
{
h[0]=distance(cx-1,cy,a[add]->gx,a[add].gy);
g[0]=0;
f[0]=g[0]+h[0];
}
else
{
f[0]=0xff;
}
if ( cy-1 <=3 && cy-1 >=0 && n[cx][cy-1]->i==free)
{
h[1]=distance(cx,cy-1,a[add]->gx,a[add].gy);
g[1]=5;
f[1]=g[1]+h[1];
}
else
{
f[1]=0xff;
}
if ( cy+1 <=3 && cy+1 >=0 && n[cx][cy+1]->i==free)
{
h[2]=distance(cx,cy+1,a[add]->gx,a[add].gy);
g[2]=5;
f[2]=g[2]+h[2];
}
else
{
f[2]=0xff;
}
}
}
void anti()
{
if(dir==0)
dir=4;
dir--;
}
void clock()
{
dir++;
if(dir>3)
dir=0;
}
char distance(char x1, char y1, char gx1, char gy1)
{
unsigned char p,q;
char d;
p=gx1-x1;
q=gy1-y1;
d=p+q;
return (d*5);
}
void main()
{
while(1)
{
poll(LC1,STATUS);
poll(LC2,STATUS);
poll(SC,STATUS);
agv(0);
agv(1);
agv(2);
}
}