Class Bertl

Dependencies:   HCSR

Dependents:   LEDTestmitButton

Fork of ur_Bertl by BERTL_CHEL18

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ur_Bertl.h Source File

ur_Bertl.h

00001 /***********************************
00002 name:   ur_Bertl.h      Version: 3.0
00003         class Bertl included
00004 author: PE HTL BULME
00005 email:  pe@bulme.at
00006 WIKI:   https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/
00007 description:
00008         Definition portion of the class ur_Bertl The Robot
00009         Step wise turns on left and rigth
00010         int ReturnButtonPressed() added which returns the int value of button pressed 
00011 ***********************************/
00012 #include "mbed.h"
00013 #include "const.h"
00014 
00015 #ifndef UR_BERTL_H
00016 #define UR_BERTL_H
00017 
00018 #define LEFTSENSOR P1_12
00019 #define RIGHTSENSOR P1_13
00020 /********************************************//**
00021  name:   ur_Bertl.h \n
00022  version: 3.0 \n
00023    class Bertl included \n
00024  author:PE HTL BULME \n
00025  email: pe@bulme.at \n
00026  WIKI:  https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage \n
00027  description: 
00028     Definition and documentation portion of the class ur_Bertl The Robot.
00029    
00030 ***********************************************/
00031 /** 
00032 @code
00033 //
00034 @endcode
00035 
00036 Example motor sensor test:
00037 @code
00038 #include "mbed.h"
00039 #include "ur_Bertl.h"
00040 #include "const.h"
00041  
00042 int main()
00043 {
00044     ur_Bertl karel(LEFTSENSOR);  // RIGHTSENSOR
00045 
00046     while(true) {
00047         karel.NibbleLeds(karel.Read());
00048     }
00049 }
00050 @endcode
00051 
00052 Example moving the robot around:
00053 @code
00054 #include "mbed.h"
00055 #include "ur_Bertl.h"
00056 #include "const.h"
00057 
00058 int main()
00059 {
00060     ur_Bertl karel;
00061     
00062     while(karel.WaitUntilButtonPressed()){}
00063     //karel.Move();
00064     karel.TurnLeft();
00065     karel.ShutOff();
00066 }
00067 @endcode
00068 
00069 Example LEDs:
00070 @code
00071 #include "mbed.h"
00072 #include "ur_Bertl.h"
00073 #include "const.h"
00074 
00075 int main()
00076 {
00077    ur_Bertl karel;
00078    
00079    while(karel.WaitUntilButtonPressed()){}
00080 
00081    karel.TurnLedOn(LED_FL1 | LED_FR1);  // see const.h
00082    wait(1);
00083    karel.TurnLedOn(0xFF);               // or use hex
00084    wait(1);
00085    karel.RGBLed(1,0,0);     // red
00086    wait(1);
00087    karel.RGBLed(0,1,0);     // green
00088    wait(1);
00089    karel.RGBLed(0,0,1);     // blue
00090    karel.BlueLedsON();
00091    karel.NibbleLeds(karel.Read());
00092    wait(1);
00093    karel.BlueLedsOFF();
00094    karel.TurnLedOff(0xFF);
00095    karel.ShutOff();
00096 } 
00097 @endcode
00098 Example IF/ELSE Commands (update ur_Bertl 2.0 from https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/
00099 @code
00100 /*Sorry, but there are Javascript problems with this code
00101 
00102 int main()
00103 {
00104     ur_Bertl karel;
00105 
00106     while( karel.WaitUntilButtonPressed() ) {}
00107     if( karel.NextToABeeper()) {
00108         karel.PickBeeper();
00109         karel.NibbleLeds(karel.AnyBeeperInBag());   //show number of beepers in bag on 4 yellow Leds
00110     }
00111     wait(1);
00112     if( karel.AnyBeeperInBag() ) {
00113         karel.PutBeeper();
00114         karel.NibbleLeds(karel.AnyBeeperInBag());  
00115     }
00116     wait(1);
00117     if( karel.FrontIsClear() )
00118         karel.Move();
00119     else
00120         karel.TurnLeft();
00121 
00122     karel.ShutOff();
00123 }
00124 
00125 
00126 @endcode
00127  */
00128 class ur_Bertl
00129 {
00130 protected:
00131     int beepersInBag;       /**< how many beepers does the robot have in his bag;\n you can show it with: karel.NibbleLeds(karel.AnyBeeperInBag())*/
00132     char cmd[3];            /**< I2C command */
00133     int16_t btns;           /**< which button is pressed */
00134     InterruptIn _interrupt; /**< interrupted used*/
00135     volatile int _count;    /**< values of motor sensor*/
00136 
00137     /**
00138     protected methodes for internal purposes only
00139     */
00140     void increment();       /**< ISR to increment sensor values of motor */
00141     bool backIsClear();     /**< don't now for what */
00142     bool frontButtonPressed();/**< TRUE if a a button on the front of Robot is pressed else FALSE */
00143     int bottomIsBlack();    /**< check line sensor; returns BCD value */
00144     void error();           /**< Error: stops the robot and all LEDs are blinking*/
00145 
00146 public:
00147     ur_Bertl();                 /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/
00148     ur_Bertl(PinName pin);      /**< parameterized constructor; on what pin should the interrupt work; SPEED, DISTANCE or ANGLE have to bee defined in config.h */
00149 
00150     //void Move();                /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/      
00151     void Move();                /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/      
00152     void TurnLeft();            /**< Robot turns left as much as the constant ANGLE*/      
00153     void PutBeeper();           /**< if Robot has any Beepers in his bag he can put one or more Beeper; if not --> Error(()*/  
00154     void PickBeeper();          /**< if Robot stands on a black item he can pick one or more Beeper (max. 15 --> Error()); if not --> Error()*/   
00155     void TurnOff();             /**<  turnes the robot off */
00156     bool WaitUntilButtonPressed();  /**< wait until any button is pressed at the robot */
00157     bool FrontIsClear();        /**< returns a boolean value true if front is free; if not false */ 
00158     bool NextToABeeper();       /**< returns a boolean value true if the robot is on a black place or line; if not --> false */ 
00159     bool IsButtonPressed(const int btn); /**< returns true if Button btn is pressed, else false */
00160     int ReturnButtonPressed();  /**< returns the int value of button pressed */
00161     int AnyBeeperInBag();       /**< returns an int value (if > 0 equal true) how many beepers in bag; if zero --> false */ 
00162     void NibbleLeds(int value); /**< methode for the 4 (half byte) yellow LEDs at the back left side; ie. you can show how many beeper a robot has in his bag with: karel.NibbleLeds(karel.AnyBeeperInBag())*/
00163     void TurnLedOn(int16_t led);/**< turns the specified one or more LEDs ON; description and name in const.h, such as LED_FL1 = 0x01; front LED white */
00164     void TurnLedOff(int16_t led);/**< turns the specified one or more LEDs OFF; description and name in const.h, such as LED_FL1 = 0x01; front LED white */
00165     void RGBLed(bool red, bool green, bool blue); /**<RGB Led with red, green and blue component of the Color */
00166     void BlueLedsOFF();         /**< OFF all blue LEDs which are on the same Port 1_28 */   
00167     void BlueLedsON();          /**< ON all blue LEDs which are on the same Port 1_28 */   
00168     int Read();
00169 };
00170 /********************************************//**
00171  name:   Bertl.h \n
00172  version: 3.0 \n
00173  author:PE HTL BULME \n
00174  email: pe@bulme.at \n
00175  WIKI:  https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage \n
00176  description: 
00177     Definition and documentation portion of the class Bertl The Robot.
00178    
00179 ***********************************************/
00180 
00181 /** 
00182 @code
00183 //
00184 @endcode
00185 
00186 Example motor sensor test:
00187 @code
00188 #include "mbed.h"
00189 #include "ur_Bertl.h"
00190 #include "const.h"
00191  
00192 int main()
00193 {
00194     ur_Bertl karel(LEFTSENSOR);  // RIGHTSENSOR
00195 
00196     while(true) {
00197         karel.NibbleLeds(karel.Read());
00198     }
00199 }
00200 @endcode
00201 
00202 Example follow a line:
00203 @code
00204 #include "mbed.h"
00205 #include "ur_Bertl.h"
00206 #include "const.h"
00207 
00208 int main()
00209 {
00210     Bertl karel;
00211     
00212     while(karel.WaitUntilButtonPressed())
00213     {
00214         karel.NibbleLeds(karel.GetLineValues());
00215         switch(karel.GetLineValues())
00216         {
00217         case 0x00:
00218             karel.TurnLeftStep(50);
00219             break;
00220         case 0x03: case 0x01: case 0x07:
00221             karel.TurnLeftStep(20);
00222             break;
00223         case 0x0E: case 0x0A: case 0x08:
00224             karel.TurnRigthStep(20);
00225             break;
00226         default:
00227             karel.Move(20);
00228             break;
00229         }
00230         if(!karel.FrontIsClear())
00231             karel.TurnLeftStep(1000);
00232     }
00233 }
00234 @endcode
00235 */
00236 class Bertl : public ur_Bertl
00237 {
00238 protected:
00239 public:
00240     //Bertl();                 /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/
00241     int Move(int move = MOVE);                /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/      
00242     int MoveBackwards(int move = MOVE);       /**< Robot moves as much back as the constant DISTANCE; if one of the buttons fire --> Error()*/
00243     void TurnRigth();           /**< Robot turns rigth as much as the constant ANGLE*/ 
00244     void TurnLeftStep(int step=STEPTIME);   /**< Robot turns left for a short time defined in STEPTIME */
00245     void TurnRigthStep(int step=STEPTIME);  /**< Robot turns rigth for a short time defined in STEPTIME */
00246     uint8_t GetLineValues();    /**< in the lower 4 bit are the values of the line sensor */
00247     void RGBLed(bool red, bool green, bool blue); /**<RGB Led with red, green and blue component of the Color */
00248 };
00249 #endif