Class Bertl added

Dependencies:   HCSR

Dependents:   BertlDrive_V2 BertlDrive_V2

Committer:
bulmecisco
Date:
Thu Mar 26 12:39:40 2015 +0000
Revision:
2:1cd559ff516b
Parent:
1:fafbac0ba96d
Child:
3:01b183fe8b41
Time for TurnLeft and Move added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bulmecisco 0:66e9a0afcbd6 1 /***********************************
bulmecisco 0:66e9a0afcbd6 2 name: ur_Bertl.cpp Version: 1.1
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 Implementation portion of class ur_Bertl The Robot
bulmecisco 0:66e9a0afcbd6 7 Blue LED and RGB LED test added
bulmecisco 0:66e9a0afcbd6 8
bulmecisco 0:66e9a0afcbd6 9 ***********************************/
bulmecisco 0:66e9a0afcbd6 10 #include "mbed.h"
bulmecisco 0:66e9a0afcbd6 11 #include "config.h"
bulmecisco 0:66e9a0afcbd6 12 #include "ur_Bertl.h"
bulmecisco 0:66e9a0afcbd6 13
bulmecisco 0:66e9a0afcbd6 14 // Constructor
bulmecisco 0:66e9a0afcbd6 15 ur_Bertl::ur_Bertl() : _interrupt(P1_12) // left sensor P1_13
bulmecisco 0:66e9a0afcbd6 16 {
bulmecisco 0:66e9a0afcbd6 17 i2c.frequency(40000); // I2C Frequenz 40kHz
bulmecisco 0:66e9a0afcbd6 18 mg1 = mg2 = SPEED;
bulmecisco 0:66e9a0afcbd6 19 _interrupt.rise(this, &ur_Bertl::increment); // attach increment function of this counter instance ie. motor sensor
bulmecisco 0:66e9a0afcbd6 20 _count = 0;
bulmecisco 0:66e9a0afcbd6 21 beepersInBag = 0;
bulmecisco 0:66e9a0afcbd6 22 }
bulmecisco 0:66e9a0afcbd6 23
bulmecisco 0:66e9a0afcbd6 24 ur_Bertl::ur_Bertl(PinName pin) : _interrupt(pin) // create the InterruptIn on the pin specified to Counter
bulmecisco 0:66e9a0afcbd6 25 {
bulmecisco 0:66e9a0afcbd6 26 i2c.frequency(40000); // I2C Frequenz 40kHz
bulmecisco 0:66e9a0afcbd6 27 mg1 = mg2 = SPEED;
bulmecisco 0:66e9a0afcbd6 28 _interrupt.rise(this, &ur_Bertl::increment); // attach increment function of this counter instance ie. motor sensor
bulmecisco 0:66e9a0afcbd6 29 _count = 0;
bulmecisco 0:66e9a0afcbd6 30 beepersInBag = 0;
bulmecisco 0:66e9a0afcbd6 31 }
bulmecisco 0:66e9a0afcbd6 32
bulmecisco 0:66e9a0afcbd6 33
bulmecisco 0:66e9a0afcbd6 34 // Pulblic methodes
bulmecisco 0:66e9a0afcbd6 35 void ur_Bertl::Move()
bulmecisco 0:66e9a0afcbd6 36 {
bulmecisco 0:66e9a0afcbd6 37 int count = _count;
bulmecisco 0:66e9a0afcbd6 38 MotorR_EN=MotorL_EN=1; // both motor ENABLE
bulmecisco 0:66e9a0afcbd6 39 MotorR_FORWARD = MotorL_FORWARD = 1; // both motor forward ON
bulmecisco 2:1cd559ff516b 40 #ifdef TIME
bulmecisco 2:1cd559ff516b 41 wait_ms(MOVE);
bulmecisco 2:1cd559ff516b 42 #else
bulmecisco 0:66e9a0afcbd6 43
bulmecisco 0:66e9a0afcbd6 44 while(_count < count+DISTANCE) {
bulmecisco 0:66e9a0afcbd6 45 //if(!FrontIsClear()) // more convenient because there are no accidents :-)
bulmecisco 0:66e9a0afcbd6 46 // break;
bulmecisco 0:66e9a0afcbd6 47 #ifdef FRONTBUTTON
bulmecisco 0:66e9a0afcbd6 48 if(frontButtonPressed())
bulmecisco 0:66e9a0afcbd6 49 error();
bulmecisco 0:66e9a0afcbd6 50 #endif
bulmecisco 0:66e9a0afcbd6 51 DEBUG_PRINT("count: %d _count: %d", count, _count);
bulmecisco 0:66e9a0afcbd6 52 }
bulmecisco 2:1cd559ff516b 53 #endif
bulmecisco 0:66e9a0afcbd6 54 MotorR_FORWARD = MotorL_FORWARD = 0; // both motor off
bulmecisco 0:66e9a0afcbd6 55 MotorR_EN=MotorL_EN=0;
bulmecisco 0:66e9a0afcbd6 56 wait_ms(250);
bulmecisco 0:66e9a0afcbd6 57 }
bulmecisco 0:66e9a0afcbd6 58
bulmecisco 0:66e9a0afcbd6 59 void ur_Bertl::PutBeeper()
bulmecisco 0:66e9a0afcbd6 60 {
bulmecisco 0:66e9a0afcbd6 61 // wait_ms(500);
bulmecisco 0:66e9a0afcbd6 62 if(beepersInBag > 0)
bulmecisco 0:66e9a0afcbd6 63 beepersInBag--;
bulmecisco 0:66e9a0afcbd6 64 else
bulmecisco 0:66e9a0afcbd6 65 error();
bulmecisco 0:66e9a0afcbd6 66 }
bulmecisco 0:66e9a0afcbd6 67
bulmecisco 0:66e9a0afcbd6 68 void ur_Bertl::PickBeeper()
bulmecisco 0:66e9a0afcbd6 69 {
bulmecisco 0:66e9a0afcbd6 70 // wait_ms(500);
bulmecisco 0:66e9a0afcbd6 71 if (linesensor)
bulmecisco 0:66e9a0afcbd6 72 beepersInBag++;
bulmecisco 0:66e9a0afcbd6 73 else
bulmecisco 0:66e9a0afcbd6 74 error();
bulmecisco 0:66e9a0afcbd6 75 }
bulmecisco 0:66e9a0afcbd6 76
bulmecisco 0:66e9a0afcbd6 77 void ur_Bertl::TurnLeft()
bulmecisco 0:66e9a0afcbd6 78 {
bulmecisco 0:66e9a0afcbd6 79 int count = _count;
bulmecisco 0:66e9a0afcbd6 80 MotorR_EN=MotorL_EN=1; // motor left and right ENABLE
bulmecisco 0:66e9a0afcbd6 81
bulmecisco 0:66e9a0afcbd6 82 MotorR_FORWARD = MotorL_REVERSE = 1;
bulmecisco 2:1cd559ff516b 83 #ifdef TIME
bulmecisco 2:1cd559ff516b 84 wait_ms(TURN);
bulmecisco 2:1cd559ff516b 85 #else
bulmecisco 2:1cd559ff516b 86
bulmecisco 0:66e9a0afcbd6 87 while(_count < count+ANGLE) {
bulmecisco 0:66e9a0afcbd6 88 #ifdef FRONTBUTTON
bulmecisco 0:66e9a0afcbd6 89 if(frontButtonPressed()) // get out if to much problems
bulmecisco 0:66e9a0afcbd6 90 error();
bulmecisco 0:66e9a0afcbd6 91 #endif
bulmecisco 0:66e9a0afcbd6 92 DEBUG_PRINT("count: %d _count: %d", count, _count);
bulmecisco 0:66e9a0afcbd6 93 }
bulmecisco 2:1cd559ff516b 94 #endif
bulmecisco 0:66e9a0afcbd6 95 MotorR_FORWARD = MotorL_REVERSE = 0;
bulmecisco 0:66e9a0afcbd6 96 MotorR_EN=MotorL_EN=0;
bulmecisco 0:66e9a0afcbd6 97 wait_ms(250); // only to step the robot
bulmecisco 0:66e9a0afcbd6 98 }
bulmecisco 0:66e9a0afcbd6 99
bulmecisco 0:66e9a0afcbd6 100 bool ur_Bertl::WaitUntilButtonPressed()
bulmecisco 0:66e9a0afcbd6 101 {
bulmecisco 0:66e9a0afcbd6 102 char cmd[3];
bulmecisco 0:66e9a0afcbd6 103 int16_t btns;
bulmecisco 0:66e9a0afcbd6 104 bool wert;
bulmecisco 0:66e9a0afcbd6 105
bulmecisco 0:66e9a0afcbd6 106 RGB_blue=RGB_red=RGB_green=0;
bulmecisco 0:66e9a0afcbd6 107 cmd[0] = 0x06;
bulmecisco 0:66e9a0afcbd6 108 cmd[1] = 0x00;
bulmecisco 0:66e9a0afcbd6 109 i2c.write(addr, cmd, 2);
bulmecisco 0:66e9a0afcbd6 110
bulmecisco 0:66e9a0afcbd6 111 cmd[0]=0x01;
bulmecisco 0:66e9a0afcbd6 112 i2c.write(addr, cmd, 1);
bulmecisco 0:66e9a0afcbd6 113 i2c.read(addr|1, cmd, 1);
bulmecisco 0:66e9a0afcbd6 114 btns = cmd[0];
bulmecisco 0:66e9a0afcbd6 115 if( btns & (0xFF))
bulmecisco 0:66e9a0afcbd6 116 wert = false;
bulmecisco 0:66e9a0afcbd6 117 else
bulmecisco 0:66e9a0afcbd6 118 wert = true;
bulmecisco 0:66e9a0afcbd6 119 DEBUG_PRINT("\right\nWERT: %d \right\n", wert);
bulmecisco 0:66e9a0afcbd6 120 return wert;
bulmecisco 0:66e9a0afcbd6 121 }
bulmecisco 0:66e9a0afcbd6 122
bulmecisco 0:66e9a0afcbd6 123 void ur_Bertl::ShutOff()
bulmecisco 0:66e9a0afcbd6 124 {
bulmecisco 0:66e9a0afcbd6 125 MotorR_FORWARD = MotorL_FORWARD = 0; // motor OFF
bulmecisco 0:66e9a0afcbd6 126 MotorR_EN=MotorL_EN=0; // motor disable
bulmecisco 0:66e9a0afcbd6 127 }
bulmecisco 0:66e9a0afcbd6 128
bulmecisco 0:66e9a0afcbd6 129 // LEDs methodes
bulmecisco 0:66e9a0afcbd6 130
bulmecisco 0:66e9a0afcbd6 131 void ur_Bertl::BlueLedsON()
bulmecisco 0:66e9a0afcbd6 132 {
bulmecisco 0:66e9a0afcbd6 133 LED_blue=0;
bulmecisco 0:66e9a0afcbd6 134 }
bulmecisco 0:66e9a0afcbd6 135
bulmecisco 0:66e9a0afcbd6 136 void ur_Bertl::BlueLedsOFF()
bulmecisco 0:66e9a0afcbd6 137 {
bulmecisco 0:66e9a0afcbd6 138 LED_blue=1;
bulmecisco 0:66e9a0afcbd6 139 }
bulmecisco 0:66e9a0afcbd6 140
bulmecisco 0:66e9a0afcbd6 141 void ur_Bertl::RGBLed(bool red, bool green, bool blue)
bulmecisco 0:66e9a0afcbd6 142 {
bulmecisco 0:66e9a0afcbd6 143 RGB_blue=!blue;
bulmecisco 0:66e9a0afcbd6 144 RGB_red=!red;
bulmecisco 0:66e9a0afcbd6 145 RGB_green=!green;
bulmecisco 0:66e9a0afcbd6 146 }
bulmecisco 0:66e9a0afcbd6 147
bulmecisco 0:66e9a0afcbd6 148 void ur_Bertl::TurnLedOn(int16_t led)
bulmecisco 0:66e9a0afcbd6 149 {
bulmecisco 0:66e9a0afcbd6 150 char cmd[3];
bulmecisco 0:66e9a0afcbd6 151
bulmecisco 1:fafbac0ba96d 152 if(led == 0xBB) {
bulmecisco 1:fafbac0ba96d 153 LED_blue=0;
bulmecisco 1:fafbac0ba96d 154 return;
bulmecisco 1:fafbac0ba96d 155 } else if (led == 0xFF) {
bulmecisco 1:fafbac0ba96d 156 RGBLed(1,1,1);
bulmecisco 1:fafbac0ba96d 157 LED_blue=0;
bulmecisco 1:fafbac0ba96d 158 }
bulmecisco 0:66e9a0afcbd6 159 cmd[0] = 0x02;
bulmecisco 0:66e9a0afcbd6 160 cmd[1] = ~led;
bulmecisco 0:66e9a0afcbd6 161 i2c.write(addr, cmd, 2);
bulmecisco 0:66e9a0afcbd6 162 wait(0.5);
bulmecisco 0:66e9a0afcbd6 163 }
bulmecisco 0:66e9a0afcbd6 164
bulmecisco 0:66e9a0afcbd6 165 void ur_Bertl::TurnLedOff(int16_t led)
bulmecisco 0:66e9a0afcbd6 166 {
bulmecisco 0:66e9a0afcbd6 167 char cmd[3];
bulmecisco 1:fafbac0ba96d 168 if(led == 0xBB) {
bulmecisco 1:fafbac0ba96d 169 LED_blue=1;
bulmecisco 1:fafbac0ba96d 170 return;
bulmecisco 1:fafbac0ba96d 171 } else if (led == 0xFF) {
bulmecisco 1:fafbac0ba96d 172 RGBLed(0,0,0); //don't work?
bulmecisco 1:fafbac0ba96d 173 LED_blue=1;
bulmecisco 1:fafbac0ba96d 174 }
bulmecisco 0:66e9a0afcbd6 175 cmd[0] = 0x02;
bulmecisco 0:66e9a0afcbd6 176 cmd[1] = led;
bulmecisco 0:66e9a0afcbd6 177 i2c.write(addr, cmd, 2);
bulmecisco 0:66e9a0afcbd6 178 wait(0.5);
bulmecisco 0:66e9a0afcbd6 179 }
bulmecisco 0:66e9a0afcbd6 180
bulmecisco 0:66e9a0afcbd6 181 void ur_Bertl::NibbleLeds(int value)
bulmecisco 0:66e9a0afcbd6 182 {
bulmecisco 0:66e9a0afcbd6 183 NibbleLEDs = value%16;
bulmecisco 0:66e9a0afcbd6 184 }
bulmecisco 0:66e9a0afcbd6 185
bulmecisco 0:66e9a0afcbd6 186 //-----------------INTERNAL USE ONLY ----------------------------
bulmecisco 0:66e9a0afcbd6 187 void ur_Bertl::error()
bulmecisco 0:66e9a0afcbd6 188 {
bulmecisco 0:66e9a0afcbd6 189 int wait = 500;
bulmecisco 0:66e9a0afcbd6 190 MotorR_FORWARD = MotorL_FORWARD = 0; // both motor off
bulmecisco 0:66e9a0afcbd6 191 MotorR_REVERSE = MotorL_REVERSE = 0; // both motor off
bulmecisco 0:66e9a0afcbd6 192 MotorR_EN=MotorL_EN=0;
bulmecisco 0:66e9a0afcbd6 193 while(1) {
bulmecisco 0:66e9a0afcbd6 194 TurnLedOff(0xFF);
bulmecisco 0:66e9a0afcbd6 195 LED_D10 = LED_D11 = LED_D12 = LED_D13 = 0;
bulmecisco 0:66e9a0afcbd6 196 LED_blue=1;
bulmecisco 0:66e9a0afcbd6 197 RGB_blue=RGB_green=RGB_red=1;
bulmecisco 0:66e9a0afcbd6 198 wait_ms(wait);
bulmecisco 0:66e9a0afcbd6 199 TurnLedOn(0xFF);
bulmecisco 0:66e9a0afcbd6 200 LED_D10 = LED_D11 = LED_D12 = LED_D13 = 1;
bulmecisco 0:66e9a0afcbd6 201 LED_blue=0;
bulmecisco 0:66e9a0afcbd6 202 RGB_blue=RGB_green=1;RGB_red=0;
bulmecisco 0:66e9a0afcbd6 203 wait_ms(wait);
bulmecisco 0:66e9a0afcbd6 204 }
bulmecisco 0:66e9a0afcbd6 205 }
bulmecisco 0:66e9a0afcbd6 206
bulmecisco 0:66e9a0afcbd6 207 bool ur_Bertl::frontButtonPressed()
bulmecisco 0:66e9a0afcbd6 208 {
bulmecisco 0:66e9a0afcbd6 209 char cmd[3]; // array for I2C
bulmecisco 0:66e9a0afcbd6 210 int16_t btns;
bulmecisco 0:66e9a0afcbd6 211 bool wert;
bulmecisco 0:66e9a0afcbd6 212
bulmecisco 0:66e9a0afcbd6 213 cmd[0] = 0x06;
bulmecisco 0:66e9a0afcbd6 214 cmd[1] = 0x00;
bulmecisco 0:66e9a0afcbd6 215 i2c.write(addr, cmd, 2);
bulmecisco 0:66e9a0afcbd6 216
bulmecisco 0:66e9a0afcbd6 217 cmd[0]=0x01;
bulmecisco 0:66e9a0afcbd6 218 i2c.write(addr, cmd, 1);
bulmecisco 0:66e9a0afcbd6 219 i2c.read(addr|1, cmd, 1);
bulmecisco 0:66e9a0afcbd6 220 btns = cmd[0];
bulmecisco 0:66e9a0afcbd6 221 if( btns & (BTN_FL|BTN_FM|BTN_FR|BTN_FRR|BTN_FLL))
bulmecisco 0:66e9a0afcbd6 222 wert = true;
bulmecisco 0:66e9a0afcbd6 223 else
bulmecisco 0:66e9a0afcbd6 224 wert = false;
bulmecisco 0:66e9a0afcbd6 225 DEBUG_PRINT("WERT: %d", wert);
bulmecisco 0:66e9a0afcbd6 226 return wert;
bulmecisco 0:66e9a0afcbd6 227 }
bulmecisco 0:66e9a0afcbd6 228
bulmecisco 0:66e9a0afcbd6 229 // ISR
bulmecisco 0:66e9a0afcbd6 230
bulmecisco 0:66e9a0afcbd6 231 void ur_Bertl::increment()
bulmecisco 0:66e9a0afcbd6 232 {
bulmecisco 0:66e9a0afcbd6 233 _count++;
bulmecisco 0:66e9a0afcbd6 234 }
bulmecisco 0:66e9a0afcbd6 235
bulmecisco 0:66e9a0afcbd6 236 int ur_Bertl::Read()
bulmecisco 0:66e9a0afcbd6 237 {
bulmecisco 0:66e9a0afcbd6 238 return _count;
bulmecisco 0:66e9a0afcbd6 239 }
bulmecisco 0:66e9a0afcbd6 240
bulmecisco 0:66e9a0afcbd6 241 //----------------------------------------------------------------------
bulmecisco 1:fafbac0ba96d 242
bulmecisco 0:66e9a0afcbd6 243 bool ur_Bertl::FrontIsClear()
bulmecisco 0:66e9a0afcbd6 244 {
bulmecisco 1:fafbac0ba96d 245 #ifdef HCSR
bulmecisco 0:66e9a0afcbd6 246 int dist = 0;
bulmecisco 0:66e9a0afcbd6 247 usensor.start();
bulmecisco 0:66e9a0afcbd6 248 wait_ms(10);
bulmecisco 0:66e9a0afcbd6 249 dist=usensor.get_dist_cm();
bulmecisco 0:66e9a0afcbd6 250 if(dist < 5)
bulmecisco 0:66e9a0afcbd6 251 return false;
bulmecisco 0:66e9a0afcbd6 252 else
bulmecisco 0:66e9a0afcbd6 253 return true;
bulmecisco 1:fafbac0ba96d 254 #else
bulmecisco 0:66e9a0afcbd6 255 // if there is no ultra sonic sensor use this - with front buttons
bulmecisco 0:66e9a0afcbd6 256 char cmd[3]; // array for I2C
bulmecisco 0:66e9a0afcbd6 257 int16_t btns;
bulmecisco 0:66e9a0afcbd6 258 bool wert;
bulmecisco 0:66e9a0afcbd6 259
bulmecisco 0:66e9a0afcbd6 260 cmd[0] = 0x06;
bulmecisco 0:66e9a0afcbd6 261 cmd[1] = 0x00;
bulmecisco 0:66e9a0afcbd6 262 i2c.write(addr, cmd, 2);
bulmecisco 0:66e9a0afcbd6 263
bulmecisco 0:66e9a0afcbd6 264 cmd[0]=0x01;
bulmecisco 0:66e9a0afcbd6 265 i2c.write(addr, cmd, 1);
bulmecisco 0:66e9a0afcbd6 266 i2c.read(addr|1, cmd, 1);
bulmecisco 0:66e9a0afcbd6 267 btns = cmd[0];
bulmecisco 0:66e9a0afcbd6 268 if( btns & (BTN_FL|BTN_FM|BTN_FR))
bulmecisco 0:66e9a0afcbd6 269 wert = false;
bulmecisco 0:66e9a0afcbd6 270 else
bulmecisco 0:66e9a0afcbd6 271 wert = true;
bulmecisco 0:66e9a0afcbd6 272 DEBUG_PRINT("WERT: %d", wert);
bulmecisco 0:66e9a0afcbd6 273 return wert;
bulmecisco 1:fafbac0ba96d 274 #endif
bulmecisco 0:66e9a0afcbd6 275 }
bulmecisco 0:66e9a0afcbd6 276
bulmecisco 1:fafbac0ba96d 277 /*
bulmecisco 0:66e9a0afcbd6 278 bool ur_Bertl::NextToABeeper()
bulmecisco 0:66e9a0afcbd6 279 {
bulmecisco 0:66e9a0afcbd6 280 if (BottomIsBlack())
bulmecisco 0:66e9a0afcbd6 281 return true;
bulmecisco 0:66e9a0afcbd6 282 else
bulmecisco 0:66e9a0afcbd6 283 return false;
bulmecisco 0:66e9a0afcbd6 284 }
bulmecisco 0:66e9a0afcbd6 285
bulmecisco 0:66e9a0afcbd6 286 int ur_Bertl::AnyBeeperInBag()
bulmecisco 0:66e9a0afcbd6 287 {
bulmecisco 0:66e9a0afcbd6 288 if(beepersInBag > 0)
bulmecisco 0:66e9a0afcbd6 289 return beepersInBag;
bulmecisco 0:66e9a0afcbd6 290 else
bulmecisco 0:66e9a0afcbd6 291 return 0;
bulmecisco 0:66e9a0afcbd6 292 }
bulmecisco 0:66e9a0afcbd6 293
bulmecisco 0:66e9a0afcbd6 294 bool ur_Bertl::backIsClear()
bulmecisco 0:66e9a0afcbd6 295 {
bulmecisco 0:66e9a0afcbd6 296 char cmd[3]; // array for I2C
bulmecisco 0:66e9a0afcbd6 297 int16_t btns;
bulmecisco 0:66e9a0afcbd6 298 bool wert;
bulmecisco 0:66e9a0afcbd6 299
bulmecisco 0:66e9a0afcbd6 300 cmd[0] = 0x06;
bulmecisco 0:66e9a0afcbd6 301 cmd[1] = 0x00;
bulmecisco 0:66e9a0afcbd6 302 i2c.write(addr, cmd, 2);
bulmecisco 0:66e9a0afcbd6 303
bulmecisco 0:66e9a0afcbd6 304 cmd[0]=0x01;
bulmecisco 0:66e9a0afcbd6 305 i2c.write(addr, cmd, 1);
bulmecisco 0:66e9a0afcbd6 306 i2c.read(addr|1, cmd, 1);
bulmecisco 0:66e9a0afcbd6 307 btns = cmd[0];
bulmecisco 0:66e9a0afcbd6 308 if( btns & (BTN_BL|BTN_BM|BTN_BR))
bulmecisco 0:66e9a0afcbd6 309 wert = false;
bulmecisco 0:66e9a0afcbd6 310 else
bulmecisco 0:66e9a0afcbd6 311 wert = true;
bulmecisco 0:66e9a0afcbd6 312 DEBUG_PRINT("WERT: %d", wert);
bulmecisco 0:66e9a0afcbd6 313 return wert;
bulmecisco 0:66e9a0afcbd6 314 }
bulmecisco 0:66e9a0afcbd6 315
bulmecisco 0:66e9a0afcbd6 316 int ur_Bertl::BottomIsBlack()
bulmecisco 0:66e9a0afcbd6 317 {
bulmecisco 0:66e9a0afcbd6 318 int detect;
bulmecisco 0:66e9a0afcbd6 319
bulmecisco 0:66e9a0afcbd6 320 detect = linesensor;
bulmecisco 0:66e9a0afcbd6 321 return detect;
bulmecisco 0:66e9a0afcbd6 322 }
bulmecisco 0:66e9a0afcbd6 323
bulmecisco 0:66e9a0afcbd6 324 void ur_Bertl::MoveBackwards()
bulmecisco 0:66e9a0afcbd6 325 {
bulmecisco 0:66e9a0afcbd6 326 int count = _count;
bulmecisco 0:66e9a0afcbd6 327 //wait_ms(250); // waite until Bertl stops
bulmecisco 0:66e9a0afcbd6 328 MotorR_EN=MotorL_EN=1; // both motor ENABLE
bulmecisco 0:66e9a0afcbd6 329 MotorR_REVERSE = MotorL_REVERSE = 1; // both motor backwards ON
bulmecisco 0:66e9a0afcbd6 330 while(_count < count+DISTANCE) {
bulmecisco 0:66e9a0afcbd6 331 if(!backIsClear())
bulmecisco 0:66e9a0afcbd6 332 break;
bulmecisco 0:66e9a0afcbd6 333 DEBUG_PRINT("count: %d _count: %d", count, _count);
bulmecisco 0:66e9a0afcbd6 334 }
bulmecisco 0:66e9a0afcbd6 335 MotorR_REVERSE = MotorL_REVERSE = 0; // both motor off
bulmecisco 0:66e9a0afcbd6 336 MotorR_EN=MotorL_EN=0;
bulmecisco 0:66e9a0afcbd6 337 wait_ms(250);
bulmecisco 0:66e9a0afcbd6 338 }
bulmecisco 0:66e9a0afcbd6 339 */