I can connect to my Raspberry Pi via SSH.
I can deploy an app to a Raspberry Pi.
You will submit a link to your GitHub repo.
You will demonstrate your capacity to control your robot.
You will be asked regular comprehension questions about Raspberry Pis.
During our school's open house days, I setup a few GoPiGo robots that respond when visitors hold their hand in front of the sensors. We'll make our own version of this function. It's fun and an easy way for us to start responding to data from the ultrasonic sensor.
Power-up your robot and connect over SSH
Go to your project folder: cd PnR-Final
Launch Python: python
Import our file: import student
Instantiate our Piggy: p = student.Piggy()
Experiment with the sensor with p.dist()
Let's look at our menu and create a new option for open house. We'll keep checking dist()
and perform some sort of action when it returns a number too close
Before you start on your project to experiment with and grow your own navigational algorithm, let's go over a few helpful tricks.
Let's imagine a list of about twenty distance measurements:
[200, 210, 204, 3, 2, 7, 197, 221, 211, 1, 5, 5, 3, 205, 202]
How many obstacles do you think were found in this set of distance measurements?
Our GoPiGo's keep a list of 180 measurements, self.scan
, that corresponds to the servo's angle when taking measurements. Here's the starting code to count obstacles directly in front of the robot:
Let's try this out and see if it's accurate. Can you improve its accuracy?
Next, let's try to modify the method to get a 360 degree view of all the obstacles around our robot.
We've already experimented with self.wide_scan()
. We use that method to fill the self.scan
list with data. For example, self.scan[60]
is the distance found at the servo's 60 degree angle.
What's the distance at the midpoint of your robot?
We've also used the self.is_clear()
option to tell whether or not the space right in front of the robot is clear. Create a loop that keeps turning the robot until it's clear.
I can connect to my Raspberry Pi via SSH.
I can deploy an app to a Raspberry Pi.
You will submit a link to your GitHub repo.
You will demonstrate your capacity to control your robot.
You will be asked regular comprehension questions about Raspberry Pis.
This is a PCB with all the basic components found in a personal computer (PC)
I'll help you remote control (SSH) your robot.
sudo apt-get update
sudo apt-get upgrade
Ready to shut down? sudo shutdown now
Now that we've left the fun environment of Trinket.io, let's first build a practice project.
Now let's go to VS Code and clone your forked repo.
The URL we need is: https://github.com/YOUR-USERNAME/TurtleChase
Now let's add some new features together:
Add a button to change each player's color
Prevent players from traveling off the screen
Detect collision of players
Wire up some other SuperTurtle methods...?
Now let's commit and push our code.
We're going to take a tour of Python. You are expected to know generally what these things are, you're not yet expected to know how to use them. So no freaking out. We'll play around with some fun projects after a quick look around.
I can make a hello world app in Python.
I can differentiate between compile-time, run-time, and logic errors.
I can describe the basic constructs of programming languages such as variables, conditionals, loops, and flow control.
You will be answering comprehension questions about the layers supporting software execution.
You will be creating and submitting your first Python app using trinket.io
Let's go to trinket.io and build some simple stuff, starting with print("Hello, world")
We'll go over each of these concepts in greater detail. For now, let's skim over all the big topics.
The first thing we'll tinker with is declaring variables and storing information. Variables in Python are dynamically typed, meaning you can store one type of information in a variable and then switch it without any fuss. Other languages are more strict and don't allow such shenanigans.
We use math symbols for most common operations. But Python has some cool operators. Read!
Now we're switching from declarations and operations to control flow. Now we can direct the computer's train of thought (aka its thread).
This is how we repeat commands and iterate through a list or collection of items. Imagine you're using your hand to flip through posters at Walmart. Your hand selects each poster as it traverses the collection. That makes your hand the iterator as it is connecting with each object in the collection during the loop.
A function is a set of commands you can call. When activating this "magic spell" you can pass it parameters or ingredients.
This concept is pretty advanced. It's here as a reference point because exposure to these ideas is good (so long as you know that it's not something you need to master quite yet).
A class is how you can create your own objects. You can make an class serve as a single worker like a static library of mathematical operations or you can design your own object, like a Spaceship that can be spawned or instantiated into a game many times. It'll have its own instance variables like health and shield properties.
I can compose a higher-ordered algorithm.
I can update code on my Raspberry Pi.
I can make short, descriptive commit messages.
Your GitHub repo will be regularly reviewed.
You will demonstrate your capacity to control your robot.
You will be asked regular comprehension questions about Python and deployment.
Use the git: clone command and paste your GitHub url. You should now see your code on your editor. Explore student.py
and teacher.py
.
Remove the Piggy
folder if it's already there: rm -rf Piggy
Now we'll clone your project on the robot too with git clone https://github.com/YOURUSERNAME/Piggy
Change to your project folder: cd Piggy
Run the app: python3 student.py
You you make changes to your app and want to update the code on your robot, we first need to send the code from our computers to GitHub.
Now we'll remote control our robots using SSH. We'll use Linux commands to pull the updated code down from GitHub.
Make sure you're in the right folder: cd Piggy
Pull your updated code: git pull origin master
Run your app: python3 student.py
If it doesn't run, study the error.
We'll need to configure your class variables.
Sometimes one motor will perform faster than the other, giving the robot a noticeable veer. We can try to correct for this drift by adjusting the motor power.
Check out what commands are available from the API that's provided for you. These are the commands you're inheriting.
Your dance
method should read as close to regular English as possible. The nitty-gritty commands are all kept in the particular methods being called in your dance
algorithm. So your dance
method should just call a handful of moves. Within those moves, you'll use the specific motor commands below and get into the nitty-gritty of robot control.
deg_fwd(angle)
- how many degrees do you want your wheels to rotate? You need to pass the angle
turn_to_deg(angle)
- rotates to the given angle as calculated by the piggy's gyroscope
turn_by_deg(angle)
- turns relative to it's current heading. Positive values rotate right and negative rotate left
fwd
- powers on your robot to drive forward. You'll need to use self.stop()
to power off the motors
right
- by default, self.right()
will give the left motor 90% power and the right 0% which rotates right. You can use kwargs to adjust the power such as self.right(primary=90, counter=-90)
, which will spin the robot in place
left
- same as right but reversed.
back
- same as fwd but in reverse.
servo
- moves the servo (plugged into servo1) to the given value (use 1000 - 2000)
stop
- sets motor power to zero
read_distance
- returns the distance from the distance sensor (plugged into I2C port) in millimeters
get_heading
- returns the gyroscope's value
Visit the and fork it
Open and press CTRL + SHIFT + P
Use SSH (on Mac) or (on Windows) to connect to your robot
If the servo wasn't mounted perfectly, the midpoint won't be 1500
. But that's rarely the case. We should adjust this to fit your particular robot.