Click the magnifying glass in the top right corner of the screen and type “terminal” to find the terminal app
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!
ssh pi@pibot##.local
cd ~/pibot
wget http://osoyoo.com/driver/picar/picar-line-tracking.py
A set of 5 digits will start scrolling along the screen. These represent the status of each line sensor that the PiBot is “seeing”
python3 picar-line-tracking.py
exit
If you don't remember what a variable is, review the description from Lesson 1
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 Electrical Description section on the previous page for a description of how the sensors work
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?
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?
python3 picar-line-tracking.py
sudo shutdown -h now