Schulaufgabe 21.12.2015
Fork of Bertl by
ur_Bertl.h@0:66e9a0afcbd6, 2015-02-26 (annotated)
- Committer:
- bulmecisco
- Date:
- Thu Feb 26 10:12:06 2015 +0000
- Revision:
- 0:66e9a0afcbd6
- Child:
- 1:fafbac0ba96d
ur_Bertl based on simple class design with documentaton
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bulmecisco | 0:66e9a0afcbd6 | 1 | /*********************************** |
bulmecisco | 0:66e9a0afcbd6 | 2 | name: ur_Bertl.h Version: 1.0 |
bulmecisco | 0:66e9a0afcbd6 | 3 | author: PE HTL BULME |
bulmecisco | 0:66e9a0afcbd6 | 4 | email: pe@bulme.at |
bulmecisco | 0:66e9a0afcbd6 | 5 | description: |
bulmecisco | 0:66e9a0afcbd6 | 6 | Definition portion of the class ur_Bertl The Robot |
bulmecisco | 0:66e9a0afcbd6 | 7 | |
bulmecisco | 0:66e9a0afcbd6 | 8 | |
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 | 0:66e9a0afcbd6 | 18 | name: ur_Bertl.h |
bulmecisco | 0:66e9a0afcbd6 | 19 | version: 1.0 |
bulmecisco | 0:66e9a0afcbd6 | 20 | author: PE HTL BULME. |
bulmecisco | 0:66e9a0afcbd6 | 21 | email: pe@bulme.at |
bulmecisco | 0:66e9a0afcbd6 | 22 | description: |
bulmecisco | 0:66e9a0afcbd6 | 23 | Definition and documentation portion of the class ur_Bertl The Robot. |
bulmecisco | 0:66e9a0afcbd6 | 24 | |
bulmecisco | 0:66e9a0afcbd6 | 25 | ***********************************************/ |
bulmecisco | 0:66e9a0afcbd6 | 26 | /** |
bulmecisco | 0:66e9a0afcbd6 | 27 | @code |
bulmecisco | 0:66e9a0afcbd6 | 28 | // |
bulmecisco | 0:66e9a0afcbd6 | 29 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 30 | |
bulmecisco | 0:66e9a0afcbd6 | 31 | Example motor sensor test: |
bulmecisco | 0:66e9a0afcbd6 | 32 | @code |
bulmecisco | 0:66e9a0afcbd6 | 33 | #include "mbed.h" |
bulmecisco | 0:66e9a0afcbd6 | 34 | #include "ur_Bertl.h" |
bulmecisco | 0:66e9a0afcbd6 | 35 | #include "const.h" |
bulmecisco | 0:66e9a0afcbd6 | 36 | |
bulmecisco | 0:66e9a0afcbd6 | 37 | int main() |
bulmecisco | 0:66e9a0afcbd6 | 38 | { |
bulmecisco | 0:66e9a0afcbd6 | 39 | ur_Bertl karel(LEFTSENSOR); // RIGHTSENSOR |
bulmecisco | 0:66e9a0afcbd6 | 40 | |
bulmecisco | 0:66e9a0afcbd6 | 41 | while(true) { |
bulmecisco | 0:66e9a0afcbd6 | 42 | karel.NibbleLeds(karel.Read()); |
bulmecisco | 0:66e9a0afcbd6 | 43 | } |
bulmecisco | 0:66e9a0afcbd6 | 44 | } |
bulmecisco | 0:66e9a0afcbd6 | 45 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 46 | |
bulmecisco | 0:66e9a0afcbd6 | 47 | Example moving the robot around: |
bulmecisco | 0:66e9a0afcbd6 | 48 | @code |
bulmecisco | 0:66e9a0afcbd6 | 49 | #include "mbed.h" |
bulmecisco | 0:66e9a0afcbd6 | 50 | #include "ur_Bertl.h" |
bulmecisco | 0:66e9a0afcbd6 | 51 | #include "const.h" |
bulmecisco | 0:66e9a0afcbd6 | 52 | |
bulmecisco | 0:66e9a0afcbd6 | 53 | int main() |
bulmecisco | 0:66e9a0afcbd6 | 54 | { |
bulmecisco | 0:66e9a0afcbd6 | 55 | ur_Bertl karel; |
bulmecisco | 0:66e9a0afcbd6 | 56 | |
bulmecisco | 0:66e9a0afcbd6 | 57 | while(karel.WaitUntilButtonPressed()){} |
bulmecisco | 0:66e9a0afcbd6 | 58 | //karel.Move(); |
bulmecisco | 0:66e9a0afcbd6 | 59 | karel.TurnLeft(); |
bulmecisco | 0:66e9a0afcbd6 | 60 | karel.ShutOff(); |
bulmecisco | 0:66e9a0afcbd6 | 61 | } |
bulmecisco | 0:66e9a0afcbd6 | 62 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 63 | |
bulmecisco | 0:66e9a0afcbd6 | 64 | Example LEDs: |
bulmecisco | 0:66e9a0afcbd6 | 65 | @code |
bulmecisco | 0:66e9a0afcbd6 | 66 | #include "mbed.h" |
bulmecisco | 0:66e9a0afcbd6 | 67 | #include "ur_Bertl.h" |
bulmecisco | 0:66e9a0afcbd6 | 68 | #include "const.h" |
bulmecisco | 0:66e9a0afcbd6 | 69 | |
bulmecisco | 0:66e9a0afcbd6 | 70 | int main() |
bulmecisco | 0:66e9a0afcbd6 | 71 | { |
bulmecisco | 0:66e9a0afcbd6 | 72 | ur_Bertl karel; |
bulmecisco | 0:66e9a0afcbd6 | 73 | |
bulmecisco | 0:66e9a0afcbd6 | 74 | while(karel.WaitUntilButtonPressed()){} |
bulmecisco | 0:66e9a0afcbd6 | 75 | |
bulmecisco | 0:66e9a0afcbd6 | 76 | karel.TurnLedOn(LED_FL1 | LED_FR1); // see const.h |
bulmecisco | 0:66e9a0afcbd6 | 77 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 78 | karel.TurnLedOn(0xFF); // or use hex |
bulmecisco | 0:66e9a0afcbd6 | 79 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 80 | karel.RGBLed(1,0,0); // red |
bulmecisco | 0:66e9a0afcbd6 | 81 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 82 | karel.RGBLed(0,1,0); // green |
bulmecisco | 0:66e9a0afcbd6 | 83 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 84 | karel.RGBLed(0,0,1); // blue |
bulmecisco | 0:66e9a0afcbd6 | 85 | karel.BlueLedsON(); |
bulmecisco | 0:66e9a0afcbd6 | 86 | karel.NibbleLeds(karel.Read()); |
bulmecisco | 0:66e9a0afcbd6 | 87 | wait(1); |
bulmecisco | 0:66e9a0afcbd6 | 88 | karel.BlueLedsOFF(); |
bulmecisco | 0:66e9a0afcbd6 | 89 | karel.TurnLedOff(0xFF); |
bulmecisco | 0:66e9a0afcbd6 | 90 | karel.ShutOff(); |
bulmecisco | 0:66e9a0afcbd6 | 91 | } |
bulmecisco | 0:66e9a0afcbd6 | 92 | @endcode |
bulmecisco | 0:66e9a0afcbd6 | 93 | */ |
bulmecisco | 0:66e9a0afcbd6 | 94 | class ur_Bertl |
bulmecisco | 0:66e9a0afcbd6 | 95 | { |
bulmecisco | 0:66e9a0afcbd6 | 96 | protected: |
bulmecisco | 0:66e9a0afcbd6 | 97 | int beepersInBag; /**< how many beepers does the robot have in his bag*/ |
bulmecisco | 0:66e9a0afcbd6 | 98 | char cmd[3]; /**< I2C command */ |
bulmecisco | 0:66e9a0afcbd6 | 99 | int16_t btns; /**< which button is pressed */ |
bulmecisco | 0:66e9a0afcbd6 | 100 | InterruptIn _interrupt; /**< interrupted used*/ |
bulmecisco | 0:66e9a0afcbd6 | 101 | volatile int _count; /**< values of motor sensor*/ |
bulmecisco | 0:66e9a0afcbd6 | 102 | |
bulmecisco | 0:66e9a0afcbd6 | 103 | /** |
bulmecisco | 0:66e9a0afcbd6 | 104 | protected methodes for internal purposes only |
bulmecisco | 0:66e9a0afcbd6 | 105 | */ |
bulmecisco | 0:66e9a0afcbd6 | 106 | void increment(); /**< ISR to increment sensor values of motor */ |
bulmecisco | 0:66e9a0afcbd6 | 107 | bool backIsClear(); /**< don't now for what */ |
bulmecisco | 0:66e9a0afcbd6 | 108 | bool frontButtonPressed();/**< TRUE if a a button on the front of Robot is pressed else FALSE */ |
bulmecisco | 0:66e9a0afcbd6 | 109 | void error(); /**< Error: stops the robot and all LEDs are blinking*/ |
bulmecisco | 0:66e9a0afcbd6 | 110 | |
bulmecisco | 0:66e9a0afcbd6 | 111 | public: |
bulmecisco | 0:66e9a0afcbd6 | 112 | ur_Bertl(); /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/ |
bulmecisco | 0:66e9a0afcbd6 | 113 | 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 | 114 | |
bulmecisco | 0:66e9a0afcbd6 | 115 | void Move(); /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/ |
bulmecisco | 0:66e9a0afcbd6 | 116 | void TurnLeft(); /**< Robot turns left as much as the constant ANGLE*/ |
bulmecisco | 0:66e9a0afcbd6 | 117 | void PutBeeper(); /**< if Robot has any Beepers in his bag he can put one or more Beeper; if not --> Error(()*/ |
bulmecisco | 0:66e9a0afcbd6 | 118 | void PickBeeper(); /**< if Robot stands on a black item he can pick one or more Beeper (max. 16 --> Error()); if not --> Error()*/ |
bulmecisco | 0:66e9a0afcbd6 | 119 | void NibbleLeds(int value); /**< methode for the 4 (half byte) yellow LEDs at the back left side */ |
bulmecisco | 0:66e9a0afcbd6 | 120 | 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 | 121 | 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 | 122 | bool WaitUntilButtonPressed(); /**< wait until any button is pressed at the robot */ |
bulmecisco | 0:66e9a0afcbd6 | 123 | void RGBLed(bool red, bool green, bool blue); /**<RGB Led with red, green and blue component of the Color */ |
bulmecisco | 0:66e9a0afcbd6 | 124 | void BlueLedsOFF(); /**< OFF all blue LEDs which are on the same Port 1_28 */ |
bulmecisco | 0:66e9a0afcbd6 | 125 | void BlueLedsON(); /**< ON all blue LEDs which are on the same Port 1_28 */ |
bulmecisco | 0:66e9a0afcbd6 | 126 | void ShutOff(); /**< turnes the robot off */ |
bulmecisco | 0:66e9a0afcbd6 | 127 | int Read(); |
bulmecisco | 0:66e9a0afcbd6 | 128 | }; |
bulmecisco | 0:66e9a0afcbd6 | 129 | #endif |