Dependencies:   czosnekengine_17_06 Servo_fullrange mbed

Fork of CZOSN_ostateczny_29_06 by Klaudia Różycka

Files at this revision

API Documentation at this revision

Comitter:
jguzik
Date:
Wed Jun 29 13:13:32 2016 +0000
Parent:
4:5e3f03e75645
Commit message:

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 5e3f03e75645 -r 87151d829108 main.cpp
--- a/main.cpp	Wed Jun 29 09:04:34 2016 +0000
+++ b/main.cpp	Wed Jun 29 13:13:32 2016 +0000
@@ -8,15 +8,15 @@
 Servo cam_vertical(PC_7);
 Engine eng_left = Engine(PB_13, PB_4, PB_10);
 Engine eng_right = Engine(PB_14, PB_5, PB_3);
+HCSR04 sensor(PB_9, PB_8, 11770);
 
-HCSR04 sensor(PB_9, PB_8, 11770);
 const int BufferSize=10;
 char buffer[BufferSize];
 char right[3];
 char left[3];
 char add_horizontal[2];
 char add_vertical[2];
-int act_vertical=0, act_horizontal=0;
+int act_vertical=-20, act_horizontal=-5;
 int l=0, r=0, h=0, v=0;
 Timer t, t_sonar;
 long distance;
@@ -57,8 +57,7 @@
             return false;
         if(((int)buffer[i+4]) < 48 || ((int)buffer[i+4]) > 57)
             return false;
-    }
-    
+    }    
     return true;
 }
 
@@ -92,7 +91,6 @@
        eng_right.move(r);    
 }
 
-
 void actualize_servo_val()
 {
         //*******PRZYPISANIE DO KAMERY POZIOM*********//
@@ -127,24 +125,24 @@
 void move_camera()
 {
      cam_horizontal.position(act_horizontal);
-     cam_vertical.position(act_vertical);  
-    
+     cam_vertical.position(act_vertical);      
 }
 
 
-
 int main(){
     int i = 0;
-    cleanBuffer();
     stm.baud(115200);
+    cleanBuffer();   
+    move_camera();
     t_sonar.start();
+    
     while(true){
         if(t.read_ms()>500)//jesli przez ponad 200ms nie ma nowej ramki, zatrzymujemy robota
             { 
             eng_left.move(0);
             eng_right.move(0);
             }
-        if(t_sonar.read_ms()>1200)//dczyt odleglosci co 1,2s
+        if(t_sonar.read_ms()>1000)//dczyt odleglosci co 1,2s
         {
             distance = sensor.distance();
             stm.printf("%d\n",distance);
@@ -160,13 +158,13 @@
         if(buffer[9] == NULL){
             buffer[i] = stm.getc();
             if(i==0){
-                if(buffer[i]=='@') //zaczynamy zapelniac bufor jak dostaniemy @
+                if(buffer[i]=='@') 
                    ++i;
             }
-            else if(buffer[i]=='@'){ // i != 0 //interpretujemy jakby potencjalny poczatek ramki
+            else if(buffer[i]=='@'){ 
                 cleanBuffer();
                 buffer[0]='@';
-                i=1; //bo zerowy znak '@' juz sczytal
+                i=1; 
                 }
             else i++;
             continue;
@@ -181,7 +179,7 @@
             if(distance>25)
                 move_wheels();
             else if (distance<=25){
-                if(l<=0 && r<=0 || l*r<=0){
+                if(l<0 && r<0 || l*r<0){
                     move_wheels();
                 }
                 else{