Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
I can implement the basic constructs of programming languages such as variables, conditionals, loops, and flow control.
I can make a class wrapper that inherits from a library's class.
I can call a method from a library.
You will be submitting Trinket.io scripts demonstrating the following skills.
Class 1/24 Turtle drawing assignment:
Loops and functions allow skilled programmers to make more efficient code that's easier to maintain.
A for loop has an iterator and a collection that it traverses.
A function has a definition that lists any parameters and has a code block underneath that gets activated when called.
In the example above, the magic_spell
function isn't a part of a Class. It's on its own. If that ability was a part of a player in a game, we'd call it a method instead of function.
We're going to jump into work with a lot of advanced concepts. This is intentional. New programmers are very often intimidated by code they don't understand. I want you to get used to that early on. Enjoy tinkering with a few lines here and there and see how things change. Get comfortable swimming in the deep end.
This class (inherits) from the Turtle class which is available since we imported the turtle library. Instead of writing from turtle import Turtle
I could have also written just import turtle
in which case every time I wanted to use the Turtle class, I would have had to specify the library, such as turtle.Turtle()
The only thing that our SuperTurtle
does that the regular Turtle doesn't is the way it gets constructed. When a new Turtle is created or instantiated, we initialize or __init__
with some default properties.
Follow along as we go over a couple of skills. You aren't expected to be able to do this stuff yourself quite yet.
Make a loop and create a bunch of turtles
Add a new method to the turtle to make it go to a random location and call that method in the constructor
Make a list of colors and make each turtle randomly select a color
Make an empty list and add each turtle to the collection as it's being instantiated
Loop through the turtle collection and modify each
We'll spend some time experimenting with this code, learning by modifying existing code.
Experimenting with code given to you is fun and can be very helpful, but let's slow things down now and build some basic skills. Your Trinket.io app should look something like this:
A method or function is a group of commands that can be called. If I tell you to please clap, that's me activating or calling the command that's already defined in your head. I may give you additional parameters or arguments like, "clap 5 times loudly". In Python that may input("What's your name?")
but that doesn't save the variable, so we write it as:
name = input("What's your name?")
written as joe.clap(5, "loudly")
They both start with def
and will execute their pre-programmed commands when called. However, we'll refer to a function as something floating outside of a class and a method as an ability built within an object. For example, a method would be if an instance of the Human class, let's call him Joe, had to sneeze: joe.sneeze()
. But a function would be an anonymous helper like therancolor()
function programmed above that just returns a random string in a list of colors.
Look at the documentation, other student examples, and Google searches to modify open-source code and customize your own design. You can use one or many turtles but the end result has to have multiple colors over a fun design.
Let's make our app more interactive. Just like the print("message")
function we've been using, there's another one that takes a string input called input()
input("What's your name?")
will work but that doesn't save the user's response anywhere. So let's create a variable that will store the answer in this example:
name = input("What's your name?")
To make sure we are asked the question over again, we'll put the input within a while True:
loop.
In order to complete the Wordle program, there are a few things you need to add:
Make a new method in GamePlay.py which can be called during process_input() with different colors in the different letter situations. Keep your code D.R.Y. (4 points)
Complete the check_game_end() method in Gameplay.py and implement checks throughout your game. Make sure the game actually ends -- remember we have a boolean which controls the end of the game in main.py. (4 points)
Make sure your settings variables are all implemented within your program (for example: when you change background value to a different color, it actually makes the change in your program). (2 points)
Add a minimum of twenty 5 letter words to your word list. (1 point)
Clean up your code. Get rid of methods or imports you didn't use. (1 point)
What are the parts that make up a typical computer? Let's take one apart, label its components and talk about what each does.
I can disassemble and reassemble a computer.
I can describe the function of basic PC components.
You will be asked comprehension questions to identify parts of a computer from their images, what their primary purpose is, and what their common problems are
You will be observed disassembling and reassembling a computer and checked that you can identify all the components and that you can reassemble the machine correctly
Imagine a person juggling while singing an old song from their childhood. Part of the juggler's brain is tracking the motion of each ball and the timing of each throw. Another part of the juggler's brain is recalling the song. His stomach is fueling his muscles. His nervous system is communicating controls from his brain to his arms. His eyes are taking in information. His voice is outputting the song. We'll use this as a reference as we go over hardware.
CPUs or processors do math. They are a super complex series of logic gates made unbelievably small. What are logic gates? Imagine a wire with two light switches in a row. Since both switches are on the same wire, both need to be flipped to the ON position in order for power to flow through the line. That's an AND gate. If the wire split into two instead and each fork had its own switch, that would be an OR gate as only one or the other has to be enabled for power to flow. Processors have millions and millions of these complex arrangements made in microscopic sizes.
According to our analogy, the CPU is the part of the juggler's brain that's calculating the path of each ball while also managing all the other signals through his brain. It doesn't cover all the functions of the brain in our analogy, but it is at the center of the comparison.
CPUs use a lot of power and generate heat. Metal wires create a little resistance as electricity flows through them and that energy turns into heat. You must manage the heat that gets created by your CPU using a fan or other cooling system. If your computer collects a lot of dust, it will insolate
If a CPU is older it means it could be generating more heat while executing fewer commands. And if the CPU is slow, that means it must be connected to a whole bunch of other parts that are older and slower too.
Create a Quizlet set and practice these terms
No one writes code totally from scratch. All programmers use a variety of preexisting systems that allow for easier development. We write code that interacts with other layers. That's an API or Application Program Interface. We can interact with our operating system, helpful resources or other apps.
The BIOS or Basic Input/Output System is firmware. It's something built right into your motherboard. It helps boot your computer up and gives something for the operating system to run off of.
The OS is a big deal. It serves as a vital intermediary between software and hardware. Instead of having to program every little operation for each device in our computer, we can just use the commands provided by the operating system.
The interpreter allows us to execute our written Python code. It's our interface with the Operating System which is in turn interfacing with our hardware.
Part of what makes Python so great are all the tools and frameworks available. Want to build a web application? Use Flask or Django and you'll be up and running in minutes. Do you want tools for data analysis? Machine learning? Robotics? There's an ocean of open-source tools ready to give your app superpowers.
In case you're curious and don't mind a little challenge, learn about the and how computer engineers have gotten around it.
Look through and read how the experts recommend you shop for components
A review of the basics of computing, programming and robotics. We'll build simple Python apps and play with Raspberry Pi's.
We program little turtles to dance on the screen then we play with real robot cars. Learning how to program is an awesome time. I love my job.
Computer Science may be intimidating but like any other field of study, you don't have to learn it all at once. We're skipping so much in this class. Don't worry about it. You'll have enough tools to figure out if you want to invest the time to learn the deeper, more challenging (and more powerful) stuff.
In any line of questioning, you can keep asking "Why?" Eventually, you just stop when you think you've learned enough. For example, you can legitimately claim you know how a car works (you put gas in, turn a key, etc) even if you're hopeless as a mechanic. You've got a different acceptable layer of abstraction than a mechanic claiming too that she knows how a car works. The inner-workings of a car engine may just be an abstract idea that you only broadly understand (something about spark plugs). The point: You can start learning really cool tech without having to shift your acceptable layer of abstraction too much. It'll be fun.
In order to understand basic computer programming, you will need to understand some of the components in your computer. If you understand the basic shape of the environment, the behavior of programming languages will have better context. You won't need to understand exactly how a processor works, but you'll need to know roughly how it fits into the picture so you can solve some common problems.
Best intro: https://www.codecademy.com/ (Python, git, Command Line)
Solid: https://sololearn.com
Hard, smart: https://app.codesignal.com/
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 several small Python apps 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 video deals with the following concepts: Functions, Variables, Operators and Conditionals
Class 1/4
Class 1/11
Class 1 / 20: User defined functions
class 1/24: for / while loops
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!
Conditionals control how the program flows based on input from the user (in an app) or sensors (on a robot.
I can connect replit to my github repositories
I can clone an existing repository, fork it, and extend the code to my own project.
You will submit a link to your GitHub repo.
You will create a game based on existing turtle classes
You will be asked regular comprehension questions about Python and Github.
Create an interactive turtle application of your own design. This can be a game or other interactive program, but it must use at least two of the three types of turtle classes we have outlined (moving turtle, keyboard turtle, clickable turtle).
3 pts - Program works without errors
3pts - Program uses two classes of turtle
3pts - Program is interactive. Users can DO something with the program.
1pts - Program is cleaned up (unused imports have been deleted, for example)
To finish off the superturtle app, we are going to add the following to our program:
Move the printing of the menu options to the helper function, but run it in main.py (2 points)
Add four_square to the menu options (you should have 1. add turtle, 2. star, 3. four square at this point) and make them execute when called. (2 points)
Add at least 3 new methods to the SuperTurtle class (whatever you want, but they should be obviously different than the things we wrote together.) Add the methods to the main menu and make sure they execute when called. (9 points)
Make sure you have a creative display! (2 points)
I can connect to my Raspberry Pi via SSH.
I can deploy an app to a Raspberry Pi.
I can compose a higher-ordered algorithm.
I can update code on my Raspberry Pi.
I can make short, descriptive commit messages.
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)
Visit the project and fork it
Open Replit and start a new project from github
Use your forked github project. You should now see your code on your editor. Explore student.py
and teacher.py
.
Use SSH (on Mac) or PuTTy (on Windows) to connect to your robot. Install PuTTy if it is not on your computer.
Open putty and enter the ip address of your robot. Click open.
login: pi
password: robots1234
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
Whenyou 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. This happens in the version control tab by typing in "What did you change" and hitting Commit & Push.
Now we'll remote control our robots using SSH. We'll use Linux commands to pull the updated code down from GitHub.
Open putty and enter the ip address of your robot. Click open.
login: pi
password: robots1234
Note: You will not see the password when typing. This is a security feature!
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.
If the servo wasn't mounted perfectly, the midpoint won't be 1500
. But that's rarely the case. We should adjust this magic number to fit your particular robot.
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
To shut down your robot, type: sudo shutdown now in the putty window.
Square
Dance
Add safe_to_dance() method which checks surroundings and only dances if it has enough space.
Move to wall and stop
Move to wall and turn around. Move forward again and repeat endlessly.
Move to box and go around it
Before moving around box, figure out which side of closer. If you are closer to the left end of the box, go around left. If you are closer to the right end of the box, go around to the right.
Write a move method which scans slightly to the left and right of the robot as it moves forward.
If it senses a wall straight ahead, it goes around to the closest side as above (put that move in it's own method)
If it senses a wall at the edges of the robot, swerve slightly to miss the wall (this swerve should again be in it's own method).
Coming soon.