Class Bertl added
Dependents: BertlDrive_V2 BertlDrive_V2
Diff: ur_Bertl.cpp
- Revision:
- 12:cedc088eaf05
- Parent:
- 7:e7f74f072564
diff -r 155ce3832f01 -r cedc088eaf05 ur_Bertl.cpp --- 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