Class Bertl added
Dependents: BertlDrive_V2 BertlDrive_V2
Revision 12:cedc088eaf05, committed 2015-04-26
- Comitter:
- bulmecisco
- Date:
- Sun Apr 26 20:04:47 2015 +0000
- Parent:
- 11:155ce3832f01
- Commit message:
- Class Bertl with additional Methodes added
Changed in this revision
--- a/Robot.h Fri Apr 24 09:16:40 2015 +0000 +++ b/Robot.h Sun Apr 26 20:04:47 2015 +0000 @@ -1,5 +1,5 @@ /*********************************** -name: Robot.h Version: 0.1 +name: Robot.h Version: 1.0 author: PE HTL BULME email: pe@bulme.at WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/
--- a/config.h Fri Apr 24 09:16:40 2015 +0000 +++ b/config.h Sun Apr 26 20:04:47 2015 +0000 @@ -16,10 +16,10 @@ /*! \def DEBUG \brief Turns debugging infos off (0) and on (3) which are send to serial pc.uart */ #define DEBUG 0 -#define FRONTBUTTON /**< Error shutoff if Bertl moves against a wall*/ +//#define FRONTBUTTON /**< Error shutoff if Bertl moves against a wall*/ #define HCSR /**< if ultrsonic is installed*/ -BusOut NibbleLEDs(P1_8, P1_9, P1_10, P1_11); /**< 4 yellow LEDs as a bus defined */ +BusOut NibbleLEDs(P1_8, P1_9, P1_10, P1_11); /**< 4 yellow LEDs as a bus defined; use it i.e.: karel.NibbleLeds(karel.GetLineValues()); to show line sensor values */ DigitalOut LED_D10(P1_8); /**< wiring first LED_D10 */ DigitalOut LED_D11(P1_9); /**< wiring second LED_D11 */ DigitalOut LED_D12(P1_10); /**< wiring thired LED_D12 */
--- a/const.h Fri Apr 24 09:16:40 2015 +0000 +++ b/const.h Sun Apr 26 20:04:47 2015 +0000 @@ -1,6 +1,6 @@ /*! \file const.h \brief A Documented file. -* name: const.h Version: 2.0 \n +* name: const.h Version: 2.2 \n * author: PE HTL BULME \n * email: pe@bulme.at \n * description: @@ -9,9 +9,10 @@ */ #ifndef CONST_H #define CONST_H -#define TIME -const int MOVE=500; -const int TURN=300; +#define TIME /**< if defined Bertl uses the time and not motor encoder*/ +const int MOVE=500; /**< ms move forward or backward */ +const int TURN=500; /**< ms TurnLeft or TurnRigth (nearly 90 degree) */ +const int STEPTIME=20; /**< ms turn left or right for adjusting moves for TurnLeft or TurnRigth */ /*! \var int ULTRASONIC_DISTANCE \brief Bertl Ultrasonic Distance Sensor from 1 to n; 5 is ok for nearly 5 cm. @@ -28,7 +29,7 @@ /*! \var int ANGLE \brief 12 is nearly 90 degree turn left. \warning maybe the number has to be adjusted */ -const int ANGLE = 4; /* nearly 90 degree turn left */ +const int ANGLE = 12; /* nearly 90 degree turn left */ const int BTN_FLL = 0x80; // button front left outer const int BTN_FL = 0x04; // button front left
--- a/ur_Bertl.cpp Fri Apr 24 09:16:40 2015 +0000 +++ b/ur_Bertl.cpp Sun Apr 26 20:04:47 2015 +0000 @@ -1,5 +1,5 @@ /*********************************** -name: ur_Bertl.cpp Version: 2.1 +name: ur_Bertl.cpp Version: 2.2 author: PE HTL BULME email: pe@bulme.at WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/ @@ -40,16 +40,16 @@ } // Pulblic methodes -void ur_Bertl::Move() +void ur_Bertl::Move(int move) { int count = _count; MotorR_EN=MotorL_EN=1; // both motor ENABLE MotorR_FORWARD = MotorL_FORWARD = 1; // both motor forward ON #ifdef TIME - wait_ms(MOVE); + wait_ms(move); #else - while(_count < count+DISTANCE) { + while(_count < count+move) { //if(!FrontIsClear()) // more convenient because there are no accidents :-) // break; #ifdef FRONTBUTTON @@ -61,7 +61,8 @@ #endif MotorR_FORWARD = MotorL_FORWARD = 0; // both motor off MotorR_EN=MotorL_EN=0; - wait_ms(250); + if(move == MOVE) + wait_ms(250); } void ur_Bertl::PutBeeper() @@ -245,22 +246,6 @@ return 0; } -void ur_Bertl::MoveBackwards() -{ - int count = _count; - //wait_ms(250); // waite until Bertl stops - MotorR_EN=MotorL_EN=1; // both motor ENABLE - MotorR_REVERSE = MotorL_REVERSE = 1; // both motor backwards ON - while(_count < count+DISTANCE) { - if(!backIsClear()) - break; - DEBUG_PRINT("count: %d _count: %d", count, _count); - } - MotorR_REVERSE = MotorL_REVERSE = 0; // both motor off - MotorR_EN=MotorL_EN=0; - wait_ms(250); -} - bool ur_Bertl::IsButtonPressed(const int btn) { char cmd[3]; // array for I2C @@ -388,3 +373,106 @@ return _count; } +// -------------------- BERTL CLASS ------------------------------------- +void Bertl::MoveBackwards(int move) +{ + int count = _count; + //wait_ms(250); // waite until Bertl stops + MotorR_EN=MotorL_EN=1; // both motor ENABLE + MotorR_REVERSE = MotorL_REVERSE = 1; // both motor backwards ON +#ifndef TIME + while(_count < count+move) { + if(!backIsClear()) + break; + DEBUG_PRINT("count: %d _count: %d", count, _count); + } +#else + wait_ms(move); +#endif + MotorR_REVERSE = MotorL_REVERSE = 0; // both motor off + MotorR_EN=MotorL_EN=0; + if(move == MOVE) + wait_ms(250); +} +// ------------------------- BERT CLASS -------------------------------------- +void Bertl::TurnRigth() +{ + int count = _count; + MotorR_EN=MotorL_EN=1; // motor left and right ENABLE + + MotorR_FORWARD = MotorL_REVERSE = 0; + MotorL_FORWARD = MotorR_REVERSE = 1; +#ifdef TIME + wait_ms(TURN); +#else + + while(_count < count+ANGLE) { +#ifdef FRONTBUTTON + if(frontButtonPressed()) // get out if to much problems + error(); +#endif + DEBUG_PRINT("count: %d _count: %d", count, _count); + } +#endif + MotorL_FORWARD = MotorR_REVERSE = 0; + MotorR_FORWARD = MotorL_REVERSE = 0; + MotorR_EN=MotorL_EN=0; + wait_ms(250); // only to step the robot +} +// ------------------------- to adjust turns --------------------------------- +void Bertl::TurnRigthStep(int step) +{ + int count = _count; + MotorR_EN=MotorL_EN=1; // motor left and right ENABLE + + MotorR_FORWARD = MotorL_REVERSE = 0; + MotorL_FORWARD = MotorR_REVERSE = 1; + wait_ms(step); +#ifdef TIME +#else + + while(_count < count+1) { +#ifdef FRONTBUTTON + if(frontButtonPressed()) // get out if to much problems + error(); +#endif + DEBUG_PRINT("count: %d _count: %d", count, _count); + } +#endif + MotorL_FORWARD = MotorR_REVERSE = 0; + MotorR_FORWARD = MotorL_REVERSE = 0; + MotorR_EN=MotorL_EN=0; +// wait_ms(250); // only to step the robot +} + +void Bertl::TurnLeftStep(int step) +{ + int count = _count; + MotorR_EN=MotorL_EN=1; // motor left and right ENABLE + + MotorR_FORWARD = MotorL_REVERSE = 1; + wait_ms(step); + +#ifdef TIME +#else + + while(_count < count+1) { +#ifdef FRONTBUTTON + if(frontButtonPressed()) // get out if to much problems + error(); +#endif + DEBUG_PRINT("count: %d _count: %d", count, _count); + } +#endif + MotorR_FORWARD = MotorL_REVERSE = 0; + MotorR_EN=MotorL_EN=0; + //wait_ms(250); // only to step the robot +} + +uint8_t Bertl::GetLineValues() +{ + uint8_t detect; + + detect = linesensor; + return detect; +} \ No newline at end of file
--- a/ur_Bertl.h Fri Apr 24 09:16:40 2015 +0000 +++ b/ur_Bertl.h Sun Apr 26 20:04:47 2015 +0000 @@ -1,14 +1,15 @@ /*********************************** -name: ur_Bertl.h Version: 2.1 +name: ur_Bertl.h Version: 2.2 author: PE HTL BULME email: pe@bulme.at WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/ description: Definition portion of the class ur_Bertl The Robot - boolean commands added for if/else, while, ... + Step wise turns on left and rigth int ReturnButtonPressed() added which returns the int value of button pressed ***********************************/ #include "mbed.h" +#include "const.h" #ifndef UR_BERTL_H #define UR_BERTL_H @@ -17,7 +18,7 @@ #define RIGHTSENSOR P1_13 /********************************************//** name: ur_Bertl.h \n - version: 2.0 \n + version: 2.2 \n author:PE HTL BULME \n email: pe@bulme.at \n WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage \n @@ -94,7 +95,7 @@ @endcode Example IF/ELSE Commands (update ur_Bertl 2.0 from https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/ @code -/* Sorry, but there are Javascript problems with this code +/*Sorry, but there are Javascript problems with this code int main() { @@ -144,12 +145,12 @@ ur_Bertl(); /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/ ur_Bertl(PinName pin); /**< parameterized constructor; on what pin should the interrupt work; SPEED, DISTANCE or ANGLE have to bee defined in config.h */ - void Move(); /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/ + //void Move(); /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/ + void Move(int move = MOVE); /**< Robot moves one turn as much as the constant DISTANCE; if one of the buttons fire --> Error()*/ void TurnLeft(); /**< Robot turns left as much as the constant ANGLE*/ void PutBeeper(); /**< if Robot has any Beepers in his bag he can put one or more Beeper; if not --> Error(()*/ void PickBeeper(); /**< if Robot stands on a black item he can pick one or more Beeper (max. 15 --> Error()); if not --> Error()*/ void ShutOff(); /**< turnes the robot off */ - void MoveBackwards(); /**< Robot moves as much back as the constant DISTANCE; if one of the buttons fire --> Error()*/ bool WaitUntilButtonPressed(); /**< wait until any button is pressed at the robot */ bool FrontIsClear(); /**< returns a boolean value true if front is free; if not false */ bool NextToABeeper(); /**< returns a boolean value true if the robot is on a black place or line; if not --> false */ @@ -164,4 +165,81 @@ void BlueLedsON(); /**< ON all blue LEDs which are on the same Port 1_28 */ int Read(); }; +/********************************************//** + name: Bertl.h \n + version: 1.0 \n + author:PE HTL BULME \n + email: pe@bulme.at \n + WIKI: https://developer.mbed.org/teams/BERTL_CHEL_18/code/ur_Bertl/wiki/Homepage \n + description: + Definition and documentation portion of the class Bertl The Robot. + +***********************************************/ + +/** +@code +// +@endcode + +Example motor sensor test: +@code +#include "mbed.h" +#include "ur_Bertl.h" +#include "const.h" + +int main() +{ + ur_Bertl karel(LEFTSENSOR); // RIGHTSENSOR + + while(true) { + karel.NibbleLeds(karel.Read()); + } +} +@endcode + +Example follow a line: +@code +#include "mbed.h" +#include "ur_Bertl.h" +#include "const.h" + +int main() +{ + Bertl karel; + + while(karel.WaitUntilButtonPressed()) + { + karel.NibbleLeds(karel.GetLineValues()); + switch(karel.GetLineValues()) + { + case 0x00: + karel.TurnLeftStep(50); + break; + case 0x03: case 0x01: case 0x07: + karel.TurnLeftStep(20); + break; + case 0x0E: case 0x0A: case 0x08: + karel.TurnRigthStep(20); + break; + default: + karel.Move(20); + break; + } + if(!karel.FrontIsClear()) + karel.TurnLeftStep(1000); + } +} +@endcode +*/ +class Bertl : public ur_Bertl +{ +protected: +public: + //Bertl(); /**< default constructor; you have to define constants in config.h such as SPEED, DISTANCE or ANGLE*/ + void MoveBackwards(int move = MOVE); /**< Robot moves as much back as the constant DISTANCE; if one of the buttons fire --> Error()*/ + void TurnRigth(); /**< Robot turns rigth as much as the constant ANGLE*/ + void TurnLeftStep(int step=STEPTIME); /**< Robot turns left for a short time defined in STEPTIME */ + void TurnRigthStep(int step=STEPTIME); /**< Robot turns rigth for a short time defined in STEPTIME */ + uint8_t GetLineValues(); /**< in the lower 4 bit are the values of the line sensor */ +}; #endif \ No newline at end of file