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

Authors: Claudio Urrea; John Kern
Journal: Journal of Applied Mathematics
 (2020)

---

## Abstract

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.


---

## Body

## 1. 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–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–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–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–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.


## 2. 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 Figure1. The purpose of the system is to keep the arm vertical while the base linear movement causes the angular movement of the pendulum.Figure 1
Inverted pendulum system.An arm ofl 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θ.Figure 2
Variables involved in the inverted pendulum model.Givenτt as a net torque at instant t and applied to the m mass arm, the angular acceleration θ¨t is described by
(1)θ¨t=τtmKnowing 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.Working with these equations, the discrete model that describes the system dynamics is(2)θt−2θt−1+θt−2=δT2τtm.This second-order linear difference equation describes the evolution over discrete timet 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 Fg, which is counteracted by the dynamic friction force.For any time instantt, the torque generated by the net force Ftt which acts on the end of the l length and m mass pendulum can be assessed through the following equation:
(3)τt=Fttl=1lmg·senθt−μ·θ̇t,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 Vm, that is, ∆x=k·Vm·δT, then the angular movement caused by voltage Vm can be written as ∆θ=cos−1k·Vm·δT/l.Considering the above relations, the evolution of the system can be estimated based on the positions of the two previous instants:(4)θt=δT2mlmg·senθt−1−μ·θt−1−θt−2δT+2θt−1−θt−2−cos−1k·Vm·δTl.Equation (4) allows us to study how the angular position of the pendulum arm, θt, evolves as a result of changing the voltage Vmt 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–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].


## 3. 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 Figure3).Figure 3
Nodes and topics associated with the simulation environment in ROS.In the simulation environment, students should implement their controller over the pd_controller node, which interacts 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 Figure4.Figure 4
Image of the simulation system in RViz.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 Figure5).Figure 5
Graphs for position vs. time and motor vs. time obtained from a rqtplot tool when lifting a pendulum from resting position.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.


## 4. 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:(a)
Modeling. Students start by identifying and applying the equations that govern the rotation of a solid body to obtain the dynamics of the system from a general equation. Through interaction with the physical system, they identify the model elements and discriminate between input variables, output variables, and constant values.(b)
Analysis. From a model, students explore the effects of modifying some constant variables relevant to the system by means of simulation. Then, they analyze the system’s response to different input values. The output values of a nonlinear model are also compared with those of a linear model.(c)
Estimation. In this section, the requirements for determining the formulation parameters are studied, obtaining the model constant values from measurements in the real system. Then, students compare the simulated answer to the real, determining their model’s validity and limitations.(d)
Control. From a validated model, students can test different control techniques experimentally in a simulation and real environment. As a starting point, they distinguish between open and close control loops to then design and tune a PID controller able to keep the arm in the desired position.


## 5. 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.



---

*Source: 8987150-2020-11-18.xml*