Distanzhelm

Dependencies:   PM2_Libary

Files at this revision

API Documentation at this revision

Comitter:
madjan01
Date:
Mon May 24 20:44:16 2021 +0000
Parent:
7:3b3a2c158803
Commit message:
Abgabe Version 24.05.21

Changed in this revision

PM2_Libary.lib Show annotated file Show diff for this revision Revisions of this file
RangeFinder.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3b3a2c158803 -r 2ae54c6a9dc6 PM2_Libary.lib
--- a/PM2_Libary.lib	Wed May 12 23:35:22 2021 +0000
+++ b/PM2_Libary.lib	Mon May 24 20:44:16 2021 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/pmic/code/PM2_Libary/#8b42e643b294
+https://os.mbed.com/users/pmic/code/PM2_Libary/#6b747ad59ff5
diff -r 3b3a2c158803 -r 2ae54c6a9dc6 RangeFinder.lib
--- a/RangeFinder.lib	Wed May 12 23:35:22 2021 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/teams/altb_pmic/code/RangeFinder/#600591c78153
diff -r 3b3a2c158803 -r 2ae54c6a9dc6 main.cpp
--- a/main.cpp	Wed May 12 23:35:22 2021 +0000
+++ b/main.cpp	Mon May 24 20:44:16 2021 +0000
@@ -14,45 +14,47 @@
     DigitalOut     led(LED1);
     
     // create servo objects
-    Servo  servo_0(PA_6);
+    Servo  servo_0(PA_6); //PA_6
     
     
    //Infrarotsensor
-    DigitalIn pirlinks(PB_12);
-    DigitalIn pirhinten(PC_7);   //pc_6 puuty besetzt
-    DigitalIn pirrechts(PB_7);  //pc_8
-    DigitalIn pirvorne(PA_1); //pc-9
-    //im moment nich eingebaut
-  //  DigitalIn ultrarechts(PB_1);
-   // DigitalIn ultralinks(PB_13); //immer eins behoben
-   // DigitalIn ultravorne(PC_3); 
-    //DigitalIn ultrahinten(PA_9);// immer eins behoben
+    DigitalIn pirrechts(PB_12);
+    DigitalIn pirvorne(PC_7);  
+    DigitalIn pirhinten(PB_7);  
+    DigitalIn pirlinks(PA_1); 
+    
+  /*
+  pc-6 pc_ 9 sicher mit putty besetzt pc_8 immer eins
+  
+  
+  */
+    
+
+    
+    // Groove Ultrasonic Ranger V2.0
+    // https://ch.rs-online.com/web/p/entwicklungstools-sensorik/1743238/?cm_mmc=CH-PLA-DS3A-_-google-_-CSS_CH_DE_Raspberry_Pi_%26_Arduino_und_Entwicklungstools_Whoop-_-(CH:Whoop!)+Entwicklungstools+Sensorik-_-1743238&matchtype=&pla-306637898829&gclid=Cj0KCQjwpdqDBhCSARIsAEUJ0hOLQOOaw_2-Ob03u4YGwXthQPeSyjaazFqNuMkTIT8Ie18B1pD7P9AaAn18EALw_wcB&gclsrc=aw.ds 
+    /* create range finder object (ultra sonic distance sensor) */
+    RangeFinder ultrarechts(PC_5, 5782.0f, 0.02f, 17500); // 1/Ts_ms = 20 Hz parametrization
+    RangeFinder ultralinks(PC_3, 5782.0f, 0.02f, 17500); // 1/Ts_ms = 20 Hz parametrization
+    RangeFinder ultravorne(PB_1, 5782.0f, 0.02f, 17500); // 1/Ts_ms = 20 Hz parametrization
+    RangeFinder ultrahinten(PC_2, 5782.0f, 0.02f, 17500); // 1/Ts_ms = 20 Hz parametrization
     
     //Output
     //Servo
     DigitalOut pumpe(PB_6);
-    DigitalOut summer(PA_0);
-    
-    // Groove Ultrasonic Ranger V2.0
-    // https://ch.rs-online.com/web/p/entwicklungstools-sensorik/1743238/?cm_mmc=CH-PLA-DS3A-_-google-_-CSS_CH_DE_Raspberry_Pi_%26_Arduino_und_Entwicklungstools_Whoop-_-(CH:Whoop!)+Entwicklungstools+Sensorik-_-1743238&matchtype=&pla-306637898829&gclid=Cj0KCQjwpdqDBhCSARIsAEUJ0hOLQOOaw_2-Ob03u4YGwXthQPeSyjaazFqNuMkTIT8Ie18B1pD7P9AaAn18EALw_wcB&gclsrc=aw.ds 
-    /* create range finder object (ultra sonic distance sensor) */
-    RangeFinder ultrarechts(PB_1, 5782.0f, 0.02f, 17500); // 1/Ts_ms = 20 Hz parametrization
-    RangeFinder ultralinks(PB_13, 5782.0f, 0.02f, 17500); // 1/Ts_ms = 20 Hz parametrization
-    RangeFinder ultravorne(PC_3, 5782.0f, 0.02f, 17500); // 1/Ts_ms = 20 Hz parametrization
-    RangeFinder ultrahinten(PA_9, 5782.0f, 0.02f, 17500); // 1/Ts_ms = 20 Hz parametrization
-    
+    DigitalOut summer(PA_0); 
 
     /* input your stuff here */
     
 Timer          loop_timer;
-int            Ts_ms = 500;
+int            Ts_ms = 1000;
 char           CZustand = 0;
-int            spritz = 3000; //spritzzeit
-float          fhelp = 0.0f;
+int            spritz = 1000; //spritzzeit, summerzeit = 2*spritzzeit
+//float           dist_USSensor = 0.0f;
 
 
 
-/*Interrupt*/
+/*Interrupt nciht verwendet möglich erweiterung*/
 
 /*
 class Counter {
@@ -82,24 +84,30 @@
 
  servo_0.Enable(1500,20000);
  
+ summer =1;
+ thread_sleep_for(200);
+ summer = 0;
+//thread_sleep_for(15000);
+ 
         
 
     
     while (true) {
 
      loop_timer.reset();
-   /*  if(user_button == 0)
+   /*  if(user_button == 0) // hilfsstart zustand varbiable muss auf Wert über 10 geändert werden
      {
          printf("nicht aktiv");
          CZustand = 0;
          
          }*/
  
-        /* ------------- start hacking ------------- -------------*/
+    /* ------------- start hacking ------------- -------------*/
     if(CZustand == 0) // Aufstarten
     {
         //servo_0.SetPosition(1000);
         printf("Grundposition\n");
+
         
         thread_sleep_for(100);  
         CZustand = 1; 
@@ -107,12 +115,12 @@
     if(CZustand == 1)// Warten
     {
         led = 0;
-        //printf("Warten\n");
+        printf("Warten\n");
         if(pirrechts == 1)
         {
             CZustand = 2;
-            printf("erkennt\n");
-            thread_sleep_for(100);
+            //printf("erkennt\n");
+            //thread_sleep_for(100);
             //servo_0.SetPosition(2000);
             
         }
@@ -126,7 +134,7 @@
         }
         if(pirhinten == 1)
         {
-            printf("pirhinten\n");
+            //printf("pirhinten\n");
             CZustand = 5;
         }
         
@@ -144,50 +152,56 @@
        led = 1;
        printf("rechts\n");
        
-       servo_0.SetPosition(2100); //1250
-       if(ultrarechts.read_cm() < 200)
+       servo_0.SetPosition(1900); //1250
+       if((30 < ultrarechts.read_cm()) & (ultrarechts.read_cm() < 200))
        {
-        fhelp = ultrarechts.read_cm();
-        printf("%f;",fhelp);
-        CZustand = 6;
-        }
-        else{
-        CZustand = 0;
+            //fhelp = ultrarechts.read_cm();
+            //printf("%3.3f;",fhelp);
+            CZustand = 6;
+       }
+       else{
+            CZustand = 0;
   
-        }
+       }
         
         
         thread_sleep_for(100);
     }
+    
+    
     if(CZustand == 3)//links erkennt
     {
        printf("links\n");
-       servo_0.SetPosition(1000);
-        if(ultralinks.read_cm() < 200)
+       servo_0.SetPosition(900);
+       if((30 < ultralinks.read_cm()) & (ultralinks.read_cm() < 200))
        {
-        fhelp = ultralinks.read_cm();
-        printf("%3.3f;\r\n",fhelp);
-        CZustand = 6;
+            //fhelp = ultralinks.read_cm();
+            //thread_sleep_for(10);
+            //printf("%3.3f;\r\n",fhelp);
+        
+            CZustand = 6;
         }
         else{
-        CZustand = 0;
-        //thread_sleep_for(100);  
+            CZustand = 0;
+            //thread_sleep_for(100);  
         } 
         
         
         thread_sleep_for(100);
     }
+    
+    
     if(CZustand == 4)//vorne erkennt
     {
-        printf("vorne\n");
-       servo_0.SetPosition(1500);
-       if(ultravorne.read_cm() < 200)
+       printf("vorne\n");
+       servo_0.SetPosition(1400);
+       if((30 < ultravorne.read_cm()) & (ultravorne.read_cm() < 200))
        {
-        CZustand = 6;
+            CZustand = 6;
         }
         else{
-        CZustand = 0;
-        thread_sleep_for(100);  
+            CZustand = 0;
+            //thread_sleep_for(100);  
         } 
         
         
@@ -197,13 +211,13 @@
     if(CZustand == 5)//hinten erkennt
     {
       printf("hinten\n");
-      servo_0.SetPosition(2450);
-       if(ultrahinten.read_cm() < 200) 
+      servo_0.SetPosition(2400);
+       if((30 < ultrahinten.read_cm()) & (ultrahinten.read_cm() < 200)) 
        {
-        CZustand = 6;
+            CZustand = 6;
         }
         else{
-        CZustand = 0;
+            CZustand = 0;
          
         } 
         
@@ -211,14 +225,15 @@
     }
     if(CZustand == 6)//spritzen
     {
-        printf("spritzen");
+        printf("spritzen\n");
         summer = 1;
+        thread_sleep_for(spritz);
         pumpe = 1;
         thread_sleep_for(spritz); // Spritzzeit
+        pumpe = 0;
         summer = 0;
-        pumpe = 0;
         CZustand = 0;
-        servo_0.SetPosition(1500); 
+        servo_0.SetPosition(1400); 
         
 
     }