Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore RoboGarden-Basics

RoboGarden-Basics

Published by bassem.abdullah, 2016-02-22 07:43:00

Description: RoboGarden-Basics

Search

Read the Text Version

Robot Can SeeOur robot could sense the within environment .it could measure distance ,sense colors , measure theamount of noise around , detect if he was touched , controlled using remote and measure the lightintensity .AbstractIn this chapter , We aims at introducing the robot with it's sensors . We mainly depend on InfraredSensor and Color Sensor . Which is more attractive and give indication that the robot could really see .We begins with simple example up to semi complicated example to digest the concept of controllingrobot sensors via programming .Objectives  Introduce robot motion to trainee .  Introduce the concept of sequential programming to Kids .  Introduce the concept of sensing and physical sensors .Example(1)In this Example we want to introduce how you can enable the robot to get colors and introduce colorsensor concept with an easy blocks .Visual Code Visual Program 1When you click \"Run\" you should see alert indicating the color .

Field Layout Field Layout 1Tips  Introduce the embedded system concept via the importance of enabling device before use .  Try To change the cell color and run the program again .Example(2)Plus getting Color , Robot can move and get color while moving . In this Example robot will move amongthe first column and print colors .Visual Code Visual Program 2When you click \"Run\" you should see alert indicating the color while moving .

Field Layout Field Layout 2Tips  Introduce the embedded system concept via the importance of enabling device before use .  Try To change the cell color and run the program again .Example(3)Robot Also can rotate across its asymptotic axis . In this Example robot will move Three cells then rotateand move two cells also .Visual Code Visual Program 3When you click \"Run\" you should see alert indicating the color while moving .

Field Layout Field Layout 3Tips  Introduce the embedded system concept via the importance of enabling device before use .  Try To change the cell color and run the program again .  Try to change the sequence of blocks and let the trainee see results .Example(4)Robot can also predict the approximate distance between it and the nearest front obstacle . Using IR(Infrared ) and US (Ultrasonic) Sensors .Visual Code Visual Program 4When you click \"Run\" you should see alert indicating the color while moving .

Field Layout Field Layout 4Tips  Introduce the embedded system concept via the importance of enabling device before use .  Try To change the place of the obstacle and observe results .Example(5)One could Combine motion , sensing color and distance , into a one big example where the robot whilemoving report color and distance .Visual Code Visual Program 5When you click \"Run\" you should see alert indicating the color while moving .

Field Layout Field Layout 4Tips  Introduce the embedded system concespt via the importance of enabling device before use .  Try To change the cell color and run the program again .  Try to change the sequence of blocks and let the trainee see results .  This example could be an assignment .



SelectionsIn this Chapter we will introduce an important concept in programming .AbstractDecision making structures require that the programmer specify one or more conditions to be evaluated ortested by the program, along with a statement or statements to be executed if the condition is determined to betrue, and optionally, other statements to be executed if the condition is determined to be false.Following is the general form of a typical decision making structure found in most of the programminglanguages:. Figure 1Boolean expressionHow do you compare two values, such as whether a radius is greater than 0, equal to 0, or less than 0?Java provides six comparison operators (also known as relational operators), shown in the followingtable, which can be used to compare two values (assume width is 5 in the following table).Operator Name Example Result< less than width < 0 False<= less than or equal to width <=0 False> greater than width >0 True>= greater than or equal to width >=0 True== equal to width ==0 False!= not equal to width !=0 True

Objectives  Student be aware of Selection statements .  be aware of enabling robot to take decisions .  Robot will be more intelligent as it could differentiate between different inputs .  Boolean expression introduction .Example(1)In this Example we want to introduce how you can enable the robot to get colors .and then let the robotbehave according to the color value .Visual CodePart (1) Visual Program 2Part(2) Visual Program 3Part(3) Visual Program 4

Field Layout Field Layout 3Tips  Introduce the concept of how (if condition controlled the behavior of code ) .  Try to change cell color to observe that the robot will change his behavior .Example(2)In this Example , The robot will detect that there is an obstacle in front of him and stop .Visual Code Visual Program 4

Field Layout Field Layout 4Tips  This example is the kernel of how intelligent systems avoid crashes .  try to change the place of obstacle and comment  place it one time near and another far .Example(3)In this example student should be able to choose between multiple decisions .Robot will find theobstace then move one step backward if he found it .Visual Code Visual Program 5

Field Layout Field Layout 3Tips This example is the kernel of how intelligent systems avoid crashes .  try to change the place of obstacle and commentExample(4)This example is same as the previous example plus adding a variable called distance .Visual Code Visual Program 6

Field Layout Field Layout 4Tips  Introduce the importance of variable for portability of code .  try to change the value from 10 to 20..30..40..50 .



Inputs & OutputsIn this chapter we would introduce how Mathematical operation are done , how user could enter valuesand how processing could be done on it .Example(1)it's very simple example where student could get into how to get value and process it and out the result.Input : \"Omar\" .Output : Omar , Welcome to RoboGarden.Visual Code Visual Program 5Example(2)The previous processing was adding text only , a simple adder example could be useful here .Visual Code Visual Program 2

Example(3)Processing also could be more advanced than mathematical , taking decisions also is supported herelet's try .Visual Code Visual Program 3



LoopsIn this Chapter we will introduce an important concept in programming (Loops), Loops is the secondedge of how to fully control the flow of your code .AbstractSuppose that you need to move 5 cells . It would be tedious to have to drag the \"Move One Cell \" Blockfive times .So, how would you solve this problem?Programming provides a powerful construct called a loop that controls how many times an operation ora sequence of operations is performed in succession. Using a loop blocks , you simply tell the robot torepeat a specific behavior hundreds of time .The following figure describes the execution of loops . Figure 2Objectives Student be aware of Loops statements . Student should much control the behavior of robot . Student should be able to imagine how complicated algorithms are doing so .

Example(1)In this Example we want to introduce how you can enable the robot to get colors from multiple cellswithout repeating lines of code .Visual Code Visual Program 1Field Layout Field Layout 5Tips  Introduce the concept of repetition .  Try to change cell colors and observe the output .  Compare of doing so with loops and without .Example(2)If the robot went from origin to the green cell , it would be intelligent , Using combination of Selectionsand Loops ,Student could do so .

Visual Code Visual Program 2Field Layout Field Layout 6Tips  Try to change the field construction into the following and observe how intelligent the robot becomes . Field Layout 7 Field Layout 8

Example(3)Increasing the complexity of the field will make the mission difficult , and show us how programmingand robot can combine to form unbeatable team .Visual Code Visual Program 3Field Layout Field Layout 5



FunctionsYou are reaching too damn high numbers of lines of code that make me extremely irritated .Any small change you make will affect the whole code , you cannot debug easily .Your code is not scalable and extremely unreadable and hard to be understood .We will present one of the most important concepts of programming modularity .Modularity is how to divide your code into cooworking segments .These Segments are known as Segments .AbstractIn programming, a function is a segment that groups code to perform a specific task.Sometimes it's called Methods .You might think of methods as employees that work under you. As a programmer, you write code.However, if you need to rewrite a piece of code many times in different places with some minormodifications, you would normally have to do it yourself. Methods are there to help you. You can writea method that can do a certain task and you can call it whenever you need this task done. Methods arealso customizable, you can pass arguments to methods to specify the exact required behavior.Types of functions  no-return function Sometimes called \"Void\" , this function performs specific task but have a result to return  return function this function performs a task and returns the result .Objectives  Student be aware of Modularity Concept .  Student should develop more readable code .  Student should be aware of the difference between types of functions .Example(1)In this Example We will Introduce a basic two functions . Where student could getting started withfunctions .

Visual CodePart (1)Function DeclarationMain Program Visual Program 1 Visual Program 2Part (2)Function DeclarationMain Program Visual Program 3 Visual Program 4

Tips  Introduce how to divide tasks.  Student should state whether there are return value or not .  Student should where and how we used argument of (noOfCells ).  Does enable should be put inside or outside function . Visual Program 5Example(2)In this Example Student should be aware of that he could take decisions inside the function structure .Visual CodeFunction Declaration Visual Program 6

Main Program Visual Program 7Tips  Introduce how to divide tasks.  Student should state whether there are return value or not .  Student should where and how we used argument of (getColororNot ).  Does enable should be put inside or outside function . Visual Program 8Example(3)In this Example Student should be aware of that he could combine loops with functions and decisions ,introduce variables and how he could manipulate it for efficient and optimum code .

Visual CodeFunction Declaration Visual Program 9Main Program Visual Program 10Field Layout Field Layout 9Tips  Introduce the concept that functions call is a simple instruction .  Introduce how to divide tasks.  Student should state whether there are return value or not .

Example(4)In this example we are introducing the another types of tasks the return a value .Visual CodeFunction DeclarationMain Program Visual Program 61 Visual Program 12Field Layout Field Layout 10

Tips  Introduce the concept that functions call is a simple instruction .  Introduce how to divide tasks.  Student should state whether there are return value or not .



Advanced FunctionsIn this chapter we want to get with student to more complicated code in order to be able toObjectives  Student should master coding .  Student should combines structure of coding easily .  Student should be able to combine loops, selections functions to do more complicated tasks .Example(1)Student should write a code that enables him to detect obstacles and shoot them with a ball .Visual CodeFunction Declaration Visual Program 1Main Program Visual Program 2

Field Layout Field Layout 11Tips  Introduce how to divide tasks.  Student should be able to combine multiple loops inside each other .Example(2)In this example student could do complicated task in one command only . robot is required to find thegreen cell .Visual CodeFunction Declaration Visual Program 3

Main Program Visual Program 4 Visual Program 5Field Layout Field Layout 12Tips  Multiple functions in one program .  Parent and child functions .  One program could be done with two students .

Example(4)IR remote command executes immediately upon invocation and return None if no button is pressed .Suppose we want to wait for button pressed ???this multistage example shows this could be done.Stage (1)Visual Code Visual Program 6Field Layout Field Layout 13In this stage you should press the button you want before communicating !!

Stage (2)Visual Code 0 Visual Program 7Field Layout Field Layout 14In this stage robot will respond to your press anytime you do so, but if you needto use this segment of code many times it's not feasible to rewrite all this blocks.. So what you can do is to use functions . !!

Stage (3)Visual Code Visual Program 8Field Layout Field Layout 15In this stage \"waitForButtonPressed\" block is used whenever and wherever youwant to wait for a press .It's all about using functions .



ArraysIn this chapter we will introduce the concept of arrays , grouping data together .Objectives  Student be aware of Grouping Concept .  Student should realize the benefit of Arrays (Lists) .  Student should gain the sense of data structure .AbstractArrays or Lists could be considered as a container of data of similar type . 246 8The above table is an example for array of numbers .In RoboGarden Garden they have this shape . Visual Program 7Where myList is name of the array .Example(1)In this example we will introduce a simple print operation with lists .Visual Code Visual Program 1

Tips  Ask student to carry out the same above task without lists . Visual Program 8  Ask every two students to carry out a program that prints odd numbers between (0-10).Example(2)In this example we will use lists to store the color values of first column cells .Visual CodeVisual Program 6 Visual Program 9Tips  Introduce how to store data .  The student should realize that arrays is a storage area .  The student should be aware of getters and setters of array element .

Example(3). In this example , Student learns how code or \"Shafra\" works , how advanced motors receives it's signals. We want the robot to go from origin to the green cell without passing by red cell /using arrays .Visual Code Visual Program 10Field Layout Field Layout 16Tips  Introduce the concept that functions call is a simple instruction .  Introduce how to divide tasks.  Student should state whether there are return value or not .

Example(4)In this Example we want to get form the child where will the robot be after execution .Visual CodeFunction Declaration Visual Program 11Field Layout Field Layout 17



ApplicationsIn this chapter we are going to introduce some applications that could be solved with programming .Objectives  Student should master sequential programming .Example(1)In this example we want to tell how password application is done .Combination between I/o and Selections .Visual Code Visual Program 1Tips  Ask student to change the password to his name .  Ask student to add an infinity loop .

Example(2)In this Example we want one code that could do all the following missions .(reach the green cell ) Mission 1 Mission 2 Mission 4 Mission 3Visual Code Visual Program 2

Example(3)In this example we want the robot to maintain his position regarding obstacle , whatever the place ofobstacle has changed .Visual Code Visual Program 12Field Layout Field Layout 18



Robot can ActIn this chapter we are going to introduce some applications that could be solved with programming .thisis more applications that introduces the importance of programming in solving problemsObjectives  Student should master sequential programming .  Student should be able to divide big problem into small problems to be solved .Example(1)In this problem we want to learn how advanced Automated transportation management system worksby following line .We need to reach the black cell passing by all colored cells following the line between between anycolored cell and adjacent white one .Visual Code Visual Program 1

Field Layout Field Layout 19Tips  Ask students to change the order of the field .Example(2)A mission for the robot is to grip 3 wheels from the green cell and put them in the yellow cell , Then goback to the original place began from . Field Layout 20


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook