Robot Can See Our robot could sense the within environment .it could measure distance ,sense colors , measure the amount of noise around , detect if he was touched , controlled using remote and measure the light intensity . Abstract In this chapter , We aims at introducing the robot with it's sensors . We mainly depend on Infrared Sensor 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 controlling robot 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 color sensor concept with an easy blocks . Visual Code Visual Program 1 When you click 'Run' you should see alert indicating the color .
Field Layout Field Layout 1 Tips 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 among the first column and print colors . Visual Code Visual Program 2 When you click 'Run' you should see alert indicating the color while moving .
Field Layout Field Layout 2 Tips 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 rotate and move two cells also . Visual Code Visual Program 3 When you click 'Run' you should see alert indicating the color while moving .
Field Layout Field Layout 3 Tips 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 4 When you click 'Run' you should see alert indicating the color while moving .
Field Layout Field Layout 4 Tips 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 while moving report color and distance . Visual Code Visual Program 5 When you click 'Run' you should see alert indicating the color while moving .
Field Layout Field Layout 4 Tips 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 .
Selections In this Chapter we will introduce an important concept in programming . Abstract Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, 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 programming languages:. Figure 1 Boolean expression How 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 following table, 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 robot behave according to the color value . Visual Code Part (1) Visual Program 2 Part(2) Visual Program 3 Part(3) Visual Program 4
Field Layout Field Layout 3 Tips 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 4 Tips 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 the obstace then move one step backward if he found it . Visual Code Visual Program 5
Field Layout Field Layout 3 Tips This example is the kernel of how intelligent systems avoid crashes . try to change the place of obstacle and comment Example(4) This example is same as the previous example plus adding a variable called distance . Visual Code Visual Program 6
Field Layout Field Layout 4 Tips Introduce the importance of variable for portability of code . try to change the value from 10 to 20..30..40..50 .
Inputs & Outputs In this chapter we would introduce how Mathematical operation are done , how user could enter values and 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 5 Example(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 here let's try . Visual Code Visual Program 3
Loops In this Chapter we will introduce an important concept in programming (Loops), Loops is the second edge of how to fully control the flow of your code . Abstract Suppose that you need to move 5 cells . It would be tedious to have to drag the 'Move One Cell ' Block five times . So, how would you solve this problem? Programming provides a powerful construct called a loop that controls how many times an operation or a sequence of operations is performed in succession. Using a loop blocks , you simply tell the robot to repeat a specific behavior hundreds of time . The following figure describes the execution of loops . Figure 2 Objectives 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 cells without repeating lines of code . Visual Code Visual Program 1 Field Layout Field Layout 5 Tips 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 Selections and Loops ,Student could do so .
Visual Code Visual Program 2 Field Layout Field Layout 6 Tips 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 programming and robot can combine to form unbeatable team . Visual Code Visual Program 3 Field Layout Field Layout 5
Functions You 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 . Abstract In 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 minor modifications, you would normally have to do it yourself. Methods are there to help you. You can write a method that can do a certain task and you can call it whenever you need this task done. Methods are also 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 with functions .
Visual Code Part (1) Function Declaration Visual Program 1 Main Program Visual Program 2 Part (2) Function Declaration Visual Program 3 Main Program 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 5 Example(2) In this Example Student should be aware of that he could take decisions inside the function structure . Visual Code Function Declaration Visual Program 6
Main Program Visual Program 7 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 (getColororNot ). Does enable should be put inside or outside function . Visual Program 8 Example(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 Code Function Declaration Visual Program 9 Main Program Visual Program 10 Field Layout Field Layout 9 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 .
Example(4) In this example we are introducing the another types of tasks the return a value . Visual Code Function Declaration Visual Program 61 Main Program Visual Program 12 Field 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 Functions In this chapter we want to get with student to more complicated code in order to be able to Objectives 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 Code Function Declaration Visual Program 1 Main Program Visual Program 2
Field Layout Field Layout 11 Tips 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 the green cell . Visual Code Function Declaration Visual Program 3
Visual Program 4 Main Program Visual Program 5 Field Layout Field Layout 12 Tips 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 6 Field Layout Field Layout 13 In this stage you should press the button you want before communicating !!
Stage (2) Visual Code 0 Visual Program 7 Field Layout Field Layout 14 In this stage robot will respond to your press anytime you do so, but if you need to 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 8 Field Layout Field Layout 15 In this stage 'waitForButtonPressed' block is used whenever and wherever you want to wait for a press . It's all about using functions .
Arrays In 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 . Abstract Arrays or Lists could be considered as a container of data of similar type . 2 4 6 8 The above table is an example for array of numbers . In RoboGarden Garden they have this shape . Visual Program 7 Where 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 Code Visual Program 6 Visual Program 9 Tips 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 10 Field Layout Field Layout 16 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 .
Example(4) In this Example we want to get form the child where will the robot be after execution . Visual Code Function Declaration Visual Program 11 Field Layout Field Layout 17
Applications In 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 1 Tips 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 3 Mission 4 Visual Code Visual Program 2
Example(3) In this example we want the robot to maintain his position regarding obstacle , whatever the place of obstacle has changed . Visual Code Visual Program 12 Field Layout Field Layout 18
Robot can Act In this chapter we are going to introduce some applications that could be solved with programming .this is more applications that introduces the importance of programming in solving problems Objectives 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 works by following line . We need to reach the black cell passing by all colored cells following the line between between any colored cell and adjacent white one . Visual Code Visual Program 1
Field Layout Field Layout 19 Tips 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 go back to the original place began from . Field Layout 20
Search