Class Bertl added
Dependents: BertlDrive_V2 BertlDrive_V2
ur_Bertl.h@5:6b667e2cb800, 2015-04-10 (annotated)
- Committer:
- bulmecisco
- Date:
- Fri Apr 10 07:12:07 2015 +0000
- Revision:
- 5:6b667e2cb800
- Parent:
- 4:76acfddc26fb
- Child:
- 7:e7f74f072564
Button test added: IsButtonPressed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bulmecisco | 0:66e9a0afcbd6 | 1 | /*********************************** |
bulmecisco | 4:76acfddc26fb | 2 | name: ur_Bertl.h Version: 2.0 |
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 | 4:76acfddc26fb | 8 | boolean commands added for if/else, while, ... |
bulmecisco | 0:66e9a0afcbd6 | 9 | ***********************************/ |
bulmecisco | 0:66e9a0afcbd6 | 10 | #include "mbed.h" |
bulmecisco | 0:66e9a0afcbd6 | 11 | |
bulmecisco | 0:66e9a0afcbd6 | 12 | #ifndef UR_BERTL_H |
bulmecisco | 0:66e9a0afcbd6 | 13 | #define UR_BERTL_H |
bulmecisco | 0:66e9a0afcbd6 | 14 | |
bulmecisco | 0:66e9a0afcbd6 | 15 | #define LEFTSENSOR P1_12 |
bulmecisco | 0:66e9a0afcbd6 | 16 | #define RIGHTSENSOR P1_13 |
bulmecisco | 0:66e9a0afcbd6 | 17 | /********************************************//** |
bulmecisco | 4:76acfddc26fb | 18 | name: ur_Bertl.h \n |
bulmecisco | 4:76acfddc26fb | 19 | version: 2.0 \n |
bulmecisco | 4:76acfddc26fb | 20 | author:PE HTL BULME \n |
bulmecisco | 4:76acfddc26fb | 21 | email: pe@bulme.at \n |
bulmecisco | 4:76acfddc26fb | 22 | WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage \n |
bulmecisco | 4:76acfddc26fb | 23 | description: |
bulmecisco | 0:66e9a0afcbd6 | 24 | Definition and documentation portion of the class ur_Bertl The Robot. |
bulmecisco | 0:66e9a0afcbd6 | 25 | |
bulmecisco | 0:66e9a0afcbd6 | 26 | ***********************************************/ |
bulmecisco | 0:66e9a0afcbd6 | 27 | /** |
bulmecisco | 0:66e9a0afcbd6 | 28 | @code |
bulmecisco | 0:66e9a0afcbd6 | 29 | // |
bulmecisco | 0:66e9a0afcbd6 | 30 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 31 | |
bulmecisco | 0:66e9a0afcbd6 | 32 | Example motor sensor test: |
bulmecisco | 0:66e9a0afcbd6 | 33 | @code |
bulmecisco | 0:66e9a0afcbd6 | 34 | #include "mbed.h" |
bulmecisco | 0:66e9a0afcbd6 | 35 | #include "ur_Bertl.h" |
bulmecisco | 0:66e9a0afcbd6 | 36 | #include "const.h" |
bulmecisco | 0:66e9a0afcbd6 | 37 | |
bulmecisco | 0:66e9a0afcbd6 | 38 | int main() |
bulmecisco | 0:66e9a0afcbd6 | 39 | { |
bulmecisco | 0:66e9a0afcbd6 | 40 | ur_Bertl karel(LEFTSENSOR); // RIGHTSENSOR |
bulmecisco | 0:66e9a0afcbd6 | 41 | |
bulmecisco | 0:66e9a0afcbd6 | 42 | while(true) { |
bulmecisco | 0:66e9a0afcbd6 | 43 | karel.NibbleLeds(karel.Read()); |
bulmecisco | 0:66e9a0afcbd6 | 44 | } |
bulmecisco | 0:66e9a0afcbd6 | 45 | } |
bulmecisco | 0:66e9a0afcbd6 | 46 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 47 | |
bulmecisco | 0:66e9a0afcbd6 | 48 | Example moving the robot around: |
bulmecisco | 0:66e9a0afcbd6 | 49 | @code |
bulmecisco | 0:66e9a0afcbd6 | 50 | #include "mbed.h" |
bulmecisco | 0:66e9a0afcbd6 | 51 | #include "ur_Bertl.h" |
bulmecisco | 0:66e9a0afcbd6 | 52 | #include "const.h" |
bulmecisco | 0:66e9a0afcbd6 | 53 | |
bulmecisco | 0:66e9a0afcbd6 | 54 | int main() |
bulmecisco | 0:66e9a0afcbd6 | 55 | { |
bulmecisco | 0:66e9a0afcbd6 | 56 | ur_Bertl karel; |
bulmecisco | 0:66e9a0afcbd6 | 57 | |
bulmecisco | 0:66e9a0afcbd6 | 58 | while(karel.WaitUntilButtonPressed()){} |
bulmecisco | 0:66e9a0afcbd6 | 59 | //karel.Move(); |
bulmecisco | 0:66e9a0afcbd6 | 60 | karel.TurnLeft(); |
bulmecisco | 0:66e9a0afcbd6 | 61 | karel.ShutOff(); |
bulmecisco | 0:66e9a0afcbd6 | 62 | } |
bulmecisco | 0:66e9a0afcbd6 | 63 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 64 | |
bulmecisco | 0:66e9a0afcbd6 | 65 | Example LEDs: |
bulmecisco | 0:66e9a0afcbd6 | 66 | @code |
bulmecisco | 0:66e9a0afcbd6 | 67 | #include "mbed.h" |
bulmecisco | 0:66e9a0afcbd6 | 68 | #include "ur_Bertl.h" |
bulmecisco | 0:66e9a0afcbd6 | 69 | #include "const.h" |
bulmecisco | 0:66e9a0afcbd6 | 70 | |
bulmecisco | 0:66e9a0afcbd6 | 71 | int main() |
bulmecisco | 0:66e9a0afcbd6 | 72 | { |
bulmecisco | 0:66e9a0afcbd6 | 73 | ur_Bertl karel; |
bulmecisco | 0:66e9a0afcbd6 | 74 | |
bulmecisco | 0:66e9a0afcbd6 | 75 | while(karel.WaitUntilButtonPressed()){} |
bulmecisco | 0:66e9a0afcbd6 | 76 | |
bulmecisco | 0:66e9a0afcbd6 | 77 | karel.TurnLedOn(LED_FL1 | LED_FR1); // see const.h |
bulmecisco | 0:66e9a0afcbd6 | 78 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 79 | karel.TurnLedOn(0xFF); // or use hex |
bulmecisco | 0:66e9a0afcbd6 | 80 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 81 | karel.RGBLed(1,0,0); // red |
bulmecisco | 0:66e9a0afcbd6 | 82 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 83 | karel.RGBLed(0,1,0); // green |
bulmecisco | 0:66e9a0afcbd6 | 84 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 85 | karel.RGBLed(0,0,1); // blue |
bulmecisco | 0:66e9a0afcbd6 | 86 | karel.BlueLedsON(); |
bulmecisco | 0:66e9a0afcbd6 | 87 | karel.NibbleLeds(karel.Read()); |
bulmecisco | 0:66e9a0afcbd6 | 88 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 89 | karel.BlueLedsOFF(); |
bulmecisco | 0:66e9a0afcbd6 | 90 | karel.TurnLedOff(0xFF); |
bulmecisco | 0:66e9a0afcbd6 | 91 | karel.ShutOff(); |
bulmecisco | 0:66e9a0afcbd6 | 92 | } |
bulmecisco | 0:66e9a0afcbd6 | 93 | @endcode |
bulmecisco | 4:76acfddc26fb | 94 | Example IF/ELSE Commands (update ur_Bertl 2.0 from https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/ |
bulmecisco | 4:76acfddc26fb | 95 | @code |
bulmecisco | 4:76acfddc26fb | 96 | /* Sorry, but there are Javascript problems with this code |
bulmecisco | 4:76acfddc26fb | 97 | |
bulmecisco | 4:76acfddc26fb | 98 | int main() |
bulmecisco | 4:76acfddc26fb | 99 | { |
bulmecisco | 4:76acfddc26fb | 100 | ur_Bertl karel; |
bulmecisco | 4:76acfddc26fb | 101 | |
bulmecisco | 4:76acfddc26fb | 102 | while( karel.WaitUntilButtonPressed() ) {} |
bulmecisco | 4:76acfddc26fb | 103 | if( karel.NextToABeeper()) { |
bulmecisco | 4:76acfddc26fb | 104 | karel.PickBeeper(); |
bulmecisco | 4:76acfddc26fb | 105 | karel.NibbleLeds(karel.AnyBeeperInBag()); //show number of beepers in bag on 4 yellow Leds |
bulmecisco | 4:76acfddc26fb | 106 | } |
bulmecisco | 4:76acfddc26fb | 107 | wait(1); |
bulmecisco | 4:76acfddc26fb | 108 | if( karel.AnyBeeperInBag() ) { |
bulmecisco | 4:76acfddc26fb | 109 | karel.PutBeeper(); |
bulmecisco | 4:76acfddc26fb | 110 | karel.NibbleLeds(karel.AnyBeeperInBag()); |
bulmecisco | 4:76acfddc26fb | 111 | } |
bulmecisco | 4:76acfddc26fb | 112 | wait(1); |
bulmecisco | 4:76acfddc26fb | 113 | if( karel.FrontIsClear() ) |
bulmecisco | 4:76acfddc26fb | 114 | karel.Move(); |
bulmecisco | 4:76acfddc26fb | 115 | else |
bulmecisco | 4:76acfddc26fb | 116 | karel.TurnLeft(); |
bulmecisco | 4:76acfddc26fb | 117 | |
bulmecisco | 4:76acfddc26fb | 118 | karel.ShutOff(); |
bulmecisco | 4:76acfddc26fb | 119 | } |
bulmecisco | 4:76acfddc26fb | 120 | |
bulmecisco | 4:76acfddc26fb | 121 | |
bulmecisco | 4:76acfddc26fb | 122 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 123 | */ |
bulmecisco | 0:66e9a0afcbd6 | 124 | class ur_Bertl |
bulmecisco | 0:66e9a0afcbd6 | 125 | { |
bulmecisco | 0:66e9a0afcbd6 | 126 | protected: |
bulmecisco | 4:76acfddc26fb | 127 | 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 | 128 | char cmd[3]; /**< I2C command */ |
bulmecisco | 0:66e9a0afcbd6 | 129 | int16_t btns; /**< which button is pressed */ |
bulmecisco | 0:66e9a0afcbd6 | 130 | InterruptIn _interrupt; /**< interrupted used*/ |
bulmecisco | 0:66e9a0afcbd6 | 131 | volatile int _count; /**< values of motor sensor*/ |
bulmecisco | 0:66e9a0afcbd6 | 132 | |
bulmecisco | 0:66e9a0afcbd6 | 133 | /** |
bulmecisco | 0:66e9a0afcbd6 | 134 | protected methodes for internal purposes only |
bulmecisco | 0:66e9a0afcbd6 | 135 | */ |
bulmecisco | 0:66e9a0afcbd6 | 136 | void increment(); /**< ISR to increment sensor values of motor */ |
bulmecisco | 0:66e9a0afcbd6 | 137 | bool backIsClear(); /**< don't now for what */ |
bulmecisco | 0:66e9a0afcbd6 | 138 | bool frontButtonPressed();/**< TRUE if a a button on the front of Robot is pressed else FALSE */ |
bulmecisco | 4:76acfddc26fb | 139 | int bottomIsBlack(); /**< check line sensor; returns BCD value */ |
bulmecisco | 0:66e9a0afcbd6 | 140 | void error(); /**< Error: stops the robot and all LEDs are blinking*/ |
bulmecisco | 0:66e9a0afcbd6 | 141 | |
bulmecisco | 0:66e9a0afcbd6 | 142 | public: |
bulmecisco | 0:66e9a0afcbd6 | 143 | ur_Bertl(); /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/ |
bulmecisco | 0:66e9a0afcbd6 | 144 | 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 | 145 | |
bulmecisco | 0:66e9a0afcbd6 | 146 | void Move(); /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/ |
bulmecisco | 0:66e9a0afcbd6 | 147 | void TurnLeft(); /**< Robot turns left as much as the constant ANGLE*/ |
bulmecisco | 0:66e9a0afcbd6 | 148 | void PutBeeper(); /**< if Robot has any Beepers in his bag he can put one or more Beeper; if not --> Error(()*/ |
bulmecisco | 4:76acfddc26fb | 149 | 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 | 150 | void ShutOff(); /**< turnes the robot off */ |
bulmecisco | 4:76acfddc26fb | 151 | void MoveBackwards(); /**< Robot moves as much back as the constant DISTANCE; if one of the buttons fire --> Error()*/ |
bulmecisco | 4:76acfddc26fb | 152 | bool WaitUntilButtonPressed(); /**< wait until any button is pressed at the robot */ |
bulmecisco | 1:fafbac0ba96d | 153 | bool FrontIsClear(); /**< returns a boolean value true if front is free; if not false */ |
bulmecisco | 4:76acfddc26fb | 154 | bool NextToABeeper(); /**< returns a boolean value true if the robot is on a black place or line; if not --> false */ |
bulmecisco | 5:6b667e2cb800 | 155 | bool IsButtonPressed(const int btn); |
bulmecisco | 4:76acfddc26fb | 156 | int AnyBeeperInBag(); /**< returns an int value (if > 0 equal true) how many beepers in bag; if zero --> false */ |
bulmecisco | 4:76acfddc26fb | 157 | 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 | 158 | 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 | 159 | 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 | 160 | void RGBLed(bool red, bool green, bool blue); /**<RGB Led with red, green and blue component of the Color */ |
bulmecisco | 0:66e9a0afcbd6 | 161 | void BlueLedsOFF(); /**< OFF all blue LEDs which are on the same Port 1_28 */ |
bulmecisco | 0:66e9a0afcbd6 | 162 | void BlueLedsON(); /**< ON all blue LEDs which are on the same Port 1_28 */ |
bulmecisco | 0:66e9a0afcbd6 | 163 | int Read(); |
bulmecisco | 0:66e9a0afcbd6 | 164 | }; |
bulmecisco | 0:66e9a0afcbd6 | 165 | #endif |