Funktionen Umbennenen

Dependencies:   HCSR

Fork of Bertl by Franz Pucher

Revision:
4:76acfddc26fb
Parent:
3:01b183fe8b41
Child:
5:6b667e2cb800
--- a/ur_Bertl.cpp	Thu Mar 26 13:06:00 2015 +0000
+++ b/ur_Bertl.cpp	Tue Apr 07 12:30:39 2015 +0000
@@ -1,11 +1,11 @@
 /***********************************
-name:   ur_Bertl.cpp    Version: 1.1
+name:   ur_Bertl.cpp    Version: 2.0
 author: PE HTL BULME
 email:  pe@bulme.at
+WIKI:   https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/
 description:
-    Implementation portion of class ur_Bertl The Robot 
-    Blue LED and RGB LED test added
-      
+        Implementation portion of class ur_Bertl The Robot 
+        boolean commands added for if/else, while, ...      
 ***********************************/
 #include "mbed.h"
 #include "config.h"
@@ -14,7 +14,7 @@
 // Constructor
 ur_Bertl::ur_Bertl() : _interrupt(P1_12)            // left sensor P1_13
 {
-    i2c.frequency(40000);                           // I2C Frequenz 40kHz
+    i2c.frequency(40000);                           // I2C init
     char init1[2] = {0x6, 0x00};
     char init2[2] = {0x7, 0xff};
     i2c.write(0x40, init1, 2);
@@ -27,7 +27,7 @@
 
 ur_Bertl::ur_Bertl(PinName pin) :  _interrupt(pin)  // create the InterruptIn on the pin specified to Counter
 {
-    i2c.frequency(40000);                           // I2C Frequenz 40kHz
+    i2c.frequency(40000);                           // I2C init
     char init1[2] = {0x6, 0x00};
     char init2[2] = {0x7, 0xff};
     i2c.write(0x40, init1, 2);
@@ -38,7 +38,6 @@
     beepersInBag = 0;
 }
 
-
 // Pulblic methodes
 void ur_Bertl::Move()
 {
@@ -80,6 +79,8 @@
         beepersInBag++;
     else 
         error();   
+    if(beepersInBag > 16)
+        error();
 }
 
 void ur_Bertl::TurnLeft()
@@ -105,36 +106,13 @@
     wait_ms(250);           // only to step the robot
 }
 
-bool ur_Bertl::WaitUntilButtonPressed()
-{
-    char cmd[3];
-    int16_t btns;
-    bool wert;
-
-    RGB_blue=RGB_red=RGB_green=0;
-    cmd[0] = 0x06;
-    cmd[1] = 0x00;
-    i2c.write(addr, cmd, 2); 
-
-    cmd[0]=0x01;
-    i2c.write(addr, cmd, 1);
-    i2c.read(addr|1, cmd, 1);
-    btns = cmd[0];
-    if( btns & (0xFF))
-        wert = false;
-    else
-        wert = true;
-    DEBUG_PRINT("\right\nWERT: %d \right\n", wert);
-    return wert;
-}
-
 void ur_Bertl::ShutOff()
 {
     MotorR_FORWARD = MotorL_FORWARD = 0;    // motor OFF
     MotorR_EN=MotorL_EN=0;                  // motor disable
 }
 
-// LEDs methodes
+// Public LEDs methodes
 
 void ur_Bertl::BlueLedsON()
 {
@@ -191,61 +169,6 @@
     NibbleLEDs = value%16;
 }
 
-//-----------------INTERNAL USE ONLY ----------------------------
-void ur_Bertl::error()
-{
-    int wait = 500;
-    MotorR_FORWARD = MotorL_FORWARD = 0;    // both motor off
-    MotorR_REVERSE = MotorL_REVERSE = 0;    // both motor off
-    MotorR_EN=MotorL_EN=0;
-    while(1) {
-        TurnLedOff(0xFF);
-        LED_D10 = LED_D11 = LED_D12 = LED_D13 = 0;
-        LED_blue=1;
-        RGB_blue=RGB_green=RGB_red=1;
-        wait_ms(wait);
-        TurnLedOn(0xFF);
-        LED_D10 = LED_D11 = LED_D12 = LED_D13 = 1;
-        LED_blue=0;
-        RGB_blue=RGB_green=1;RGB_red=0;
-        wait_ms(wait);
-    }
-}
-
-bool ur_Bertl::frontButtonPressed()
-{
-    char cmd[3];            // array for I2C
-    int16_t btns;
-    bool wert;
-
-    cmd[0] = 0x06;
-    cmd[1] = 0x00;
-    i2c.write(addr, cmd, 2); 
-
-    cmd[0]=0x01;
-    i2c.write(addr, cmd, 1);
-    i2c.read(addr|1, cmd, 1);
-    btns = cmd[0];
-    if( btns & (BTN_FL|BTN_FM|BTN_FR|BTN_FRR|BTN_FLL))
-        wert = true;
-    else
-        wert = false;
-    DEBUG_PRINT("WERT: %d", wert);
-    return wert;
-}
-
-// ISR
-
-void ur_Bertl::increment()
-{
-    _count++;
-}
-
-int ur_Bertl::Read()
-{
-    return _count;
-}
-
 //----------------------------------------------------------------------
 
 bool ur_Bertl::FrontIsClear()
@@ -282,10 +205,32 @@
 #endif
 }
 
-/*
+bool ur_Bertl::WaitUntilButtonPressed()
+{
+    char cmd[3];
+    int16_t btns;
+    bool wert;
+
+    RGB_blue=RGB_red=RGB_green=0;
+    cmd[0] = 0x06;
+    cmd[1] = 0x00;
+    i2c.write(addr, cmd, 2); 
+
+    cmd[0]=0x01;
+    i2c.write(addr, cmd, 1);
+    i2c.read(addr|1, cmd, 1);
+    btns = cmd[0];
+    if( btns & (0xFF))
+        wert = false;
+    else
+        wert = true;
+    DEBUG_PRINT("\right\nWERT: %d \right\n", wert);
+    return wert;
+}
+
 bool ur_Bertl::NextToABeeper()
 {
-    if (BottomIsBlack())
+    if (bottomIsBlack())
         return true;
     else 
         return false;
@@ -299,6 +244,32 @@
         return 0;
 }
 
+void ur_Bertl::MoveBackwards()
+{
+    int count = _count;
+    //wait_ms(250);                         // waite until Bertl stops
+    MotorR_EN=MotorL_EN=1;                  // both motor ENABLE
+    MotorR_REVERSE = MotorL_REVERSE = 1;    // both motor backwards ON
+    while(_count < count+DISTANCE) {
+        if(!backIsClear())
+            break;
+        DEBUG_PRINT("count: %d _count: %d", count, _count);
+    }
+    MotorR_REVERSE = MotorL_REVERSE = 0;    // both motor off
+    MotorR_EN=MotorL_EN=0;
+    wait_ms(250);
+}
+
+// Protected methodes
+
+int ur_Bertl::bottomIsBlack()
+{
+    int detect;
+    
+    detect = linesensor;
+    return detect;
+}
+
 bool ur_Bertl::backIsClear()
 {
     char cmd[3];            // array for I2C
@@ -321,27 +292,58 @@
     return wert;
 }
 
-int ur_Bertl::BottomIsBlack()
+bool ur_Bertl::frontButtonPressed()
 {
-    int detect;
-    
-    detect = linesensor;
-    return detect;
+    char cmd[3];            // array for I2C
+    int16_t btns;
+    bool wert;
+
+    cmd[0] = 0x06;
+    cmd[1] = 0x00;
+    i2c.write(addr, cmd, 2); 
+
+    cmd[0]=0x01;
+    i2c.write(addr, cmd, 1);
+    i2c.read(addr|1, cmd, 1);
+    btns = cmd[0];
+    if( btns & (BTN_FL|BTN_FM|BTN_FR|BTN_FRR|BTN_FLL))
+        wert = true;
+    else
+        wert = false;
+    DEBUG_PRINT("WERT: %d", wert);
+    return wert;
 }
 
-void ur_Bertl::MoveBackwards()
+//-----------------INTERNAL USE ONLY ----------------------------
+void ur_Bertl::error()
 {
-    int count = _count;
-    //wait_ms(250);                         // waite until Bertl stops
-    MotorR_EN=MotorL_EN=1;                  // both motor ENABLE
-    MotorR_REVERSE = MotorL_REVERSE = 1;    // both motor backwards ON
-    while(_count < count+DISTANCE) {
-        if(!backIsClear())
-            break;
-        DEBUG_PRINT("count: %d _count: %d", count, _count);
-    }
+    int wait = 500;
+    MotorR_FORWARD = MotorL_FORWARD = 0;    // both motor off
     MotorR_REVERSE = MotorL_REVERSE = 0;    // both motor off
     MotorR_EN=MotorL_EN=0;
-    wait_ms(250);
+    while(1) {
+        TurnLedOff(0xFF);
+        LED_D10 = LED_D11 = LED_D12 = LED_D13 = 0;
+        LED_blue=1;
+        RGB_blue=RGB_green=RGB_red=1;
+        wait_ms(wait);
+        TurnLedOn(0xFF);
+        LED_D10 = LED_D11 = LED_D12 = LED_D13 = 1;
+        LED_blue=0;
+        RGB_blue=RGB_green=1;RGB_red=0;
+        wait_ms(wait);
+    }
 }
-*/
+
+// ISR
+
+void ur_Bertl::increment()
+{
+    _count++;
+}
+
+int ur_Bertl::Read()
+{
+    return _count;
+}
+