====== Objective ====== This challenge is to use the line-following and obstacle-sensing PiBot to solve a maze that has obstacles. Instructions on how to create the maze will be provided along with some hints on how to program the PiBot for solving the maze. At the end, race a friend's PiBot and see which one can complete the maze the fastest. ====== Parts Required ====== The parts below are required to complete this lesson. Note that all parts except the foam board, clear packing tape, and styrofoam blocks are included in the [[https://www.amazon.com/OSOYOO-Raspberry-Educational-Ultrasonic-Obstacle/dp/B08JLS3J7Q|OSOYOO kit]] that can be purchased on Amazon. - Assembled PiBot from [[:pibot:lesson3|Lesson 3]] - 3cm Wide Black Tape - 3/16 inch thick White Foam Board or Corrugated Plastic Yard Signs - Clear Packing Tape - Styrofoam Blocks that are at least 5in tall and 2in thick ====== Challenge Setup ====== Use the same maze from [[:pibot:challenge1|Challenge 1]] and skip steps 1 through 5 - Draw a grid with lines 12 inches apart on the foam board with a pencil\ \\ Use small lengths of the clear packing tape to join multiple pieces of the foam board together to make a larger area for your maze. Place the tape on the top of the foam board for one joint and on the bottom of the foam board for the next joint so that you can fold it up like a Z and store it flat. Use a tape measure to mark each side every 12 inches and then use a yard stick or long piece of wood to draw straight lines all the way across the foam board. Have a friend help you hold the other end of the yard stick or wood while you draw the line. Start the first line on each side 6 inches from the edge to maximize the number of grid lines Use the back of the foam board that was used for [[:pibot:lesson2|Lesson 2]] - Design a line maze that will fit on the grid drawn on the foam board\\ \\ Use a website like [[http://www.mazegenerator.net]] to help come up with a design. Set the shape to rectangular, the style to orthogonal, the width and height to the number of grid lines on each side, and select the "As Lines" option. - Lay out the maze on the foam board with the black tape as shown below\\ \\ Follow the pencil grid to keep the lines of tape straight Start the lines on the intersection of the first pencil line from the edge of the foam board {{ :pibot:challenge2:h1.png |Layout Maze}} - Place a 6 inch long strip of the black tape across the end of the line at the start point of the maze as shown below\\ \\ Place the strip of tape on a piece of paper or cardstock with a short piece of tape leading away from it to the edge of the paper so that you can change the start point of the maze. Use Scotch Tape to hold the paper or cardstock to the foam board if needed. {{ :pibot:challenge2:h2.png |Starting Line}} - Create a solid black rectangle that is at least 6 inches wide and 4.5 inches tall across the finish point of the maze as shown below\\ \\ Create the rectangle on a piece of paper or cardstock with a short piece of tape leading away from it to the edge of the paper so that you can change the finish point of the maze. Use Scotch Tape to hold the paper or cardstock to the foam board if needed. 4 pieces of tape that are 6 inches long placed side-by-side can be used to create the rectangle {{ :pibot:challenge2:h3.png |Finish Box}} - Place some styrofoam blocks so that they block off some of the paths\\ \\ Ensure that the styrofoam blocks are far enough from intersections that the PiBot can still travel through it without hitting the styrofoam block Place the styrofoam blocks in places that the PiBot will encounter them as it solves the maze {{ :pibot:challenge2:h4.png |Place Styrofoam Block Obstacles}} - Turn the PiBot on and place it so that the wheels are on the black tape of the starting line as shown below\\ \\ {{ :pibot:challenge2:h5.png |Place PiBot at Starting Line}} ====== Software ====== Select the appropriate link below for instructions to setup the software on the PiBot and hints on how to program the PiBot to solve the maze. * [[:pibot:challenge2:softwaremac|MacOS]] * [[:pibot:challenge2:softwarewin|Windows]] ====== The Challenge ====== Run the maze solving program that you created and have the robot explore the maze to determine the shortest path from start to finish. Then use a stopwatch to time a second run through the maze to see how fast your robot is. Have a friend try their robot and see whose robot is faster and doesn't make any mistakes. Compare your program to their program to see why one is faster than the other. To run the PiBot maze solving program that you created perform the following steps - Open a terminal in Visual Studio Code from the Terminal->New Terminal menu - Type the following command and press enter to make the PiBot solve the maze\\ \\ python3 picar-line-maze-obstacles.py - Reset the PiBot to the start of the maze for the second run and time how long it takes with a stopwatch - Hold down the control + C keys to stop the PiBot if necessary - When you're finished with the challenge type the following command in the terminal and press enter to shutdown the PiBot\\ \\ sudo shutdown -h now - Click on the small green rectangle in the bottom left corner of the screen and select "Close Remote Connection" - Wait 3-5 minutes for the green light on the Raspberry Pi to stop flashing and turn off the switch on the PiBot battery