Proceedings of the 2006 IEEE International Conference on Robotics and Automation Orlando, Florida - May 2006 Educating C Language Using Mindstorms Robotic Invention System 2.0 Seung Han Kim and Jae Wook Jeon School of Information and Computer Engineering Sungkyunkwan University 300 Cheoncheon-dong, Jangan-gu, Suwon-city, Korea 440-746

Abstract – A robot highly motivates students and it is one of for most of courses because it motivated students who took the best ways to connect students with the technology. LEGO these courses. This paper will propose on educating ANSI C created a set called Robotic Invention System. This system helps language to students using RIS, which can give students more students to understand the technology of both robot and interest and motivation to learn. programming language. It also improves creativeness by building Using a cross-compiler developed from Cygwin we can and controlling the robot. This paper will propose the idea on educating C language to students using Robotic Invention System control RCX by ANSI C language. BrickOS provides a 2.0. firmware that replaces the default NQC environment of RIS to program with ANSI C language. BrickOS follows the syntax Index Terms – ANSI C Language, , Robotic rule of ANSI C language. Users can write codes in ANSI C Command Explorer (RCX), Robotics Invention System (RIS) language, compile, and debug them in the way we knew. Unfortunately, not all codes of ANSI C language are compatible with RCX due to its hardware structure. Yet, it can I. INTRODUCTION cover most of contents that freshmen learn in the university LEGO Mindstorms Robotics Invention System 2.0 (RIS) course on C language. LEGO parts are used to construct is a programmable toy which contains blocks, pieces, sensors, autonomous robots. We can use LEGO beams, plates, gears, motors, and a Robotic Command Explorer (RCX). RCX is a motors, and various sensors to connect to RCX for making a programmable block using infrared (IR) transmitter to robot and programming it with ANSI C language codes to communicate with personal computers. RIS provides an iconic control. In this way, we can educate ANSI C language. programming interface application to control the RCX. The We are planning to open a course for students to educate firmware of RIS uses a language, (NQC). This ANSI C language using RIS. The course will be held with programming language is used in the iconic programming lecture on ANSI C language and experiment on RIS robots interface. The software of RIS will automatically convert an with the appropriate codes that fit the content of the lecture. iconic programming interface program into a text program of The degree of difficulty of the lecture will be flexible. NQC and download it to the RCX to run the program. Elementary students will learn the idea of robot and Although the software given to control the RCX is very programming, while university students can learn advanced simple and powerful, it will be better if RCX could be programming in C language. programmed by popular languages like C. Most of educations In section II, it will be explained how LEGO Mindstorms on C language have been performed by personal computers. RIS for education in various fields is used. In section III, They write a program with a text editor and use a compiler to LEGO Mindstorms RIS as a platform to educate ANSI C run the program. Outputs are on the monitor only. It is a language will be explained. In section IV, the method of traditional way to educate C language but it is also limited and controlling RCX using ANSI C language is explained. In fixed. With the RCX, we can download program to it and look section V, a plan for educating students will be explained. In at the program running in a robot, which is more interesting the last section, the conclusion for this paper is described. compared with the monitor based outputs [1]. RIS is widely used in many courses in the world. It is II. USING LEGO MINDSTORMS ROBOTIC INVENTION SYSTEM used to teach physics in some high schools. Many engineering 2.0 FOR EDUCATION IN VARIOUS FIELDS courses in universities use RIS to implement a robot. In some courses, Robolab of Labview is used because it has a simple Many types of robot exist in real world and these robots iconic programming interface. Some courses use RIS and highly motivate students. Robot is one of the best ways to Interactive C language to teach robot programming. connect students with technology. Indeed, robots have Interactive C language is a compile environment developed emerged as useful tools in education because robots provide for robots or embedded systems built with Motorola 6811. It ideas of science and technology [2]. is quite different from American National Standard Institute Penn State Abington College used RIS for their (ANSI) C and its aim is to control the robot instead of introductory programming course for freshman and improving the program skills. The use of RIS was successful sophomore students. Students form teams to design and implement algorithms in the Interactive C language for robots

0-7803-9505-0/06/$20.00 ©2006 IEEE 715 [3]. Although most of students had no programming interface language. Interactive C language was made to experiences, the use of robot was successful. Students could control Motorola 6811 based robots and embedded systems implement programs such as decision and a loop, and test [3]. It is a hybrid of ANSI C language. It only contains them in a real application [4]. necessary codes to control robots. Its main purpose is to Tufts University has a course in mechanical engineering control robot using a computer language. It is quite different that uses RIS. Students form a group of three and they were from ANSI C language. Interactive C language does not have provided with RCX, LEGO bricks, sensors, and Robolab the full contents of ANSI C language. Interactive C can be software. LEGO bricks allow students to create their own assumed as a programming language developed to understand robot and write their own interface and analysis software. and control robots. In this paper, we develop an environment They actively compared their results with others. Also, Tufts to write a program in ANSI C language to control RCX. University worked with pre-college courses in Shady Hill Although RCX do not support all of codes in ANSI C School using Robolab and RCX. Equipments were provided language, it can cover most of the contents that we usually to 8th grade students to teach physics. They used RIS to create learn in the language course. RCX vehicles to learn about velocity and acceleration. Afterwards, they even learned about friction and gears. Using III. LEGO MINDSTORMS ROBOTIC INVENTION SYSTEM 2.0 AS A LEGO bricks have been successful for students in all grades. PLATFORM TO EDUCATE CLANGUAGE Students were highly motivated to learn from the materials. Students got very excited to build, control, and compete with RIS comes with a Microsoft Windows software CD robots they created [5]. which provides an iconic programming interface for Eric Wang and Ryan Wang used RIS and Robolab programming. It is in structure of ‘jigsaw puzzle’ pieces software to meet the science, mathematics, and technology representing commands to control over the available actions levels of local elementary school curricula. Robolab is based by using respective sensors and hardware. Supplied software on Labview and comes with an iconic programming interface is simple enough for children to understand and get attracted which is suitable for elementary students to use [6]. This to it. program does not require any reading or writing skills of text Most important part of the RIS kit is called RCX, the based program codes. This is an important issue in teaching programmable LEGO brick. It is shown in Fig. 1. We have to elementary students. There are two modes, Pilot and Inventor notice that it is a brick. We can build robots based on RCX or mode. Pilot mode uses a fixed program to compile and run. we can design a creative and unique robot depending on our Inventor mode debugs programs under an iconic programming imagination. RCX contains a microprocessor (Hitachi H8300) interface environment. By this experiment, the author inside of a plastic case. There are three output ports and three concludes that elementary students have ability to understand input ports. Three output ports can attach motors and lamps, a program and describe its action [7]. and three input ports allow light, touch, temperature and angle Eli Kolberg and Nahum Orlev examined a course sensors. It has external liquid crystal display (LCD) that can framework for 5th and 6th grade students with understanding of show five characters at one time. Four buttons are on the top technology by using robots. Several students participated in for users to control RCX. IR communication device is building a multi functional autonomous robot. It was held in provided for users to communicate with personal computers weekly session of three hours. They design, construct, and using a universal serial bus (USB) port. assemble a complete robot as the given flow chart. The There are other important parts in the RIS kit. We have authors came with a conclusion that there was great gears, pipes, blocks, and others to use for making a robot. excitement for students who participated in this course and Most people should have seen and have been playing at least that students did their robots were faster than expected [8]. one LEGO model when they were young. It is not a big Texas A&M University-Corpus Christi opened a class problem even though he or she did not have any chance to using RIS for Software Analysis and Design Class. Students play with it before. LEGO is easy to learn. We are going to implemented seven robotic applications and they had a robot explain some special parts that are included in RIS. competition for the final project. Students developed software First of all, motors are included. The main purpose of for lawyers, doctors, and businessmen. Each project had to motor is to make a robot move. The basic set comes with two develop several documents such as analysis documents, motors. We can create robots using motors to move their requirement documents, design documents, implementation hands, legs, and wheels. There is no limit in designing a robot. documents, and testing documents. They programmed RCX as We can attach motors to any output ports as our wish. their documentation and showed many different types of robot Secondly, there is one light sensor in the set. Light sensor that could be used. All students in this course were satisfied has two functions for users to control, one is lamp and the because they can have fun and learn at the same time [1]. other is light intensity sensor. Lamp is used to help the light In this paper, we will use RIS to educate ANSI C intensity sensor to measure the light intensity. However, it language. Although existing courses use RIS to teach also disturbs the reading of light intensity sensor. The light programming skills, the language that they have been using is sensor is not a good device to measure the light intensity. The a hybrid type of C language or an iconic programming

716 light sensor gives a value from 20,000 to 65,000 to the RCX Language is the mechanism through which when it is connected to the input port. communication is realized. Without language we would be Third, there are two touch sensors in the RIS kit. isolated with our thoughts. Computer programming languages Different from the light sensor, touch sensor returns binary exist because humans have a need to communicate with a value, on/off status. It works like a door bell. By pressing computer. The microprocessor of computer, however, touch sensor the circuit is completed and the electricity flows understands a cryptic series of symbols representing on or off through it. RCX is able to detect this flow to give an state. This is called machine language and is too much appropriate value for programs to read. detailed for users to understand it. It is very difficult for users With these parts we can create a new type of robot that we to fully understand the machine codes and write machine want. LEGO is easy to make. Various types of block and programs. As time flows, programmers made programming gears can be added and connected together to turn out into a languages to communicate with computer using appropriate unique robot. As we discussed in previous section, students compilers. Programming languages for humans are usually are easily attracted by robots. If students can make a robot by called high-level language. C language is one of the high-level themselves, it will be even more attractive. This means that languages that can communicate with computers [10]. students can design and create their own robot and program it Among many program languages, C language is chosen to move as they wish. for this paper. The main reason is because it has general Two factors have seriously limited the use of robots in characteristic of a lower-level language. Students are allowed teaching programming languages. First was the high cost of to use features of the hardware. RCX has restriction for large robotic kits, and second was the lack of a framework for programs or programs which need numerous resources. In comprehensively integrating robots. These two factors lead order to maximize the use of RCX for programming, C college or educational departments to avoid the use of robots language is the most suitable. in teaching programming. Since the mid 1990s, several Until now, most of C language courses are based on the manufacturers have released standardized low-cost robot monitor output only. We write in a code by a text editor and platforms. LEGO Mindstorms RIS 2.0 is one of the kits save it as a C file. The compiler will do the next action to developed. There are several reasons to choose RIS among show the output through the monitor. With the idea of using these robots [9]. RIS, we can extend the output limit from the monitor to the COST: A single RIS kit with 750 construction pieces, moving robot. sensors, and programmable hardware, costs around US $200. FLEXIBILITY: The RIS kit supports sensors (touch, IV. CONTROLLING RCX WITH CLANGUAGE rotation and temperature), effectors (motors, lights, and IR emitters), building blocks, and a programmable control unit In order to use a compiler of ANSI C language for that can serve as the basis for user to program. controlling RCX, we need several free softwares such as STUDENT INTEREST: Many students have played with Cygwin, Bricx Command Center (BCC), and BrickOS. The LEGO building blocks. Therefore they are intrigued with it. cross compiler is made in the Cygwin shell. Users can write a Not like PC based lectures, student will fall into it even code in BCC and then compile and download it to RCX. though it is classroom work [9]. BrickOS include library files needed for compiling and coding RIS and related software provide an alternative method to [11-13]. educate C language. This alternative method will be more To develop the environment for coding in ANSI C effective to teach young students who do not learn any language, we have to download Cygwin. We have to check languages before. Even for college students, learning C necessary options to install. The default option will not make language with RIS will be marvelous. the compiler work properly. After installing Cygwin, we have to download BrickOS and use Cygwin shell program to make the cross compiler. It takes a long time to build the cross compiler. After the cross compiler is built, we have to install BCC along with the patches that links the cross compiler to BCC. All instructions are indicated on the website [11]. After we have installed the correct programs and found out it worked, we make an improved installation guide for students to use. Although BrickOS is built to use ANSI C language, it does not completely match with ANSI C language codes because of the hardware structure of RCX. We can control motors, touch sensor, and light sensor. The RCX can make sounds as well and show texts through its LCD panel. Codes to control RCX are shown in Table I. The API is provided by the BrickOS. All necessary codes Fig.1 LEGO Mindstorms RCX to control RCX in ANSI C languages are listed. The header

717 files needed for compiling are listed. Specific codes for each array of line 24-28 which is then handed to dsound_play. Line motor and sensor are introduced in detail. List of all functions, 24-28 is one example of RCX codes to make sounds. This variables, defines, enums, and typedefs are well organized. must be declared within the main function to make sounds. For more information on codes, refer to the API [14]. PITCH can be declared in the range from A0 to A8. The Table II shows a program for the Roverbot to move zig- alphabet shows the musical note and the following number is zag for eighty times to avoid obstacles in front of it. The the octave. The octave can be set into numerical numbers like Roverbot is attached with two bumpers as shown in Fig. 2. one, two, and four. This function will sound like a beep. Line One is left bumper and the other is right one. The RCX will 43 and 51 is to print on the LCD screen. It is easy to print count how many zig-zag moves it will have. When the characters on the LCD screen. We only need to use cputs. bumper is touched while moving, the Roverbot will show left However, the LCD screen of RCX can print only five or right on the LCD screen for indicating the bumper touched. characters at once. In order to show long words or sentences, Then it will move backward for a certain time. The Roverbot we have to print one line and give some delay and print the will make a turn into the side the bumper is touched. It will next line. We use lcd_number command to print numbers on move in zig-zag again for the remaining time. Line 8 - 22 in the LCD panel along with the variable or number, variable the Table II show functions to set the direction for motors type, and exponential option. Line 61 is the command to print connected to port A and C. These functions will make the the number for the counter i on the LCD. robot move backward, turn left, or turn right. There are four Many beginners have hard time in learning a computer choices in motor rotations: forward (fwd), reverse (rev), brake language, since it is difficult to understand about the error (brake), and off (off). The motor rotation direction are message. The compiler inspects a program and gives suitable opposite in fwd and rev. The brake command will immediately error messages. It is difficult for beginners to understand stop the motor and off command will stop supplying the about the meaning of error messages. However, RIS is good current to the motor so that the motor will stop its rotation for beginners to easily learn ANSI C language and to debug gradually. The name of the function can be decided as we its program by watching robots move. This is much more want. We named the function of line 18-22 as back_car to effective than working on a personal computer with a C make clear what the function does. Line 18-22 will run motor language program shown on the monitor. Among many attached to port A and C for 1,000 milli-seconds in reverse reasons, interest is the best merit it has. mode. Line 34 means that a motor connected to port A is set to speed of 255. We can select the the speed of motor from 0 V. PLAN FOR EDUCATING STUDENTS to 255. Line 9, 14, 19, and 64 show codes to control the rotation direction of the motor connected to port A. Line 21 is We are planning to open a course for educating ANSI C essential for the motor to run. If this command is not included, language using RIS. Expecting candidates are aged thirteen to the motor will not move at all. The number in line 21 is in the sixteen. The course will be prepared with personal computers units of milli-seconds we have to assign. Line 21 gives some and appropriate software to program RCX. Currently, we delay so that above codes are continued longer. Most of RCX expect the course to be held for 10 lectures which is total of related codes are in function type. For controlling motors, a 20 hours in two weeks. code should be written in the main function. For RCX to make Table III shows the plan of the course. There will be ten sounds, however, a song to play should be made up of an lectures. Each lecture will be held for two hours, and it will be divided into two sections. Most of existing lectures on C

TABLE I language start with printf. However, RCX does not support LIST OF CODES FOR RCX printf. We excluded those C language codes that RCX and Device Syntax Example Codes BrickOS do not support from the contents of the lecture. motor_x_speed(num); Personal computers with necessary applications and LEGO motor_x_dir(dir); motor_a_speed(251); Motor x={a,b,c}, num={0~255}, & motor_b_dir(fwd); Mindstorms RIS kit are needed for students to attend the dir={fwd,rev,brake,off} course. Each student is recommended to work alone. Teaching ds_active(TOUCH_x); assistants will help the course. The course will be held on Touch ds_active(TOUCH_1); (TOUCH_x!=y); Sensor (TOUCH_2!=0); lecture on C language for one hour and there will be x={1, 2, 3}, & y={0.1} experiment for another one hour. For the first lesson we will ds_active(&SENSOR_x); Light y = (SENSOR_x); ds_active(&SENSOR_2); try to teach the basic idea of C language and there will be an Sensor y = {float type variable}, & val = (SENSOR_2); experiment after the lecture. The goal of experiment is to x={1, 2, 3} motivate students. Students will make robots shown in the {PITCH_XI, T}, user manual of the LEGO Mindstorms RIS kit. In the {PITCH_END, 0} {PITCH_b6,2T}, Sound X={a,c~h}, I={1~7}, & {PITCH_END, 0} challenge section, there are three types of robot: Roverbot, T={1,2,4,8,16} Acrobot, and Inventorbot as shown in Fig. 2 [15]. Each robot cputs(“xxxxxxxxx”); has its own characteristic. For the Roverbot, it is a robot LCD lcd_number(x,y,ez); cputs(“five”); vehicle which has four wheels. Acrobot is another type of Screen x = variable, y = variable lcd_number(y,float,e0); robot with bigger wheels which can move faster. Inventorbot type, and z = {0~5} position is a typical robot that looks like human. There are three levels

718 TABLE II for each type of robot in challenge. For each level, students APROGRAM FOR ROVERBOT can attach different type of devices, which are a bumper 1 #include attached with a touch sensor and light sensor as a vision 2 #include device for the robot. For each level, we aim to teach the 3 #include 4 #include appropriate coding skills that correspond to the lecture on C 5 #include language. Controlling of motors and sensors are exclusive 6 #include functions which are only used for RCX, so codes to control 7 these devices will be taught first. When the lecture is on 8 static void for_left() { variable, we will teach students to get the value from sensors 9 motor_a_dir(brake); 10 motor_c_dir(fwd); to control the robot. As the lectures go on, students will learn 11 } more codes to control more devices for RCX and they will 12 understand the programming concepts such as decision or a 13 static void for_right() { loop. 14 motor_a_dir(fwd); 15 motor_c_dir(brake); The lecture on C language will only cover the contents 16 } that are compatible with the firmware of BrickOS. This 17 lecture will be based on ANSI C language codes and modified 18 static void back_car() { C language codes for BrickOS as well. Many codes are 19 motor_a_dir(rev); 20 motor_c_dir(rev); needed to run Robverbot even though it is the first challenge. 21 msleep(1000); As a result, most of the codes will be given for experiments in 22 } the advance. Students will fill in appropriate codes into the 23 blank lines with the codes they learn each week. As the lecture 24 static const note_t beep[] = { 25 {PITCH_H4, 1}, continues the students will have to fill in more blank lines. For 26 {PITCH_H4, 1}, the final lecture, students should be able to write a full 27 {PITCH_END, 0} program. 28 }; The experiment will start by making an appropriate robot. 29 30 int main(void) { After students finish making a robot, we will use the given 31 iconic programming interface software of RIS to run the 32 int i=0; robot. Teaching assistants will show how the robot works 33 int dir=0; when RCX is programmed in NQC. However, students should 34 motor_a_speed(255); 35 motor_c_speed(255); write a program in ANSI C language using BCC and BrickOS 36 to run the robot identically as teaching assistants showed. Our 37 while (i <= 80){ course will use BCC to write the ANSI C language code, 38 compile, and download it to a robot made with RIS kit. BCC 39 if (TOUCH_1!=0){ 40 dsound_play(beep); is a Microsoft Windows program commonly known as an 41 back_car(); 42 for_left(); TABLE III 43 cputs(“left ”); THE COURSE SCHEDULE 44 msleep(600); 45 i++; Lecture Content Experiment 46 } 47 else if (TOUCH_3!=0){ What is C RCX code to 1 48 dsound_play(beep); Roverbot Level 1 control motor 49 back_car(); Variable RCX code to 2 50 for_right(); Roverbot Level 2 control touch sensor 51 cputs(“right”); Equations and Operators RCX code to 3 52 msleep(600); Roverbot Level 3 control light sensor 53 i++; If Statement 54 } 4 Using Counter Acrobot Level 1 55 else { For Statement Using If statement with the 56 i++; 5 Acrobot Level 2 value from touch sensor 57 for_left(); Case Statement Using For statement with the 58 msleep(200); 6 59 for_right(); Acrobot Level 3 value from light sensor Array Using array and function 60 msleep(200); 7 61 lcd_number(i, sign, e0); Inventorbot Level 1 to play a song Function 62 } 8 Print on the LCD screen 63 } Inventorbot Level 2 Exibition on robots 64 motor_a_dir(brake); 9 Write a full program 65 motor_c_dir(brake); Inventorbot Level 3 66 return 0; 10 Contest 67 }

719 Fig. 2 Robots used in experiments. Fig. 3 Bricx Command Center integrated development environment for programming RCX ACKNOWLEDGMENT which is shown in Fig. 3. Students will write C code in BCC, compile, and download it to RCX. After students download This work was financially supported by the Ministry of Education and Human Resources Development (MOE), the Ministry of Commerce, Industry their programs into RCX, students will run them to check and Energy (MOCIE) and the Ministry of Labor (MOLAB) through the whether they work properly. If robots are not working as fostering project of the Lab of Excellency. students expected, students will debug their code for robot. When all of the above works are finished, students will be REFERENCES given three more exercises for the same type of robot. [1] A. Garcia and Holly Patterson-McNeill, “Learn How To Develop Unfinished work will be assigned as homework. Software Using The Toy Lego Mindstorms,” 32nd ASEE/IEEE Frontiers In When students finish the ninth lecture, we assume that Education Conference, Boston, MA, Session S4D, pp. 7-10, 6-9 November students can write C language codes to control all devices of 2002. the RIS. We will open a contest for the tenth lecture. We are [2] Javier Ruiz-del-Solar, Senior Member, IEEE, and Roberto Avilés, planning to have two contests. The first contest will be with “Robotics Courses for Children as a Motivation Tool: The Chilean the Roverbot. We will make a maze for the Roverbot to Experience,” IEEE Transaction on Education, Vol. 4, No. 4, pp. 474-480, escape from. We will not tell students about the maze. It could November 2004. have slopes and boxes that could be pushed by the Roverbot. [3] http://www.newtonlabs.com/ic/ The winning prize will be given to a student whose Roverbot [4] Robert Avanzato, “Collaborative Mobile Robot Design in an Introductory Programming Course for Engineers,” Proceedings of the ASEE Annual escapes from the maze in the shortest time. Conference, on CD-session #3520, June 1998. For the second contest, students are allowed to create any [5] Scott McNamara, Martha Cyr, Chris Rogers, and Barbara Bratzel, “LEGO types of robot and write a program to work it as they planned. Brick Sculptures and Robotics in Education,” Proceedings of the ASEE Because this contest depends on the creativity, we will not Annual Conference, on CD-session #3353, June 1999. [6] http://www.ni.com/company/robolab.htm decide the winner by the complexity of robots or the program. [7] Eric Wang and Ryan Wang, “Using and Robolab (Labview) with We will let the students vote for the winner. Elementary School Children,” 31st ASEE/IEEE Frontiers In Education Conference, Reno, NV, Session T2E, pp. 11, 10-13 October 2001. VI. CONCLUSION [8] Eli Kolberg and Nahum Orlev, “Robotics Learning as a Tool for integrating Science Technology Curriculum in K-12 Schools,” 31st ASEE/IEEE Frontiers In Education Conference, Reno, NV, Session T2E, pp. While the LEGO Mindstorms RIS kit is still limited in 12-13, 10-13 October 2001. coding C language completely, it has advantage to teach basic [9] Frank Klassner and Scott D. Anderson, “LEGO Mindstorms: Not Just For skills on coding to young students. Another merit of this kit is K-12 Anymore,” IEEE Robotics & Automation Magazine, pp. 12-18, June 2003. that it is inexpensive and it is durable. RIS and C language, [10] Dr. Tri Nguyhen and Antoine F. Sajous, “Understanding C Through joined together, is a good way to educate programming. English Grammer,” Northcon/98 Conference Proceedings, pp. 219-226, 21-23 After finishing the lecture, we will start to prepare lecture October 1998. materials to educate C language for kids. We will also start to [11] http://brickcc.sourceforge.net prepare lecture materials for university students. [12] http://brickos.sourceforge.net [13] http://www.cygwin.com In the future work it is also possible to build a robot that is [14] http://brickos.sourceforge.net/docs/APIs/html-c/ fully compatible with ANSI C language. When this robot is [15] LEGO Mindstorms Robotic Invention System 2.0 Usual Manual invented, it will become efficient and interesting to educate C language.

720