Subversion Repositories svnkaklik

Rev

Rev 217 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 217 Rev 221
Line 1... Line 1...
1
//********* Robot Camerus pro IstRobot 2007 ************
1
//********* Robot Camerus pro IstRobot 2007 ************
2
//"$Id: camerus.c 217 2007-03-26 11:43:40Z kakl $"
2
//"$Id: camerus.c 221 2007-04-01 21:34:53Z kakl $"
3
//*****************************************************
3
//*****************************************************
4
// Verze pouzita na Robot Challenge 
-
 
5
 
4
 
6
#include ".\camerus.h"
5
#include ".\camerus.h"
7
 
6
 
8
#USE FAST_IO (C)     // Brana C je ve FAST_IO modu, aby slo rychle cist z kamery
7
#USE FAST_IO (C)     // Brana C je ve FAST_IO modu, aby slo rychle cist z kamery
9
 
8
 
Line 34... Line 33...
34
#define CASMAX 192
33
#define CASMAX 192
35
#define CASAVR ((CASMAX+CASMIN) / 2)
34
#define CASAVR ((CASMAX+CASMIN) / 2)
36
 
35
 
37
#define OFFSETO   0x9F //0x9F         // Vystredeni serva pro objeti prekazky
36
#define OFFSETO   0x9F //0x9F         // Vystredeni serva pro objeti prekazky
38
 
37
 
39
#define TRESHOLD 128
38
#define THR_H 128
-
 
39
#define THR_L 90
40
 
40
 
41
#byte INTCON      = 0x0B         // Interrupt configuration register
41
#byte INTCON      = 0x0B         // Interrupt configuration register
42
   #bit GIE       = INTCON.7
42
   #bit GIE       = INTCON.7
43
   #bit PEIE      = INTCON.6
43
   #bit PEIE      = INTCON.6
44
   #bit TMR0IE    = INTCON.5
44
   #bit TMR0IE    = INTCON.5
Line 170... Line 170...
170
      output_low(MOT_L); // je odraz -> vpred
170
      output_low(MOT_L); // je odraz -> vpred
171
      output_low(MOT_R);
171
      output_low(MOT_R);
172
      return;
172
      return;
173
   };
173
   };
174
   output_low(IRTX);    // Zapni LED na detekci prekazky
174
   output_low(IRTX);    // Zapni LED na detekci prekazky
175
   delay_ms(10);
175
   delay_ms(5);
176
   if (input(IRRX))     // stale nas signal?
176
   if (input(IRRX))     // stale nas signal?
177
   {
177
   {
178
      output_low(MOT_L); // neni odraz -> vpred
178
      output_low(MOT_L); // neni odraz -> vpred
179
      output_low(MOT_R);
179
      output_low(MOT_R);
180
      return;
180
      return;
181
   };
181
   };
182
 
182
 
183
   SetServo((CASAVR-CASMIN));   // rovne
-
 
184
   delay_ms(100);
-
 
185
   brzda();
-
 
186
 
-
 
187
//!!!   if(stav==cihla) while(true); // Zastav na furt, konec drahy
183
//!!!   if(stav==cihla) while(true); // Zastav na furt, konec drahy
188
//   if(stav==cihla) return; // Po druhe nic neobjizdej
184
//   if(stav==cihla) return; // Po druhe nic neobjizdej
189
// Pozor na rozjezd
185
// Pozor na rozjezd
190
 
186
 
191
   if(stav==jizda)   // Objed cihlu
187
   if(stav==jizda)   // Objed cihlu
192
   {
188
   {
193
      #include ".\objizdka_R.c"
189
      #include ".\objizdka_L.c"
194
   }
190
   }
195
}
191
}
196
 
192
 
197
 
193
 
198
//---------------------------------- MAIN --------------------------------------
194
//---------------------------------- MAIN --------------------------------------
Line 428... Line 424...
428
            disp(0x01);
424
            disp(0x01);
429
            while(get_timer1()<=4) // Ujed alespon 12cm
425
            while(get_timer1()<=4) // Ujed alespon 12cm
430
            {
426
            {
431
               set_adc_channel(LMAX);    // Levy UV sensor
427
               set_adc_channel(LMAX);    // Levy UV sensor
432
               delay_us(40);
428
               delay_us(40);
433
               if(read_adc()<TRESHOLD) {cas=CASMIN; break;};  // Prejeli jsme caru vlevo
429
               if(read_adc()<THR_L) {cas=CASMIN; break;};  // Prejeli jsme caru vlevo
434
               set_adc_channel(RMAX);    // Pravy UV sensor
430
               set_adc_channel(RMAX);    // Pravy UV sensor
435
               delay_us(40);
431
               delay_us(40);
436
               if(read_adc()<TRESHOLD) {cas=CASMAX; break;};  // Prejeli jsme caru vpravo
432
               if(read_adc()<THR_L) {cas=CASMAX; break;};  // Prejeli jsme caru vpravo
437
               cas=CASAVR-CASMIN;    // Cara je rovne
433
               cas=CASAVR-CASMIN;    // Cara je rovne
438
            };
434
            };
439
            stav=rozjezd;
435
            stav=rozjezd;
440
         };
436
         };
441
      }
437
      }
Line 446... Line 442...
446
 
442
 
447
      while(true) // Ve zbytku casu snimku cti krajni UV senzory
443
      while(true) // Ve zbytku casu snimku cti krajni UV senzory
448
      {
444
      {
449
         set_adc_channel(LMAX);    // Levy UV sensor
445
         set_adc_channel(LMAX);    // Levy UV sensor
450
         for(n=0;n<20;n++) if(input(HREF)) goto next_snap;
446
         for(n=0;n<20;n++) if(input(HREF)) goto next_snap;
451
         if(read_adc()<TRESHOLD) cas=CASMIN;
447
         if(read_adc()<THR_L) cas=CASMIN;
452
         set_adc_channel(RMAX);    // Pravy UV sensor
448
         set_adc_channel(RMAX);    // Pravy UV sensor
453
         for(n=0;n<20;n++) if(input(HREF)) goto next_snap;
449
         for(n=0;n<20;n++) if(input(HREF)) goto next_snap;
454
         if(read_adc()<TRESHOLD) cas=CASMAX;
450
         if(read_adc()<THR_L) cas=CASMAX;
455
      };
451
      };
456
   }
452
   }
457
}
453
}