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