Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Bertl by
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 int16_t leds; /**< save led status*/ 00137 00138 /** 00139 protected methodes for internal purposes only 00140 */ 00141 void increment(); /**< ISR to increment sensor values of motor */ 00142 bool backIsClear(); /**< don't now for what */ 00143 bool frontButtonPressed();/**< TRUE if a a button on the front of Robot is pressed else FALSE */ 00144 int bottomIsBlack(); /**< check line sensor; returns BCD value */ 00145 void error(); /**< Error: stops the robot and all LEDs are blinking*/ 00146 00147 public: 00148 ur_Bertl(); /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/ 00149 ur_Bertl(PinName pin); /**< parameterized constructor; on what pin should the interrupt work; SPEED, DISTANCE or ANGLE have to bee defined in config.h */ 00150 00151 //void Move(); /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/ 00152 void Move(); /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/ 00153 void TurnLeft(); /**< Robot turns left as much as the constant ANGLE*/ 00154 void PutBeeper(); /**< if Robot has any Beepers in his bag he can put one or more Beeper; if not --> Error(()*/ 00155 void PickBeeper(); /**< if Robot stands on a black item he can pick one or more Beeper (max. 15 --> Error()); if not --> Error()*/ 00156 void TurnOff(); /**< turnes the robot off */ 00157 bool WaitUntilButtonPressed(); /**< wait until any button is pressed at the robot */ 00158 bool FrontIsClear(); /**< returns a boolean value true if front is free; if not false */ 00159 bool NextToABeeper(); /**< returns a boolean value true if the robot is on a black place or line; if not --> false */ 00160 bool IsButtonPressed(const int btn); /**< returns true if Button btn is pressed, else false */ 00161 int ReturnButtonPressed(); /**< returns the int value of button pressed */ 00162 int AnyBeeperInBag(); /**< returns an int value (if > 0 equal true) how many beepers in bag; if zero --> false */ 00163 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())*/ 00164 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 */ 00165 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 */ 00166 void RGBLed(bool red, bool green, bool blue); /**<RGB Led with red, green and blue component of the Color */ 00167 void BlueLedsOFF(); /**< OFF all blue LEDs which are on the same Port 1_28 */ 00168 void BlueLedsON(); /**< ON all blue LEDs which are on the same Port 1_28 */ 00169 int Read(); 00170 bool IsLedOn(const int led); 00171 00172 }; 00173 /********************************************//** 00174 name: Bertl.h \n 00175 version: 3.0 \n 00176 author:PE HTL BULME \n 00177 email: pe@bulme.at \n 00178 WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage \n 00179 description: 00180 Definition and documentation portion of the class Bertl The Robot. 00181 00182 ***********************************************/ 00183 00184 /** 00185 @code 00186 // 00187 @endcode 00188 00189 Example motor sensor test: 00190 @code 00191 #include "mbed.h" 00192 #include "ur_Bertl.h" 00193 #include "const.h" 00194 00195 int main() 00196 { 00197 ur_Bertl karel(LEFTSENSOR); // RIGHTSENSOR 00198 00199 while(true) { 00200 karel.NibbleLeds(karel.Read()); 00201 } 00202 } 00203 @endcode 00204 00205 Example follow a line: 00206 @code 00207 #include "mbed.h" 00208 #include "ur_Bertl.h" 00209 #include "const.h" 00210 00211 int main() 00212 { 00213 Bertl karel; 00214 00215 while(karel.WaitUntilButtonPressed()) 00216 { 00217 karel.NibbleLeds(karel.GetLineValues()); 00218 switch(karel.GetLineValues()) 00219 { 00220 case 0x00: 00221 karel.TurnLeftStep(50); 00222 break; 00223 case 0x03: case 0x01: case 0x07: 00224 karel.TurnLeftStep(20); 00225 break; 00226 case 0x0E: case 0x0A: case 0x08: 00227 karel.TurnRigthStep(20); 00228 break; 00229 default: 00230 karel.Move(20); 00231 break; 00232 } 00233 if(!karel.FrontIsClear()) 00234 karel.TurnLeftStep(1000); 00235 } 00236 } 00237 @endcode 00238 */ 00239 class Bertl : public ur_Bertl 00240 { 00241 protected: 00242 public: 00243 //Bertl(); /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/ 00244 int Move(int move = MOVE); /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/ 00245 int MoveBackwards(int move = MOVE); /**< Robot moves as much back as the constant DISTANCE; if one of the buttons fire --> Error()*/ 00246 void TurnRigth(); /**< Robot turns rigth as much as the constant ANGLE*/ 00247 void TurnLeftStep(int step=STEPTIME); /**< Robot turns left for a short time defined in STEPTIME */ 00248 void TurnRigthStep(int step=STEPTIME); /**< Robot turns rigth for a short time defined in STEPTIME */ 00249 uint8_t GetLineValues(); /**< in the lower 4 bit are the values of the line sensor */ 00250 void RGBLed(bool red, bool green, bool blue); /**<RGB Led with red, green and blue component of the Color */ 00251 }; 00252 #endif
Generated on Fri Jul 15 2022 00:03:39 by
1.7.2
