User Tools

Site Tools


pibot:challenge1:softwarewin

Software Setup

  1. Open the VSCode from the Applications directory on the flash drive
  2. Click on the small green square in the bottom left corner of the screen

    VSCode Main Screen

  3. Select the “Connect Current Window to Host…” option

    VSCode Remote-SSH

  4. Type “pi@pibot##” and press enter

    Replace the text “pibot##” with the label on the pibot

    The password to enter when prompted is “DogsAndCatsAreNice2.” without the quotes. The '.' at the end is important!

    It may take a couple of minutes while it installs some files on the PiBot

    VSCode Remote Connection

  5. Click the “Open Folder” button

    VSCode Open Folder

  6. Select the “pibot” folder and click the “OK” button

    VSCode Browse

  7. Select the picar-line-tracking.py file in the list on the left

    VSCode picar-line-tracking.py

  8. Select File→Save As… and save the file as picar-line-maze.py

    VSCode picar-line-maze.py

  9. Use the information below to change the code so that the PiBot will solve the maze
  10. After the changes to the code are complete, save it with File→Save

Software Explanation

  • Read through the presentation found here to learn how to make a robot solve a maze

    Pay special attention to the section on Intersection and Turn Handling starting on slide 26

  • Make the changes to handle all of the decisions for the intersections in the while loop at the end of the file
  • Create new functions for any code that you need to use multiple times and to keep the code in the while loop readable
  • Use a list to save the decisions so that the PiBot can complete the maze in the shortest path the second time through

    To make a variable a list, assign a value to it inside of square brackets

    listvar = []

    To add a new value to a list use the append method

    listvar.append("L")

    To remove items from the list use the pop method

    listvar.pop() # Remove the last element
    listvar.pop(0) # Remove the first element
    listvar.pop(1) # Remove the second element
    listvar.pop(-1) # Remove the last element
    listvar.pop(-2) # Remove the second from last element

    To access the value of a particular item in the list place the index of the item in square brackets. The index of the first item is '0'. Negative numbers start at the end of the list.

    myval = listvar[3] # Retrieve the 4th element
    myval = listvar[1] # Retrieve the 2nd element
    lastval = listvar[-1] # Retrieve the last element
    almostlastval = listvar[-2] # Retrieve the 2nd to last element

    A variable can also be used as the index. In that case the value of the variable must be a number and will be used to determine the index for the value that is returned from the list.

    ivar = 3
    ivar2 = ivar + 3
    myval = listvar[ivar] # Retrieve the 4th element
    myval2 = listvar[ivar2] # Retrieve the 7th element
  • The logic to drive the PiBot along the line need to be made as fast as possible, but the decisions that determine if it is in an intersection need to be done more slowly
    • Use a loop counter in the while loop and only make decisions on finding the intersections every 'n' loops
    • There may be instances where the PiBot will “see” an intersection in the middle of the line where there isn't one as it is driving along
  • Print out information as the PiBot makes decisions to help debug if things don't go the way you expect
  • The PiBot wheels will be placed on the starting line, so to the sensors it will look just like a straight line ahead
  • The PiBot must stop when it gets to the box at the end of the maze
  • The program can pause when it reaches the end of the maze and wait for a keypress to tell it to start again when it's back at the start
    • Use the “input” function to wait for an “enter” keypress
    • A more advanced way to handle the restart is to save the path to a file and then quit when it reaches the end. That way it can read the file at the beginning if it exists and run the same maze even after it is turned off. See this link for information on how to read and write lists to files
    • If you want to get really fancy, have the program get the file name from a parameter entered when it is run so that multiple mazes can be saved and re-run whenever desired

      The sys module will need to be imported to get parameters from the command line. The argparse module is helpful to make defining and getting parameters easier. Google is your friend to figure out how to implement this

  • For an extra challenge write the program so that the PiBot can go back through the maze in reverse, end to finish, instead of carrying it all the way back to the start for its 2nd run.

    Not only will the decisions be in reverse order, the turns will also be backwards.

  • Bonus points if you make the PiBot do a “Happy Dance” when it reaches the end of the maze :-)

    Great embarassment will be yours if it performs its “Happy Dance” before reaching the end of the maze :-(

Return to Challenge 1

""
pibot/challenge1/softwarewin.txt · Last modified: 2022/10/20 21:53 by 127.0.0.1