Integrating ROS and IoT in a Virtual Laboratory for Control System Engineering

This article presents the implementation of a learning environment for the teaching of control systems. This environment integrates physical equipment and simulation, monitoring, and control through a network. A software platform based on ROS (Robotic Operating System) grants access to the system through intranet and Internet, facilitating the integration of new test equipment. The environment developed can be used in didactic experiences both inside and outside the classroom, enhancing the learning of four main study topics: modeling, analysis, parameter estimation, and controller design.


Introduction
Automatic control systems are essential in modern life. Air conditioning at workplaces as well as the provision of drinking water and energy, transportation, communications, and the most varied industrial processes all require automatic control systems to achieve efficiency, reliability, and safety. Hence, it is important to study these systems in several engineering fields.
The design and implementation of control systems is a complex process that requires advanced algebra and calculus, in addition to data analysis, mathematical modeling, and programming skills. In engineering undergraduate programs, traditional systems are studied from a mathematical perspective and students are given tasks to compare theoretical results and measurements in real or simulated systems. In these tasks, well-designed equipment is key for demonstrations and didactic activities [1][2][3][4][5][6].
The system theory identifies four main topics that define the contents of a study plan for control systems: modeling, analysis, parameter estimation, and controller design. Modeling is a critical step in the application of system theory to real processes, as it consists of finding a mathematical model that describes a physical situation accurately. During this step, the system limits and variables need to be chosen based on previous knowledge and assumptions about the model uncertainties. After model definition, the behavior of the system is analyzed in terms of stability, sensitivity, identifiability, and observability. Parameter or status estimation takes place after obtaining an identifiable and observable model. Here, the estimation of unknown variables is addressed from an input/output data set. Finally, different control strategies are studied focusing on the calculation of a specific input in such a way that the controlled system displays a desired behavior [7].
To develop the skills necessary to carry out these activities, it is necessary to work with mathematical analysis tools based on empirical data obtained from real systems or computer simulations. Consequently, the introduction of technology to the classroom is necessary to teach control systems.
Research has demonstrated that the introduction of technology to the classroom in any discipline is not an easy matter, but a process that should take into account the students' specific needs and expectations, the methodological and curricular decisions, and the resistance to change from teachers, among other factors [8][9][10]. In engineering education, it should also be considered that the training received by future engineers should prepare them for the challenges of the future, that is, to face rapid technological advances and critical stakes more than ever [11]. All the above makes it necessary for students to develop learning strategies that bring them closer to the solution for real problems and to the technologies of the real world [12].
The purpose of engineering is to manipulate the materials, energy, and energy available to solve the problems of society. Therefore, the training of engineers historically has demanded practical laboratory work to develop these skills, incorporating technology as a tool [13]. Regarding the teaching of control systems, different experiences have proved that making students integrate current simulation technologies and interaction with conventional technologies is the most effective way of learning [2,14]. In addition, it is also essential to address motivational issues because the lack of didactic learning might influence the dropout of engineering students to a great extent [15].
Several educational institutions have contributed with valuable experiences in the design of educational equipment and software tools for the teaching of control systems. These tools can be used for both face-to-face lessons and learning experiences out of the classroom, such as virtual laboratories (remote access to simulated systems) and remote laboratories (remote access to real equipment). To teach control systems in face-to-face environments, software packages such as MatLab or LabView have been the preferred option, since they contain several libraries and specialized tools (toolboxes) that even allow users to combine simulation environments with physical laboratory equipment [16][17][18][19].
For example, in [20], a deep learning-based pipeline smart system is developed, which is able to recognize block diagrams from control systems with handwritten feedback control architectures in a whiteboard and transforms them automatically into simulation diagrams in the MatLab software. In this way, the control system is visualized, executed, and analyzed in an interactive way using MatLab. In [21], a new teaching method for robot control systems called AVPC (Algorithm, Virtual experiment, Programming, and Controller) is presented. This method shows students the stages considered during the development, verification, and application of robot algorithms, taking a typical robot with 6 DoF as a teaching case. The solutions for the algorithms are obtained by means of MatLab, and then, the dynamic model of the arm is exported to the V-REP (Virtual Robot Experimentation Platform) software (currently denominated CoppeliaSim [22]). In [23], a teaching methodology that considers system model-oriented design methods for mechatronic systems is employed to address the essential concepts of automatic control. Control algorithms are created using library modules that are installed in MatLab-Simulink. Subsequently, the executable code is generated through compilers, to then be implemented in the DSP-controllers TMS and SRM32.
Nevertheless, using these packages out of the classroom is limited by license restrictions and difficulties in working with several devices in a network. To overcome these obstacles, some experimental platforms based on the Robotic Operating System (ROS) have been developed over the last years [24][25][26][27].
ROS is particularly useful as an educational platform for the teaching of control systems due to three main characteristics: (1) It is a free open code software, very stable, and with great support from a very active community. (2) It has a large number of libraries available, which facilitate the development of programs in different languages and support the interconnection of multiple sensors and actuators. (3) It has excellent tools for visualizing graphs and 2D and 3D simulations. Additionally, the implementation of ROS in service allows access to online resources by means of intranet or Internet. This way, ROS has gained acceptance in the robotics and automation field at both the research and educational environment levels [26,27].
The main advantage of the approach proposed in this work is that students do not need to be physically present in an educational center laboratory, nor do they need a software license that sometimes may be difficult to obtain due to the related costs. Using free software and low-cost hardware elements, students can expand their knowledge in control systems through simulation and also through interaction with a real physical system from their computers, employing tools for real-time data acquisition and graph visualization as well.
Below, we present the implementation of a ROS-based learning environment for the study of digital control strategies in control system laboratories. The discrete equations modeling the system are presented, and the way in which ROS interacts with the system to create a simulation and control environment is explained. In addition, a didactic sequence is presented to address the four main points in control systems by means of methodological strategies that combine real equipment and simulation with ROS.

Description of the System under Study
A learning environment has been developed to study the well-known linear inverted pendulum system, which is shown in Figure 1. The purpose of the system is to keep the arm vertical while the base linear movement causes the angular movement of the pendulum.
An arm of l length concentrates all the mass m on its end. The τ torque on the arm causes angular acceleration € θ, which will initiate the arm motion at a _ θ angular speed and change its θ angular position. Figure 2 shows the essential variables involved in the system. The base linear movement needs to be controlled along the x-axis to keep the arm in a vertical position, that is, to compensate the angular movement θ through the motion of the base, which equals Δx = −l · cos θ.
Given τ½t as a net torque at instant t and applied to the m mass arm, the angular acceleration € θ½t is described by Knowing the angular acceleration € θ½t, the angular speed _ θ½t at instant t can be estimated as _ θ½t = _ θ½t − 1 + € θ½t · δT, where _ θ½t − 1 is the angular speed at a previous moment, € θ½t is the angular acceleration at the current moment, and δT is the time interval passed. In addition, the angular position θ½t at instant t can be estimated as θ½t = θ½t − 1 + _ θ½t · δT, where θ½t − 1 is the angular position at a previous moment, _ θ½t is the angular speed at the current moment, and δT is the time interval passed.

Journal of Applied Mathematics
Working with these equations, the discrete model that describes the system dynamics is This second-order linear difference equation describes the evolution over discrete time t at δT intervals of the arm's angular position θ½t as a result of torque τ½t action over an m mass.
In the system under study, torque τ applied to the arm is the result of the gravity force F g , which is counteracted by the dynamic friction force.
For any time instant t, the torque generated by the net force F t ½t which acts on the end of the l length and m mass pendulum can be assessed through the following equation: where mg · senθ½t is the gravity force component perpendicular to the arm, μ is the friction coefficient, and μ · _ θ½t is the friction force that opposes arm movement.
Additionally, the movement of the base causes an angular movement defined by Δx = −l · cos θ. If the linear movement of the base can be expressed in a way approximately proportional to the voltage applied to motor V m , that is, Δx = k · V m · δT, then the angular movement caused by voltage V m can be written as Δθ = cos −1 ðk · V m · δT/lÞ.
Considering the above relations, the evolution of the system can be estimated based on the positions of the two previous instants: Equation (4) allows us to study how the angular position of the pendulum arm, θ½t, evolves as a result of changing the voltage V m ½t applied to the motor in order to move the pendulum's base. This base represents a second-order nonlinear system used to simulate the system. Since the mass and the friction coefficient have small values, the system has quick dynamics that allow us to observe instantly the effect of modifications to the controller parameters as well as the effect of the perturbations. All these characteristics make ROS suitable for the study of control systems. The inverted pendulum system has been typically studied in control system subjects, and currently, learning experiences continue to be developed, including control techniques and modern technologies [28][29][30][31][32][33][34]. The learning environment ROS also facilitates the study of these new techniques, as modifications to the model and controller design are made using open source software libraries with broad support [35].

Description of the Learning Environment
To implement a learning environment that facilitates the study of the inverted pendulum system, physical components and the ROS software environment are integrated by means of a data acquisition and a control interface developed by Arduino, which is connected to the intranet as a node. This configuration enables easy integration with ROS, which, in turn, facilitates the monitoring of the pendulum position and the motor's electric variables, as well as the issuing of control orders to move the base. The communication between the physical system and ROS provides students with an environment that facilitates system modeling, analysis, and parameter estimation. This allows students to manipulate the physical system from their laptop and use some tools for real-time data acquisition and graph visualization.
To facilitate the controller design stage, a simulation node that uses the 3D RViz visualization tool from ROS was developed. Using the simulation node, students can test their solutions and observe the system's behavior utilizing graphs and 3D models before implementing them in the real system (see Figure 3).
In the simulation environment, students should implement their controller over the pd_controller node, which interacts   Journal of Applied Mathematics with RViz to modify the angular position and visualize the pendulum movement. In this way, students can observe the system's behavior with different types of controllers and different controller parameters. The interaction is intuitive and realistic and allows them to explore in a safe environment, as shown in Figure 4.
The ROS environment also includes the data acquisition tool rqtplot, through which graphs can be created to analyze system behavior. Using this tool, students can choose the variables of interest and built graphs or record data that can be subsequently used in other data analysis environments. Additionally, it is possible to acquire data and create graphs from both the real system and the simulation environment (see Figure 5).
Considering that ROS is an open software environment, it also allows us to develop personalized modules for specific tasks, which can be written by the same students in C++ and Python.

Methodological Proposal
The use of the learning environment proposed allows students to address the four essential topics of the control theory in an integrated and sequential fashion, as described as follows:

Conclusions
The software package ROS, a middleware well known in robotics, has been used to implement a learning environment for the teaching of control systems in engineering programs. The environment proposed allows students to work in connection with the physical system from the classroom and to share learning experiences out of the classroom in a simulation environment. The characteristics of the platform developed make it possible to extend its use to virtual (remote access to simulated systems) and remote (remote access to physical systems) laboratories. The use of this learning environment in an automatic control subject allows us to address in an integrated way the four basic topics of control theory, which are modeling, analysis, estimation, and control. To this end, multiple data acquisition tools from ROS are employed, allowing the creation of modules utilizing programming in C++ or Python.
In the current development stage, the system has been implemented in a local server, enabling access to resources from the intranet. From this work, it is possible to extend the functions of this learning environment by adding new test systems and granting access to physical resources from locations out of the classroom through the Internet.

Data Availability
The data used to support the findings of this study are included within the article.

Conflicts of Interest
The authors declare that they have no conflicts of interest regarding the publication of this paper.