User Tools

Site Tools


pibot:lesson2:softwarewin

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
pibot:lesson2:softwarewin [2021/12/02 19:21] – Fixed tooltip jstruebelpibot:lesson2:softwarewin [2022/10/20 19:53] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +====== Software Setup ======
 +
 +  - Open the putty app from the Applications\PuTTY\<version> folder on the Flash drive\\ \\ <WRAP round tip>The <version> folder will be something like "0.75". Use the latest version available.</WRAP>
 +  - Type "pibot##" in the Host Name (or IP address)" box where the ## comes from the label on the PiBot.\\ \\ <WRAP box>{{ :pibot:lesson2:softwarewin:s1.png |PuTTY Configuration}}</WRAP>
 +  - Click the "Open" button to connect to the Raspberry Pi terminal via SSH\\ \\ <WRAP box>{{ :pibot:lesson2:softwarewin:s2.png |PuTTY Open Connection}}</WRAP>
 +  - If a "PuTTY Security Alert" window pops up, click the "Accept" button\\ \\ <WRAP box>{{ :pibot:lesson2:softwarewin:s3.png |PuTTY Security Alert}}</WRAP>
 +  - Type "pi" at the "login as:" prompt and press Enter\\ \\ <WRAP round important>The password to enter when prompted is "DogsAndCatsAreNice2." without the quotes. The '.' at the end is important!</WRAP><WRAP box>{{ :pibot:lesson2:softwarewin:s4.png |PuTTY Login}}</WRAP>
 +  - Type the following command and press enter to change to the directory for the PiBbot code\\ \\ <code>cd ~/pibot</code>
 +  - Type the following command and press enter to download the Python code for this lesson\\ \\ <code>wget http://osoyoo.com/driver/picar/picar-line-tracking.py</code>
 +  - 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\\ \\ <code>python3 picar-line-tracking.py</code>
 +  - Hold down the Ctrl + C keys to stop the PiBot
 +  - Type the following command and press enter to close the SSH connection\\ \\ <code>exit</code>
 +
 +===== 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\\ \\ <WRAP box>{{ :pibot:lesson2:softwarewin:s5.png |VSCode Main Screen}}</WRAP>
 +    - Select the "Connect Current Window to Host..." option\\ \\ <WRAP box>{{ :pibot:lesson2:softwarewin:s6.png |VSCode Remote-SSH}}</WRAP>
 +    - Type "pi@pibot##" and press enter\\ \\ <WRAP round important>Replace the text "pibot##" with the label on the PiBot</WRAP> <WRAP round important>The password to enter when prompted is "DogsAndCatsAreNice2." without the quotes. The '.' at the end is important!</WRAP> <WRAP round tip>It may take a couple of minutes while it installs some files on the PiBot</WRAP> <WRAP box>{{ :pibot:lesson2:softwarewin:s7.png |VSCode Remote Connection}}</WRAP>
 +    - Click the "Open Folder" button\\ \\ <WRAP box>{{ :pibot:lesson2:softwarewin:s8.png |VSCode Open Folder}}</WRAP>
 +    - Select the "pibot" folder and click the "OK" button\\ \\ <WRAP box>{{ :pibot:lesson2:softwarewin:s9.png |VSCode Browse}}</WRAP>
 +    - Select the picar-line-tracking.py file in the list on the left\\ \\ <WRAP box>{{ :pibot:lesson2:softwarewin:s10.png |VSCode picar-line-tracking.py}}</WRAP>
 +  - 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?\\ \\ <WRAP round tip>If you don't remember what a variable is, review the description from [[:pibot:lesson1:softwarewin#software_explanation|Lesson 1]]</WRAP>
 +  - 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?\\ \\ <WRAP round tip>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.</WRAP> <WRAP round tip>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'.</WRAP> <WRAP round tip>See the [[:pibot:lesson2#electrical_description|Electrical Description]] section on the previous page for a description of how the sensors work</WRAP>
 +  - Find the other places in the code where the "If" statements are used. What do you think is happening with those "If" statements?\\ \\ <WRAP round tip>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</WRAP> <WRAP round tip>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"</WRAP> <WRAP round tip>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.</WRAP> <WRAP round tip>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?</WRAP>
 +  - Look at line 114 in the code. What do you think this line does?\\ \\ <WRAP round tip>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?</WRAP>
 +  - 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\\ \\ <code>python3 picar-line-tracking.py</code>
 +  - When you're finished testing out your changes type the following command in the terminal and press enter to shutdown the PiBot\\ \\ <code>sudo shutdown -h now</code>
 +  - 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]]
 +