roboticsandcoding.files.wordpress.com€¦  · web viewwriting programs. when you write a program...

12
Writing programs When you write a program for your Edison robot in EdScratch, you are writi ng the instructions that will tell the robot what to do and in what order to do each thing. Each EdScratch block is one action you are telli ng the robot to take. The order in which you connect the blocks together in your program tells the robot in what sequence to do each action. Edison will do the actions in order, one at a time, starting with the top block. Look at this EdScratch program: All EdScratch programs need to have the yellow Start block at the very top. This lets the robot know that the program starts with the first block below the Start block. Read each line block by block, starting with the top block below the Start block. If you download this this program to the Edison, what will the Edison do? Self-walking pet Bugs and debugging The bug box in the EdScratch programming environment is a special feature to help you find and fix any bugs in your code. The warning messages that appear in the bug box are there to give you information about any problems or potential problems in your code. These messages are EdScratch's way of saying that there is an error in your code, or,

Upload: vohanh

Post on 29-Aug-2019

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: roboticsandcoding.files.wordpress.com€¦  · Web viewWriting programs. When you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell

Writing programsWhen you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell the robot what to do and in what order to do each thing. Each EdScratch block is one action you are telling the robot to take.

The order in which you connect the blocks together in your program tells the robot in what sequence to do each action. Edison will do the actions in order, one at a time, starting with the top block.

Look at this EdScratch program:

All EdScratch programs need to have the yellow Start block at the very top. This lets the robot know that the program starts with the first block below the Start block.

Read each line block by block, starting with the top block below the Start block. If you download this this program to the Edison, what will the Edison do?

Self-walking pet

Bugs and debuggingThe bug box in the EdScratch programming environment is a special feature to help you find and fix any bugs in your code. The warning messages that appear in the bug box are there to give you information about any problems or potential problems in your code. These messages are EdScratch's way of saying that there is an error in your code, or, that you might find an error when you run your program in Edison. In coding, there are two main types of errors: syntax errors and logical errors. Syntax errors: are caused by problems in how you wrote the code which break the rules of the language. These errors are sort of like typos or spelling mistakes in writing.

Page 2: roboticsandcoding.files.wordpress.com€¦  · Web viewWriting programs. When you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell

Logical errors: are problems with the logic of a program. Logical errors are basically problems with the way of thinking in a program. Programs that do not make sense to the computer and programs that ask a computer to do something that it cannot do are examples of logical errors. If a program works differently than you expected it to work, there is a good chance that there's a logical error somewhere.

Page 3: roboticsandcoding.files.wordpress.com€¦  · Web viewWriting programs. When you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell

Doodle-bot challenge

Dance party

PseudocodeWhat is pseudocode? Pseudocode is a way of writing out a program in a simple, easy to read format. Instead of worrying about syntax, pseudocode uses normal words to describe what the program will do. Pseudocode looks a bit like a simplified program language, but it isn’t based on any specific program language. That’s why pseudocode can be used to plan programs in any coding language.

When you plan out your program using pseudocode, you don't need to write everything out in detail or worry about exactly how it will end up looking when you code it. You just need to write a simple version of your plan that makes it easy to follow the flow of the program.Here's an example of some pseudocode for a driving program for Edison:

Drive forwardTurn left

The pseudocode outlines the basic plan but doesn't include all of the details. Those get worked out later when you code the program. Here’s the program that the pseudocode translated into:

Do you see how the basic plan from the pseudocode translated into the program?

Writing out a plan in pseudocode first makes it easy to get the structure of your program worked out. You can then adjust it and fill in the details when you write the code.

Page 4: roboticsandcoding.files.wordpress.com€¦  · Web viewWriting programs. When you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell

To make you’re pseudocode easy to read, you should keep it neat. Write your pseudocode so that it flows the same way the code will when you program it in EdScratch. That means you should write each step one after another, line-by-line.

Using pseudocode is especially helpful to plan programs that use control structures like loops or conditionals. You should indent actions that are inside of loops or conditionals to show that this code is inside of the loop or 'if' statement. Organising your pseudocode in this way makes it a lot easier to understand.

Here is an example of some pseudocode describing a clap-controlled driving program and the corresponding program in EdScratch:

Now try writing your own Code.

Page 5: roboticsandcoding.files.wordpress.com€¦  · Web viewWriting programs. When you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell

Messaging with EdisonTo use messaging with Edison robots, you always need at least two robots, one to send out the IR messages and one to detect and to react to the IR messages. For this activity, you need a partner or a group. One robot is going to send out a message. All other robots need to wait until they detect a message, each robot should react by dancing.

To send a message you will need this block:

Spider trapWrite a program in edscratch that will get Edison to drive in an inward spiral shape. Edison should drive, then turn then repeat over and over spiralling inwards. Your program should use a variable to help you control how far the Edison drives each time.

Page 6: roboticsandcoding.files.wordpress.com€¦  · Web viewWriting programs. When you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell

Exploring using variables with sensor data

Write the program in edscratch, then download it to your Edison and test it out.

Next we are going to write a program that gets the Edison to behave like a 400 meter runner, increasing speed as the robot passes black lines on a course. Your program should use Edison’s line tracking sensor and a variable to help count how many lines the robot has encounted.

Page 7: roboticsandcoding.files.wordpress.com€¦  · Web viewWriting programs. When you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell

Flag machineThe goal of this activity is to build and program a flag machine that you can use to help makestudying for a test more fun. You will need to work with a partner for this activity and use two Edison robots. One robot will be the flag machine which will have a two-sided flag with the word 'Yes' on one side of the flag and the word 'No' on the other side. This 'flag machine' robot will receive messages. The other robot will be the controller bot that will send out the messages.

The controller bot program:

The flag bot program:

Page 8: roboticsandcoding.files.wordpress.com€¦  · Web viewWriting programs. When you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell

Play a song in a round

Once you chose your song, you will need to program each robot to play it. Each robot’s program will be a little bit different as you need each robot to wait until the right time to join in the round.

Page 9: roboticsandcoding.files.wordpress.com€¦  · Web viewWriting programs. When you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell
Page 10: roboticsandcoding.files.wordpress.com€¦  · Web viewWriting programs. When you write a program for your Edison robot in EdScratch, you are writing the instructions that will tell

Each of your performer bots' programs needs to check for an IR message, then store the value of that message as a variable. Depending on the value of that variable, the performer bot should either start playing or just clear the data and go back to waiting for its IR message.Use your plan to help write a program for each of your performer bots.You also need to program the conductor bot using your plan as a guide. Remember, your conductor bot will also need to check for an IR message, then store the value of that message as a variable. Depending on the value of the variable, the conductor bot will need to send out a different IR message to get the next performer bot to start.