504 |
kaklik |
1 |
#define DOLEVA 0 |
|
|
2 |
#define DOPRAVA 1 |
|
|
3 |
|
|
|
4 |
void cikcak() |
|
|
5 |
{ |
|
|
6 |
unsigned int8 i=0; |
|
|
7 |
|
|
|
8 |
uhel=KOLMO1; // aby se dalo tocit na miste |
|
|
9 |
Delay_ms(100); |
|
|
10 |
|
|
|
11 |
if (line==L2) line=L3; // poznamenej, kde byla cara pred brzdenim |
|
|
12 |
if (line==S) line=L3; |
|
|
13 |
if (line==R2) line=R3; |
|
|
14 |
|
|
|
15 |
Delay_ms(3); // prodleva na cteni senzoru pred prenosem |
|
|
16 |
|
|
|
17 |
output_low(STROBE); // zapni zobrazovani na posuvnem registru |
|
|
18 |
sensors = spi_read(0); // cteni senzoru |
|
|
19 |
sensors=~sensors; |
|
|
20 |
output_high(STROBE); // vypni zobrazovani na posuvnem registru |
|
|
21 |
|
|
|
22 |
while(true) |
|
|
23 |
{ |
|
|
24 |
Delay_ms(3); |
|
|
25 |
|
|
|
26 |
if (line==L3) |
|
|
27 |
{ |
|
|
28 |
GO(L,B,160);GO(R,F,160); |
|
|
29 |
}; |
|
|
30 |
if (line==R3) |
|
|
31 |
{ |
|
|
32 |
GO(R,B,160);GO(L,F,160); |
|
|
33 |
}; |
|
|
34 |
if (line==S) {STOPL;STOPR; i++;} else i=0; |
|
|
35 |
|
|
|
36 |
if (i>=100) break; // pokud je dostatecne dlouho cara vprostred, vypadni |
|
|
37 |
|
|
|
38 |
output_low(STROBE); // zapni zobrazovani na posuvnem registru |
|
|
39 |
sensors = spi_read(0); // cteni senzoru |
|
|
40 |
sensors=~sensors; |
|
|
41 |
output_high(STROBE); // vypni zobrazovani na posuvnem registru |
|
|
42 |
|
|
|
43 |
if(bit_test(sensors,3)) //...|...// |
|
|
44 |
{ |
|
|
45 |
line=S; |
|
|
46 |
continue; |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
if(bit_test(sensors,0)) //|......// // z duvodu zkraceni doby reakce se cidla nevyhodnocuji poporade ale od krajnich k prostrednimu |
|
|
50 |
{ |
|
|
51 |
line=L3; |
|
|
52 |
continue; |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
if(bit_test(sensors,6)) //......|// |
|
|
56 |
{ |
|
|
57 |
line=R3; |
|
|
58 |
continue; |
|
|
59 |
} |
|
|
60 |
|
|
|
61 |
if(bit_test(sensors,1)) //.|.....// |
|
|
62 |
{ |
|
|
63 |
line=L3; |
|
|
64 |
continue; |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
if(bit_test(sensors,5)) //.....|.// |
|
|
68 |
{ |
|
|
69 |
line=R3; |
|
|
70 |
continue; |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
if (bit_test(sensors,2)) //..|....// |
|
|
74 |
{ |
|
|
75 |
line=L3; |
|
|
76 |
continue; |
|
|
77 |
} |
|
|
78 |
|
|
|
79 |
if (bit_test(sensors,4)) //....|..// |
|
|
80 |
{ |
|
|
81 |
line=R3; |
|
|
82 |
continue; |
|
|
83 |
} |
|
|
84 |
} |
|
|
85 |
} |
|
|
86 |
//////////////////////////////////////////////////////////////////////////////// |
|
|
87 |
void objizdka() |
|
|
88 |
{ |
|
|
89 |
BL;FR; |
|
|
90 |
Delay_ms(300); |
|
|
91 |
FL;BR; |
|
|
92 |
Delay_ms(100); |
|
|
93 |
STOPL;STOPR; |
|
|
94 |
|
|
|
95 |
uhel=STRED; |
|
|
96 |
FL;FR; |
|
|
97 |
Delay_ms(360); // rovne |
|
|
98 |
|
|
|
99 |
uhel=STRED+55; |
|
|
100 |
STOPR;FL; |
|
|
101 |
Delay_ms(190); // doprava |
|
|
102 |
|
|
|
103 |
uhel=STRED; |
|
|
104 |
FR;FL; |
|
|
105 |
Delay_ms(300); // rovne |
|
|
106 |
|
|
|
107 |
uhel=STRED+55; |
|
|
108 |
FL;STOPR; |
|
|
109 |
Delay_ms(190); // doprava |
|
|
110 |
|
|
|
111 |
uhel=STRED; |
|
|
112 |
FR;FL; |
|
|
113 |
Delay_ms(200); // rovne |
|
|
114 |
|
|
|
115 |
While((sensors & 0b11111110)!=0) //dokud neni cara |
|
|
116 |
{ |
|
|
117 |
sensors = spi_read(0); // cteni senzoru |
|
|
118 |
sensors=~sensors; |
|
|
119 |
Delay_ms(3); // cekani na SLAVE nez pripravi data od cidel |
|
|
120 |
} |
|
|
121 |
BL;BR; |
|
|
122 |
Delay_ms(300); |
|
|
123 |
|
|
|
124 |
uhel=STRED-55; |
|
|
125 |
FR;STOPL; // doleva |
|
|
126 |
delay_ms(250); |
|
|
127 |
|
|
|
128 |
line=L3; |
|
|
129 |
cikcak(); |
|
|
130 |
} |
|
|
131 |
|