Kobe University Repository : Kernel Title Designing City Traffic Simulating System using LEGO Robot - A Example of Robot Education Author(s) Dong, Haiwei Citation Designing City Traffic Simulating System using LEGO Robot - A Example of Robot Education, : Issue date 2011-10-21 Resource Type Research Paper / 研究報告書 Resource Version author URL http://www.lib.kobe-u.ac.jp/handle_kernel/90001528 Create Date: 2016-03-05 Technical Note Designing City Traffic Simulating Simulating System using LEGO Robot - A Example of Robot Education Haiwei Dong Japan Society for the Promotion of Science and Kobe University Address: 1-1 Rokkodai-cho, Nada-ku, Kobe 657-0011, Japan Email: haiwei@gold.kobe-u.ac.jp Homepage: http://www2.kobe-u.ac.jp/~haiwei/ 2011/10/21 1. System Structure The designed city traffic simulating system is based on a bachelor education project on robot. The whole system is in the area of 4.4m by 4.4m. In this system, the traffic lights are controlled by single chips. The LEGO robot moves in the city street (moving straight, turning left, turning right and stopping) according to the infrared traffic signal from traffic light panel. Besides, there are also LED arrays, which are like the real traffic lights. To control the traffic flows of the entire city, we use a PC as master. The communication between PC and single chips is by RS485. Based on the system, we can test and verify many traffic flow control algorithms. Fig.1 System architecture. The development of the system involves hardware design and software design and robot control. More specifically, the hardware design is composed of three parts: traffic light panel design, RS-485 communication design and infrared light circuit design. The software design consists of two parts: traffic signal control and robot control. The traffic signal control is not just programming the embedded system, separately. Yet we use Embedded Real Time Operating System (ERTOS) to coordinate tasks. The designed robot control makes the robot move along the lines in the center of street. In addition, it needs to recognize the infrared light from the traffic light panel. 2. Infrared Signal Communication The infrared signal data package is composed of an 8-bit byte, including 1 initial bit, 8 data bits, 1 check bit and 1 stop bit. The frequency of the infra light is 38KHz. The Baud rate is 2400 b/s. The infrared signal protocol is defined in Table 1. 1 Technical Note Table 1 Infrared communication protocol. To be convenient for single-chip programming, we create the following four tables in the memory containing the four kinds of data packages in Table 1. To send traffic signal, we just send the corresponding package from the serial ports. typedef tByte unsigned char; tByte code message1_table[ ]={0x55,0xff,0x00,0xf7,0x08,0x01,0xfe,0xf8,0x07}; tByte code message2_table[ ]={0x55,0xff,0x00,0xf7,0x08,0x02,0xfd,0xf9,0x06}; tByte code message3_table[ ]={0x55,0xff,0x00,0xf7,0x08,0x03,0xfc,0xfa,0x05}; tByte code message4_table[ ]={0x55,0xff,0x00,0xf7,0x08,0x04,0xfb,0xfb,0x04}; 3. LEGO Robot and Its Programming The LEGO robot in this study is created by various kinds of blocks, including RCX block (centurial processing part), motor blocks, sensor blocks, etc. More specifically, the three inputs of RCX are connected with three grayscale sensors for recognizing traffic crossing, recognizing the line in the middle of the street and recognizing obstacles. On the other hands, three outputs of RCX are connected with three motors. Two of them are used to drive the robot to move. The other motor is applied for manipulator to pick obstacle up. Here we use two ways to program RCX, i.e. Not Quite C (NQC) and ROBOLAB. The former is a text-based programming way and the latter is an icon-based programming way. Fig.2 LEGO robot and simulating city map. 4. Display Panel Design and Programming The counting panel is composed of 34 LED lights. These lights can be green and red in different traffic conditions, i.e. green for allowing passing and red for stopping. In addition, there are two high brightness infrared LED light to give traffic signal to LEGO robot. Fig.3 Traffic display module design. For the control signals, there are three kinds: serial data input, shift clock and latch clock. The basic control procedures are shown as follows. In one traffic corner, the same 2 Technical Note directions share the same shift clock and serial data input. All the traffic lights in one traffic corner share the same latch clock. References , [1] ROBOLAB 2.5 Programmer Manual(ver0.9.9).www.semia.com 2003 , [2] ROBOLAB Researcher Mannual (ver1.0.1).www.semia.com 2003 , [3] Using ActiveX to Control, RCX.www.ceeo.com/activeX 2004 [4] Andrew O’Grady.ROBOLAB Troubleshooting Guide.Tufts University Press , ,2003 [5] ROBOLAB_Reference_Guide(version1.2).www.lego.com/education 2002 , ChrisRogers.Engineering with Department of Mechanical Engineering,2002 [6] Eric.L.Wang LEGO bricks and ROBOLAB. , [7] Matthew Bates.NQC Programmer Reference.The Open University 2000 , [8] Dave Baum.NQC Programmier Guide.www.robotdiy.com 2003 [9] William J.Taffe.Programming LEGO Robots Using NQC.Department of Computer , Science Utrecht University 2002 ,1999 [10] Jonathan B.Knudsen.LEGO MINDSTORMS Robots.www.oreilly.com/catalog [11] Walton Hall , Milton Keynes.What Is the Best Environment Language For , Teaching Robotics Using LEGO MindStorms.The Open University 2002 , [12] David Hanley Sean Hearne.LEGO Mindstorms programming with VB.WIT Press 2002 , , [13] Quickstart Guide.www.LEGO.com/education/MINDSTORMS 2004 [14] Controlling LEGO Programmable Bricks Technical Reference.www.ceeo. com/ , Pbrick 1998 , [15] Fred G. Martin.The Art of LEGO Design.The Robotics Practitioner Press 1995 3 Technical Note (a) System structure. (b) Software design architecture. Fig.1 System architecture. 4 Technical Note (a) (b) (c) (d) (e) Fig.2 LEGO robot and simulated city map. 5 Technical Note (a) PCB board. (b) Display circuit design. Fig.3 Traffic display module design. 6 Technical Note Table 1 Infrared communication protocol. Information Data package Meaning 0x01 0x55 0xff 0x00 0xf7 0x08 0x01 0xfe 0xf8 0x07 Move straight 0x02 0x55 0xff 0x00 0xf7 0x08 0x02 0xfd 0xf9 0x06 Turn left 0x03 0x55 0xff 0x00 0xf7 0x08 0x03 0xfc 0xfa 0x05 Turn right 0x04 0x55 0xff 0x00 0xf7 0x08 0x04 0xfb 0xfb 0x04 Stop index 7 Technical Note Appendix 1 Source code of ROBOLAB 8 Technical Note Appendix 2 Source code of NQC #define BLACK 45 #define WHITE 49 #define THRESHOLD (BLACK+WHITE)/2 #define left( ) On(OUT_A+OUT_C);Wait(63);Toggle(OUT_A);Wait(128); #define right( ) On(OUT_A+OUT_C);Wait(90);Toggle(OUT_C);Wait(120); int sem; void init( ) // Initialization { SetSensorType(SENSOR_3,SENSOR_TYPE_LIGHT); SetSensorMode(SENSOR_3,SENSOR_MODE_RAW); SetSensor(SENSOR_2,SENSOR_LIGHT); SetSensor(SENSOR_1,SENSOR_LIGHT); ClearSensor(SENSOR_3); ClearSensor(SENSOR_2); ClearSensor(SENSOR_1); ClearMessage( ); sem=0; } task check_turn_signal( ) // Recognition of traffic corner { while(true) { if(SENSOR_1<THRESHOLD-1) { PlaySound(SOUND_CLICK); start turn; } 9 Technical Note } } task check_obstacle_signal( ) // Avoid obstacles { while(true) { if(SENSOR_3<500) { PlaySound(SOUND_DOUBLE_BEEP); stop trace; stop check_turn_signal; Off(OUT_A+OUT_C); until(SENSOR_3>530); Wait(200); start check_turn_signal; start trace; } } } task turn( ) // Turning { stop check_turn_signal; stop trace; sem+=1; switch(sem) { case 1: break; case 2: { if(Message( )= =2) left( ); else { Off(OUT_A+OUT_C); until(Message( )==2); 10 Technical Note left( ); } break; } case 3: { if(Message( )==2) right( ); else { Off(OUT_A+OUT_C); until(Message( )==3); right( ); } break; } case 4: StopAllTasks( ); } ClearMessage( ); start check_turn_signal; start trace; } task trace( ) // Moving along black line { while(true) { OnFwd(OUT_A+OUT_C); if(SENSOR_2>THRESHOLD) { Float(OUT_C); until(SENSOR_2<=THRESHOLD); } if(SENSOR_2<THRESHOLD) { Float(OUT_A); until(SENSOR_2>=THRESHOLD); 11 Technical Note } } } task main( ) // main function { init( ); PlaySound(SOUND_UP); Wait(100); start check_obstacle_signal; start check_turn_signal; start trace; } 12