Intro to Robots Lab 8. Intro to Robots Exercise 1: Follow the text’s suggestion and Google “color names list” Collect from the list a set of 25 colors.

Slides:



Advertisements
Similar presentations
First of all – lets look at the windows you are going to use. At the top you have a toolbar, with all your various tools you can use when customising your.
Advertisements

Getting Started with PowerPoint
Create a Simple Game in Scratch
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Drawing In One-Point Perspective
Create a Simple Game in Scratch
RAPTOR Syntax and Semantics By Lt Col Schorsch
Introduction to Computing Science and Programming I
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
Intro to Robots Lab 6: Robot Behaviours. Intro to Robots Further Braitenberg Vehicles: Timid: –Moves forward in a straight line –One threshold light sensor.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
TEKS 8.6 (A,B) & 8.7 (A,D) This slide is meant to be a title page for the whole presentation and not an actual slide. 8.6 (A) Generate similar shapes using.
Let's zoom in on one corner of the coordinate plane
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
INTRODUCTION TO SCRATCH. About Me Resources Scratch Website Learn Scratch Washington-Lee Computer.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Games and Simulations O-O Programming in Java The Walker School
GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
Testbed: Exercises.
Animation CSC 161: The Art of Programming Prof. Henry Kautz 10/14/2009.
In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.
GAME:IT Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
Step 2: Solve the 1st side/layer
Optical Manufacturing Solutions 1 FOLLOW THE DIRECTIONS BELOW AFTER INSTALLING A NEW CUTTER BODY WITH POLISHING WHEELS INTO THE 7E TYPE MACHINES. IT IS.
Chapter 2 - Algorithms and Design
> 1 Diagrams in Word Faculty of Health Alan Grace.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
SOLIDWORKS: Lesson II – Revolutions, Fillets, & Chamfers UCF Engineering.
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
PHY281 Scientific Java Programming LoopsSlide 1 Loops In this section we will learn how to repeat a series of instructions using loops and to use this.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
SKETCHING IN Pro/ENGINEER Part 1. Improved Intent Manager n Terminology –Entity, origin, constraint, reference, relation, parameter, weak dimension, strong.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
PowerPoint Practice Exercise 1 1.Save this file in your AV-TECH Folder as PowerPoint Practice Exercise 1. 2.Open this file in PowerPoint. 3.Edit each slide.
Design Studies 20 ‘Show Off’ Project How to make a computer monitor In Google Sketchup By: Liam Jack.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Learning PowerPoint Presenting your ideas as a slide show… …on the computer!
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Computer Programming Modeling a Passive Solar Home.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
Sight Words.
Good Morning! Friday, 12/10 Your “Modeling Transpiration” lab was scheduled to be turned in today. Hang on to them until Tuesday, I will collect them when.
Hyperstudio: A Beginner’s Tutorial By Judy Swaim.
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
Digipacks. Emily Batts. Front View.. TITLE – The title for this album is ‘Myth’. This is a mysterious name, and the colourings used are quite random as.
+ This step by step tutorial demonstrates drawing a keyboard illustration using rectangles, grids, move and transform effects.
Perspective Drawings Linear perspective is a geometric method of representing the apparent diminishing of scale as the distance from object to viewer increases.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Getting Started With Alice: The Basics. Step 1: Background Open up Alice, and choose a background for your Alice world. Your world is something you can.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Introduction to Scratch
Sound and more Animations
Create a Halloween Computer Game in Scratch
MOM! Phineas and Ferb are … Aims:
Scratch for Interactivity
Introduction To Repetition The for loop
What to do when a test fails
Java Programming: Guided Learning with Early Objects
Conditions and Ifs BIS1523 – Lecture 8.
An Introduction to VEX IQ Programming with Modkit
Module 2 Lesson 3 Over and Over Again
Go to =>
Unit 11 – PowerPoint Interaction
Chap. 3 Functions Start Python IDLE (Shell) and open a new file.
Module 2 Lesson 3 Over and Over Again
Module 2 Lesson 3 Over and Over Again
Creating a Simple Game in Scratch
Presentation transcript:

Intro to Robots Lab 8

Intro to Robots Exercise 1: Follow the text’s suggestion and Google “color names list” Collect from the list a set of 25 colors or so and in a new Python program put them in a list data structure. Write code that creates a graphics window and then loops through the elements of the colors list, changing the color of the graphics window background. colors = [‘DarkCyan’, ‘DarkGoldenRod’, …]

Intro to Robots Exercise 2: Follow up on Exercise 1 by doing the following –Add a point on the graphics window each time you change the background color. –Use some kind of systematic method of assigning the point coordinates like (i,i) and increment i each time you change the background color. The outcome will be something like:

Intro to Robots Exercise 3: In class we saw the code that draws the following picture. Extend this code to draw the following picture. Hint 1: Figure out what the four corner point coordinates will be. Hint 2: Use 4 loops

Intro to Robots Exercise 4: Add to the program in Exercise 3 by including the code to the loops that control the drawings of the lines. What behaviour do you get? wait(0.3) L.undraw()

Intro to Robots Exercise 5: Consider the Bouncing Circle program # Moving circle; Animate a circle... from myro import * from random import * def main(): # create and draw the graphics window winWidth = winHeight = 500 w = GraphWin("Bouncing Circle", winWidth, winHeight) w.setBackground("white") # Create a red circle radius = 25 c = Circle(Point(53, 250), radius) c.setFill("red") c.draw(w) # Animate it dx = dy = 3 main() while timeRemaining(15): # move the circle c.move(dx, dy) # make sure it is within bounds center = c.getCenter() cx, cy = center.getX(), center.getY() if (cx+radius >= winWidth) or (cx-radius <= 0): dx = -dx if (cy+radius >= winHeight) or (cy-radius <= 0): dy = -dy wait(0.01)

Intro to Robots Part 1: Modify the previous program so that each time the Circle is moved it leaves a Point at its previous center.

Intro to Robots Exercise 5, Part 2: After you draw the Circle, draw a rectangle in the middle of the Bouncing Circle window and color it yellow: Use the coordinates (200,100) and (300,400) Now rerun the program and notice that the ball moves behind the rectangle. R = (Rectangle(Point1,Point2)) # Point1 is the top left-hand corner # Point2 is the bottom right-hand corner (200,100) (300,400)

Intro to Robots Exercise 5 (cont): Modify the program so that the ball will bounce off the rectangle just like it bounces off the edge of the graphics window. Initially there are four situations to consider:

Intro to Robots Case 1: If the ball approaches the rectangle side whose coordinates are given below then the test for the program variables is: (200,100) (200,400) cx + radius >= 200 and cx – radius <= 300 and cy between 100 and 400 program code: ( (cx + radius >= 200) and (cx – radius = 100) and (cy <= 400)) (300,400) (300,100)

Intro to Robots Cases 2, 3 and 4: Evaluate the same expressions for the following three cases: Put this code into the original program and watch the circle move around the window.

Intro to Robots Exercise 5 (cont): If you implement this code you will see that everything works well except at the corners. In this case we can see that the test conditions fails. What part of it fails? (200,100) (200,400) ( (cx + radius >= 200) and (cx – radius = 100) and (cy <= 400)) fails:

Intro to Robots Exercise 5 (cont): In order for the circle to bounce off the yellow rectangle it must be inside the outer rectangle in one of the areas labeled A, B, C, D or 1 … 8. This is not enough however. In the areas labeled 4 and 5 the circle can inside the outer rectangle but still not be touching the inner rectangle. Variables: (cx,cy) - center of circle radius – radius of circle Inside outer rectangle condition: cx + radius >= 200 and cx – radius = 100 and cy – radius = 200 and cx <= 300 and cy <= 100 Inside B, C, D condition: ? Inside 1 condition: inside outer rectangle and not in A, B, C or D and cx <= 200 and cy <= 100 and 200 – cx <= 100 – cy Inside condition? Inside 1 and touching rectangle condition: inside 1 and (200 – cx) 2 + (cy – 100) 2 < radius 2

Intro to Robots Exercise 5 (cont): Modify your program to take these new conditions into account. The pseudocode is: if inside outer rectangle: if inside A: flip dy elif inside B: flip dx elif inside C: flip dy elif inside D: flip dx elif inside 1: if touching inner rectangle: flip dy elif inside 2: if touching inner rectangle: flip dx... ( 6 more cases) Added clear rectangle to see where Circle center is when Circle touches rectangle

Intro to Robots Exercise 5 (cont): A bug: Circle starts here entered area 2 are exited correctly entered area 8 and got “stuck” passed through area 8 ok back and forth, back and forth until it exits area 2

Intro to Robots Exercise 5, Bug Analysis: Each time we move the Circle we move it 3 pixels on the x-axis and 3 pixels on the y-axis. When we cross the line into the outer rectangle we flip either the x- or y- increment and the next move typically takes us back outside the rectangle. However this is not necessarily true in the corners... bouncing back we are still inside and so flip again; this keeps us inside until the end of the line

Intro to Robots Exercise 5, Bug Solution: When you enter the outer rectangle and flip either the x- increment or the y-increment you must not flip again until you have at least left the outer rectangle. Our problem here is that once too far inside the outer rectangle we stay there by flipping back and forth. Code Solution: Add a boolean flag to your program that gets turned on whenever you flip and only turned off once you leave the rectangle. Then don’t ever allow a flip to happen if the flag is turned on.

Intro to Robots Exercise 5, Bug Solution Pseudocode Exercise: Implement this pseudocode # outside while-loop turn flag off if inside outer rectangle: if flag turned on: continue # skips to top of while-loop if inside A: flip dy turn flag on elif inside B, C, D:... elif inside 1: if touching inner rectangle: # inside circular arc flip dy turn flag on elif inside 2, …, 8:... ( 6 more cases) else: # outside outer rectangle turn flag off

Intro to Robots Exercise 5 (one last time) Make the robot beep each time you flip the x- or y- increment. Make it beep differently if it is hitting the outside will than if it is hitting the rectangle.

Intro to Robots Exercise 6 (Sound): The human ear can not distinguish between sounds which are very close together. Execute the beep() command over a range of frequency values to determine your audible range. Execute the beep() command over a range of close-by frequency pairs to see how far apart the pairs need to be for you to distinguish the sounds beep(1,300), beep(1,400), beep(1,1000), beep(1,2000), … beep(1, 300), beep(1, 305), … beep(1, 1000), beep(1, 1010), beep(1, 440), beep(1, 441) …

Intro to Robots Exercise 7 (siren): A siren is two sounds repeated constantly. Find a good pair for sounds for a siren.

Intro to Robots Exercise 8: Musical Scale Data Structure In the past we have used the dictionary data structure to hold data that comes in pairs. Remember the englishToSpanish dictionary in Chap 1? Create a dictionary called notes with notes from 9 different octaves (from A0 to C8). These are the notes Scribbler is able to make. Method 1: Key in by hand. Method 2:: freqs = [‘C’, ‘C#’, D, ‘D#’, ‘E’, ‘F’, ‘F#’, ‘G’, ‘G#’, ‘A’, ‘A#’, ‘B’] notes = {} notes[‘A0’] = 27.5; notes[‘A#0’] = 29.14; notes[‘B0’] = 30.87; notes[‘C8’] = for i in range(7): j = 1 for f in freqs: notes[f+str(i+1)] = (notes[‘B0’])*2**(i+j/12.0) j = j+1

Intro to Robots Musical Notes: Google ‘musical note frequencies’ and compare what you find there with the numbers you have created with the code on the previous page.

Intro to Robots Exercise 9: Pick a simple song you remember and make your robot play your song. Remember that the robot can only play chords with two notes.

Intro to Robots Exercise 10: Working with another team in the lab, play a duet – one robot plays the treble clef and the other the bass clef notes.

Intro to Robots Exercise 11: Since our robot may at times need to express emotion you might find some short tunes that express –Determination –Sadness –Victory –Curiosity –Plodding along –Full steam ahead –Any other emotions that seem appropriate …

Intro to Robots Exercise 12: Write a function that will draw a maple leaf. Now cover a graphics window with maple leaves of different sizes (small, medium, large) and colors (red, yellow, orange). def mapleLeaf(anchor point, size, color, window):...

Intro to Robots Exercise 13: Draw the following robot using the function: Now use this function to draw the following picture. def drawRobot(anchor point, window):... def drawPyramid(window):...