/** * * Same function as moveForward but updates and check if there's an error * * @param sensor the desired sensor to read and update * @param centimeters the longest distance the iRobot will move */ void moveFowardUpdate(oi_t* sensor, int centimeters){ // if the current state of the iRobot has an error, return if(errorDetection(0) != 0){ serial_puts("CAN'T MOVE!\n\r\n\r"); return; } int millimeters = centimeters * 10; int sum = 0; oi_set_wheels(150, 150); // move forward; while (sum < millimeters) { // check if there's an error detectiion while moving // if so, break out the loop and stop if(errorDetection(0) != 0) { char error[30]; sprintf(error, "\n\rSTOPPED DUE TO SENSORS!\n\rMOVED ONLY %02d CM\n\r", sum/10); serial_puts(error); oi_set_wheels(0, 0); break; } sum += sensor->distance; } oi_set_wheels(0, 0); // stop oi_free(sensor); }
static void destroy () { if (this->data) oi_free (this->allocated, this->data); }