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 |
FL;BR; // doprava 90 |
|
|
90 |
Delay_ms(300); |
|
|
91 |
BL;FR; // brzdi z toceni |
|
|
92 |
Delay_ms(100); |
|
|
93 |
STOPL;STOPR; |
|
|
94 |
|
|
|
95 |
uhel=STRED; |
|
|
96 |
FL;FR; |
|
|
97 |
Delay_ms(380); // rovne |
|
|
98 |
|
|
|
99 |
uhel=STRED-55; |
|
|
100 |
STOPL;FR; |
|
|
101 |
Delay_ms(190); // doleva |
|
|
102 |
|
|
|
103 |
uhel=STRED; |
|
|
104 |
FR;FL; |
|
|
105 |
Delay_ms(300); // rovne |
|
|
106 |
|
|
|
107 |
uhel=STRED-55; |
|
|
108 |
FR;STOPL; |
|
|
109 |
Delay_ms(190); // doleva |
|
|
110 |
|
|
|
111 |
uhel=STRED; |
|
|
112 |
FR;FL; |
|
|
113 |
Delay_ms(100); // 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; // zabrzdi |
|
|
122 |
Delay_ms(250); |
|
|
123 |
|
|
|
124 |
uhel=KOLMO1; |
|
|
125 |
FL;BR; // doprava |
|
|
126 |
While((sensors & 0b11111110)!=0) //dokud neni cara |
|
|
127 |
{ |
|
|
128 |
sensors = spi_read(0); // cteni senzoru |
|
|
129 |
sensors=~sensors; |
|
|
130 |
Delay_ms(3); // cekani na SLAVE nez pripravi data od cidel |
|
|
131 |
} |
|
|
132 |
STOPL;STOPR; // zabrzdi |
|
|
133 |
Delay_ms(300); |
|
|
134 |
// delay_ms(250); |
|
|
135 |
|
|
|
136 |
line=R3; |
|
|
137 |
cikcak(); |
|
|
138 |
} |
|
|
139 |
|