3rd 3rd IFAC IFAC Workshop Workshop on on Internet Internet Based Based Control Control Education Education 3rd IFAC Workshop on Internet Based Control Education November 4-6, Brescia, Italy 3rd IFAC Workshop Internet Based Control November 4-6, 2015. 2015.on Brescia, Italy 3rd IFAC Workshop on Internet Based Control Education Education November 4-6, 2015. Brescia, Italy Available online at www.sciencedirect.com November 4-6, 2015. Brescia, Italy November 4-6, 2015. Brescia, Italy
ScienceDirect IFAC-PapersOnLine 48-29 (2015) 247–252
Remote Interoperability Protocol: A bridge Remote Interoperability Protocol: A bridge Remote Interoperability Protocol: A bridge Remote Interoperability Protocol: A bridge between interactive interfaces and between interactive interfaces and between interactive interfaces and between interactive interfaces and engineering systems. engineering systems. engineering systems. engineering systems. ∗ ∗∗ ∗∗
∗ Gonzalo Farias ∗∗ Hector Vargas ∗∗ Jes´ u ss Chac´ o n Jes´ u Chac´ o n Farias ∗∗ Vargas ∗ ∗∗ ∗ Gonzalo ∗∗ Hector ∗∗ ∗∗∗ Farias ∗ Jes´ u ssAntonio Chac´ o n Gonzalo Hector Vargas ∗Visioli ∗∗ ∗∗ Jes´ u Chac´ o n Gonzalo Farias Hector Vargas ∗∗∗ Sebasti´ ∗ a n Dormido Jes´ usAntonio Chac´ o n Gonzalo Farias Hector Vargas Visioli Sebasti´ a n Dormido ∗∗∗ ∗ ∗∗∗ Sebasti´ Antonio Visioli Visioli ∗∗∗ an n Dormido Dormido ∗∗ Antonio Sebasti´ a Antonio Visioli Sebasti´ an Dormido ∗ ∗ Universidad Nacional de Educaci´ o n a Distancia, Nacional de Educaci´ o n a Distancia, ∗ ∗ Universidad Nacional de Educaci´ o n a Distancia, ∗ Universidad Universidad Nacional de Educaci´ o n a Distancia, e-mail:
[email protected]. Universidad Nacional de Educaci´ o n a Distancia, e-mail:
[email protected]. ∗∗ e-mail:
[email protected]. e-mail:
[email protected]. ∗∗ Pontificia Universidad Cat´ o lica de Valpara´ ıso, Chile. e-mail:
[email protected]. Pontificia Universidad Cat´ o lica de Valpara´ ıso, Chile. ∗∗ ∗∗ ∗∗∗Pontificia Universidad Cat´ o lica de Valpara´ ıso, Chile. ∗∗ Universidad Cat´ o lica de Valpara´ ıso, Chile. ∗∗∗Pontificia Dipartimento di Ingegneria Meccanica e Industriale, Pontificia Universidad Cat´ o lica de Valpara´ ıso, Chile. di Ingegneria Meccanica e Industriale, ∗∗∗ ∗∗∗ Dipartimento Dipartimento didegli Ingegneria Meccanica e Industriale, Industriale, ∗∗∗ Dipartimento di Ingegneria Meccanica e Universit` a Studi di Brescia, Italia. Dipartimento di Ingegneria Meccanica e Industriale, Universit` a degli Studi di Brescia, Italia. Universit` a degli Studi di Brescia, Italia. Universit` a Universit` a degli degli Studi Studi di di Brescia, Brescia, Italia. Italia. Abstract: The process of building remote or virtual laboratories to be deployed via Internet Abstract: The process of building remote or virtual laboratories to be deployed via Internet Abstract: The process of building remote or virtual laboratories to be deployed via Internet Abstract: The process of building remote or virtual laboratories to be deployed via Internet usually involves communication between different software tools. Very often, there is a separation Abstract: The process of building remote or virtual laboratories to be deployed via Internet usually involves communication between different software tools. Very often, there is a separation usually involves communication between different software tools. Very often, there is a separation usually involves communication between different software tools. Very often, there is a separation between the software which interfaces with the model or real system, and the software responsible usually involves communication between different software tools. Very often, there is a separation between the software which interfaces with the model or real system, and the software responsible between the software software which interfaces with the the model orrepresentation real system, system, and thedata software responsible between the which interfaces with model or real the software responsible of providing the student with an interactive and visual of the provided by the between the software which interfaces with the model orrepresentation real system, and and thedata software responsible of providing the student with an interactive and visual of the provided by the of providing the student with an interactive and visual representation of the data provided by the of providing the student with an interactive and visual representation of the data provided by the engineering system. Abstracting the way these two elements communicate with each other from of providing the student with an interactive and visual representation of the data provided by the engineering system. Abstracting the way these two elements communicate with each other from engineering system. Abstracting the way these two elements communicate with each other from engineering system. Abstracting the way these two elements communicate with each other from the particular implementation, the requirements are frequently the same: connection and session engineering system. Abstracting the way these two elements communicate with each other from the particular implementation, the requirements are frequently the same: connection and session the implementation, the are frequently the same: connection and session the particular particular implementation, the requirements requirements arehandling, frequentlyetc. theThis same: connection and session control, data transmission control, user interaction work describes aa generic the particular implementation, the requirements are frequently the same: connection and session control, data transmission control, user interaction handling, etc. This work describes control, data transmission control, user kind interaction handling, etc. This work describes a generic generic control, data transmission control, user interaction handling, etc. This work describes a generic protocol to interoperate remotely any of engineering software. The solution proposes to control, data transmission control, user interaction handling, etc. This work describes a generic protocol to interoperate remotely any kind of engineering software. The solution proposes to protocol to interoperate remotely any kind of engineering software. The solution proposes to protocol to interoperate remotely any kind of engineering software. The solution proposes to encapsulate all the communication issues into an interoperability API that can be implemented protocol to interoperate remotely any kind of engineering software. The solution proposes to encapsulate all the communication issues into an interoperability API that can be implemented encapsulate all thesystems. communication issues into an interoperability API that can be implemented encapsulate all communication issues into an API that can be in many different In order to show flexibility of such API, an implementation to encapsulate all the thesystems. communication issues intothe an interoperability interoperability API that can be implemented implemented in many different In order to show the flexibility of such API, an implementation to in many different systems. In order to show the flexibility of such API, an implementation to in many different systems. In order to show the flexibility of such API, an implementation to interoperate MATLAB from Java user interfaces via JSONRPC is explained in detail. in many different systems. In order to show the flexibility of such API, an implementation to interoperate MATLAB from Java user interfaces via JSONRPC is explained in detail. interoperate MATLAB MATLAB from from Java Java user user interfaces interfaces via via JSONRPC JSONRPC is is explained explained in in detail. detail. interoperate interoperate MATLAB from Java user interfaces via JSONRPC is explained in detail. © 2015, IFAC (International Federation of Automatic Control) Hosting by Elsevier Ltd. All rights reserved. Keywords: control education, interactive, teaching, computer interfaces, communication Keywords: Keywords: control control education, education, interactive, interactive, teaching, teaching, computer computer interfaces, interfaces, communication communication Keywords: control education, interactive, teaching, computer interfaces, communication protocols Keywords: control education, interactive, teaching, computer interfaces, communication protocols protocols protocols protocols 1. INTRODUCTION all the opportunities that these technologies offer, three 1. INTRODUCTION all the opportunities that these technologies offer, three 1. INTRODUCTION INTRODUCTION all the opportunities that these technologies offer, three 1. all the opportunities that these technologies offer, three of them present features of special interest to teaching 1. INTRODUCTION all the opportunities that these technologies offer, three of them present features of special interest to teaching of them present features of special interest to teaching of them present features of special interest to teaching engineering: network communications, visualization, and Networks such such as as the the Internet Internet are are widely widely distributed distributed in in of them present features of special interest to teaching engineering: network communications, visualization, and Networks network communications, visualization, and Networksconnecting such as as the the Internet areof widely widely distributed in engineering: engineering: network communications, visualization, and interactivity. Networks such Internet are distributed in society, people across the world. The conengineering: network communications, visualization, and interactivity. Networks such as the Internet are widely distributed in society, connecting people across of the world. The coninteractivity. society, connecting people across of the world. The coninteractivity. society, connecting people across of the world. The connectivity between many different computational devices is interactivity. society, connecting people across of the world. The connectivity between many different computational devices is Visualization and interactivity have proved to be crucial nectivity between between many different computational devices is Visualization and interactivity have proved to be crucial nectivity many different computational devices is increasing every year and, nowadays, the scientific comand interactivity have proved to be crucial nectivity between many different computational devices is Visualization increasing every year and, nowadays, the scientific comVisualization and interactivity have proved to aspects when designing virtual labs, i.e. simulations that increasing every year and, nowadays, the scientific comand interactivity have proved to be be crucial crucial aspects when designing virtual labs, i.e. simulations that increasing every year and, nowadays, the scientific community andevery engineering companies invest economical and Visualization aspects when designing virtual labs, i.e. simulations that increasing year and, nowadays, the scientific community and engineering companies invest economical and aspects when designing virtual labs, i.e. simulations that are to be used for pedagogical purposes, in the field of munity and and engineering companies invest invest economical and and aspects when designing virtual labs, i.e. simulations that are to be used for pedagogical purposes, in the field of munity engineering companies economical research effort in the development of technologies are to be used for pedagogical purposes, in the field of munity and engineering companies invest economical and research effort in the development of technologies are to be used for pedagogical purposes, in the field of control engineering. The graphical graphical capabilities offield comresearch effort in the development of technologies and are to be used for pedagogical purposes, in the of control engineering. The capabilities of comresearch effort in the development of technologies and standard for the Internet of Things (IoT, sometimes Incontrol engineering. The graphical capabilities of comresearch effort in the development of technologies and standard for the Internet of Things (IoT, sometimes Incontrol engineering. The graphical capabilities of computers, using images or animations, can help students to standard for the Internet of Things (IoT, sometimes Incontrol engineering. The graphical capabilities of computers, using images or animations, can help students to standard for of Things (IoT, sometimes Internet of Under term, there is a network using images or animations, can help students to standard for the the Internet Internet of this Things (IoT, sometimes In- puters, ternet of Everything). Everything). Under this term, there is network puters, using images or can students to understand easily the key concepts of the system ternet of Everything). Under this term, there is aaatonetwork network usingmore images or animations, animations, can help help students to understand more easily the key concepts of the system ternet of Everything). Under this there is of physical things or or objects objects withterm, connectivity enable puters, understand more easily the key concepts of the system ternet of Everything). Under this term, there is a network of physical things with connectivity to enable understand more easily the key concepts of the system under study. Moreover, interactivity allows students to of physical things or objects with connectivity to enable understand more easily the key concepts of the system under study. Moreover, interactivity allows students to of physical things or objects with connectivity to enable data communication with other devices. Within the IoT, under study. Moreover, interactivity allows students to of physical things or with objects with connectivity tothe enable data communication other devices. Within IoT, under study. Moreover, interactivity allows students to simultaneously see the the response response of the the systems to any any data communication with other devices. Within the IoT, under study. Moreover, interactivity allows students to simultaneously see of systems to data communication with other devices. Within the IoT, there are countless devices that can be sensed or controlled simultaneously see the response of the systems to any data communication with other devices. Within the IoT, there are countless devices that can be sensed or controlled simultaneously see the response of the systems to any change introduced by the user (Dormido et al., 2005a; there are countless devices that can be sensed or controlled simultaneously see the response of the systems to any change introduced by the user (Dormido et al., 2005a; there are devices that can or via Internet, encouraging integration between physical change introduced by the user (Dormido et al., 2005a; there are countless countless devicesthe that can be be sensed sensed or controlled controlled via Internet, encouraging the integration between physical change introduced by the (Dormido et al., aanchez et al., 2002). features add to via Internet, Internet, encouraging the integration between physical S´ change introduced by These the user user (Dormido et engineering al., 2005a; 2005a; S´ nchez et al., 2002). These features add to engineering via encouraging the integration between physical world and computer-based systems. S´ a nchez et al., 2002). These features add to engineering via Internet, encouraging the integration between physical world and computer-based systems. S´ aanchez et al., 2002). These features add to engineering simulations rich visual content and the possibility of an world and and computer-based computer-based systems. systems. S´ nchez et al., 2002). These features add to engineering simulations rich visual content and the possibility of an world simulations rich visual content and the possibility of an world and can computer-based systems. simulations rich visual content and the possibility of an immediate observation of system response, which turns Educators also benefit from this situation offering their simulations rich visual content and the possibility of an immediate observation of system response, which turns Educators can also benefit from this situation offering their immediate observation of system response, which turns Educatorsnew can ways also benefit benefit fromlearning this situation situation offering their aimmediate observation of system response, which turns simulation into a natural and human-friendly way to Educators can also from this offering their students to access resources without immediate observation of system response, which turns aa simulation into a natural and human-friendly way to Educators can also benefit from this situation offering their students new ways to access learning resources without simulation into aastudent natural and human-friendly way to students new ways constraints. to access access learning learning resources without a simulation into natural and human-friendly way to learn, helping the to get useful practical insight students new ways to resources without time and location And, in fact, in the last alearn, simulation into a natural and human-friendly way to helping the student to get useful practical insight students new ways to access learning resources without time and location constraints. And, in fact, in the last learn, helping the student to get useful practical insight time and location constraints. And, in fact, in the last learn, helping the student to get useful practical insight into engineering systems fundamentals. time and location constraints. And, in fact, in the last years the scientific community has devoted great efforts to learn, helping the student to get useful practical insight into engineering systems fundamentals. time and location constraints. And, in fact, in the last years the scientific community has devoted great efforts to engineering systems systems fundamentals. fundamentals. years the the scientific community hastodevoted devoted greateducation efforts to to into engineering years scientific community has great efforts apply the advances in these fields engineering into engineering systems fundamentals. years scientific community hasto greateducation efforts to into apply the advances in these these fields fields todevoted engineering education Currently, there are many tools available to build simuapply the the advances in engineering Currently, there are many tools available to build simuapply the advances in these fields to engineering education (Heck, 1999; Dormido, 2004), yielding a plethora of online Currently, there are many tools available to build simuapply the advances in these fields to engineering education (Heck, 1999; Dormido, 2004), yielding a plethora of online Currently, there are many tools available to build simulations of a wide range of systems in control engineering. (Heck, 1999; Dormido, 2004), yielding a plethora of online Currently, there are many tools available to build simulations of a wide range of systems in control engineering. (Heck, 1999; Dormido, 2004), yielding a plethora of online interactive tools, presented either as simulations or as lationstools of aa wide wide range of capabilities systems in in control control engineering. (Heck, 1999; Dormido, 2004), yielding a plethora of online interactive tools, presented either as simulations or as lations of range of systems engineering. These provide great that allow to study interactive tools, presented either as simulations or as lations of a wide range of systems in control engineering. These tools provide great capabilities that allow to study interactive tools, either simulations orone as remote experiences in real plants. But, as in IoT, tools provide great capabilities that allow to study interactive tools, presented presented either as as simulations as These remote experiences in real plants. But, as in IoT, one These tools great capabilities that to the behaviour of the systems under different scenarios, as remote experiences in scalability real plants. plants. But, as in in IoT, IoT,orone one These tools provide provide great capabilities that allow allow to study study the behaviour of the systems under different scenarios, as remote experiences in real But, as of the concerns is the and interoperability, in the behaviour of the systems under different scenarios, as remote experiences in real plants. But, as in IoT, one of the concerns is the scalability and interoperability, in the behaviour of the systems under different scenarios, as well as countless hardware drivers to connect any kind of of the thedue concerns is the scalability and interoperability, in the behaviour of the systems under different scenarios, as well as countless hardware drivers to connect any kind of of concerns is the scalability and interoperability, in part to the variety of devices and the intense use well as countless hardware drivers to connect any kind of of the concerns is the scalability and interoperability, in part due to the variety of devices and the intense use well as countless hardware drivers to connect any kind of device. In control enginering, MATLAB (The MathWorks, part due to the variety of devices and the intense use well as countless hardware drivers to connect any kind of device. In control enginering, MATLAB (The MathWorks, part due to the variety of devices and the intense use of machine-to-machine (M2M) communications. Among device. In control enginering, MATLAB (The MathWorks, part due to the variety of devices and the intense use of machine-to-machine (M2M) communications. Among device. In control enginering, MATLAB (The MathWorks, 2015) is the de facto standard software tool. It is a techof machine-to-machine (M2M) communications. Among device. In control enginering, MATLAB (The MathWorks, 2015) is the de facto standard software tool. It is a techof machine-to-machine (M2M) communications. Among is the de facto computing standard software tool. Itwhich is a tech of This machine-to-machine (M2M) communications. Among 2015) 2015) is de standard tool. is nical and numerical environment, was 2015) is the the de facto facto computing standard software software tool. It Itwhich is a a techtechnical and numerical environment, was This work work has has been been funded funded by by the the National National Plan Plan Project Project DPI2012DPI2012 nical and numerical computing environment, which was This work has been funded by the National Plan Project DPI2012 31303 ofwork the Spanish Spanish Ministry of Science Science and Innovation Innovation andDPI2012FEDER nical and numerical computing environment, which was This has been funded by the National Plan Project born as a tool to manipulate matrix. But there are many 31303 of the Ministry of and and FEDER nical and numerical computing environment, which was This work has been funded by the National Plan Project DPI2012born as a tool to manipulate matrix. But there are many 31303 of of the the Spanish Spanish Ministry Ministry of of Science Science and and Innovation Innovation and and FEDER FEDER born as a tool to manipulate matrix. But there are many funds. 31303 born as as aa tool tool to to manipulate manipulate matrix. matrix. But But there there are are many many funds. of the Spanish Ministry of Science and Innovation and FEDER 31303 born
funds. funds. funds. Copyright © 2015 247 2405-8963 © IFAC (International Federation of Automatic Control) Copyright © 2015, 2015 IFAC IFAC 247 Hosting by Elsevier Ltd. All rights reserved. Copyright © 2015 IFAC 247 Copyright © 2015 IFAC 247 Peer review under responsibility of International Federation of Automatic Copyright © 2015 IFAC 247Control. 10.1016/j.ifacol.2015.11.244
IFAC IBCE 2015 248 November 4-6, 2015. Brescia, Italy
Jesús Chacón et al. / IFAC-PapersOnLine 48-29 (2015) 247–252
other tools, either commercial products such as LabVIEW, Sysquake, Maple, Mathematica, open source tools like Scilab, Maxima, Octave, or even programming languages with numerical computing libraries such as NumPy/SciPy for Python, and Numeric.js for JavaScript. Though some of these tools have support to develop graphical interfaces, usually they are far from being ideal for unexperienced programmers to develop interactive tools. The aim of this paper is to describe an interoperability protocol for remote and virtual laboratories, based on previous work (S´ anchez et al., 2002; Dormido et al., 2005b; Farias et al., 2011; Chacon et al., 2015). The basic needs of an online interactive learning tool are captured in an easyto-use and easy to implement protocol to help interconnect human interfaces to engineering simulations. With this protocol, the development of an interactive learning tool for engineering can be decoupled in two tasks. On the one hand, the model of the engineering simulation or the interface to the process is created using a specialized software like MATLAB, LabVIEW or whatever the developer feels comfortable with. On the other hand, the human interface can be created using another software tool specialized in the design and implementation of graphical interfaces for non-expert programmers as, for example, Easy Java Simulations (EJS, (Esquembre, 2015)). This two components can be easily connected through a welldefined, simple and effective protocol, having a high-degree of independence. In this way, not only the development effort is rationalized, because many software components can be reused and shared between different interactive tools, but also help the educator focus on the design of the experience and the visualization, while devoting less effort to the low-level implementation details. Moreover, if an engineering system adhere to the protocol, it is even possible to use it without knowing these implementation details, but only using the interface to interact with it. This enable a new paradigm of design, where physical resources can be shared between different universities, having the same or different views and experiences to carry out with the system, depending on the particular needs of each user. Despite from that, there are other cases where it can be useful to reuse a model or a system interface. For example, many academic plants are deployed with some sample software developed in MATLAB or LabVIEW, to demonstrate the capabilities of the system or to propose learning experiences. The paper is organized as follows. Section 2 describes briefly the creation of standard engineering simulations. In Section 3 a communication protocol to connect engineering software with an interactive human interface is presented. Section 4 adapts the communication protocol to perform remote operation of engineering simulations. Finally main conclusions are discussed. 2. BUILDING SIMULATIONS 2.1 Overview Any interactive simulation that uses a model previously created on an existing engineering software can be conceptually separated on two differentiated components. The 248
first one is the system, a real process or a simulation created with a standard engineering software that models the process of interest. The second one is the interactive view through which users can observe and manipulate the system. The client application adds to the underlying (external) engineering application an upper layer that allows students to interactively manipulate and visualize the response of the system. The external application is controlled by the client application and provides it data for visualization. But, no matter what kind of software is being used, there always are some common needs to communicate the engineering system and the interactive view, such as the initial configuration, a way to read/modify the value of the variables or states (for visualization and manipulation) and also, depending on the system, a way to control the execution, pause, or more complex commands. These actions can be abstracted from the particular implementation, and captured into a generic interoperability protocol. Ideally, the subscription to the protocol should allow a complete decoupling between the two components (the system and the view) in a bidirectional way: on the one hand, an existent model or system can be accessed through different views, for example, to carry out different learning experiences on the same system or to present different visualization depending on the kind of user. On the other hand, an interactive view can be shared by different systems. For example, to connect with different systems depending on their time availability. Focusing on the interconnection between MATLAB and EJS, one have to cope with several problems. First, there are different approaches to control MATLAB from Java, such as compiling the program with Builder JA to create a Java wrapper, or use a third-party library like JMatlink or matlabcontrol that allow to control the MATLAB engine/GUI (see (Altman, 2012) for more details). Then the EJS/Java code must be implemented to solve the specific problem for the laboratory in development. In case there is a need to change the component on which the connection relies (due to compatibility issues, a substitution of the engineering software, etc.), the EJS application must be modified, requiring additional effort to adapt the laboratory. Encapsulating all the interconnection issues into a reusable component, the development can be rationalised, and only the components actually involved in the change have to be adapted. The communication protocol described in the next section shows a simple, but powerful application programming interface (API) that any engineering software should conform to, in order to provide all the features required to effectively implement the interoperate approach.
3. REMOTE INTEROPERABILITY PROTOCOL In a common scenario, the client connects to the resource and acquire basic information about the capabilities of the system, such as: can I control the execution or only behold the evolution of the system? what methods can I invoke? which variables can I obtain from the system? and which can I modify?. After the negotiation phase, the client has obtained sufficient knowledge about the ways to interact with the system. Taking a close look to the functionalities that the engineering system must support, they can be divided into different categories:
IFAC IBCE 2015 November 4-6, 2015. Brescia, Italy
Jesús Chacón et al. / IFAC-PapersOnLine 48-29 (2015) 247–252
249
• Connection and session control These methods allow to establish communication with the server, configure the execution and, eventually, finish the connection properly. • Data transmission control Under this category rely all the methods that can read or modify the state of the server. • Command execution The client application should be able to execute server specific commands. Note that the protocol only specify the way of sending commands. The interpretation of these commands is responsibility of the server, and as that, these can be as simple or as complex as the server necessities. For example, in the case of MATLAB, the client can send MATLAB code. 3.1 The basics Using the KISS principle 1 (Dalzell, 2008), the API has been kept reduced to a minimum set of methods, yet covering all the basic functionality: 2 • connection control · connect() · disconnect() • data transmission · get(variable) · set(variable, value) • session control · start() · stop() · open(file) · close(file) • command execution · eval(command, schedule) · step()
Fig. 1. Sequence diagram of a typical session: First, the client connects to the server and get info about its capabilities. Once established the connection, the client synchronize variables and send commands to be evaluated by the server. Eventually, the client finalize the session, freeing resources for future connections. • disconnect() - This method allows to finalize the connection with the server in a properly way, closing any opened resource that client might have opened.
Figure 1 shows a sequence diagram corresponding to a typical session. After establish the connection, usually the client enter into a loop where periodically updates the values of some variables in the server, executes one or more commands and ask for the new values of the variables of interest. The following paragraphs contain, for each method, a brief description of the purpose and parameters expected. The following lines detail how each method must be defined. Connection Control The implementation of the connect() and disconnect() methods is mandatory, because the system must provide a way of establish and finish the connection in a proper an orderly way.
Data transmission With respect to data transmission, usually both methods get and set are needed. But because some systems may be only readable or writable, the method get must be implemented if there are readable variables reported, being the same valid for the method set and writable variables. • get() - Receive a variable or list or variables from the ones reported by the server as readable, and returns the values of that variables. • set() - Receive a variable or list or variables from the ones reported as writable by the server, together with the values to be assigned.
• connect() - For the handshake, the server has to inform a few things to the client: · A list of the methods that are actually provided by the server, since there are optional methods than may or may not be implemented. · A list of all the variables available in the server, indicating whether they can be read, written or both.
Session control The session control methods and command execution are optional, i.e. they can be implemented or not, because they depend on the capabilities and complexity of the server. Under some circumstances, for example, it could be useful to load a file in the server, start/stop the execution of a simulation, etc. But, as opposed to the methods discussed before, they are not always needed. So it does not make sense to require the implementation for all systems.
Keep it simple, stupid principle states that simplicity should be a primary design goal, avoiding unncecesary complexity. It was noted by the U.S. Navy in 1960. 2 The mandatory methods are formatted as monospaced, and the optional methods are formatted as italic.
• open() - An invocation of the method open provokes the ’opening’ of an element, which can be an experience, access to a hardware resource of whatever the server needs to expose.
1
249
IFAC IBCE 2015 250 November 4-6, 2015. Brescia, Italy
Jesús Chacón et al. / IFAC-PapersOnLine 48-29 (2015) 247–252
• close() - A call to the method close() has as result the closing of a resource that has been previously opened. • start() - In case the execution of the server can be controller by the user, that must be done with a call to the method start(). This is useful, for example, to run a simulation. • stop() - A call to the method stop() provokes the stop of the activity began with an invocation of the method start(). 4. EXAMPLE OF IMPLEMENTATION A reference implementation is provided based on the JavaScript Object Notation (JSON) and JsonRpc v2.0 (JSON-RPC Working Group, 2015). The implementation relies on three components: • An RpcMatlabServer, a service running in the PC in which MATLAB is installed. It implements the JsonRPC v2.0 protocol and provides the API described in Section 3, making use of the matlabcontrol library (Matlabcontrol, 2015; Altman, 2012). • A Java implementation of RpcMatlabClient, which provides access to the API at the client side, encapsulating the jsonrpc implementation details. • An EJS Model Element, which provides a high-level interface and some utility methods to incorporate into an EJS simulation. 4.1 The RPC server The RPC server has been implemented in Java, and it is deployed as a jar file that runs in the PC where the MATLAB Software is installed. Though the internal details are not discussed, the general architecture is depicted in Figure 2. The class MatlabConnector implements the RIP API as a facade to make use of the matlabcontrol library, which allows to establish a local connection with MATLAB to send commands and access the MATLAB workspace. The class RpcMatlabServer is responsible of exposing the API through the protocol JsonRpc v2.0. For this purpose, it use the library libjsonrpc, which have also been developed by the authors. The implementation of the API methods are detailed in the following paragraphs, providing excerpts of the client/server dialogues for each method call. • connect() - An invocation of the method connect() ends with one of the following results: · A new connection with the server is created, registering the user for supervision or control of the hardware, and returning an identifier which can be used to reference the open connection. · An error response if there was any problem with the connection. In JsonRpc: 1 2
{
3 4 5
3 4 5 6 7 8 9 10 11 12 13 14 15 16
}
The id field allows to bind a response to an invokation. The server fills this field with the corresponding value sent by the client, so that it can be correctly interpreted. • disconnect() - A call to the method disconnect() provokes the server to finish the client session. Since the method does not expect response, there is no need to send the id field. An example of disconnect() invokation is: 2
" jsonrpc " : " 2.0 " , " method " : " connect " , " id " : " 02 b25611 -021 c -4604 - ad6f -32 adbbdf00d2 "
" jsonrpc " : " 2.0 " , " result " : { " session_id " : " b5224563 " , " methods " : [ " connect " , " disconnect " , " get " , " set " , " eval " ], " read " : [ "t" , "x" , "y" , "u" ] , " write " : [ " t " , " x " , " y " , " u " ] , }, " id " : " 02 b25611 -021 c -4604 - ad6f -32 adbbdf00d2 "
2
1
{
3 4 5
}
" jsonrpc " : " 2.0 " , " method " : " disconnect " , " params " : " b5224563 " ,
}
• set() - The methods set and get are used to directly read and write the variables provided by the server. The method set receive two params: a variable (or
And the server responds: 1
Fig. 2. The implementation relies on three components: An RpcMatlabServer, a service running in the PC which MATLAB installed, an RpcMatlabClient, which provides access to the API at the client side, and an EJS model element, which provides a high-level interface and some utility methods to incorporate into an EJS simulation.
{
250
IFAC IBCE 2015 November 4-6, 2015. Brescia, Italy
Jesús Chacón et al. / IFAC-PapersOnLine 48-29 (2015) 247–252
251
list of variables) to be modified and the new value(s). For example, the following call set the value of the variable u to the vector (0.0, 1.0, 2.0). 1 2
{
3 4 5
" jsonrpc " : " 2.0 " , " method " : " set " , " params " : [ " u " , [ 0 . 0 , 1 . 0 , 2 . 0 ] ]
}
• get() - The method get receive one param: the variable (or list of variables) requested. For example, to obtain the value of the variable x : 1 2
{
3 4 5 6
" jsonrpc " : " 2.0 " , " method " : " get " , " params " : [ " x " ] , " id " : " 78 ab4cf2 -05 e8 -411 b - b05c - f5fecf73e3ac "
}
Fig. 3. The MatlabConnector element is an EJS add-on which can be incorporated into an EJS simulation, just dragging and dropping, to add connectivity with a MATLAB/Simulink model. The configuration dialog of the element allows to introduce the server URL, the variables that should be synchronized, and some additional options.
• eval() - The method eval() allows to execute commands provided by the server (in this case, any MATLAB command). 1 2
{
3 4 5
" jsonrpc " : " 2.0 " , " method " : " eval " , " params " : [ " y = cos ( w * t ) ; " ] ,
}
7 8
By default, the command is immediately evaluated after 9 the invocation is processed. A second argument will allow 10 to specify a scheduling, for example ’now’ or ’every 10 11 ms’. But currently only the immediate execution is imple- 12 13 mented. 14
4.2 The RPC client
15 16
1 2 3
}, {
" jsonrpc " : " 2.0 " , " method " : " eval " , " params " : [ " y = cos (2* pi * f * t ) ; " ] ,
" jsonrpc " : " 2.0 " , " method " : " get " , " params " : [ " y " ] , " id " : " 78 ab4cf2 -05 e8 -411 b - b05c - f5fecf73e3ac "
} The basic API provided by the server can be used to 17 control a MATLAB session at the client side, evaluat- 18 ] ing commands and synchronizing workspaces. A common functionality which is needed very often is the execution 4.3 The EJS Element of a simulation step by step. Here a step is understood as a sequence of three actions: The implementation of the API has been encapsulated • Update the value of several variables (usually the inside an EJS element so, in order to enable the current input of the model or system) simulation to communicate with a MATLAB server, the • Execute a command, for example to integrate a time interface designer only have to drag an icon from the interval of a simulation model, to update a controller, library and drop to the current simulation (see Figure 3). etc. Then, some configuration is required. At a minimum, the • Read a set of variables which have been affected by URL where the server is listening. Once the element has the command executed. been configured, the API described in Section 3 can be accessed through the instance added to the simulation. This actions can be decomposed as three successive invocaTo implement the cosine computation example, a new tions of the methods set(), eval(), and get(). For example, Initialization page is created with the following code (see suppose the client want to use the MATLAB server to Figure 4): compute the value of the expression y = cos(wt) over the 1 time (though it is like using a sledgehammer to crack a matlab . c o n n e c t ( ) ; nut, the example is functionally similar to the execution 2 matlab . e v a l ( " w =2*3.1416*1; t =0; " , " at init " ) ; of a complex MATLAB model). A way of doing that is using a batch call (sending different method calls in one where the first sentence connects to the server, and the second one sets a command to be evaluated at the initializamessage). An example of such a call codified in JsonRpc: tion phase. Then, an Evolution Page is created containing [ the code to be periodically executed: {
4 5 6
{
},
" jsonrpc " : " 2.0 " , " method " : " set " , " params " : [ " t " , 1 . 0 ]
1 2 3 4
251
matlab . s e t ( " t " , t ) ; matlab . e v a l ( " y = cos ( w * t ) ; " , " now " ) ; y = ( double ) matlab . g e t ( " y " ) ; t += 0 . 0 5 ;
IFAC IBCE 2015 252 November 4-6, 2015. Brescia, Italy
Jesús Chacón et al. / IFAC-PapersOnLine 48-29 (2015) 247–252
Fig. 4. The Initialization pages allow to introduce lines of Java code that should be runned at the initialization of the simulation. On the left, the code corresponds to the low-level commands approach. On the right, the code is introduced through the configuration dialog.
Fig. 5. The Evolution pages allow to introduce lines of Java code that should be runned at every integration step of the simulation. On the left, the code corresponds to the low-level commands approach. On the right, the code is introduced through the configuration dialog. REFERENCES
the update of the variable t is sent to the server, then the command is executed and finally the value of y is requested to the server. As mentioned, this approach uses the lowlevel API calls. But there are another possible approaches. For example, using the step definition given before, one can configure the element to automatically get ride of all these actions: • Synchronize the variables t and y between EJS and MATLAB. In this case, the variables at both sides has the same name, but this is only for convenience, not a requirement. • Run a command at initialization, i.e. after the first call of the method start or step. • Set the command to be executed every time the method step is invoked.
5. CONCLUSIONS The work has focused on the definition of a protocol to specify how engineering systems must publish their services in order to be able of decoupling from the user interface that allow access to them. The common requirements, which usually cover the functionalities of connection and session control, data transmission control, and user interaction handling, have been captured into an interoperability API. In this way, not only the development of these system is rationalized, but it provides with new possibilities like for example the development of different interfaces that can access the same engineering system, or vice-versa, a unique interface that can connect to different systems, depending on the availabilty. The benefits of this approach is studied in an example of implementation using MATLAB, a well-know engineering software, and EJS, a software tool commonly used to create interactive simulations. The API is implemented with JsonRpc v2.0, which allows to be deployed over the Internet in a portable manner. 252
Altman, Y. (2012). Undocumented Secrets of MATLABJava Programming. CRC Press. Chacon, J., Vargas, H., Farias, G., Sanchez, J., and Dormido, S. (2015). EJS, JIL Server and LabVIEW: How to build a remote lab in the blink of an eye. Learning Technologies, IEEE Transactions on. doi: 10.1109/TLT.2015.2389245. Dalzell, T. (2008). The Routledge Dictionary of Modern American Slang and Unconventional English. Taylor Francis. Dormido, S. (2004). Control learning: Present and future. In Annual Reviews in Control, volume 28, 115–136. Dormido, S., Dormido-Canto, S., Dormido, R., and S´anchez, J. (2005a). The role of interactivity in control learning. The International Journal of Engineering Education, 21(6), 1122–1133. Dormido, S., Esquembre, F., Farias, G., and S´ anchez, J. (2005b). Adding interactivity to existing simulink models using easy java simulations. In 44th IEEE CDCECC’05, 4163–4168. Esquembre, F. (2015). Easy Java Simulations home page. www.fem.um.es/Ejs. Farias, G., Dormido, S., and Esquembre, F. (2011). Interactive Human Interfaces with Engineering Software. In 18th IFAC World Congress. Heck, B. (1999). Special report: Future directions in control education. IEEE Control Systems Magazine, 19(5), 35–58. JSON-RPC Working Group (2015). JSON-RPC 2.0 Specification. http://www.jsonrpc.org/specification. Matlabcontrol (2015). matlabcontrol home page. https://code.google.com/p/matlabcontrol/. S´anchez, J., Morilla, F., Dormido, S., Aranda, J., and Ruip´erez, P. (2002). Virtual and Remote control labs using java: a qualitative approach. IEEE Control Systems Magazine, 22(2), 8–20. The MathWorks (2015). MATLAB home page. www.mathworks.com.