| Line 8... |
Line 8... |
| 8 |
#define RIGHT 1 |
8 |
#define RIGHT 1 |
| 9 |
#define DET_EN 0 // povoluje nebo zakazuje vyhodnoceni SHARP |
9 |
#define DET_EN 0 // povoluje nebo zakazuje vyhodnoceni SHARP |
| 10 |
|
10 |
|
| 11 |
// regulator |
11 |
// regulator |
| 12 |
#define CONP 2 // konstanta pro proporcionalni regulator (2) |
12 |
#define CONP 2 // konstanta pro proporcionalni regulator (2) |
| 13 |
#define CONI 50 // konstanta pro integracni regulator *0,01 (45) |
13 |
#define CONI 40 // konstanta pro integracni regulator *0,01 (45) |
| 14 |
#define COND 25 // konstanta pro derivacni regulator *0,01 (20) |
14 |
#define COND 20 // konstanta pro derivacni regulator *0,01 (20) |
| 15 |
|
15 |
|
| 16 |
#define SPD_LO 210 // zaklad pro vypocet rychlosti pomalejsiho motoru (130) |
16 |
#define SPD_LO 220 // zaklad pro vypocet rychlosti pomalejsiho motoru (130) |
| 17 |
#define SPD_HI 210 // zaklad pro vypocetrychlosti rychlejsiho motoru (155) |
17 |
#define SPD_HI 220 // zaklad pro vypocetrychlosti rychlejsiho motoru (155) |
| 18 |
#define SPD_MAX 210 // rychlost po rovince (240) |
18 |
#define SPD_MAX 220 // rychlost po rovince (240) |
| 19 |
|
19 |
|
| 20 |
int8 reg_out; |
20 |
int8 reg_out; |
| 21 |
int8 err1; // odchylka prvni hodnoty |
21 |
int8 err1; // odchylka prvni hodnoty |
| 22 |
int8 err2; |
22 |
int8 err2; |
| 23 |
int8 err3; |
23 |
int8 err3; |
| 24 |
int8 err4; |
24 |
int8 err4; |
| 25 |
int8 err5; // odchylka posledni hodnoty |
25 |
int8 err5; // odchylka posledni hodnoty |
| 26 |
int8 errp; // prumer chyb |
26 |
int8 errp; // prumer chyb |
| 27 |
|
27 |
|
| 28 |
// mezera |
28 |
// mezera |
| 29 |
#define SPACE 8 // jak dlouho robot smi nic nevidet (8) |
29 |
#define SPACE 5 // jak dlouho robot smi nic nevidet (8) |
| 30 |
#define CONT 17 // kontrast, kdy nic nevidime |
30 |
#define CONT 17 // kontrast, kdy nic nevidime |
| 31 |
|
31 |
|
| 32 |
// univerzalni LED diody |
32 |
// univerzalni LED diody |
| 33 |
#define LED1 PIN_E1 |
33 |
#define LED1 PIN_E1 |
| 34 |
#define LED2 PIN_E0 |
34 |
#define LED2 PIN_E0 |
| Line 611... |
Line 611... |
| 611 |
if(line_r<WHITE) // cara videna pravym modrym senzorem |
611 |
if(line_r<WHITE) // cara videna pravym modrym senzorem |
| 612 |
{ |
612 |
{ |
| 613 |
position=100; |
613 |
position=100; |
| 614 |
line_sector=RIGHT; |
614 |
line_sector=RIGHT; |
| 615 |
} |
615 |
} |
| 616 |
/*if(line_sector==LEFT) |
- |
|
| 617 |
{ |
- |
|
| 618 |
position=1; |
- |
|
| 619 |
line_sector=LEFT; |
- |
|
| 620 |
} |
- |
|
| 621 |
if(line_sector==RIGHT) |
- |
|
| 622 |
{ |
- |
|
| 623 |
position=99; |
- |
|
| 624 |
line_sector=RIGHT; |
- |
|
| 625 |
}*/ |
- |
|
| 626 |
} |
616 |
} |
| 627 |
calc_error(); |
617 |
calc_error(); |
| 628 |
calc_regulator(); |
618 |
calc_regulator(); |
| 629 |
//printf("regulator: %u\r\n",reg_out); |
619 |
//printf("regulator: %u\r\n",reg_out); |
| 630 |
if(position<45) // prepocet regulatoru pro motory, pokud je cara vlevo |
620 |
if(position<46) // prepocet regulatoru pro motory, pokud je cara vlevo |
| 631 |
{ |
621 |
{ |
| 632 |
lm_speed=SPD_LO-(2*reg_out); |
622 |
lm_speed=SPD_LO-(2*reg_out); |
| 633 |
rm_speed=SPD_HI; |
623 |
rm_speed=SPD_HI; |
| 634 |
line_sector=LEFT; |
624 |
line_sector=LEFT; |
| 635 |
} |
625 |
} |
| 636 |
if((position>44)&&(position<56)) // nastaveni rychlosti, pokud je cara uprostred |
626 |
if((position>45)&&(position<55)) // nastaveni rychlosti, pokud je cara uprostred |
| 637 |
{ |
627 |
{ |
| 638 |
lm_speed=SPD_MAX; |
628 |
lm_speed=SPD_MAX; |
| 639 |
rm_speed=SPD_MAX; |
629 |
rm_speed=SPD_MAX; |
| 640 |
} |
630 |
} |
| 641 |
if(position>55) // prepocet regulatoru pro motory, pokud je cara vpravo |
631 |
if(position>54) // prepocet regulatoru pro motory, pokud je cara vpravo |
| 642 |
{ |
632 |
{ |
| 643 |
lm_speed=SPD_HI; |
633 |
lm_speed=SPD_HI; |
| 644 |
rm_speed=SPD_LO-(2*reg_out); |
634 |
rm_speed=SPD_LO-(2*reg_out); |
| 645 |
line_sector=RIGHT; |
635 |
line_sector=RIGHT; |
| 646 |
} |
636 |
} |