.:: Roomba Trajectory Simulator ::.
Roomba robot vacuum cleaner simulation
This project is a simulation of the popular Roomba Vacuum Cleaner. When I first saw the Roomba in action, I was a bit disappointed. It turned out that there is no algorithm for cleaning. The rooma calculates the size of the room and based on that sets a timer. Within that time, random traversing will eventually clean the room, however it takes a very long time and drains the battery. The LG Hombot 3.0 on the other hand uses zig zags as well as two cameras to track its location and avoids going to the previous locations.
SOFTWARE WRITTEN IN C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Drawing; namespace RoombaWalls { class Program { static void Main(string[] args) { double width = 80; double height = 24; bool[,] RoombaWalls = new bool[(int)width, (int)height]; int[,] RoombaHistory = new int[(int)width, (int)height]; double drawX = 0; double drawY = 0; bool drawing = true; while (drawing) { ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.Enter) { drawing = false; } if (key.Key == ConsoleKey.UpArrow) { if (drawY > 0) { drawY--; RoombaWalls[(int)drawX, (int)drawY] = true; PaintRoomba(RoombaWalls, width, height, "#", ConsoleColor.Blue); } } if (key.Key == ConsoleKey.DownArrow) { if (drawY < ((int)height - 1)) { drawY++; RoombaWalls[(int)drawX, (int)drawY] = true; PaintRoomba(RoombaWalls, width, height, "#", ConsoleColor.Blue); } } if (key.Key == ConsoleKey.LeftArrow) { if (drawX > 0) { drawX--; RoombaWalls[(int)drawX, (int)drawY] = true; PaintRoomba(RoombaWalls, width, height, "#", ConsoleColor.Blue); } } if (key.Key == ConsoleKey.RightArrow) { if (drawX < ((int)width - 1)) { drawX++; RoombaWalls[(int)drawX, (int)drawY] = true; PaintRoomba(RoombaWalls, width, height, "#", ConsoleColor.Blue); } } } Random rnd1 = new Random(Environment.TickCount); double angle = rnd1.Next(0,360); double vx = Math.Cos(angle * (Math.PI / 180)); double vy = Math.Sin(angle * (Math.PI / 180)); int steps = 0; double area = width * height; double botX = (int)(width / 2); double botY = (int)(height / 2); double minX = width / 2; double maxX = width / 2; double minY = height / 2; double maxY = height / 2; while (true) { steps++; if (botX > maxX) { maxX = botX; area = Math.Abs(maxX - minX) * Math.Abs(maxY - minY); } if (botX < minX) { minX = botX; area = Math.Abs(maxX - minX) * Math.Abs(maxY - minY); } if (botY > maxY) { maxY = botY; area = Math.Abs(maxX - minX) * Math.Abs(maxY - minY); } if (botY < minY) { minY = botY; area = Math.Abs(maxX - minX) * Math.Abs(maxY - minY); } area = Math.Round(area); if (RoombaHistory[(int)botX, (int)botY] < 10) { RoombaHistory[(int)botX, (int)botY]++; } while (RoombaWalls[(int)(botX + vx), (int)(botY)] == true) { angle = rnd1.Next(0, 360); vx = Math.Cos(angle * (Math.PI / 180)); vy = Math.Sin(angle * (Math.PI / 180)); } while (RoombaWalls[(int)(botX), (int)(botY + vy)] == true) { angle = rnd1.Next(0, 360); vx = Math.Cos(angle * (Math.PI / 180)); vy = Math.Sin(angle * (Math.PI / 180)); } while (RoombaWalls[(int)(botX + vx), (int)(botY + vy)] == true) { angle = rnd1.Next(0, 360); vx = Math.Cos(angle * (Math.PI / 180)); vy = Math.Sin(angle * (Math.PI / 180)); } botX += vx; botY += vy; PaintRoomba(RoombaWalls, width, height, "#",ConsoleColor.Blue); PaintRoomba(RoombaHistory, width, height, "@"); Console.SetCursorPosition(0, 24); Console.BackgroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Black; double percent = Math.Round((steps / (area * 5)) * 100,2); Console.Write("CODED BY: ROSTISLAV PERSION (seeplusplus@gmail.com) STEPS: " + steps.ToString() + " AREA: " + area.ToString()); } Console.ReadLine(); } static void PaintRoomba(bool[,] area,double width,double height, string letter, ConsoleColor col) { for (int y = 0; y < (int)height; y++) { for (int x = 0; x < (int)width; x++) { if (area[x, y] == true) { Console.BackgroundColor = col; Console.SetCursorPosition(x, y); Console.Write(letter); } } } } static void PaintRoomba(int[,] area,double width,double height, string letter) { for (int y = 0; y < (int)height; y++) { for (int x = 0; x < (int)width; x++) { if (area[x, y] > 0) { Console.SetCursorPosition(x, y); if ((area[x, y] > 0) && (area[x, y] < 3)) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write("@"); } if ((area[x, y] > 3) && (area[x, y] < 6)) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Green; Console.Write("@"); } if ((area[x, y] > 6) && (area[x, y] < 9)) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.Write("@"); } } } } } } } |