<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Fuzzy system as a method of controlling LEGO Linefollower vehicle using C# programming language</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Krzysztof Grzesica</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Jakub Wadas</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Faculty of Applied Mathematics, Silesian University of Technology</institution>
          ,
          <addr-line>Kaszubska 23, 44-100 Gliwice</addr-line>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>SYSTEM 2020: Symposium for Young Scientists in Technology, Engineering and Mathematics</institution>
          ,
          <addr-line>Online</addr-line>
        </aff>
      </contrib-group>
      <fpage>9</fpage>
      <lpage>15</lpage>
      <abstract>
        <p>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. lect such libraries and optimize them for robotic constructions. Also some approaches are based on frameIn 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 elmay 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 dewe 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 interestin 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 proOn 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 conLEGO 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 congramming languages in developing such robots. trolled by our developed artificial intelligence to folHowever the most necessary is tu use an optimal low the line. our experiment shows that our construclibrary, 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-</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;LEGO robot</kwd>
        <kwd>Line detection</kwd>
        <kwd>Fuzzy rules</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>© 2020 Copyright for this paper by its authors. Use permitted under Creative
CPWrEooUrckReshdoinpgs IhStpN:/c1e6u1r3-w-0s.o7r3g CCoEmUmoRns WLiceonrsekAsthtriobuptioPnr4o.0cIneteerdnaitniognasl ((CCC EBYU4R.0)-.WS.org)</p>
    </sec>
    <sec id="sec-2">
      <title>2. Model</title>
      <p>In this section we will describe how we have developed
the model both from programming side and thinking
model.</p>
      <sec id="sec-2-1">
        <title>2.1. Project assumptions</title>
        <p>The aim of this project was to build an artificial
intelligence system based on fuzzy logic, which would
steer the vehicle used in LEGO Line-follower
competition. Based on readings, the system must decide how
to change the speed of each engine, so that:
• The vehicle does not go of the road (A moment
when a black line is not between vehicle’s wheels
is considered going of the road)
  = 100 (2)
• The vehicle goes as fast as possible   −</p>
        <p>Where   and  are accordingly, maximum and</p>
        <p>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
conThen, based on calculation results appropriate com- figuration. Reading output is determined using the
folmands from the computer are sent to robot. lowing formula:</p>
      </sec>
      <sec id="sec-2-2">
        <title>2.2. Robot Construction</title>
        <p>
          = |( 
− 
) ∗   − 100|
(
          <xref ref-type="bibr" rid="ref2">3</xref>
          )
To accomplish that task we have built a vehicle using  = |(ℎ −  ) ∗   − 100| (
          <xref ref-type="bibr" rid="ref10 ref4">4</xref>
          )
bLrEiGckO, iptairstse. quTihpeperdobwoitthis tbwaosecdoloonr isnetneslolirgse,nwthEiVch3 rWawhevreual es returnedabnydlefℎt and right coalroerrseesnpesoctri.vely
hmieclaesuisredrthiveelnevbeyl towf oreiflencdteedpelnigdhetnttheenygeinmeist.wThhiechved-i- means atontdal white,t1a0k0e -vpaluureesbflraocmk. 0 to 100, where 0
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:
        </p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>3. Mathematical Model</title>
      <sec id="sec-3-1">
        <title>3.1. Normalization</title>
        <p>
          Firstly, we must normalize the readings from color
sensors to negate the hardware diferences. To do that we
must first calculate parameters   and   accordingly
as:
  =
 
100
− 
(1)
=

− 
10
(
          <xref ref-type="bibr" rid="ref6">5</xref>
          )
If both color sensors went of the road the variable
 i set to 10 or -10 depending on the side of road
the sensors are located.
        </p>
      </sec>
      <sec id="sec-3-2">
        <title>3.2. Fuzzyfication</title>
        <p>To determine grade of membership Bell shaped and
Linear functions are used. The formulas are as follows:</p>
        <p>{

=</p>
        <p>
          1
1+|  − |2
0
{
,  ⩽  ⩽ 
,  &lt; 
∨  &gt; 
 = 01 ,,  &lt;⩾00 (
          <xref ref-type="bibr" rid="ref13">7</xref>
          )
Where ,  are parameters. Variables  and  are
endpoints of interval. Variable  stands for center of
function. In our project  = 2.5 and  = 2.5 in all but
one membership function. The membership function
Straight uses  = 1.5. The reading membership
functions can be seen in Fig.3, while speed membership
functions in Fig. 4.   ∗   +   ∗   +   ∗
        </p>
        <p>Then, the resultant vehicle speed composed from  =
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 coeficients of
bership for all of speed membership functions and ac- speed rules.
cordingly to fuzzy rules base shown in Tab. 1 we
conduct necessary calculations.</p>
        <p>The results are being grouped by the rules they
correspond with and for each of rule we choose the biggest
value. Lets assume that the biggest value for rule slow
is   , for medium -   and for fast -   . The final
resultant speed is obtained by using center of gravity
method defined as:</p>
        <p>
          (
          <xref ref-type="bibr" rid="ref15">8</xref>
          )
        </p>
      </sec>
      <sec id="sec-3-3">
        <title>3.3. Defuzyfication</title>
        <p>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,
accordingly 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
biggest 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
by using center of gravity method defined as:
ℎ 
=

(19)

=
 1 ∗  1 +  2 ∗  2 +  3 ∗  3 +  4 ∗  4 +  5 ∗  5</p>
        <p>
          1 +  2 +  3 +  4 +  5
arewchoeerficeie n1ts=o−f 1in0c0l,in2at=io−n5r0u,le3s a=cc0o,rd4in=g5ly0,fo5r H=L1,00 4.2. Program code
EL, S, ER and HR. The program is written in  #. In addition to the
stanof Fmineamllbye,rtshheipruvlaeluweitihs tchheosgernea.tDesetpienncdliinnagtioonn igt,rathdee ldiabrrdar.y for cloimbrmaruiensi,cathtieonprboegtwraemenutshees ctohme p.uter and3
engines speeds are calculated and set. For Hard Left the robot. The program has been divided into classes
(
          <xref ref-type="bibr" rid="ref19">10</xref>
          ) 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).
        </p>
        <p>Based on the mathematical model described above, we
have created a robot control application. The
application has a very simple graphical user interface, which
makes it user-friendly. In Fig. 5 and Fig. 6 application
window can be seen.
  
ℎ 
  
ℎ 
  
  
ℎ 
  
ℎ 

4
=
= 
= 
=</p>
        <p>Reading method This method is responsible for the
normalization of color sensor data. This method also
serve as a precaution against loosing the route by a
robot. Method code can be seen in Fig. 7.
(12) HowTheRouteRuns method This method is a
frag(13) ment of the fuzzy system. It combines the route
incli</p>
        <p>nation with the current vehicle speed and decides how
(14) to react based on that data. A piece of the method code
(15) is in Fig. 8.</p>
        <p>Robot class This is the class which object
repre(17) sents vehicle instances in the program. The most
important class fields and properties representing the state
of the object can be seen in Fig. 9.   class
object, which belongs to the . 3 library represents
the LEGO EV3 brick.  property represents
the state of connection between the program and the
robot. Fields   and  ℎ store values
obtained from color sensors. Fields _   and
_ ℎ  store current motors speeds.
The method is responsible for choosing the direction
in which the robot should go. The code for this method
is shown in Fig. 11.</p>
        <p>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
ckoedsethoafttmheovmeebthyosdetctianngbtehefopuonwdeirnoFfimg.o1t0o.rs. The full aolpseorahtaiosn  s are analoganouds tℎo the     methomdsetwhohdo.se

ChooseTurn method This method belongs to the
class. It is called in the loop described above.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>5. Tests</title>
      <p>In order to test how the vehicle performs we created a
test route (Fig. 13). The route is a 19-millimeter-wide
black line on a white background. It is quite
complicated due to a lot of 90◦ angle turns, it does not contain
crossroads though. The vehicle runs through the route
precisely but with little speed. It is worth mentioning
that the system is incredibly sensitive to any changes
in lightning and the non-uniformity of it. A part of a
test ride can be seen in Fig. 14.</p>
    </sec>
    <sec id="sec-5">
      <title>6. Conclusion</title>
      <p>Because of poor functioning of some of . 3
library functions that our project was based on, the
results were not as good as we had imagined. Commands
must have been initialized for a specified time amount
which led to delays and unstable movement of vehicle.
What is more, in order to work properly the program
had to use function  (), which stops the robot
suddenly for few milliseconds.</p>
      <p>Considering that . 3 library has not been
updated for 7 years and it’s author oficially abandoned
the project, rewriting the whole project to 
language seems to be the best way to improve program’s
performance, allowing the program to run on EV3 brick
itself. Apart from solving problems mentioned above,
that approach would also terminate problems
connected with Bluetooth connection latency.
rule-based systems, Journal of Artificial
Intelligence and Soft Computing Research 10 (2020)
271–285.
[12] M. Woźniak, D. Połap, Hybrid neuro-heuristic
methodology for simulation and control of
dynamic systems over time interval, Neural
Networks 93 (2017) 45–56.
[13] G. Capizzi, F. Bonanno, C. Napoli, Hybrid neural
networks architectures for soc and voltage
prediction 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
chargedischarge simulation of advanced lithium-ions
battery energy storage, 2012, pp. 941–945.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          <source>Interactive Learning Environments</source>
          <volume>27</volume>
          (
          <year>2019</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>N. L.</given-names>
            <surname>Fanchamps</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Slangen</surname>
          </string-name>
          , P. Hennissen,
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          <string-name>
            <surname>cation</surname>
          </string-name>
          (
          <year>2019</year>
          )
          <fpage>1</fpage>
          -
          <lpage>20</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>A.</given-names>
            <surname>Spanò</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Cortesi</surname>
          </string-name>
          ,
          <article-title>Legodroid: A type-driven</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          <string-name>
            <surname>erability</surname>
          </string-name>
          ,
          <source>Sensors</source>
          <volume>20</volume>
          (
          <year>2020</year>
          )
          <year>1926</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>J.</given-names>
            <surname>Vega</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. M.</given-names>
            <surname>Cañas</surname>
          </string-name>
          , Pybokids: An innova-
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          <article-title>real and simulated arduino robots, Electronics 8</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>J.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Du</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Wang</surname>
          </string-name>
          , Research &amp; imple-
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          <article-title>mentation of multitasking lego robots</article-title>
          ,
          <source>in: 2019</source>
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>IEEE 4th International Conference on Advanced</mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          <string-name>
            <surname>Robotics</surname>
          </string-name>
          and
          <string-name>
            <surname>Mechatronics (ICARM),</surname>
            <given-names>IEEE</given-names>
          </string-name>
          ,
          <year>2019</year>
          ,
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          pp.
          <fpage>655</fpage>
          -
          <lpage>659</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>R.</given-names>
            <surname>Giuliano</surname>
          </string-name>
          , G. Cardarilli,
          <string-name>
            <given-names>C.</given-names>
            <surname>Cesarini</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Di</surname>
          </string-name>
          Nun-
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          <string-name>
            <surname>Electronics</surname>
          </string-name>
          (Switzerland)
          <volume>9</volume>
          (
          <issue>2020</issue>
          )
          <fpage>1</fpage>
          -
          <lpage>20</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>M.</given-names>
            <surname>Woźniak</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Połap</surname>
          </string-name>
          ,
          <article-title>Soft trees with neural</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          <string-name>
            <surname>tous Computing</surname>
          </string-name>
          (
          <year>2020</year>
          )
          <fpage>1</fpage>
          -
          <lpage>13</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>M.</given-names>
            <surname>Woźniak</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Połap</surname>
          </string-name>
          , Intelligent home systems
        </mixed-citation>
      </ref>
      <ref id="ref18">
        <mixed-citation>
          <source>tions on Industrial Informatics</source>
          (
          <year>2019</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref19">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>G.</given-names>
            <surname>Capizzi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. Lo</given-names>
            <surname>Sciuto</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Napoli</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Polap</surname>
          </string-name>
          , [1]
          <string-name>
            <surname>L. I. Kovács</surname>
          </string-name>
          ,
          <article-title>Gesture-driven lego robots, Acta M. Woźniak, Small lung nodules detection based</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref20">
        <mixed-citation>
          <string-name>
            <given-names>Universitatis</given-names>
            <surname>Sapientiae</surname>
          </string-name>
          ,
          <source>Informatica</source>
          <volume>11</volume>
          (
          <year>2019</year>
          )
          <article-title>on fuzzy-logic and probabilistic neural network</article-title>
        </mixed-citation>
      </ref>
      <ref id="ref21">
        <mixed-citation>
          80-
          <fpage>94</fpage>
          .
          <article-title>with bio-inspired reinforcement learning</article-title>
          ,
          <source>IEEE [2] Á</source>
          .
          <string-name>
            <surname>Martínez-Tenor</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          <string-name>
            <surname>Cruz-Martín</surname>
          </string-name>
          ,
          <source>J.-A. Transactions on Fuzzy Systems</source>
          <volume>6</volume>
          (
          <year>2020</year>
          ).
        </mixed-citation>
      </ref>
      <ref id="ref22">
        <mixed-citation>
          <string-name>
            <surname>Fernández-Madrigal</surname>
          </string-name>
          ,
          <source>Teaching machine learning</source>
          [11]
          <string-name>
            <given-names>J. T.</given-names>
            <surname>Starczewski</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Goetzen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Napoli</surname>
          </string-name>
          , Triangu-
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>