Roboshark / Mbed 2 deprecated Michu_Proeble_V6

Dependencies:   mbed

Fork of Roboshark_V6 by Roboshark

Files at this revision

API Documentation at this revision

Comitter:
ahlervin
Date:
Sun May 06 15:18:14 2018 +0000
Parent:
8:a7f1ee7840d0
Commit message:
IR Front ?berwacht das nicht zu weit gefahren wird

Changed in this revision

Fahren.cpp Show annotated file Show diff for this revision Revisions of this file
Fahren.h Show annotated file Show diff for this revision Revisions of this file
Regler.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Fahren.cpp	Sun May 06 14:17:07 2018 +0000
+++ b/Fahren.cpp	Sun May 06 15:18:14 2018 +0000
@@ -15,11 +15,12 @@
 const float Fahren :: PERIOD = 0.8f;
 
 //Konstruktor
-Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, Regler& regler, int reglerEin):
-    controller(controller), counterLeft(counterLeft), counterRight(counterRight), regler(regler), reglerEin(reglerEin) {         //IRSENSOR IETAH
+Fahren::Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, Regler& regler, int reglerEin, IRSensor& iRSensor):
+    controller(controller), counterLeft(counterLeft), counterRight(counterRight), regler(regler), reglerEin(reglerEin), iRSensor (iRSensor) {         //IRSENSOR IETAH
     
     SpeedR = 50;
     SpeedL = 50;
+    disF = 0;
     ticker.attach(callback(this, &Fahren::getSpeed), PERIOD);
 }
 
@@ -37,7 +38,7 @@
     }else {SpeedR = regler.getSpeedR();
             SpeedL = regler.getSpeedL();
     }
-    
+    disF = iRSensor.readF();
     //printf("SpeedR in F = %f\n",SpeedR);
     //printf("SpeedL in F = %f\n",SpeedL);
 }
@@ -124,13 +125,13 @@
        // printf("Encoderlinks %d \n\r", counterLeft.read());                     //Debugging Zweck (Putty benutzen!)
         
         //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen
-        if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts){    
+        if(counterRight.read() - initialClicksRight >= wegRechts || counterRight.read() - initialClicksRight <= -wegRechts || disF <= 50){
             controller.setDesiredSpeedRight(0);
             stopRight = true;
             }
             
         //If Schleife, wenn Clicks erreicht sind, muss der Motor stoppen    
-        if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks){
+        if(counterLeft.read() - initialClicksLeft >= wegLinks || counterLeft.read() - initialClicksLeft <= -wegLinks || disF <= 50){
             controller.setDesiredSpeedLeft(0);
             stopLeft = true;
             }
--- a/Fahren.h	Sun May 06 14:17:07 2018 +0000
+++ b/Fahren.h	Sun May 06 15:18:14 2018 +0000
@@ -18,7 +18,7 @@
 class Fahren{
     
     public:    
-    Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, Regler& regler, int reglerEin); //Konstruktor
+    Fahren(Controller& controller, EncoderCounter& counterLeft, EncoderCounter& counterRight, Regler& regler, int reglerEin, IRSensor& iRSensor); //Konstruktor
     
     virtual ~Fahren();
     
@@ -36,6 +36,7 @@
     EncoderCounter& counterLeft;
     EncoderCounter& counterRight;
     Regler& regler;
+    IRSensor& iRSensor;
     Ticker ticker;
     void getSpeed();
 
@@ -51,6 +52,7 @@
     short stopLeft;
     float SpeedR;
     float SpeedL;
+    float disF;
     static const float PERIOD;
     int reglerEin;
    
--- a/Regler.cpp	Sun May 06 14:17:07 2018 +0000
+++ b/Regler.cpp	Sun May 06 15:18:14 2018 +0000
@@ -32,7 +32,7 @@
     }
     
     void Regler::setSpeed (){
-        measR2 = iRSensor.readR();            // Converts and read the analog input value (value from 0.0 to 1.0)
+        measR2 = iRSensor.readR();            // Converts and read the analog input value 
         measL2 = iRSensor.readL(); 
         
         if(measR2 == measL2){                                                   //DAS ISCH MIN GAGAREGLER zum Pröble gsi
--- a/main.cpp	Sun May 06 14:17:07 2018 +0000
+++ b/main.cpp	Sun May 06 15:18:14 2018 +0000
@@ -70,7 +70,7 @@
 
 Regler regler(IrRight, IrLeft, iRSensor);
 
-Fahren fahren(controller, counterLeft, counterRight, regler, reglerEin);                           //Reihenfolge!!!!!!!!!!!!!!!!!!! Ultra wichtig
+Fahren fahren(controller, counterLeft, counterRight, regler, reglerEin, iRSensor);                           //Reihenfolge!!!!!!!!!!!!!!!!!!! Ultra wichtig
 
 int main()
 {