=Paper=
{{Paper
|id=Vol-2694/paper2
|storemode=property
|title=Fuzzy system as a method of controlling LEGO
Linefollower vehicle using C# programming language
|pdfUrl=https://ceur-ws.org/Vol-2694/p2.pdf
|volume=Vol-2694
|authors=Krzysztof Grzesica,Jakub Wadas
|dblpUrl=https://dblp.org/rec/conf/system/GrzesicaW20
}}
==Fuzzy system as a method of controlling LEGO
Linefollower vehicle using C# programming language==
Fuzzy system as a method of controlling LEGO Linefollower vehicle using C# programming language Krzysztof Grzesicaa , Jakub Wadasa a Faculty of Applied Mathematics, Silesian University of Technology, Kaszubska 23, 44-100 Gliwice Abstract In this article we present our implementation of intelligent system developed for a LEGO robot. We have built a robot which is using sensors to trace the line and follow it. The model of tracing is based on fuzzy rules, which have been done to follow the shape of a black line on the white background. The system was implemented using C# language for LEGO Mindstorm elements. Results of our experiments show that the robot is able to follow various shapes of black lines. Keywords LEGO robot, Line detection, Fuzzy rules 1. Introduction lect such libraries and optimize them for robotic con- structions. Also some approaches are based on frame- In many fields of industry and production various ro- works, as proposed in [5] that frameworks are also botics are applied to help in situations where the work possible for other constructions based on arduino el- may be dangerous for humans or there is required high ements, which provide similar possibilities of robotic precision at work. To start the research in such field constructions. All these what we want to create de- we have selected LEGO mindstorm elements. This rob- pends on our ability to develop the construction and ot model is easy to develop just by using simple bricks than to implement the control software. An interest- in many shapes from the set. The set also provides ing discussion was given by [6, 7]. a programmable electronics with a variety of sensors. The other aspect of robotic models is to select a pro- On the other hand such approach is widely presented per decision support model. In many IoT constructions in other literature, what gave us an inspiration to de- we can find various approaches. In [8] was proposed velop our idea. how to combine neural networks with rules in a form In [1] a model of LEGO blocks was used to work of soft set table. While in [9] the fuzzy rule system with human gestures, where sensors were used to read was implemented with neural networks to work in a gestures and therefore take actions in mindstorm ele- smart house environment. It is also very popular to ments. In [2] was presented how to use such LEGO develop fuzzy rules working on images, as discussed models to help in first contact with machine intelli- in [10]. Mechanical vehicle constructions also very gence. Authors describe good practices when using often benefit from artificial intelligence, both at con- LEGO Mindstorm as a platform for programming ar- struction and simulation level, as proposed in [11, 12, tificial intelligence systems. As presented in [3] these 13, 14]. models also support creative thinking, especially when Our approach is using C# language to implement we develop new algorithms that must be programmed control system based on fuzzy rules to first detect and in a special way accepted by the LEGO Mindstorm than follow the line. The LEGO Mindstorm robot is platform. There are various approaches to use pro- using two servo-motors as accelerators of wheels con- gramming languages in developing such robots. trolled by our developed artificial intelligence to fol- However the most necessary is tu use an optimal low the line. our experiment shows that our construc- library, which will support all necessary function that tion is well defined and can follow even the complex provide optimal connection and configuration between lines on the board. elements of the robot. In [4] was discussed how to se- SYSTEM 2020: Symposium for Young Scientists in Technology, 2. Model Engineering and Mathematics, Online, May 20 2020 " krzygrz684@student.polsl.pl (K. Grzesica); In this section we will describe how we have developed jakuwad985@student.polsl.pl (J. Wadas) the model both from programming side and thinking ยฉ 2020 Copyright for this paper by its authors. Use permitted under Creative model. Commons License Attribution 4.0 International (CC BY 4.0). CEUR Workshop Proceedings http://ceur-ws.org ISSN 1613-0073 CEUR Workshop Proceedings (CEUR-WS.org) Figure 1: Vehicle construction 2.1. Project assumptions The aim of this project was to build an artificial in- telligence system based on fuzzy logic, which would steer the vehicle used in LEGO Line-follower compe- tition. Based on readings, the system must decide how to change the speed of each engine, so that: Figure 2: The bottom of the vehicle โข The vehicle does not go off the road (A moment when a black line is not between vehicleโs wheels is considered going off the road) 100 ๐๐ = (2) โข The vehicle goes as fast as possible ๐ ๐ถ๐ โ ๐ต๐ถ๐ Where ๐ ๐ถ๐ฟ and ๐ต๐ถ๐ฟ are accordingly, maximum and The robot is connected to computer via Bluetooth. minimum reading value of left sensor. ๐ ๐ถ๐ and ๐ต๐ถ๐ The robot sends raw readings and data to computer are maximum and minimum reading values of right where all necessary calculations are being performed. sensor. These values are obtained during setup con- Then, based on calculation results appropriate com- figuration. Reading output is determined using the fol- mands from the computer are sent to robot. lowing formula: 2.2. Robot Construction ๐๐๐๐๐ฟ = |(๐๐๐๐๐๐๐๐ฟ๐๐ ๐ก โ ๐ต๐ถ๐ฟ) โ ๐๐ฟ โ 100| (3) To accomplish that task we have built a vehicle using ๐๐๐๐๐ = |(๐๐๐๐๐๐๐๐ ๐๐โ๐ก โ ๐ต๐ถ๐ ) โ ๐๐ โ 100| (4) LEGO parts. The robot is based on intelligent EV3 Where ๐๐๐๐๐๐๐๐ฟ๐๐ ๐ก and ๐๐๐๐๐๐๐๐ ๐๐โ๐ก are respectively brick, it is equipped with two color sensors, which raw vuales returned by left and right color sensor. measure the level of reflected light they emit. The ve- ๐๐๐๐๐ฟ and ๐๐๐๐๐ take values from 0 to 100, where 0 hicle is driven by two independent engines which di- means total white, 100 - pure black. rectly spin the wheels. The actual look of vehicle can After that, the resultant reading value meaning the be seen in Fig. 1 and Fig. 2. inclination of the road is calculated accordingly to the following formula: 3. Mathematical Model ๐๐๐๐๐ โ ๐๐๐๐๐ฟ ๐๐๐๐๐๐๐ = (5) 3.1. Normalization 10 Firstly, we must normalize the readings from color sen- If both color sensors went off the road the variable sors to negate the hardware differences. To do that we ๐๐๐๐๐๐๐ i set to 10 or -10 depending on the side of road must first calculate parameters ๐๐ฟ and ๐๐ accordingly the sensors are located. as: 100 ๐๐ฟ = (1) ๐ ๐ถ๐ฟ โ ๐ต๐ถ๐ฟ 10 Figure 3: Reading membership functions Figure 5: Application window before configuration Figure 6: Application window after configuration Figure 4: Speed membership functions Table 1 3.2. Fuzzyfication Speed base of rules To determine grade of membership Bell shaped and Linear functions are used. The formulas are as follows: Left/Right rear slow medium fast { rear rear slow slow slow 1 1+| ๐ฅโ๐ ,๐ฆ โฉฝ๐ฅ โฉฝ๐ง slow slow slow medium medium (6) 2๐ ๐ต๐๐๐ = ๐ | medium slow medium medium fast 0 ,๐ฅ <๐ฆโจ๐ฅ >๐ง fast slow medium fast fast { 1 ,๐ฅ <0 ๐ฟ๐๐๐๐๐ = (7) 0 ,๐ฅ โฉพ0 Where ๐, ๐ are parameters. Variables ๐ฆ and ๐ง are end- The results are being grouped by the rules they cor- points of interval. Variable ๐ stands for center of func- respond with and for each of rule we choose the biggest tion. In our project ๐ = 2.5 and ๐ = 2.5 in all but value. Lets assume that the biggest value for rule slow one membership function. The membership function is ๐ข๐ค , for medium - ๐ข๐ and for fast - ๐ข๐ . The final Straight uses ๐ = 1.5. The reading membership func- resultant speed is obtained by using center of gravity tions can be seen in Fig.3, while speed membership method defined as: functions in Fig. 4. ๐ข๐ค โ ๐๐ + ๐ข๐ โ ๐๐ + ๐ข๐ โ ๐๐ Then, the resultant vehicle speed composed from ๐ ๐๐๐๐ = (8) ๐ข๐ค + ๐ข๐ + ๐ข๐ separate engines speeds is being calculated. In order to determine it we calculate each engineโs grade of mem- where ๐๐ = 10, ๐๐ = 50 and ๐๐ = 90 are coefficients of bership for all of speed membership functions and ac- speed rules. cordingly to fuzzy rules base shown in Tab. 1 we con- duct necessary calculations. 11 Table 2 Inclination base of rules Speed/Reading HL EL S ER HR fast HL HL S HR HR medium HL EL S ER HR slow HL EL S ER HR HL - Hard Left, EL - Easy Left, S - Straight, ER - Easy Right, HR - Hard Right Figure 7: Reading method 3.3. Deffuzyfication ๐๐๐ ๐ ๐๐โ๐ก๐๐๐ก๐๐ = (19) The next step is to calculate the inclination, which con- 4 sists of resultant speed and resultant reading values. where ๐๐๐ is the inclination value calculated before. In order to determine it we calculate resultant speed In case of Easy Left and Easy Right if the ๐๐๐ value is grade of membership for all of speed membership func- lesser than -50 or greater than 50, then it is set to 50. tions and resultant reading grade of membership for all of reading membership functions. Then, accord- ingly to fuzzy rules base shown in Tab. 2 we conduct 4. Implementation necessary calculations. The results are being grouped by the rules they correspond with and for each of rule Let us now present the software we have done. we choose the biggest value. Lets assume that the big- gest value for rule HL is ๐ข1 , for EL - ๐ข2 , for S - ๐ข3 , for ER 4.1. Application - ๐ข4 and for HR - ๐ข5 . The final inclination is obtained Based on the mathematical model described above, we by using center of gravity method defined as: have created a robot control application. The applica- tion has a very simple graphical user interface, which ๐๐๐ = ๐ข1 โ ๐1 + ๐ข2 โ ๐2 + ๐ข3 โ ๐3 + ๐ข4 โ ๐4 + ๐ข5 โ ๐5 makes it user-friendly. In Fig. 5 and Fig. 6 application ๐ข1 + ๐ข2 + ๐ข3 + ๐ข4 + ๐ข5 window can be seen. (9) where ๐1 = โ100, ๐2 = โ50, ๐3 = 0, ๐4 = 50, ๐5 = 100 are coefficients of inclination rules accordingly for HL, 4.2. Program code EL, S, ER and HR. The program is written in ๐ถ#. In addition to the stan- Finally, the rule with the greatest inclination grade dard .๐ ๐ธ๐ libraries, the program uses the ๐ฟ๐๐๐.๐ธ๐ฃ3 of membership value is chosen. Depending on it, the library for communication between the computer and engines speeds are calculated and set. For Hard Left the robot. The program has been divided into classes (10) and (11), for Easy Left (12) and (13), for Straight and appropriate methods. (14) and (15), for Easy Right (16) and (17) and for Hard Right (18) and (19). Reading method This method is responsible for the ๐๐๐ normalization of color sensor data. This method also ๐ฟ๐๐ ๐ก๐๐๐ก๐๐ = (10) serve as a precaution against loosing the route by a 4 robot. Method code can be seen in Fig. 7. ๐ ๐๐โ๐ก๐๐๐ก๐๐ = ๐๐๐ (11) ๐ฟ๐๐ ๐ก๐๐๐ก๐๐ = ๐๐๐ โ 1.5 (12) HowTheRouteRuns method This method is a frag- ๐ ๐๐โ๐ก๐๐๐ก๐๐ = ๐๐๐ โ 2 (13) ment of the fuzzy system. It combines the route incli- nation with the current vehicle speed and decides how ๐ฟ๐๐ ๐ก๐๐๐ก๐๐ = 100 (14) to react based on that data. A piece of the method code ๐ ๐๐โ๐ก๐๐๐ก๐๐ = 100 (15) is in Fig. 8. ๐ฟ๐๐ ๐ก๐๐๐ก๐๐ = ๐๐๐ โ 2 (16) Robot class This is the class which object repre- ๐ ๐๐โ๐ก๐๐๐ก๐๐ = ๐๐๐ โ 1.5 (17) sents vehicle instances in the program. The most im- portant class fields and properties representing the state ๐ฟ๐๐ ๐ก๐๐๐ก๐๐ = ๐๐๐ (18) 12 Figure 11: ChooseTurn method Figure 8: HowTheRouteRuns method Figure 12: TurnHard method Figure 9: Robot class Figure 10: Go method of the object can be seen in Fig. 9. ๐ต๐๐๐๐ class ob- ject, which belongs to the ๐ฟ๐๐๐.๐ธ๐ฃ3 library represents Figure 13: Test route the LEGO EV3 brick. ๐ถ๐๐๐๐๐๐ก๐๐ property represents the state of connection between the program and the robot. Fields ๐๐๐ ๐ก๐๐๐๐ ๐๐ and ๐๐๐โ๐ก๐๐๐๐ ๐๐ store values The method is responsible for choosing the direction obtained from color sensors. Fields _๐๐๐ ๐ก๐๐๐ก๐๐ and in which the robot should go. The code for this method _๐๐๐โ๐ก๐๐๐ก๐๐ store current motors speeds. is shown in Fig. 11. Go method This method belongs to the ๐ ๐๐๐๐ก class. TurnHard method This method also belongs to the The method is responsible for the robotโs movement. ๐ ๐๐๐๐ก class. It is responsible for updating the variables It contains loop in which the fuzzy system makes cal- representing the current motors power. The full code culations, decides about the next move and finally ma- of the method can be seen in Fig. 12. The ๐ ๐๐๐๐ก class kes that move by setting the power of motors. The full also has ๐๐ข๐๐๐ธ๐๐ ๐ฆ and ๐บ๐๐๐ก๐๐๐๐โ๐ก methods whose code of the method can be found in Fig. 10. operations are analogous to the ๐๐ข๐๐๐ป ๐๐๐ method. ChooseTurn method This method belongs to the ๐ ๐๐๐๐ก class. It is called in the loop described above. 13 Figure 14: A part of a test ride 5. Tests Interactive Learning Environments 27 (2019) 293โ306. In order to test how the vehicle performs we created a [3] N. L. Fanchamps, L. Slangen, P. Hennissen, test route (Fig. 13). The route is a 19-millimeter-wide M. Specht, The influence of sra programming black line on a white background. It is quite compli- on algorithmic thinking and self-efficacy using cated due to a lot of 90โฆ angle turns, it does not contain lego robotics in two types of instruction, Inter- crossroads though. The vehicle runs through the route national Journal of Technology and Design Edu- precisely but with little speed. It is worth mentioning cation (2019) 1โ20. that the system is incredibly sensitive to any changes [4] A. Spanรฒ, A. Cortesi, Legodroid: A type-driven in lightning and the non-uniformity of it. A part of a library for android and lego mindstorms interop- test ride can be seen in Fig. 14. erability, Sensors 20 (2020) 1926. [5] J. Vega, J. M. Caรฑas, Pybokids: An innova- tive python-based educational framework using 6. Conclusion real and simulated arduino robots, Electronics 8 Because of poor functioning of some of ๐ฟ๐๐๐.๐ธ๐ 3 li- (2019) 899. brary functions that our project was based on, the re- [6] J. Wang, X. Du, H. Wang, Research & imple- sults were not as good as we had imagined. Commands mentation of multitasking lego robots, in: 2019 must have been initialized for a specified time amount IEEE 4th International Conference on Advanced which led to delays and unstable movement of vehicle. Robotics and Mechatronics (ICARM), IEEE, 2019, What is more, in order to work properly the program pp. 655โ659. had to use function ๐ท๐๐๐๐ฆ(), which stops the robot [7] R. Giuliano, G. Cardarilli, C. Cesarini, L. Di Nun- suddenly for few milliseconds. zio, F. Fallucchi, R. Fazzolari, F. Mazzenga, M. Re, Considering that ๐ฟ๐๐๐.๐ธ๐ 3 library has not been up- A. Vizzarri, Indoor localization system based on dated for 7 years and itโs author officially abandoned bluetooth low energy for museum applications, the project, rewriting the whole project to ๐ ๐๐๐๐ก๐ถ lan- Electronics (Switzerland) 9 (2020) 1โ20. guage seems to be the best way to improve programโs [8] M. Woลบniak, D. Poลap, Soft trees with neural performance, allowing the program to run on EV3 brick components as image-processing technique for itself. Apart from solving problems mentioned above, archeological excavations, Personal and Ubiqui- that approach would also terminate problems connect- tous Computing (2020) 1โ13. ed with Bluetooth connection latency. [9] M. Woลบniak, D. Poลap, Intelligent home systems for ubiquitous user support by using neural net- works and rule based approach, IEEE Transac- References tions on Industrial Informatics (2019). [10] G. Capizzi, G. Lo Sciuto, C. Napoli, D. Polap, [1] L. I. Kovรกcs, Gesture-driven lego robots, Acta M. Woลบniak, Small lung nodules detection based Universitatis Sapientiae, Informatica 11 (2019) on fuzzy-logic and probabilistic neural network 80โ94. with bio-inspired reinforcement learning, IEEE [2] ร. Martรญnez-Tenor, A. Cruz-Martรญn, J.-A. Transactions on Fuzzy Systems 6 (2020). Fernรกndez-Madrigal, Teaching machine learning [11] J. T. Starczewski, P. Goetzen, C. Napoli, Triangu- in robotics interactively: the case of rein- lar fuzzy-rough set based fuzzification of fuzzy forcement learning with legoยฎ mindstorms, 14 rule-based systems, Journal of Artificial Intel- ligence and Soft Computing Research 10 (2020) 271โ285. [12] M. Woลบniak, D. Poลap, Hybrid neuro-heuristic methodology for simulation and control of dy- namic systems over time interval, Neural Net- works 93 (2017) 45โ56. [13] G. Capizzi, F. Bonanno, C. Napoli, Hybrid neural networks architectures for soc and voltage pre- diction of new generation batteries storage, 2011, pp. 341โ344. [14] F. Bonanno, G. Capizzi, C. Napoli, Some remarks on the application of rnn and prnn for the charge- discharge simulation of advanced lithium-ions battery energy storage, 2012, pp. 941โ945. 15