Class Bertl added
Dependencies: HCSR
Dependents: BERTL_ButtonLeds Bertl_Arbeit FollowLine SerialPC ... more
Fork of ur_Bertl by
ur_Bertl.h@12:cedc088eaf05, 2015-04-26 (annotated)
- Committer:
- bulmecisco
- Date:
- Sun Apr 26 20:04:47 2015 +0000
- Revision:
- 12:cedc088eaf05
- Parent:
- 7:e7f74f072564
- Child:
- 13:3ce84646fd74
Class Bertl with additional Methodes added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bulmecisco | 0:66e9a0afcbd6 | 1 | /*********************************** |
bulmecisco | 12:cedc088eaf05 | 2 | name: ur_Bertl.h Version: 2.2 |
bulmecisco | 0:66e9a0afcbd6 | 3 | author: PE HTL BULME |
bulmecisco | 0:66e9a0afcbd6 | 4 | email: pe@bulme.at |
bulmecisco | 4:76acfddc26fb | 5 | WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/ |
bulmecisco | 0:66e9a0afcbd6 | 6 | description: |
bulmecisco | 4:76acfddc26fb | 7 | Definition portion of the class ur_Bertl The Robot |
bulmecisco | 12:cedc088eaf05 | 8 | Step wise turns on left and rigth |
bulmecisco | 7:e7f74f072564 | 9 | int ReturnButtonPressed() added which returns the int value of button pressed |
bulmecisco | 0:66e9a0afcbd6 | 10 | ***********************************/ |
bulmecisco | 0:66e9a0afcbd6 | 11 | #include "mbed.h" |
bulmecisco | 12:cedc088eaf05 | 12 | #include "const.h" |
bulmecisco | 0:66e9a0afcbd6 | 13 | |
bulmecisco | 0:66e9a0afcbd6 | 14 | #ifndef UR_BERTL_H |
bulmecisco | 0:66e9a0afcbd6 | 15 | #define UR_BERTL_H |
bulmecisco | 0:66e9a0afcbd6 | 16 | |
bulmecisco | 0:66e9a0afcbd6 | 17 | #define LEFTSENSOR P1_12 |
bulmecisco | 0:66e9a0afcbd6 | 18 | #define RIGHTSENSOR P1_13 |
bulmecisco | 0:66e9a0afcbd6 | 19 | /********************************************//** |
bulmecisco | 4:76acfddc26fb | 20 | name: ur_Bertl.h \n |
bulmecisco | 12:cedc088eaf05 | 21 | version: 2.2 \n |
bulmecisco | 4:76acfddc26fb | 22 | author:PE HTL BULME \n |
bulmecisco | 4:76acfddc26fb | 23 | email: pe@bulme.at \n |
bulmecisco | 4:76acfddc26fb | 24 | WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage \n |
bulmecisco | 4:76acfddc26fb | 25 | description: |
bulmecisco | 0:66e9a0afcbd6 | 26 | Definition and documentation portion of the class ur_Bertl The Robot. |
bulmecisco | 0:66e9a0afcbd6 | 27 | |
bulmecisco | 0:66e9a0afcbd6 | 28 | ***********************************************/ |
bulmecisco | 0:66e9a0afcbd6 | 29 | /** |
bulmecisco | 0:66e9a0afcbd6 | 30 | @code |
bulmecisco | 0:66e9a0afcbd6 | 31 | // |
bulmecisco | 0:66e9a0afcbd6 | 32 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 33 | |
bulmecisco | 0:66e9a0afcbd6 | 34 | Example motor sensor test: |
bulmecisco | 0:66e9a0afcbd6 | 35 | @code |
bulmecisco | 0:66e9a0afcbd6 | 36 | #include "mbed.h" |
bulmecisco | 0:66e9a0afcbd6 | 37 | #include "ur_Bertl.h" |
bulmecisco | 0:66e9a0afcbd6 | 38 | #include "const.h" |
bulmecisco | 0:66e9a0afcbd6 | 39 | |
bulmecisco | 0:66e9a0afcbd6 | 40 | int main() |
bulmecisco | 0:66e9a0afcbd6 | 41 | { |
bulmecisco | 0:66e9a0afcbd6 | 42 | ur_Bertl karel(LEFTSENSOR); // RIGHTSENSOR |
bulmecisco | 0:66e9a0afcbd6 | 43 | |
bulmecisco | 0:66e9a0afcbd6 | 44 | while(true) { |
bulmecisco | 0:66e9a0afcbd6 | 45 | karel.NibbleLeds(karel.Read()); |
bulmecisco | 0:66e9a0afcbd6 | 46 | } |
bulmecisco | 0:66e9a0afcbd6 | 47 | } |
bulmecisco | 0:66e9a0afcbd6 | 48 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 49 | |
bulmecisco | 0:66e9a0afcbd6 | 50 | Example moving the robot around: |
bulmecisco | 0:66e9a0afcbd6 | 51 | @code |
bulmecisco | 0:66e9a0afcbd6 | 52 | #include "mbed.h" |
bulmecisco | 0:66e9a0afcbd6 | 53 | #include "ur_Bertl.h" |
bulmecisco | 0:66e9a0afcbd6 | 54 | #include "const.h" |
bulmecisco | 0:66e9a0afcbd6 | 55 | |
bulmecisco | 0:66e9a0afcbd6 | 56 | int main() |
bulmecisco | 0:66e9a0afcbd6 | 57 | { |
bulmecisco | 0:66e9a0afcbd6 | 58 | ur_Bertl karel; |
bulmecisco | 0:66e9a0afcbd6 | 59 | |
bulmecisco | 0:66e9a0afcbd6 | 60 | while(karel.WaitUntilButtonPressed()){} |
bulmecisco | 0:66e9a0afcbd6 | 61 | //karel.Move(); |
bulmecisco | 0:66e9a0afcbd6 | 62 | karel.TurnLeft(); |
bulmecisco | 0:66e9a0afcbd6 | 63 | karel.ShutOff(); |
bulmecisco | 0:66e9a0afcbd6 | 64 | } |
bulmecisco | 0:66e9a0afcbd6 | 65 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 66 | |
bulmecisco | 0:66e9a0afcbd6 | 67 | Example LEDs: |
bulmecisco | 0:66e9a0afcbd6 | 68 | @code |
bulmecisco | 0:66e9a0afcbd6 | 69 | #include "mbed.h" |
bulmecisco | 0:66e9a0afcbd6 | 70 | #include "ur_Bertl.h" |
bulmecisco | 0:66e9a0afcbd6 | 71 | #include "const.h" |
bulmecisco | 0:66e9a0afcbd6 | 72 | |
bulmecisco | 0:66e9a0afcbd6 | 73 | int main() |
bulmecisco | 0:66e9a0afcbd6 | 74 | { |
bulmecisco | 0:66e9a0afcbd6 | 75 | ur_Bertl karel; |
bulmecisco | 0:66e9a0afcbd6 | 76 | |
bulmecisco | 0:66e9a0afcbd6 | 77 | while(karel.WaitUntilButtonPressed()){} |
bulmecisco | 0:66e9a0afcbd6 | 78 | |
bulmecisco | 0:66e9a0afcbd6 | 79 | karel.TurnLedOn(LED_FL1 | LED_FR1); // see const.h |
bulmecisco | 0:66e9a0afcbd6 | 80 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 81 | karel.TurnLedOn(0xFF); // or use hex |
bulmecisco | 0:66e9a0afcbd6 | 82 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 83 | karel.RGBLed(1,0,0); // red |
bulmecisco | 0:66e9a0afcbd6 | 84 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 85 | karel.RGBLed(0,1,0); // green |
bulmecisco | 0:66e9a0afcbd6 | 86 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 87 | karel.RGBLed(0,0,1); // blue |
bulmecisco | 0:66e9a0afcbd6 | 88 | karel.BlueLedsON(); |
bulmecisco | 0:66e9a0afcbd6 | 89 | karel.NibbleLeds(karel.Read()); |
bulmecisco | 0:66e9a0afcbd6 | 90 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 91 | karel.BlueLedsOFF(); |
bulmecisco | 0:66e9a0afcbd6 | 92 | karel.TurnLedOff(0xFF); |
bulmecisco | 0:66e9a0afcbd6 | 93 | karel.ShutOff(); |
bulmecisco | 0:66e9a0afcbd6 | 94 | } |
bulmecisco | 0:66e9a0afcbd6 | 95 | @endcode |
bulmecisco | 4:76acfddc26fb | 96 | Example IF/ELSE Commands (update ur_Bertl 2.0 from https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/ |
bulmecisco | 4:76acfddc26fb | 97 | @code |
bulmecisco | 12:cedc088eaf05 | 98 | /*Sorry, but there are Javascript problems with this code |
bulmecisco | 4:76acfddc26fb | 99 | |
bulmecisco | 4:76acfddc26fb | 100 | int main() |
bulmecisco | 4:76acfddc26fb | 101 | { |
bulmecisco | 4:76acfddc26fb | 102 | ur_Bertl karel; |
bulmecisco | 4:76acfddc26fb | 103 | |
bulmecisco | 4:76acfddc26fb | 104 | while( karel.WaitUntilButtonPressed() ) {} |
bulmecisco | 4:76acfddc26fb | 105 | if( karel.NextToABeeper()) { |
bulmecisco | 4:76acfddc26fb | 106 | karel.PickBeeper(); |
bulmecisco | 4:76acfddc26fb | 107 | karel.NibbleLeds(karel.AnyBeeperInBag()); //show number of beepers in bag on 4 yellow Leds |
bulmecisco | 4:76acfddc26fb | 108 | } |
bulmecisco | 4:76acfddc26fb | 109 | wait(1); |
bulmecisco | 4:76acfddc26fb | 110 | if( karel.AnyBeeperInBag() ) { |
bulmecisco | 4:76acfddc26fb | 111 | karel.PutBeeper(); |
bulmecisco | 4:76acfddc26fb | 112 | karel.NibbleLeds(karel.AnyBeeperInBag()); |
bulmecisco | 4:76acfddc26fb | 113 | } |
bulmecisco | 4:76acfddc26fb | 114 | wait(1); |
bulmecisco | 4:76acfddc26fb | 115 | if( karel.FrontIsClear() ) |
bulmecisco | 4:76acfddc26fb | 116 | karel.Move(); |
bulmecisco | 4:76acfddc26fb | 117 | else |
bulmecisco | 4:76acfddc26fb | 118 | karel.TurnLeft(); |
bulmecisco | 4:76acfddc26fb | 119 | |
bulmecisco | 4:76acfddc26fb | 120 | karel.ShutOff(); |
bulmecisco | 4:76acfddc26fb | 121 | } |
bulmecisco | 4:76acfddc26fb | 122 | |
bulmecisco | 4:76acfddc26fb | 123 | |
bulmecisco | 4:76acfddc26fb | 124 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 125 | */ |
bulmecisco | 0:66e9a0afcbd6 | 126 | class ur_Bertl |
bulmecisco | 0:66e9a0afcbd6 | 127 | { |
bulmecisco | 0:66e9a0afcbd6 | 128 | protected: |
bulmecisco | 4:76acfddc26fb | 129 | int beepersInBag; /**< how many beepers does the robot have in his bag;\n you can show it with: karel.NibbleLeds(karel.AnyBeeperInBag())*/ |
bulmecisco | 0:66e9a0afcbd6 | 130 | char cmd[3]; /**< I2C command */ |
bulmecisco | 0:66e9a0afcbd6 | 131 | int16_t btns; /**< which button is pressed */ |
bulmecisco | 0:66e9a0afcbd6 | 132 | InterruptIn _interrupt; /**< interrupted used*/ |
bulmecisco | 0:66e9a0afcbd6 | 133 | volatile int _count; /**< values of motor sensor*/ |
bulmecisco | 0:66e9a0afcbd6 | 134 | |
bulmecisco | 0:66e9a0afcbd6 | 135 | /** |
bulmecisco | 0:66e9a0afcbd6 | 136 | protected methodes for internal purposes only |
bulmecisco | 0:66e9a0afcbd6 | 137 | */ |
bulmecisco | 0:66e9a0afcbd6 | 138 | void increment(); /**< ISR to increment sensor values of motor */ |
bulmecisco | 0:66e9a0afcbd6 | 139 | bool backIsClear(); /**< don't now for what */ |
bulmecisco | 0:66e9a0afcbd6 | 140 | bool frontButtonPressed();/**< TRUE if a a button on the front of Robot is pressed else FALSE */ |
bulmecisco | 4:76acfddc26fb | 141 | int bottomIsBlack(); /**< check line sensor; returns BCD value */ |
bulmecisco | 0:66e9a0afcbd6 | 142 | void error(); /**< Error: stops the robot and all LEDs are blinking*/ |
bulmecisco | 0:66e9a0afcbd6 | 143 | |
bulmecisco | 0:66e9a0afcbd6 | 144 | public: |
bulmecisco | 0:66e9a0afcbd6 | 145 | ur_Bertl(); /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/ |
bulmecisco | 0:66e9a0afcbd6 | 146 | ur_Bertl(PinName pin); /**< parameterized constructor; on what pin should the interrupt work; SPEED, DISTANCE or ANGLE have to bee defined in config.h */ |
bulmecisco | 0:66e9a0afcbd6 | 147 | |
bulmecisco | 12:cedc088eaf05 | 148 | //void Move(); /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/ |
bulmecisco | 12:cedc088eaf05 | 149 | void Move(int move = MOVE); /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/ |
bulmecisco | 0:66e9a0afcbd6 | 150 | void TurnLeft(); /**< Robot turns left as much as the constant ANGLE*/ |
bulmecisco | 0:66e9a0afcbd6 | 151 | void PutBeeper(); /**< if Robot has any Beepers in his bag he can put one or more Beeper; if not --> Error(()*/ |
bulmecisco | 4:76acfddc26fb | 152 | void PickBeeper(); /**< if Robot stands on a black item he can pick one or more Beeper (max. 15 --> Error()); if not --> Error()*/ |
bulmecisco | 4:76acfddc26fb | 153 | void ShutOff(); /**< turnes the robot off */ |
bulmecisco | 4:76acfddc26fb | 154 | bool WaitUntilButtonPressed(); /**< wait until any button is pressed at the robot */ |
bulmecisco | 1:fafbac0ba96d | 155 | bool FrontIsClear(); /**< returns a boolean value true if front is free; if not false */ |
bulmecisco | 4:76acfddc26fb | 156 | bool NextToABeeper(); /**< returns a boolean value true if the robot is on a black place or line; if not --> false */ |
bulmecisco | 7:e7f74f072564 | 157 | bool IsButtonPressed(const int btn); /**< returns true if Button btn is pressed, else false */ |
bulmecisco | 7:e7f74f072564 | 158 | int ReturnButtonPressed(); /**< returns the int value of button pressed */ |
bulmecisco | 4:76acfddc26fb | 159 | int AnyBeeperInBag(); /**< returns an int value (if > 0 equal true) how many beepers in bag; if zero --> false */ |
bulmecisco | 4:76acfddc26fb | 160 | 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())*/ |
bulmecisco | 0:66e9a0afcbd6 | 161 | 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 */ |
bulmecisco | 0:66e9a0afcbd6 | 162 | 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 */ |
bulmecisco | 0:66e9a0afcbd6 | 163 | void RGBLed(bool red, bool green, bool blue); /**<RGB Led with red, green and blue component of the Color */ |
bulmecisco | 0:66e9a0afcbd6 | 164 | void BlueLedsOFF(); /**< OFF all blue LEDs which are on the same Port 1_28 */ |
bulmecisco | 0:66e9a0afcbd6 | 165 | void BlueLedsON(); /**< ON all blue LEDs which are on the same Port 1_28 */ |
bulmecisco | 0:66e9a0afcbd6 | 166 | int Read(); |
bulmecisco | 0:66e9a0afcbd6 | 167 | }; |
bulmecisco | 12:cedc088eaf05 | 168 | /********************************************//** |
bulmecisco | 12:cedc088eaf05 | 169 | name: Bertl.h \n |
bulmecisco | 12:cedc088eaf05 | 170 | version: 1.0 \n |
bulmecisco | 12:cedc088eaf05 | 171 | author:PE HTL BULME \n |
bulmecisco | 12:cedc088eaf05 | 172 | email: pe@bulme.at \n |
bulmecisco | 12:cedc088eaf05 | 173 | WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage \n |
bulmecisco | 12:cedc088eaf05 | 174 | description: |
bulmecisco | 12:cedc088eaf05 | 175 | Definition and documentation portion of the class Bertl The Robot. |
bulmecisco | 12:cedc088eaf05 | 176 | |
bulmecisco | 12:cedc088eaf05 | 177 | ***********************************************/ |
bulmecisco | 12:cedc088eaf05 | 178 | |
bulmecisco | 12:cedc088eaf05 | 179 | /** |
bulmecisco | 12:cedc088eaf05 | 180 | @code |
bulmecisco | 12:cedc088eaf05 | 181 | // |
bulmecisco | 12:cedc088eaf05 | 182 | @endcode |
bulmecisco | 12:cedc088eaf05 | 183 | |
bulmecisco | 12:cedc088eaf05 | 184 | Example motor sensor test: |
bulmecisco | 12:cedc088eaf05 | 185 | @code |
bulmecisco | 12:cedc088eaf05 | 186 | #include "mbed.h" |
bulmecisco | 12:cedc088eaf05 | 187 | #include "ur_Bertl.h" |
bulmecisco | 12:cedc088eaf05 | 188 | #include "const.h" |
bulmecisco | 12:cedc088eaf05 | 189 | |
bulmecisco | 12:cedc088eaf05 | 190 | int main() |
bulmecisco | 12:cedc088eaf05 | 191 | { |
bulmecisco | 12:cedc088eaf05 | 192 | ur_Bertl karel(LEFTSENSOR); // RIGHTSENSOR |
bulmecisco | 12:cedc088eaf05 | 193 | |
bulmecisco | 12:cedc088eaf05 | 194 | while(true) { |
bulmecisco | 12:cedc088eaf05 | 195 | karel.NibbleLeds(karel.Read()); |
bulmecisco | 12:cedc088eaf05 | 196 | } |
bulmecisco | 12:cedc088eaf05 | 197 | } |
bulmecisco | 12:cedc088eaf05 | 198 | @endcode |
bulmecisco | 12:cedc088eaf05 | 199 | |
bulmecisco | 12:cedc088eaf05 | 200 | Example follow a line: |
bulmecisco | 12:cedc088eaf05 | 201 | @code |
bulmecisco | 12:cedc088eaf05 | 202 | #include "mbed.h" |
bulmecisco | 12:cedc088eaf05 | 203 | #include "ur_Bertl.h" |
bulmecisco | 12:cedc088eaf05 | 204 | #include "const.h" |
bulmecisco | 12:cedc088eaf05 | 205 | |
bulmecisco | 12:cedc088eaf05 | 206 | int main() |
bulmecisco | 12:cedc088eaf05 | 207 | { |
bulmecisco | 12:cedc088eaf05 | 208 | Bertl karel; |
bulmecisco | 12:cedc088eaf05 | 209 | |
bulmecisco | 12:cedc088eaf05 | 210 | while(karel.WaitUntilButtonPressed()) |
bulmecisco | 12:cedc088eaf05 | 211 | { |
bulmecisco | 12:cedc088eaf05 | 212 | karel.NibbleLeds(karel.GetLineValues()); |
bulmecisco | 12:cedc088eaf05 | 213 | switch(karel.GetLineValues()) |
bulmecisco | 12:cedc088eaf05 | 214 | { |
bulmecisco | 12:cedc088eaf05 | 215 | case 0x00: |
bulmecisco | 12:cedc088eaf05 | 216 | karel.TurnLeftStep(50); |
bulmecisco | 12:cedc088eaf05 | 217 | break; |
bulmecisco | 12:cedc088eaf05 | 218 | case 0x03: case 0x01: case 0x07: |
bulmecisco | 12:cedc088eaf05 | 219 | karel.TurnLeftStep(20); |
bulmecisco | 12:cedc088eaf05 | 220 | break; |
bulmecisco | 12:cedc088eaf05 | 221 | case 0x0E: case 0x0A: case 0x08: |
bulmecisco | 12:cedc088eaf05 | 222 | karel.TurnRigthStep(20); |
bulmecisco | 12:cedc088eaf05 | 223 | break; |
bulmecisco | 12:cedc088eaf05 | 224 | default: |
bulmecisco | 12:cedc088eaf05 | 225 | karel.Move(20); |
bulmecisco | 12:cedc088eaf05 | 226 | break; |
bulmecisco | 12:cedc088eaf05 | 227 | } |
bulmecisco | 12:cedc088eaf05 | 228 | if(!karel.FrontIsClear()) |
bulmecisco | 12:cedc088eaf05 | 229 | karel.TurnLeftStep(1000); |
bulmecisco | 12:cedc088eaf05 | 230 | } |
bulmecisco | 12:cedc088eaf05 | 231 | } |
bulmecisco | 12:cedc088eaf05 | 232 | @endcode |
bulmecisco | 12:cedc088eaf05 | 233 | */ |
bulmecisco | 12:cedc088eaf05 | 234 | class Bertl : public ur_Bertl |
bulmecisco | 12:cedc088eaf05 | 235 | { |
bulmecisco | 12:cedc088eaf05 | 236 | protected: |
bulmecisco | 12:cedc088eaf05 | 237 | public: |
bulmecisco | 12:cedc088eaf05 | 238 | //Bertl(); /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/ |
bulmecisco | 12:cedc088eaf05 | 239 | void MoveBackwards(int move = MOVE); /**< Robot moves as much back as the constant DISTANCE; if one of the buttons fire --> Error()*/ |
bulmecisco | 12:cedc088eaf05 | 240 | void TurnRigth(); /**< Robot turns rigth as much as the constant ANGLE*/ |
bulmecisco | 12:cedc088eaf05 | 241 | void TurnLeftStep(int step=STEPTIME); /**< Robot turns left for a short time defined in STEPTIME */ |
bulmecisco | 12:cedc088eaf05 | 242 | void TurnRigthStep(int step=STEPTIME); /**< Robot turns rigth for a short time defined in STEPTIME */ |
bulmecisco | 12:cedc088eaf05 | 243 | uint8_t GetLineValues(); /**< in the lower 4 bit are the values of the line sensor */ |
bulmecisco | 12:cedc088eaf05 | 244 | }; |
bulmecisco | 0:66e9a0afcbd6 | 245 | #endif |