Conceptual Design of BCI for Mobile Robot Control

This paper presents an application of Hierarchical Systems (HS) technology in conceptual and detailed design of Brain Computer Interface (BCI) system to control a mobile robot. The BCI is a biomechatronic system that includes biological (brain), computer (control PC), electronic (sensors), visual informatics (LCD—liquid crystal display, GUI—graphic user interface) and executive electro-mechanical (MR—mobile robot) subsystems. Therefore, the conceptual model of the designed BCI system should present connected formal models of the above subsystems presented in the general systemic basis. The structure of the BCI system, its dynamic realization as a unit in its environment and MR environment are presented formally as well. In addition, the conceptual model should also take into account the BCI inter-level relations performed by MR coordinator implemented in the form of the design and control system. Therefore, HS model (and its standard block aed—ancient Greek word) is selected and described as the formal basis of the conceptual model of BCI system in the first part of the given paper. BCI system detailed design is under consideration in the second part of the paper. BCI control system and MR design results, as well as MR control process are also described in the final part of the paper.


Introduction
At the end of the 20th century, leading research centers around the world, i.e., Graz University of Technology, Austria; University of Rochester, USA; EPFL, Switzerland; etc., initiated research aimed at developing Brain Computer Interfaces-BCI, which provide communication between a computer and a human brain. In the presented work, we deal with the conceptual design of the laboratory-level BCI system created in Process Control Dept., AGH University of Science and Technology, Poland [1,2]. This BCI system consists of measuring and computer control subsystems, mobile robot (MR) and man-operator. All the subsystems are briefly described in this paper. Formal basis for the Conceptual Design (CD) of the BCI system and its brief conceptual model are presented in the first part (Sections 2.1 and 2.2) of the paper. The results of the BCI system detailed design and MR control processes are described in the second part (Sections 2.2 and 2.3). A review of the literature on BCI systems will not be given in the paper since the focus of this work is to apply the Hierarchical Systems technology [2] to the BCI system design, which is a novel concept to this area of research.
Concerning the first part, the conceptual model of BCI being created at the conceptual design phase [2] must be coordinated with numerical and geometrical systems, taking into account connected mechanical, electro-mechanical, electronic, computer, and biological subsystems of BCI biomechatronic system. Besides, a conceptual model, which will be implemented in systems coordination (design and control), should describe all the subsystems, the mechanism of their interaction, technology of subsystems integration in the structure of higher level, and the system environment in common formal basis. Therefore, creation of a BCI conceptual model that will meet all the above mentioned requirements is a task of a high importance. This task is crucial for mechatronic systems and computer aided design (CAD) systems in particular [3].
According to the above formulated requirements, the conceptual model implemented in BCI design must be a hierarchical construction that connects any level BCI subsystem with its lower and higher levels. Therefore, Hierarchical System (HS) [4], with its standard block aed [5][6][7][8][9], which meets all of the above requirements for the BCI conceptual model, was selected as the formal basis for BCI system conceptual design (Section 2) in this paper. An overview of the other conceptual design methods is presented in the monograph [9] available online. An issue of interest in this study was to verify whether HS technology and the conceptual model could be implemented in the conceptual design of the BCI system taking into account all the subsystems (mechanical, electromechanical, electronic, and biological) of a BCI-MR biomechatronic system. The results of this study are given below.
Concerning the second part, the BCI system detailed design for performing MR control processes is executed in a laboratory environment. The purpose of this work is to control MR utilizing bioelectric activity of the human brain. This study was based on the use of visually evoked potentials, which are the brain's response to retinal light stimulation. The possibility to use the BCI system by people with disabilities is one of the tasks of this work. The desired characteristics of the BCI system are real-time efficient operation, safety and ease of use. Providing real-time control without response delay requires proper optimization of the implemented algorithm and reduction of hardware requirements where possible. Ease of use can be achieved with high-frequency visually evoked potentials. In such conditions, a person will not be exposed to excessive noticeable stimuli of flickering light. On the other hand, the detection of the higher frequencies of electroencephalogram (EEG) signals is complicated [10]. Another important characteristic is safety. To minimize the possibility of the MR getting into forbidden places, one should be focused on the mobile robot motion. The definition of the MR workspace and the appropriate MR control algorithms should ensure the safety of the patient and his environment.

Theoretical Basis for Conceptual Design
Aed model S considered below unites the codes of the two level system [5] and general systems theory [11], numeric positional codes L s , geometry, and cybernetic methods. Aed is a standard element of Hierarchical Systems [5][6][7][8][9], which implements the general laws of systems organization on each level and the inter-level connections (see Figure 1). Aed S contains ω and σ models connected by coordinator S 0 : where ω is the dynamic representation of the level system in its environment ε S ; σ is the system structure; S 0 is the coordinator; ∈ L s , L s is numerical positional system. Aed scheme is given in Figure 1. Connected dynamic representations ω of aed elements, i.e., object o S , processes oπ S , επ S and environment ε S are presented in (ρ, ϕ) form: where ρ and ϕ are reactions and state transition functions respectively, C is state, X is input, Y is output, and T is time of level . Object o S , processes π S ↔ { oπ S , επ S } and environment ε S are connected by their states, inputs and outputs [5-9].  The structure of system  S is defined in the following way: and  σ is as follows: where  0 S is a coordinator, Being the main element of hierarchical systems, the coordinator performs the design and control tasks on its strata [5][6][7][8][9]. The coordinator is presented according to aed model (1) in the form (5): S is the coordinator control unit. Coordinator  0 S is constructed recursively, and performs the design and control tasks on its selection, learning and self-organization strata [5][6][7][8][9].
Geometrical signs and metric characteristics μ ℓ of systems S ℓ being designed and controlled are defined in the framework of aed formal model in codes of numeric positional system S L [5][6][7][8][9]. The main of them are constructive dimension δ ℓ and connection defect ξ ℓ . For instance, the constructive dimension δ ℓ is presented in code S L as follows: ↔ ↔ Figure 1. Structural scheme of aed-standard block of HS. S 0 is the coordinator, ε S is the environment, S i are subsystems, π S i are subprocesses, π S l is the process of level , X l and Y l are the input and output of mechatronic system S l ; and c i , z i , γ, w i , u i , y i are interactions.
The structure of system S is defined in the following way: and σ is as follows: where S 0 is a coordinator, ω ±1 are aggregated dynamic models of subsystems S ±τ , and σ γ are structural connections. σ is the set of ω ±1 subsystems and their structural connections σ γ coordinated with external ones ω γ = σ γ ±τ S . Being the main element of hierarchical systems, the coordinator performs the design and control tasks on its strata [5][6][7][8][9]. The coordinator is presented according to aed model (1) in the form (5): where ω 0 is the dynamic realization of S 0 , σ 0 is the structure of coordinator S 0 , and S 00 is the coordinator control unit. Coordinator S 0 is constructed recursively, and performs the design and control tasks on its selection, learning and self-organization strata [5][6][7][8][9]. Geometrical signs and metric characteristics µ of systems S being designed and controlled are defined in the framework of aed formal model in codes of numeric positional system L S [5-9]. The main of them are constructive dimension δ and connection defect ξ . For instance, the constructive dimension δ is presented in code L S as follows: where δ ω and δ σ are constructive dimensions of σ and ω respectively. This representation of geometrical information about systems S being designed allows execution of all computer operations with geometric images as operations with numeric codes. Aed formal model briefly described above presents a theoretical basis for the BCI biomechatronic system conceptual design and control.

Conceptual Model for BCI System Design
The conceptual model of the BCI system is briefly presented below, as an example of a biomechatronic system description in the theoretical basis of hierarchical systems (HS). The object under consideration in this work is the BCI system ( Figure 2), with its measuring, computer, man-operator, and mobile robot subsystems, developed in AGH University of Science and Technology, Poland [1,2]. Systemic conceptual model of the BCI system is given in aed form (6) of HS: where, ω is an aggregated dynamic representation of BCI, σ is the system structure, S 0 is BCI system coordinator (design & control system), and is the index of level. Structural scheme of the BCI system being designed is presented in Figure 2 in agreement with aed diagram (Figure 1). According to (3,4), BCI system structure σ contains coordinator S 0 , the set of sub-systems ω −1 and their structural connections σ γ . The BCI subsystems S ±τ presented in ω −1 form (2) are: ω −1 1 : man-operator; ω −1 2 : measuring system; ω −1 3 : computer control system; ω −1 4 : mobile robot. BCI system coordinator S 0 is presented by man-coordinator and distributed design and control units. Computer control BCI subsystem ω −1 3 partially performs coordinator functions as well.
where ω δ and σ δ are constructive dimensions of σ and ω respectively.
This representation of geometrical information about systems S ℓ being designed allows execution of all computer operations with geometric images as operations with numeric codes. Aed formal model briefly described above presents a theoretical basis for the BCI biomechatronic system conceptual design and control.

Conceptual Model for BCI System Design
The conceptual model of the BCI system is briefly presented below, as an example of a biomechatronic system description in the theoretical basis of hierarchical systems (HS). The object under consideration in this work is the BCI system ( Figure 2), with its measuring, computer, man-operator, and mobile robot subsystems, developed in AGH University of Science and Technology, Poland [1,2]. Systemic conceptual model of the BCI system is given in aed form (6) of HS: where,  ω is an aggregated dynamic representation of BCI,  σ is the system structure,  0 S is BCI system coordinator (design & control system), and  is the index of level.
Structural scheme of the BCI system being designed is presented in Figure 2 in agreement with aed diagram (Figure 1). According to (3,4), BCI system structure  σ contains coordinator   In their turn, each subsystem i S −1 of level −1 has its own structural elements-lower level −2 subsystems presented in aggregated dynamic ij ω −2 form. For the Mindstorms NXT 2.0 mobile robot As for the mobile robot 4 S −1 subsystem, concerning its motion process, the realization 4 ω −1 used at the conceptual design phase in (ρ,ϕ) form (2) can be presented in form (8) at the detailed design phase as the following kinematics equations [12]: (8) which connects linear .
x, . y and angular . ϕ velocities of robot center point P(x,y) (located in the middle of the axis connecting driven robot wheels) as the output 4 Y −1 with the input 4 X −1 , i.e., linear velocities of the centers of the left v l and right v r wheels of robot. a is the distance between the centers of the left and right wheels, and ϕ is the angle between Xg and Xr axes of the global g and the local robot r coordinate systems respectively ( Figure 3). The robot designed has the independent drives of both wheels and Instantaneous Center of Curvature (ICC), around which the rotary motion is performed by robot. ICC is placed in the line connecting the centers of the two wheels. For the case of the robot motion shown in Figure 3, ICC is separated from point P(x,y) by the distance R. The rotation around the ICC point takes place if speed values of each wheel are different.
For example, servos 42ω ℓ-2 and wheels 41ω ℓ-2 are connected by gear transmission, which is the structural connection of them, and at the same time is subsystem of level l−3, i.e., structural element of servo 42ω ℓ-2 . Similarly, the higher level subsystems 1 −  ω are connected by their common parts, i.e., structural connections σγ ℓ-1 that are the elements of lower levels. Man-operator 1ω ℓ-1 and measuring subsystem 2ω l−1 are connected by their common elements-electrodes attached to human's head. Aggregated dynamic realizations ω ℓ-1 , i.e., dynamic models i(ρ,φ) ℓ-1 of BCI subsystems are formed after the definition of their inputs-outputs according to each concrete sub-process they execute. As for the mobile robot 4S ℓ-1 subsystem, concerning its motion process, the realization 4ω ℓ-1 used at the conceptual design phase in (ρ,φ) form (2) can be presented in form (8) at the detailed design phase as the following kinematics equations [12]: which connects linear ,̇ and angular ̇ velocities of robot center point P(x,y) (located in the middle of the axis connecting driven robot wheels) as the output 4Y ℓ-1 with the input 4X ℓ-1 , i.e., linear velocities of the centers of the left vl and right vr wheels of robot. a is the distance between the centers of the left and right wheels, and φ is the angle between Xg and Xr axes of the global g and the local robot r coordinate systems respectively ( Figure 3). The robot designed has the independent drives of both wheels and Instantaneous Center of Curvature (ICC), around which the rotary motion is performed by robot. ICC is placed in the line connecting the centers of the two wheels. For the case of the robot motion shown in Figure 3, ICC is separated from point P(x,y) by the distance R. The rotation around the ICC point takes place if speed values of each wheel are different.  The model of robot kinematics was implemented within the frameworks of Matlab/Simulink program environment for performing a kinematic task at the detailed design phase. The general view of the model is presented in Figure 4. The inputs of RobotKinematicModel block are linear velocities of the centers of the left v l and right v r wheels of the robot respectively. The outputs are point P coordinates (x,y), ICC coordinates xICC and yICC, distance R, and angle ϕ value phi ( Figure 4a). The detailed structure of the RobotKinematicModel block is shown in Figure 4b, which illustrates the graphical representation of the robot kinematics equations describing the robot's location.
Appl. Sci. 2020, 10, x FOR PEER REVIEW 6 of 16 4a). The detailed structure of the RobotKinematicModel block is shown in Figure 4b, which illustrates the graphical representation of the robot kinematics equations describing the robot's location.
(a) (b) At the detailed design phase, simulation studies of the mobile robot movement were carried out. For this purpose, a special environment was created to animate the movement of the robot. The robot's movement was set by the linear velocity value of the left vl and the right vr of the wheel.  At the detailed design phase, simulation studies of the mobile robot movement were carried out. For this purpose, a special environment was created to animate the movement of the robot. The robot's movement was set by the linear velocity value of the left v l and the right v r of the wheel. As for the robot dynamics, aggregated dynamic model ) , (   of the MR can be presented at the phase of the detailed design like in [13] or in the following form: State equation in (9) corresponds to the state transition function  in MR conceptual model (2) and the second output equation corresponds to the reaction  . Vectors x, y, u and matrices A, B, C must be predefined. In the case of the mobile robot motion, the elements of states vector x = [x1 x2] T are the displacement x1 and velocity x2. Mobile robot kinematics and dynamics tasks, briefly described above, belong to analysis design task of the BCI subsystem being designed, i.e., mobile robot in our case.
Concerning the man-operator subsystem, its model  As for the robot dynamics, aggregated dynamic model (ρ, ϕ) of the MR can be presented at the phase of the detailed design like in [13] or in the following form: State equation in (9) corresponds to the state transition function ϕ in MR conceptual model (2) and the second output equation corresponds to the reaction ρ. Vectors x, y, u and matrices A, B, C must be predefined. In the case of the mobile robot motion, the elements of states vector x = [x 1 x 2 ] T are the displacement x 1 and velocity x 2 . Mobile robot kinematics and dynamics tasks, briefly described above, belong to analysis design task of the BCI subsystem being designed, i.e., mobile robot in our case.
Concerning the man-operator subsystem, its model ω − 1   1 can be constructed on its inputs X −1 1 , i.e., visual stimuli signals, perceived by human eyes; its outputs Y −1 1 , i.e., EEG signals recorded by measuring system ω −1 2 , taking into consideration human's physiological state C −1 1 . Measuring subsystem ω −1 2 purpose is EEG signals registration, processing and data transmitting to BCI control system by TrueScan 24 subsystem. TruScan Acquisition program is used as software means to perform impedance measurements. The electroencephalographic (EEG) signal was recorded using the EEG cap of Deymed Diagnostic company (Figure 6a), containing 19 chlorine silver electrodes (Ag/AgCl) arranged according to the International System 10-20. In addition, the cap contained a reference electrode and a grounding electrode (Figure 6b). The cap is placed on the head of the subject, i.e., man-operator, being examined (Figure 6c). EEG gel application to the measuring electrodes allowed to maintain electrodes impedance at 2-5 kΩ level during the conducted tests.
as software means to perform impedance measurements. The electroencephalographic (EEG) signal was recorded using the EEG cap of Deymed Diagnostic company (Figure 6a), containing 19 chlorine silver electrodes (Ag/AgCl) arranged according to the International System 10-20. In addition, the cap contained a reference electrode and a grounding electrode (Figure 6b). The cap is placed on the head of the subject, i.e., man-operator, being examined (Figure 6c). EEG gel application to the measuring electrodes allowed to maintain electrodes impedance at 2-5 kΩ level during the conducted tests. The BCI environment has its own structure and contains the following sub-systems: panel . All these processes are described according to (2).
So, all the subsystems of the BCI biomechatronic system, i.e., man-operator The BCI environment has its own structure and contains the following sub-systems: panel ω +1 1 which generates light stimuli perceived by man-operator's eyes; floor area ω +1 2 where the mobile robot moves; man-coordinator ω +1 3 , which places electrodes on man-operator's ω −1 1 head and attaches the measuring system; the higher level l + 1 design and control system ω +1 4 . The BCI system contains π S i sub-processes, which are the parts of the higher-level process π S (see Figure 1) performed by the entire BCI system: ( π S 1 ) ionic current flows generation within the neurons of the human brain, performed by the man-operator, ( π S 2 ) EEG signal acquisition by the measuring system; ( π S 3 ) data analysis and control signals generation for the mobile robot performed by computer subsystem; ( π S 4 ) mobile robot motion. Each process contains its lower-level sub-processes, e.g., ( π S 3 ) process of computer subsystem contains low-level −1 process of data reading π S −1 31 , digital filtering π S −1 32 , Fast Fourier Transformation π S −1 33 , signal spectral analysis π S −1 34 , frequency verification π S −1 35 , and generation of control signals for the mobile robot π S −1 36 . All these processes are described according to (2).
So, all the subsystems of the BCI biomechatronic system, i.e., man-operator S 1 , measuring S 2 , computer S 3 , and mobile robot S 4 systems have their aggregated dynamic ω and structural σ descriptions. All the connected descriptions of the subsystems S i and their processes π S i are presented in the knowledge base of the coordinator that performs the design and control tasks, connecting in this way structure σ and dynamic realization ω of the BCI system being coordinated.
BCI coordinator S 0 is described according to (5) and implemented by the human-computer design and control BCI subsystems including the MR controller. The coordinator maintains BCI functional modes by the man-operator and control system and performs the design process by the higher level CAD system. The BCI control system is described in the following Section 2.3.

Design of BCI Control System
The design process of BCI control system of the mobile robot (MR) also contains two stages, i.e., conceptual and detailed design phases. The conceptual model of the BCI control system is presented in form (5) of HS coordinator (S 0 ) briefly described above in Section 2.1 as well as in another work [2]. Aggregated dynamic model ω 0 of the BCI control system (S 0 ) is built on the relation of the control system inputs X 0t , outputs Y 0t and states C 0t , presented in the following (ρ, ϕ) 0 form: Appl. Sci. 2020, 10, 2557 9 of 16 The inputs X 0 and outputs Y 0 of the coordinator of − 1 level are defined on the sets of its coordination signals G and feedbacks W as follows: As for the control system of Mindstorms mobile robot (Figure 7), it is presented by the internal control unit NXT 2.0 (which consists of ARM7 and AVR microcontrollers) and BCI control PC in the form of the coordinator according to the scheme presented in Figure 1 (Section 2.1).
[2]. Aggregated dynamic model 0 ω of the BCI control system ( 0 S ) is built on the relation of the control system inputs The inputs X0 and outputs Y0 of the coordinator of ℓ − 1 level are defined on the sets of its coordination signals G and feedbacks W as follows: As for the control system of Mindstorms mobile robot (Figure 7), it is presented by the internal control unit NXT 2.0 (which consists of ARM7 and AVR microcontrollers) and BCI control PC in the form of the coordinator according to the scheme presented in Figure 1 (Section 2.1).

Figure 7. BCI control PC
 0 S and NXT control unit is a feedback from MR, i.e., NXT 2.0 control unit, to the BCI PC control system S0 of higher level ℓ. G ℓ are the control signals from control PC S0 to mobile robot 4S ℓ−1 . The NXT 2.0 controller 4S0 is directly connected by its input X ℓ = (G ℓ ,W ℓ−1 ) and output Y ℓ = (G ℓ−1 ,W ℓ ) with the MR actuating systems and with the higher level ℓ coordinator S0, i.e., BCI PC design and control system, where Concrete values of the BCI PC control system S 0 inputs X 0 , outputs Y 0 and states C 0 are defined and detailed in the design phase and described below. A concrete model of BCI control system S 0 was implemented in the form of finite state machine [14] at the detailed design phase according to its conceptual model. Finite state machine model of BCI control system (CS) was implemented within the frameworks of Matlab program system using Simulink Stateflow module. To implement control algorithms by generating control codes, Matlab, Simulink, and Embedded Coders were used. The proposed control system developed in Matlab is presented in Figure 8. The main element of the BCI control system is MainController unit, which realizes logic laws of control of TruStan 24 electroencephalograph (EEG) unit, the light stimulator and the mobile robot. According to the BCI CS conceptual model, inputs X 0 and outputs Y 0 of MainController.ock unit are given in Table 1. Table 2 presents the BCI control system states C 0 .
implemented within the frameworks of Matlab program system using Simulink Stateflow module. To implement control algorithms by generating control codes, Matlab, Simulink, and Embedded Coders were used. The proposed control system developed in Matlab is presented in Figure 8. The main element of the BCI control system is MainController unit, which realizes logic laws of control of TruStan 24 electroencephalograph (EEG) unit, the light stimulator and the mobile robot. According to the BCI CS conceptual model, inputs  0 X and outputs  0 Y of MainController.ock unit are given in Table 1. Table 2 presents the BCI control system states  0 C .    The first state 1 C 0 of the proposed BCI control system is the Idle state (Table 2). It is an idle state in which the connection to the TruScan 24 electroencephalograph is checked. The process of establishing the connection with the electroencephalograph is simulated by the variable eegStatus, which takes the value 1 for a correctly established connection. Idle state activity is represented by the idle variable. After receiving the connection information, the system remains in Idle status until the BCI system is started by the Start button being pressed, which is reflected in the start variable.
When there is no error related to the connection to the TruScan 24 device and the Start button is on, the system goes into 2 C 0 Running state, in which the light stimulator is activated first. The activation of the light stimulator is represented by the variable led = 1. In this state there are three sub-states: Waiting the Waiting sub-state. From this sub-state, the system goes to DataRecStart after 1 s. This sub-state is responsible for the process of switching on the EEG signal recording by the TruScan 24 device, which has been set for 5 s. The DataRecStart subroutine activity is indicated by the variable dataRec. In the next step, after the 5 s have passed, the system goes to the DataRecStop sub-state where the system disables the EEG signal registration process.
After leaving the DataRecStop sub-station, the quality of recorded data is checked. For this purpose, errorLen and errorImp functions are used. The errorLen function examines the length of the recorded signal. The result of the function is error error2 = 1, when the registered signal does not contain an adequate number of samples. The errorImp function examines the impedance value of measuring electrodes. The result of this function is error error3 = 1, when the impedance value exceeds 5 kΩ. If error2 or error3 occurs, immediate return to Idle status takes place. State 2 C 0 Running is abandoned when the connection to the electroencephalograph is broken error1 = 1 or when the value of start = 0 (start button disabling). The exit from the state turns off the light stimulator (led = 0). Table 2. BCI PC control system S 0 states C 0 .

Idle Running DataProcessing
When errors error2 and error3 do not occur, the system goes to DataProcessing state 3 C 0 . The activity of this state is represented by the variable dataProc. This 3 C 0 state consists of four substates, listed in the order of calling: 31 C 0 DataShowing, 32 C 0 DataPreprocessing, 33 C 0 FeatureExtraction and 34 C 0 Classification. In the DataShowing sub-state, the recorded results are displayed using the show function. The dataShow value represents the DataShowing sub-state activity. Then the system goes to DataPreprocessing sub-state 32 C 0 , in which the pre-processing of the registered signal is performed, signaled by the variable dataPre = 1.
Pre-processing of the registered signal consists in extracting a fragment of data of a specific length (dataPreProc function) and filtration using the predefined filters (filtration function). The obtained results are further analyzed in the FeatureExtraction state 33 C 0 . The purpose of this state is to isolate characteristic features from the signal.
In order to test the designed BCI state machine, the detection of characteristic parameters was based on the FFT analysis [15]. This method is based on reading the frequency at which the largest amplitude value was obtained. Determination of the Fourier transform in the FeatureExtraction state 33 C 0 is performed by the fftProc function, and the reading of the frequency with the highest amplitude value is performed by the fMaxFind function. The FeatureExtraction state activity represents the fEPoc variable. The last sub-state 34 C 0 of DataProcessing 3 C 0 state is the Classification, in which a classification of characteristics and sending a control command to the mobile robot is made. Since the task of the developed BCI system is the mobile robot control, one of five characteristics (modes) may be selected as a result of classification: The command controlling the robot movement is called after that in the state machine using the coder. extrinsic function.

Verification of BCI Control System
To verify the correct operation of the MainController-based BCI control system, the necessary tests were carried out. Testing was performed by "injecting" recorded signals, i.e., (EEG) electro-encephalographic signals from one measuring electrode and its corresponding impedance value. In addition, a set of simulation signals was introduced into the system: activation of the start button (variable start), connection to the TruScan 24 device (variable eegStatus) and execution of the task by the mobile robot (isDone variable).
There are two control scenarios realized in the experimental study: (1) properly operating machine; (2) occurrence of impedance error.
The first scenario which presents one cycle of the correct functioning of the BCI control system is shown in the work. Data "injected" into the BCI system is presented in Figure 9.
-MoveBack; -MoveLeft; -Unclassified. The command controlling the robot movement is called after that in the state machine using the coder. extrinsic function.

Verification of BCI Control System
To verify the correct operation of the MainController-based BCI control system, the necessary tests were carried out. Testing was performed by "injecting" recorded signals, i.e., (EEG) electro-encephalographic signals from one measuring electrode and its corresponding impedance value. In addition, a set of simulation signals was introduced into the system: activation of the start button (variable start), connection to the TruScan 24 device (variable eegStatus) and execution of the task by the mobile robot (isDone variable).
There are two control scenarios realized in the experimental study: (1) properly operating machine; (2) occurrence of impedance error. The first scenario which presents one cycle of the correct functioning of the BCI control system is shown in the work. Data "injected" into the BCI system is presented in Figure 9.
The operation of the BCI control system is shown in Figure 10. The initial state (initializing) is the Idle state. It is a waiting state from which the output takes place when a connection is established with the TruScan 24 device (variable error1 = 0) and the start button is on (variable start = 1). Calling the errorConnection function in each simulation step determines the value of the error1 variable. The operation of the BCI control system is shown in Figure 10. The initial state (initializing) is the Idle state. It is a waiting state from which the output takes place when a connection is established with the TruScan 24 device (variable error1 = 0) and the start button is on (variable start = 1). Calling the errorConnection function in each simulation step determines the value of the error1 variable.
Because the connection to the TruScan 24 device has been established correctly, after the start button is triggered in a 0.5 s simulation ( Figure 10a) the system goes into the Running state, activating its default Waiting condition. Switching to the Running state means leaving the Idle state, which reflects the change in the idle value and the light stimulator activation (Figure 10c).
After 1 s, the Waiting sub-state switches to the DataRecording sub-state, in which the control system waits for 5 s for the recorded data from the TruScan 24 device. This step illustrates the variable datRec shown in Figure 10d. The quality of the received data is checked by the errorLen and errorImp functions, and their results are assigned to the error variables error2 and error3 respectively. Then the logical value of these variables is checked. The quality of the "injected" data met the above criteria, and the system went into the DataProcessing state. This moment (in 6.5 s) reflects the change in the value of the led variable and dataRec of Running status (Figure 10d) and the variable dataProc of the DataProcessing state (Figure 10e).
Transitions between consecutive substates: DataShowing, DataPreprocessing, FeatureExtraction and Classification are shown in the DataProcessing graph in Figure 10e. After classifying and sending a control command (6.9 s), the system moves from the DataProcessing state to the RobotWorking state. This is shown in Figure 10f by the variable robProc. In 8.8 s of the simulation, the system receives information about the robot completing the task, which is shown by the isDone variable on the RobotWorking chart (Figure 10a,f).  Because the connection to the TruScan 24 device has been established correctly, after the start button is triggered in a 0.5 s simulation ( Figure 10a) the system goes into the Running state, After leaving the RobotWorking state, the Running status is activated again. It was activated for 0.5 s because the start button was turned off, which caused the system transition to the Idle state. The system remained in this state till the end of the simulation.

Discussion
One of the research issues addressed in this work was the design of a BCI system and its implementation in mobile robot control. For this aim, the conceptual model of the BCI system was developed at the conceptual design phase first, and concrete construction of the BCI system including BCI control system were implemented at the detailed design phase after that. The BCI control system was designed to fulfil the control modes of mobile robot being controlled. Another research problem addressed in the work was the use of biological signal processing algorithms that would allow the extraction of characteristic parameters from the electroencephalographic signal that could be used to control the brain-computer interfaces. The main attention was paid to the analysis and detection of the characteristic parameters of Steady-State Visual Evoked Potentials (SSVEP) [10], generated in the brain by stimulation of the retina with a light stimulus at a frequency above 6 Hz. The development of the system using the characteristic parameters of the electroencephalographic signal to control the selected output device was preceded by experiments aimed at selecting the best light stimulus dedicated to BCI systems.
When designing a new BCI control system, it was important to use the Model-Based Design (MBD) methodology of HS, i.e., design using systems models. This methodology is based on the implementation of each sub-system that is a part of the new system of higher level, using models built in the MATLAB/Simulink software. By preparing the object model, one can simulate the entire control system and check how it affects the objects before the construction of the prototype. The main advantage of the MBD methodology of HS is that the hierarchical connections between particular components of the designed system are strictly defined at the modeling stage of the conceptual and detailed design phases. After verifying the correctness of the system operation, using the automatic code generation tools available in the MATLAB (MATLAB Coder, Simulink Coder, Embedded Coder) package, one can implement the control algorithm on the target device. Control of the executive element in the designed BCI system was carried out based on the state machine, which was implemented in the MATLAB 2014a/Simulink environment. As part of the aforementioned Simulink environment, Stateflow module was used for modeling and simulation of event-controlled systems with finite state machines. The main advantage of the Stateflow module is the availability of linguistic elements; hierarchy; and deterministic executive semantics that allow to describe complex logic in a natural, understandable and legible way. In addition, Stateflow module has got the following advantages: (a) application of flow diagram notations and state changes on one diagram, traditional C language syntax with input and output arguments; (b) description of the operation of the finite machine proposed by David Harel [15], enabling the representation of the hierarchy; (c) parallel operation and history within the states; (d) scheduling state changes using time operators; and (e) equipping with an integrated debugger that allows viewing data step-by-step through the subsequent stages of the model. BCI system implementation requires a control system development that will meet the relevant requirements. The most important element of the designed BCI control system is the MainController unit, which contains the entire logic necessary to control BCI sub-systems, i.e., TruStan 24 electroencephalograph, a light stimulator and a mobile robot.
The development of a BCI system using the characteristic parameters of the electroencephalographic signal to control the mobile robot allowed formulation of the following conclusions. The offline tests of the proposed algorithms for SSVEP characteristic parameters detection confirmed that the accuracy of the parameters classification is influenced by the length of the analyzed signal, the number of multiples taken for analysis, and the number of measuring electrodes. The offline tests allowed the selection of control algorithms based on statistical methods (LASSO) to be more efficient in detecting characteristic parameters of SSVEP [10] in comparison with methods using spectral analysis (PSDA). A virtual environment was created that fully imitated the brain-computer interface, implementing feedback based on the control system model and the mobile robot's kinematic model. This environment allowed free offline testing by "injecting" previously registered data, and then used it to conduct final online tests. This approach significantly reduced the time needed to develop the resulting system. The conducted online tests confirmed the SSVE potentials fitness to control a mobile robot. The presented conclusions also confirm the effectiveness of the electroencephalographic signals application as control signals in the brain-computer interfaces.

Conclusions
Application of novel Hierarchical Systems technology in conceptual and detailed design of a BCI (Brain Computer Interface) system implemented to control a mobile robot is presented in this paper. Proposed conceptual model of the designed biomechatronic BCI system (Section 2.2) contains connected systemic models of the BCI subsystems of various natures, i.e., biological (brain), computer (control PC), visual informatics (LCD, GUI), electronic (sensors) and executive electro-mechanical (mobile robot), presented in the general formal basis of HS. Connections of the conceptual systemic models of the BCI subsystems with their models used at the detailed design phase are revealed. The BCI control system is presented at the conceptual design phase in the form of an HS coordinator. At the detailed design phase, the BCI control system was implemented by internal control unit NXT 2.0, which consists of ARM7 and AVR microcontrollers and BCI control PC. A concrete model of BCI CS was implemented in BCI control PC in the form of finite state machine within the frameworks of Matlab program system using Simulink Stateflow module. The main element of the BCI control system is the MainController unit, which realizes logic laws of control of TruStan 24 electroencephalograph (EEG) unit, light stimulator and mobile robot. The mobile robot being controlled is Mindstorms robot. Necessary tests were carried out to verify the MainController-based BCI control system designed. Testing was performed by "injecting" recorded electroencephalographic (EEG) signals and introducing a set of simulation signals into the system. The offline tests allowed the selection of control algorithms based on statistical methods more efficient in detecting characteristic parameters of SSVEP [1,10]. The conducted tests confirmed the effectiveness of SSVE potential application in a mobile robot control, as well as EEG signals application as control signals in a BCI system. Further research aimed at implementing learning strategies of HS coordinator in the BCI MR control system to realize high-level behaviors of mobile robot learning from its low-level motions while performing selected tasks is planned. It will make possible further improvement of the BCI MR control system and realization of learning and decision-making functions in robot control tasks.