====== Software Setup ====== - Open the putty app from the Applications\PuTTY\ folder on the Flash drive\\ \\ The folder will be something like "0.75". Use the latest version available. - Type "pibot##" in the Host Name (or IP address)" box where the ## comes from the label on the PiBot.\\ \\ {{ :pibot:lesson2:softwarewin:s1.png |PuTTY Configuration}} - Click the "Open" button to connect to the Raspberry Pi terminal via SSH\\ \\ {{ :pibot:lesson2:softwarewin:s2.png |PuTTY Open Connection}} - If a "PuTTY Security Alert" window pops up, click the "Accept" button\\ \\ {{ :pibot:lesson2:softwarewin:s3.png |PuTTY Security Alert}} - Type "pi" at the "login as:" prompt and press Enter\\ \\ The password to enter when prompted is "DogsAndCatsAreNice2." without the quotes. The '.' at the end is important!{{ :pibot:lesson2:softwarewin:s4.png |PuTTY Login}} - Type the following command and press enter to change to the directory for the PiBbot code\\ \\ cd ~/pibot - Type the following command and press enter to download the Python code for this lesson\\ \\ wget http://osoyoo.com/driver/picar/picar-line-tracking.py - Make sure that the PiBot is facing along the black tape path - Type the following command and press enter to make the PiBot follow the black tape path\\ \\ python3 picar-line-tracking.py - Hold down the Ctrl + C keys to stop the PiBot - Type the following command and press enter to close the SSH connection\\ \\ exit ===== Software Explanation ===== - To view the code that makes the PiBot run perform the following steps - 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\\ \\ {{ :pibot:lesson2:softwarewin:s5.png |VSCode Main Screen}} - Select the "Connect Current Window to Host..." option\\ \\ {{ :pibot:lesson2:softwarewin:s6.png |VSCode Remote-SSH}} - 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 {{ :pibot:lesson2:softwarewin:s7.png |VSCode Remote Connection}} - Click the "Open Folder" button\\ \\ {{ :pibot:lesson2:softwarewin:s8.png |VSCode Open Folder}} - Select the "pibot" folder and click the "OK" button\\ \\ {{ :pibot:lesson2:softwarewin:s9.png |VSCode Browse}} - Select the picar-line-tracking.py file in the list on the left\\ \\ {{ :pibot:lesson2:softwarewin:s10.png |VSCode picar-line-tracking.py}} - Find line 37 in the picar-line-tracking.py file. What is the name of the variables on that line and the ones below it? What do you think they are for based on their names?\\ \\ If you don't remember what a variable is, review the description from [[:pibot:lesson1:softwarewin#software_explanation|Lesson 1]] - Find the places in the code where the sensor# variables are used. What do you think the sts# variables are for? Is that different from what you thought earlier?\\ \\ The "If" statement allows the code to make decisions based on the result of a test. If the result is "True" or "1" then it executes assigns the first value, else the result was "False" or "0" and it assigns the last value. The sts# variables are assigned a '0' value if the GPIO pin is a '1' and a '1' value if the GPIO pin is not a '1'. See the [[:pibot:lesson2#electrical_description|Electrical Description]] section on the previous page for a description of how the sensors work - Find the other places in the code where the "If" statements are used. What do you think is happening with those "If" statements?\\ \\ The second group of "If" statements are standalone and not part of assigning a value to a variable. This is the most common use of the "If" statement. When the expression after the "If" is "True" then it will run the code after the "If" statement, otherwise it will skip that code and go to the next statement You can check for multiple values of a variable in an "If" statement by combining them with the "or" operator. When any of the values matches, then the result is "True" The "or" operator is part of boolean logic which allows computers to make decisions based on any input. Boolean logic is the basis for how computers work. Comments can be added to the code to describe what it is doing. They always start with a "#" character and everything else on the line after that is a comment and not run as part of the code. The comments in the code aren't always correct. Can you spot the errors? - Look at line 114 in the code. What do you think this line does?\\ \\ The "While" statement is similar to the "If" statement. It will continue to run the code under it as long as the expression is "True". We call this a loop because when it gets to the end of the code under the "While" statement it loops back to the beginning. How long do you think this "While" loop will keep running? - The PiBot moves pretty jerkily as it tries to stay on the line. How do you think you can change the code so that it follows the line more smoothly? Make those changes to the code and save it with File->Save - Open a terminal in Visual Studio Code from the Terminal->New Terminal menu - Type the following command and press enter to make the PiBot move with your changes\\ \\ python3 picar-line-tracking.py - When you're finished testing out your changes 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 [[:pibot:lesson2#software|Return to Lesson 2]]