DEVELOPMENT OF THE CONTROL SYSTEM FOR LEGO MINDSTORMS EV3 MOBILE ROBOT BASED ON MATLAB/SIMULINK ELEMENTS

The Mindstorms EV3 robot, developed by LEGO, is one of the popular robots that has been widely used in various fields. Unlike previous versions of mobile LEGO robots, EV3 allows the development of real­time appli­ cations for teaching a variety of subjects, as well as for conducting research experiments. The object of research in this case is the Mindstorms EV3 robot connected to MATLAB/Simulink. The design consists of a controller, one color sensor, two servo motors and one support wheel. Each servo motor is built on a DC collector motor with a matching gearbox and has the ability to measure the number of revolutions corresponding. A digital sensor with a sampling frequency of 1 kHz is used as a color sensor, which can determine the color or brightness of light. Despite its popularity, the EV3 robot control system in interaction with the MATLAB/Simulink programming environment is a rather complex solution and therefore requires further research. The scientific part of the research focuses on discovering the regularities of the Mindstorms EV3 control system, developing a control system model, and explor­ ing the potential of MATLAB/Simulink to expand the robot’s capabilities. An analysis of the main elements of the control system, such as sensors and servos, was carried out. The graphs of the dependences of the characteristics of the servo drives were built and the efficiency of the robot movement was checked depending on the parameters set in the program. The result of the development of the mobile robot control system was the adjustment of the mobile robot movement regulators along a given trajectory in the form of a drawn line, which allowed estimating the maximum permissible speed of the robot movement. The presented research and development of a control sys­ tem based on MATLAB/Simulink elements allows using the proposed method to control a mobile robot with high precision, analyze and verify the robot’s electromechanical parameters in real time. This control system has a high potential and can practically be integrated into industrial objects of mobile robotics, provided types the sensors and executive mechanisms of the mobile robot match.


Introduction
During the last few years there have seen significant advances in robotics both in terms of hardware capabili ties as well as in terms of artificial intelligence.Arduino, Raspberry Pi, and Kinect are the most common lowcost devices for developing application control systems [1][2][3][4].In terms of robotics, a variety of lowcost mobile robots such as Adept, EPuck, Moway, LEGO Mindstorms, etc. have emerged in the last few years [5][6][7].These devices do not offer the same precision as industrial robots, but they are sufficient for educational purposes in engineering or even for experiments and research tests.
In the field of robotics, LEGO platforms are useful at various application levels, which are confirmed by a number of works.For example, in [8], LEGO Mindstorms was used in mobile robotics to implement Kalman filter (EKF).In [9], describes a set of projects that implement artificial intel ligence techniques using LEGO Mindstorms NXT.In [10], LEGO NXT Mindstorms was used in mechatronics, to teach the basics of mobile robot control, remote control, line tracing, fuzzy logic control techniques, and reactive navigation.In [11], cational handson project subsystems, a web camera, and convenient tools for finding and mapping indoor obstacles were proposed, and LEGO robot tracking was implemented using color marker detection and EKF.
LEGO Mindstorms EV3 is a robot building set that al lows creating and programming your own autonomous robots.There are various programming languages (C, Java, ADA, Phyton, LabView) that can be used to program these robots, but in this article, let's focus on using MATLAB [12,13].MATLAB is a popular software for numerical computation and data analysis, which can be used for robot develop ment and programming.
Pros of using MATLAB for programming LEGO Mind storms EV3 robots: 1. Ease of use: MATLAB has a simple and intuitive interface that makes robot programming easy.TECHNOLOGY AUDIT AND PRODUCTION RESERVES -№ 1/2(69), 2023 ISSN 2664-9969 2. Rich functionality: MATLAB provides a rich set of functions for numerical computations and data analysis, which can be useful when designing and programming robots.
3. Wide support: MATLAB has broad support and a large user community that can help with troubleshooting.
4. Integration with other tools: MATLAB can integrate with other tools and programming languages, allowing for expanded robot capabilities.
5. Support for various operating systems: MATLAB sup ports various operating systems, making it possible to use it on different devices.
Cons of using MATLAB for programming LEGO Mind storms EV3 robots: 1. High cost: MATLAB is paid software, which can be a barrier for some users.
2. High system requirements: MATLAB requires a high performance system, which can be an issue for users with weaker computers.
3. Limited capabilities: MATLAB may be limited in certain aspects of robot programming, especially when high speed and accuracy are required.
4. Limited selection of addon modules: MATLAB has a limited selection of addon modules for robots, which can be problematic for users who want to use a specific module or sensor.
5. Additional tools needed: Programming a robot with MATLAB may require additional equipment and tools, which can increase the overall cost of using the software.
The MATLAB Support Package for LEGO Mindstorms EV3 provides MATLAB functions to control the motors and interface with hardware input sensors and output capabilities.This support package enables the following tasks to be perfor med directly from MATLAB: -Motor control.
-Reading color and light intensity.
-Measuring distance and proximity.
-Acquiring rotation angle and speed.
-Displaying text on the EV3 Brick LCD.
-Emitting sound signals and playing tones on the EV3 speaker.
-Detecting button presses.The LEGO EV3 robot can be connected to a MATLAB desktop using Bluetooth, WiFi, or USB, and then MATLAB and the LEGO EV3 sensors can be used to program the robot to perform tasks such as line following, object detection, object sorting and collision avoidance.
Simulink support package for LEGO Mindstorms EV3.The Simulink support package for LEGO Mindstorms EV3 enables programming and running algorithms on LEGO Mind storms EV3 robots.The support package includes a library of Simulink blocks (Fig. 1) for configuring and accessing the robot's sensors, actuators, and communication interfaces.
It is possible to develop algorithms in Simulink, simulate them to ensure they function correctly, and load the com pleted algorithm for autonomous execution on the device (via USB, Bluetooth, WiFi, or Ethernet connections).It is also possible to adjust parameters in realtime from the Simulink model, and the algorithm executes on the EV3 block.
The support package includes: -A library of Simulink blocks that connect to LEGO Mindstorms EV3 I/O, including buttons and speakers; numerous input sensors, including color, touch, gyroscopic, ultrasonic, infrared, and encoders; and output sensors such as servo motors, status indicators, and displays.
-Support for LEGO Mindstorms NXT sensors on LEGO Mindstorms EV3 Bricks, including ultrasonic, touch, sound, battery, timer, and gyroscope.
-Interactive configuration of output parameters and monitoring of sensor input signals for applications run ning on LEGO Mindstorms EV3.
-UDP and TCP/IP blocks that allow communication with LEGO Mindstorms EV3 from Arduino, Raspber ry Pi™, and mobile devices (Android and iOS).
-Deployment of the model for autonomous operation.Despite its popularity, the EV3 robot control system in interaction with the MATLAB programming environ ment is a rather complex solution and therefore requires further research.The purpose of this study is to develop an effective control system for the EV3 robot using MATLAB with the study of the performance of the executive mecha nisms (motors) of the EV3 robot.

Materials and Methods
The object of research in this case is the EV3 robot developed by LEGO.The research was carried out using MATLAB software.The theoretical methods employed in this study include system identification and control theory.
In this case, the mobile robot is a differential vehicle with two servomotors, each connected to one of the wheels B and C. Each servo motor is built on a DC collector motor with a matching gearbox and has the ability to measure the number of revolutions corresponding to the wheel sensor.The mobile robot also has a color sensor that is mounted on the front of the vehicle and pointed directly at the ground.TECHNOLOGY AUDIT AND PRODUCTION RESERVES -№ 1/2(69), 2023

ISSN 2664-9969
The color sensor is a digital sensor that can detect the color or brightness of light entering a small window on the front of the sensor.This sensor can operate in three different modes: Color Mode, Reflected Light Intensity Mode, and Ambient Light Intensity Mode.The sampling rate of the color sensor is 1 kHz.In Reflected Light Intensity mode, the color sensor detects the brightness of light reflected from a red lamp.The sensor uses a scale from 0 (very dark) to 100 (very light).This means that the robot can be programmed to move on a white surface until a black line is detected.
Equations that describe the electric processes in a DC motor.In the armature circuit of the motor, a current The output differential equations of the DC motor are based on the laws of physics.The second Kirchhoff's law is used for the electric circuit, according to which the equation can be written as: where t is the current time; R AΣ I A characterizes the voltage drop on the active resistance of the armature circuit according to Ohm's law, and L AΣ (dI A /dt) reflects the presence of the counterEMF of selfinduction that arises in the winding when the armature current changes.The voltage drop on the brushes, which depends nonlinearly on the armature cur rent, is not taken into account in equation ( 1), but usually has a relatively small value compared to the voltage U A .
The differential equation that characterizes the pro cesses in the mechanical part of the motor is formed on the basis of the second law of Newton: where ω M is angular speed of rotation of the motor shaft.This equation does not take into account the action of friction forces that arise during the rotation of the rotor and have a relatively weak effect on the acceleration of the DC motor shaft.
Using the formulas provided above and bringing the differential equations to the normal Cauchy form, let's obtain the description of the DC motor in the form: The development of the control program for a mobile robot system that provides movement of the robot along a line of an arbitrary trajectory (Fig. 2) using an automa ton approach.The system consists of two parts: the robot executor and a user interface for a personal computer (PC).
The robot executor and the interface communicate with each other through a USB channel.The robot executor works in two modes: line movement (autonomous) and movement controlled by the PC user.To enable the robot to find and recognize a line on the ground, a color sensor must be used.For the color sensor to work correctly, the line thickness should be approximately 2 cm.
The control program algorithm is shown in Fig. 3.At the start, the color sensor determines the color of the object it is pointed at.Then, the value obtained from the color sensor is compared to a set threshold value using a comparator.If the value obtained from the color sensor is greater or less than the threshold value, the comparator will output the corresponding binary signal «1» or «0».The binary signal obtained from the comparator can be used to decide on further action.For example, if the binary signal is equal to «1», it means that the object's color meets a certain condition, and if the binary signal is equal to «0», the condition is not met.ISSN 2664-9969 made by the EV3 Controller, a digital signal is generated, which will be sent to the servos.

Results and Discussion
Line following is a classic robotics program that com bines algorithms for sensing, actuation, and control robots designed for line following are relatively simple to create and can navigate along a predetermined path autonomously without human intervention.This model (Fig. 4) imple ments a linefollowing algorithm on a twowheeled EV3 robot with a single color sensor.The robot uses feedback from the color sensor to follow the line and feedback from the motor sensors to maintain forward motion speed.Two controllers control speed and tracking.The controller is a common technique used in vari ous kinds of machineries such as vehicles, robots and even rockets, etc.The controller calculates the difference between the output and a required setpoint, and attempts to mini mize this difference by adjusting the inputs of system [14].
The sensors and motors contain blocks that interact with the EV3 hardware.State estimation uses the value of each mo tor sensor to calculate the position and speed of the robot.The desired speed takes the userspecified speed (m/s) and converts it to the required state values for the speed controller.The de sired light source takes the white and black color sensor values to select the appropriate reference value for the light source.
The robot is capable of following a line with smooth turns, but on sharp turns, the robot loses the line.The speed of the track is quite high.The proportionalintegralderiva tive (PID) controller allows achieving the best results, but it is quite complex to tune due to the presence of three coefficients.Thus, a PID controller can be recommended for the best routing, but careful tuning of the controller in changing conditions is required.If the speed of the robot along the line is not high, then it is better to use simpler algorithms, for example, PI or PD.The speed control is implemented with a PI controller to control the speed of the movement.The line tracking controller is implemented with a PD controller to control the turn.
In this section, the controller is designed using MATLAB/ SIMULINK, where the parameters of the coefficients should be adjusted, for the best distance covered by the robot.There are several ways to adjust the parameters: the gradient de scent method, the ZieglerNichols method [15], based on the obtained nonlinear dependencies of the robot's behavior.In our case, the behavior of the actuators was studied in detail on the basis of physical modeling of the operation of direct current motors.The following charts (Fig. 5-8) show the characteris tics of the EV3 servomotor versus applied load.EV3 was powered at 9 V. Power level is 100 % for all charts.Fig. 5 shows that the maximum mechanical power of 1.7 W is achieved with a torque load of approximately 21 N•cm after which it sharply decreases.In Fig. 6, the speed of rotation in relation to the torque decreases with the load and has an almost linear character.Fig. 7 shows that the maximum efficiency of 43 % of the engine is achieved at a torque load of approximately 10 N•cm.Fig. 8 shows the dependence of the current on the torque, and the current increases linearly with the load, which corresponds to the laws of electromechanics.All these studies were used to effectively configure the mobile robot control system.The results of the system are summarized in Table 1.

Table 1
The results of the experiment The proposed mobile robot control system showed high results of following the Mindstorms EV3 mobile robot along the line.At a movement speed of up to 0.2 m/s, the robot travels the full distance without errors.When the speed increases, the controller does not have time to react to the disturbance, which leads to the robot moving away from the distance.In further research, it is planned to improve robot motion controllers based on the use of a fuzzy controller that will process the nonlinear charac teristics obtained in this article and issue a control signal taking into account the theory of fuzzy sets.

Conclusions
In this paper, LEGO Mindstorms EV3 can potentially be used as a robust robotic platform for learning theoreti cal algorithms.The platform allows implementing control algorithms by simply programming on a highlevel lan guage interface.
The results showed that this control system allows ensuring the desired behavior of the robot depending on the color of the object to which the sensor is directed.Speed control has the implementation of a PI controller to control the speed of movement.Line tracking control has a PD controller implementation for position control.
Experimental results show that at a speed of 0.1, 0.2 m/sthe robot drives precisely and smoothly along the track; 0.3 m/s -the robot moves with small errors on turns; 0.35 m/s -the robot drives with a large error after turn ing, but always returns to the track; 0.4 m/s -the robot goes off track after the first turn and does not return.
The obtained results can be useful for the further de velopment of mobile robot control systems that use servos and a color sensor.For example, based on the obtained results, it is possible to develop control algorithms that will ensure efficient and accurate movement of the ro bot in various conditions.Positive results were obtained regarding the performance and accuracy of the control system based on MATLAB elements.

Fig. 1 .
Fig. 1.Simulink block library for EV3 I A flows under the influence of the DC voltage U A of the power supply and the counterEMF of the motor E. This circuit is characterized by the parameters: the active resis tance R A [Ohm] and inductance L A [H] of the armature winding, as well as the active resistances and inductances of the connected series choke (R CH [Ohm], L CH [H]) and transformer (R TR [Ohm], L TR [H]).The rotating rotor, which has a moment of inertia J A [kg•m 2 ], and the working element connected to it with the moment of inertia J WE are set in motion simultaneously by the action of the electromagnetic moment of the motor M EMM and the moment of resistance of external forces M N applied to the working element.

Fig. 4 .
Fig. 4. MATLAB control system model for a mobile robot

Speed Result of the experiment 0. 1 m
/s The robot drives accurately and smoothly along the track 0.2 m/s The robot drives accurately and smoothly along the track 0.3 m/s The robot drives with slight errors on turns 0.35 m/sThe robot drives with a large error after the turn, but always returns to the track 0.4 m/s The robot deviates from the track after the first turn and does not return