Author(s): <p>Gorazd Gec</p>
ABSTRACT
A computer is a device that allows us to solve a wide variety of problems: from the simplest calculation to controlling a space rocket. But how can we get a computer to do all of the above?. By writing appropriate programs for it. A program is nothing but a sequence of instructions to solve a particular problem. The computer executes the programs that we write for it. The word programming refers to the activity of writing programs. Due to the prevalence of computers and computing devices, programming is one of the key skills today.
In programming, we come across different principles: conditional statements, loops, event statements and various expressions. Learning these can be very tiring and difficult for some. Since most of the students have already encountered playing with Lego blocks while growing up, we decided to try to learn the basic principles by programming LEGO robots. First, we assembled a LEGO robot that will move (vehicle, animal, etc.). We attached some sensors to it (light sensor, touch sensor, ultrasonic sensor, etc.) with which we added intelligence to the robot. Then, using the LEGO robot programming software, we wrote a program that allowed the robot to move in certain situations (when touched, at a certain distance from an obstacle, in certain light, etc.). We used basic principles in the program and thus learned the basic principles of programming.
A computer is a machine that executes a sequence of commands (a computer program) given to it by a human. A computer program is therefore a mapping of a solution to a problem (eg how to write, edit and save text) into commands that a computer can execute. For each computer program, we must first have an idea, which must then be elaborated in more detail and then written down in one of the programming languages.
In computer programs, three basic principles of problem solving mainly appear - sequence, branching and repetition.
A sequence is usually the execution of steps, where they are executed sequentially in the order they are specified.
Branching allows us to perform an alternative sequence of steps given a certain execution condition.
Repetition (Eng. iteration) is used if the execution steps in the process must be repeated several times with the same or similar execution data.
We will learn how to develop a simple program while learning about variables, basic data types, ways to direct a program, and the use of loops to automate repetitive processes.
Programming is therefore writing computer programs with which we solve problems. But this is not always easy. Therefore, we will tackle programming through a game using a LEGO robot [1].
“Few programmers are compared to artists, even though programming is an extremely creative job. It is creativity based on logic”.
A computer is a device that allows us to solve a wide variety of problems - from the simplest calculation to controlling a space rocket. Today, we actually do much more with computers than just solve problems, namely edit texts, search for a wide variety of information, communicate, educate ourselves, correspond, have fun, make phone calls (yes, even the devices you carry in your pocket are actually computers!) ... It is difficult to find an area where computers have not yet intervened.
How can we get a computer to do all of the above (and more)? By writing appropriate programs for it. A program is nothing more than a sequence of instructions for solving a specific problem [2]. The computer executes the programs that we write for it. The word programming refers to the activity of writing programs. Due to the prevalence of computers and computer devices, programming is one of the key skills today [3].
Computers are reliable - they will always execute every program the same way. Unlike us, they don’t get tired. However, they are also relatively “dumb” as they require extremely precise instructions.
A program is a set of logically connected commands, instructions that tell the computer how to process certain data in order to solve a problem [4]. A simple definition of programming is writing related commands, instructions that actually tell the computer how to process certain data. Programming creates a program. Through the game using the LEGO Mindstorms software, we will create programs and thus familiarize ourselves with the basic concepts of programming.
The algorithm represents a list of instructions for performing a task [4]. In the algorithm, we define a sequence of actions (or procedures) over the data to achieve the desired result (in our case, we grab the desired object). If we want the computer to solve the task, we must write the algorithm precisely and unambiguously enough so that it can solve it with the commands available to it. We have to anticipate all possible situations (e.g. for the previous example we should anticipate the possibility that the chair is in another room that can be reached by stairs). The algorithm must therefore uniquely define the final sequence of actions to achieve the desired goal.
The algorithm can be written in different ways. Since the steps of the algorithm are instructions, their description usually differs depending on the areas of life in which we use this algorithm. In general, the algorithm can be given orally or in writing.
One of the possibilities of presenting the algorithm is in the form of a flowchart with action rectangles (or other symbols) connected by arrows [5]. The arrows indicate the sequence of actions to be performed.
Flowcharts allow a graphical representation of the execution of individual parts of the program (commands, subroutines, program code segments). We use them mainly in cases where we want to clarify with the client of the program whether our algorithm meets the wishes of the client. Most people find it easier to understand the steps of a process from a drawn picture than to write a text that is several pages long to explain the process.
Figure 1: LEGO Mindstorms
The LEGO Mindstorms package consists of Lego bricks for constructing robots, an intelligent cube that houses the computer and power supply that drive the robots, and various sensors. LEGO robots are programmed using LEGO Mindstorms software. An older version of the tool that we also used is called LEGO Mindstroms NXT version 2.1.
The basis of the LEGO Mindstorms package is the so-called. i. an intelligent cube that houses the computer and power supply that drive the robots. It also has a high-resolution screen, a USB port and an SD memory card reader, and it can communicate wirelessly with a computer or mobile device via a bluetooth transmitter.
Figure 2: An Intelligent Cube with Connected Motors and Sensors
The lego mindstorms intelligent cube has three servo motors and touch, light, sound and distance sensors connected.
There are various sensors in the basic package, the most interesting of which are the light sensor, the touch sensor and the ultrasonic sensor. The RGB sensor, which detects different colors, is also very useful.
To program the robot, we used the LEGO Mindstorms NXT 2.1 program, which uses different types of blocks for programming:
We write the program by selecting the type of block and inserting the appropriate block at the beginning of the program. The other blocks are added one by one to create a program that is then transferred to the intelligent cube that makes up the robot. The program is then run on the cube and the robot is set in motion.
Figure 3: The basic Window for Writing Programs for the Robot
Showing the Main LEGO Mindstorms NXT Robot Programming Window.
As an example, program, we have chosen a touch sensor, an ultrasonic sensor and two motors. We connected everything to the intelligent cube according to the following scheme.
Figure 4: Connection Diagram of Motors and Sensors
Two servo motors were connected to inputs B and C on the intelligent cube, and sensors to inputs 1 (touch sensor) and 4 (ultrasonic sensor).
The motors are connected to terminals B and C. The touch sensor is connected to input 1 and the ultrasonic sensor to input 4.
The final program looked like this:
Figure 5: The Final Program for the Robot Final robot program with all associated blocks.
At the beginning, we have a decision block (touch sensor), and then, in case of touch, a loop that repeats itself four times. In the loop we have a sequence of a new decision block (ultrasonic sensor) and a normal motor control block. The entire program controls the robot according to the following scenario - upon touching the touch sensor, the robot starts to move. Turn the motor until the robot approaches the obstacle less than 30 cm, then turn the robot 180 and repeat the whole thing four more times. Then the robot stops.
The flow chart for the entire program looks like this:
Figure 6: Flow Chart for the Complete Program for the Robot
The final robot program diagram contains start and end blocks, decision blocks and event blocks.
In the program, we used the basic principles of programming - sequence, branching and repetition. The students learned about these principles in a simple way and will understand them more easily when programming in a certain programming language.
Programming is not easy to learn, as it requires abstract thinking, mathematical skills, problem-solving skills, and knowledge of a programming language and programming tools, which is why learning programming through play is all the more desirable.
We achieved this by using legos - specifically a LEGO robot and by writing instructions for it. With a simple user interface, we gave instructions to the robot to move (turn the motors), react to certain conditions (different sensors) and stop. In this way, we learned the basic principles of programming - sequence, branching and repetition. Writing a program for a LEGO robot was similar to creating a flowchart, which is used to write down an algorithm that is a solution to a problem in the form of instructions and is the basis of a computer program.
The students were happy to work on a project that they will be able to use at home. Some have already bought the kits and are diligently using the knowledge gained in the project at home. Programming will therefore be more interesting and easier to understand for some students in higher years.
Short Presentation of the Author
Gorazd Gec is a Univ. B.Sc. and with. calc. and inf. and as a professor teaches courses in the field of computer science at Ravne Secondary School in Koroškem. He mainly deals with web technologies, programming and databases.
At the beginning of his career as a professor, he taught computer science at Ravne Grammar School, and later computer science. In 1997, he found new challenges at Ravne High School in the computer technician and electrical technician secondary professional education programs. For more than 25 years, he has been actively involved in adult education at the Ravne People’s University, as well as a lecturer at the Ravne Vocational College.