pibot:challenge1:softwarewin
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
pibot:challenge1:softwarewin [2022/01/03 12:18] – Changed terminology from "enter" to "type" jstruebel | pibot:challenge1:softwarewin [2022/10/20 19:53] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Software Setup ====== | ||
+ | |||
+ | - Open the VSCode from the Applications directory on the flash drive | ||
+ | - Click on the small green square in the bottom left corner of the screen\\ \\ <WRAP box>{{ : | ||
+ | - Select the " | ||
+ | - Type " | ||
+ | - Click the "Open Folder" | ||
+ | - Select the " | ||
+ | - Select the picar-line-tracking.py file in the list on the left\\ \\ <WRAP box>{{ : | ||
+ | - Select File-> | ||
+ | - Use the information below to change the code so that the PiBot will solve the maze | ||
+ | - After the changes to the code are complete, save it with File-> | ||
+ | |||
+ | ===== Software Explanation ===== | ||
+ | |||
+ | * Read through the presentation found [[https:// | ||
+ | * 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\\ \\ <WRAP round tip>To make a variable a list, assign a value to it inside of square brackets <code python> | ||
+ | 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 | ||
+ | </ | ||
+ | myval = listvar[1] # Retrieve the 2nd element | ||
+ | lastval = listvar[-1] # Retrieve the last element | ||
+ | almostlastval = listvar[-2] # Retrieve the 2nd to last element | ||
+ | </ | ||
+ | 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 ' | ||
+ | * There may be instances where the PiBot will " | ||
+ | * 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 " | ||
+ | * 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 [[https:// | ||
+ | * 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\\ \\ <WRAP round tip>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.\\ \\ <WRAP round tip>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 :-)\\ \\ <WRAP round alert> | ||
+ | |||
+ | [[: | ||