扫地机器人的循边
已有 804 次阅读2018-7-7 06:42
task main()
{
/* */
short touched_count = 0;
const short wall_count = 4;
const float speed = 100;
/* four walls should be touched */
while(touched_count < wall_count){
// starts to go forward
setMotorSpeed(leftMotor, speed);
setMotorSpeed(rightMotor, speed);
// loop untill touched a wall
while(getBumperValue(bumpSwitch) == 1){
++touched_count;
// backward a little
setMotorSpeed(leftMotor, -speed);
setMotorSpeed(rightMotor, -speed);
sleep(300);
// turn left 90 degrees
setMotorSpeed(leftMotor, -speed);
setMotorSpeed(rightMotor, speed);
sleep(470); // when the speed is 100, it is exact 90 degrees
}
}
/* */
stopAllMotors();
}