% r = roomba(20) % m = mobiledev for i = 1:1000 c = r.getCliffSensors; cl = c.left; clf = c.leftFront; crf = c.rightFront; cr = c.right; l = r.getLightBumpers; ll = l.left; llf = l.leftFront; llc = l.leftCenter; lrc = l.rightCenter; lrf = l.rightFront; lr = l.right; b = r.getBumpers; bl = b.left; br = b.right; bf = b.front; s = orientlog(m); roll = s(end,3); pitch = s(end,2); if (llc > 50) + (lrc > 50) >= 1 r.setDriveVelocity(0); img = r.getImage; imshow(img) red = mean(mean(img(:,:,1)));% reads the mean amount of red pixels green = mean(mean(img(:,:,2)));% reads the mean amount of green pixels blue = mean(mean(img(:,:,3)));% reads the mean amount of blue pixels if (red > 110) + (green < 90) == 2 r.setDriveVelocity(.2) if (bl == 1) + (bf == 1) + (br == 1) >= 1 r.setDriveVelocity(0) r.turnAngle(160) end elseif (red < 130) + (green > 110) + (blue < 100) == 3 r.beep r.turnAngle(160) else r.turnAngle(160) end end if (clf > 2000) + (crf > 2000) >= 1 r.setDriveVelocity(0) r.beep r.turnAngle(315) r.moveDistance(.15) end if roll > 30 r.turnAngle(-1) elseif roll < -30 r.turnAngle(1) elseif pitch > 15 && pitch < 30 r.setDriveVelocity(.2) elseif pitch >= 30 r.setDriveVelocity(.01*pitch) elseif pitch < -30 r.setDriveVelocity(-.2) else r.setDriveVelocity(0) end end