Dominik Święch
/
JakKrisowy_
.
Fork of JakKrisowy by
Revision 1:1e01b12063cd, committed 2016-07-14
- Comitter:
- yruiewyrui3
- Date:
- Thu Jul 14 13:31:01 2016 +0000
- Parent:
- 0:f3a3f80e3202
- Commit message:
- .;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r f3a3f80e3202 -r 1e01b12063cd main.cpp --- a/main.cpp Thu Jul 07 12:56:54 2016 +0000 +++ b/main.cpp Thu Jul 14 13:31:01 2016 +0000 @@ -20,9 +20,10 @@ char buffer1[BufferSize]; char buffer2[BufferSize]; char camove[2]; +char tablicaf[4]; int wall=30; // odleglosc od sciany w cm int act_vertical=0, act_horizontal=0, move=0, val=0; -Timer t, t_sonar; +Timer t, t_sonar, t_fidu; long distance; volatile unsigned int speed_car = 0; @@ -72,6 +73,15 @@ return 0; } +char* intToChar(int value, char tab[3]) +{ + tab[0]= (char)(value/100 + 48); + tab[1]= (char)((value-(100*(value/100)))/10 + 48); + tab[2]= (char)(value-(100*(value/100))-(10*((value-(100*(value/100)))/10)) + 48); + tab[3]= ';'; + return tab; +} + void hard_stop() // zatrzymujaca robota { eng_left.move(0); @@ -121,8 +131,10 @@ void set_camera_zero() // zerujaca kamere { - cam_horizontal.position(-5); - cam_vertical.position(-20); + cam_horizontal.position(-8); + cam_vertical.position(-20); + act_horizontal=-8; + act_vertical=-20; } void set_val() // odczytująca wartosc @@ -139,9 +151,11 @@ cleanBuffer2(); set_camera_zero(); t_sonar.start(); + t_fidu.start(); + int i=0; while(true){ - stm.printf("Poczatek while \n"); + //stm.printf("Poczatek petli nr %d \n", i); if(t.read_ms()>500) //jesli przez ponad 500ms nie ma nowej ramki, zatrzymujemy robota { eng_left.move(0); @@ -150,29 +164,36 @@ if(t_sonar.read_ms()>1000) //odczyt odleglosci co 1,2s { distance = sensor.distance(); - stm.printf("%d\n",distance); + //stm.printf("distance z czujnika: %d\n",distance); t_sonar.stop(); t_sonar.reset(); t_sonar.start(); } while(stm.readable()){ - stm.gets(buffer1, 13); + + /*stm.gets(buffer1, 13); + stm.puts(buffer1); + break;}*/ + + for (int x=0; x<12; x++){ + if(t_fidu.read_ms()>1000){ + stm.printf("urywam;"); + t_fidu.stop(); + t_fidu.reset(); + break;} + buffer1[x]=stm.getc(); + if(buffer1[x]==';'){ + t_fidu.stop(); + t_fidu.reset(); + t_fidu.start(); + break;} + } + stm.puts(buffer1); break;} - stm.printf("bufor pierwszy: \n"); - - for (int f=0; f<20; f++) - { - stm.printf("%c", buffer1[f]); - } - - stm.printf("\n"); - set_val(); - stm.printf("%i", val); - t.stop(); t.reset(); t.start(); @@ -186,21 +207,21 @@ break; case 2: eng_right.move(speed_car); - eng_left.move(speed_car - map(val, 0, 255, 0, speed_car)); - cam_horizontal.position(15); - cam_vertical.position(0); + eng_left.move(speed_car - map(val, 0, 100, 0, speed_car)); + cam_horizontal.position(7); + cam_vertical.position(-20); break; case 3: eng_left.move(speed_car); - eng_right.move(speed_car - map(val, 0, 255, 0, speed_car)); - cam_horizontal.position(0); - cam_vertical.position(-35); + eng_right.move(speed_car - map(val, 0, 100, 0, speed_car)); + cam_horizontal.position(-23); + cam_vertical.position(-20); break; case 4: eng_left.move(-val); eng_right.move(-val); set_camera_zero(); - speed_car = val; + speed_car = -val; break; case 5: hard_stop(); @@ -227,17 +248,17 @@ move_camera_right(val); break; case 12: - set_camera_zero(); + set_camera_zero(); break; default: - stm.printf("unknown_command \n"); + //stm.printf("unknown_command \n"); break; } cleanBuffer1(); cleanBuffer2(); - stm.printf("Koniec while \n"); + i++; - wait_ms(2000); + //wait_ms(200); } } \ No newline at end of file