Class Bertl added

Dependencies:   HCSR

Fork of ur_Bertl by Dr. Pucher

Files at this revision

API Documentation at this revision

Comitter:
bulmecisco
Date:
Mon Apr 27 13:13:45 2015 +0000
Parent:
12:cedc088eaf05
Commit message:
Bertl version 3.0 updated

Changed in this revision

config.h Show annotated file Show diff for this revision Revisions of this file
const.h Show annotated file Show diff for this revision Revisions of this file
ur_Bertl.cpp Show annotated file Show diff for this revision Revisions of this file
ur_Bertl.h Show annotated file Show diff for this revision Revisions of this file
diff -r cedc088eaf05 -r 3ce84646fd74 config.h
--- a/config.h	Sun Apr 26 20:04:47 2015 +0000
+++ b/config.h	Mon Apr 27 13:13:45 2015 +0000
@@ -1,6 +1,6 @@
 /*! \file config.h
 \brief A Documented file.
-* name:   config.h    Version: 1.1 \n
+* name:   config.h    Version: 3.0 \n
 * author: PE HTL BULME \n
 * email:  pe@bulme.at \n
 * description:
@@ -16,8 +16,9 @@
 /*! \def DEBUG
 \brief Turns debugging infos off (0) and on (3) which are send to serial pc.uart */
 #define DEBUG 0
-//#define FRONTBUTTON     /**< Error shutoff if Bertl moves against a wall*/
-#define HCSR            /**< if ultrsonic is installed*/
+//#define FRONTBUTTON       /**< Error shutoff if Bertl moves against a wall*/
+#define HCSR                /**< if ultrsonic is installed*/
+#define MOTORENC P1_12        /**< P1_12: left encoder P1_13: rigth encoder (motor) */
 
 BusOut NibbleLEDs(P1_8, P1_9, P1_10, P1_11);   /**< 4 yellow LEDs as a bus defined; use it i.e.: karel.NibbleLeds(karel.GetLineValues()); to show line sensor values */
 DigitalOut LED_D10(P1_8);    /**<  wiring first LED_D10 */
diff -r cedc088eaf05 -r 3ce84646fd74 const.h
--- a/const.h	Sun Apr 26 20:04:47 2015 +0000
+++ b/const.h	Mon Apr 27 13:13:45 2015 +0000
@@ -1,6 +1,6 @@
 /*! \file const.h
 \brief A Documented file.
-* name:   const.h    Version: 2.2 \n
+* name:   const.h    Version: 3.0 \n
 * author: PE HTL BULME \n
 * email:  pe@bulme.at \n
 * description:
@@ -62,6 +62,4 @@
 const int West = 2; 
 const int North = 3;
 const int South = 4;
-
-
 #endif
\ No newline at end of file
diff -r cedc088eaf05 -r 3ce84646fd74 ur_Bertl.cpp
--- a/ur_Bertl.cpp	Sun Apr 26 20:04:47 2015 +0000
+++ b/ur_Bertl.cpp	Mon Apr 27 13:13:45 2015 +0000
@@ -1,5 +1,6 @@
 /***********************************
-name:   ur_Bertl.cpp    Version: 2.2
+name:   ur_Bertl.cpp    Version: 3.0
+        class Bertl included
 author: PE HTL BULME
 email:  pe@bulme.at
 WIKI:   https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/
@@ -13,7 +14,7 @@
 #include "ur_Bertl.h"
 
 // Constructor
-ur_Bertl::ur_Bertl() : _interrupt(P1_12)            // left sensor P1_13
+ur_Bertl::ur_Bertl() : _interrupt(MOTORENC)         
 {
     i2c.frequency(40000);                           // I2C init
     char init1[2] = {0x6, 0x00};
@@ -374,7 +375,7 @@
 }
 
 // -------------------- BERTL CLASS -------------------------------------
-void Bertl::MoveBackwards(int move)
+int Bertl::MoveBackwards(int move)
 {
     int count = _count;
     //wait_ms(250);                         // waite until Bertl stops
@@ -393,8 +394,35 @@
     MotorR_EN=MotorL_EN=0;
     if(move == MOVE)
         wait_ms(250);
+    return _count - count;
 }
 // ------------------------- BERT CLASS --------------------------------------
+int Bertl::Move(int move)
+{
+    int count = _count;
+    MotorR_EN=MotorL_EN=1;                  // both motor ENABLE
+    MotorR_FORWARD = MotorL_FORWARD = 1;    // both motor forward ON
+#ifdef TIME
+    wait_ms(move);
+#else
+
+    while(_count < count+move) {
+        //if(!FrontIsClear())       // more convenient because there are no accidents :-)
+          //  break;
+#ifdef FRONTBUTTON
+        if(frontButtonPressed())
+            error();
+#endif
+        DEBUG_PRINT("count: %d _count: %d", count, _count);
+    }
+#endif
+    MotorR_FORWARD = MotorL_FORWARD = 0;    // both motor off
+    MotorR_EN=MotorL_EN=0;
+    if(move == MOVE)
+        wait_ms(250);
+    return _count - count;
+}
+
 void Bertl::TurnRigth()
 {
     int count = _count;
@@ -475,4 +503,11 @@
     
     detect = linesensor;
     return detect;
-}
\ No newline at end of file
+}
+
+void Bertl::RGBLed(bool red, bool green, bool blue)
+{
+      RGB_blue=!blue;
+      RGB_red=!red;
+      RGB_green=!green;
+}
diff -r cedc088eaf05 -r 3ce84646fd74 ur_Bertl.h
--- a/ur_Bertl.h	Sun Apr 26 20:04:47 2015 +0000
+++ b/ur_Bertl.h	Mon Apr 27 13:13:45 2015 +0000
@@ -1,5 +1,6 @@
 /***********************************
-name:   ur_Bertl.h      Version: 2.2
+name:   ur_Bertl.h      Version: 3.0
+        class Bertl included
 author: PE HTL BULME
 email:  pe@bulme.at
 WIKI:   https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/
@@ -18,7 +19,8 @@
 #define RIGHTSENSOR P1_13
 /********************************************//**
  name:   ur_Bertl.h \n
- version: 2.2 \n
+ version: 3.0 \n
+   class Bertl included \n
  author:PE HTL BULME \n
  email: pe@bulme.at \n
  WIKI:  https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage \n
@@ -167,7 +169,7 @@
 };
 /********************************************//**
  name:   Bertl.h \n
- version: 1.0 \n
+ version: 3.0 \n
  author:PE HTL BULME \n
  email: pe@bulme.at \n
  WIKI:  https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage \n
@@ -236,10 +238,12 @@
 protected:
 public:
     //Bertl();                 /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/
-    void MoveBackwards(int move = MOVE);       /**< Robot moves as much back as the constant DISTANCE; if one of the buttons fire --> Error()*/
+    int Move(int move = MOVE);                /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/      
+    int MoveBackwards(int move = MOVE);       /**< Robot moves as much back as the constant DISTANCE; if one of the buttons fire --> Error()*/
     void TurnRigth();           /**< Robot turns rigth as much as the constant ANGLE*/ 
     void TurnLeftStep(int step=STEPTIME);   /**< Robot turns left for a short time defined in STEPTIME */
     void TurnRigthStep(int step=STEPTIME);  /**< Robot turns rigth for a short time defined in STEPTIME */
     uint8_t GetLineValues();    /**< in the lower 4 bit are the values of the line sensor */
+    void RGBLed(bool red, bool green, bool blue); /**<RGB Led with red, green and blue component of the Color */
 };
 #endif
\ No newline at end of file