<?xml version="1.0" encoding="UTF-8"?>
<TEI xml:space="preserve" xmlns="http://www.tei-c.org/ns/1.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.tei-c.org/ns/1.0 https://raw.githubusercontent.com/kermitt2/grobid/master/grobid-home/schemas/xsd/Grobid.xsd"
 xmlns:xlink="http://www.w3.org/1999/xlink">
	<teiHeader xml:lang="en">
		<fileDesc>
			<titleStmt>
				<title level="a" type="main">Implementing the MDETools&apos;18 challenge with ThingML ⋆</title>
			</titleStmt>
			<publicationStmt>
				<publisher/>
				<availability status="unknown"><licence/></availability>
			</publicationStmt>
			<sourceDesc>
				<biblStruct>
					<analytic>
						<author>
							<persName><forename type="first">Jakob</forename><surname>Høgenes</surname></persName>
							<affiliation key="aff0">
								<orgName type="institution">SINTEF Digital</orgName>
								<address>
									<settlement>Oslo</settlement>
									<country key="NO">Norway</country>
								</address>
							</affiliation>
						</author>
						<author>
							<persName><forename type="first">Brice</forename><surname>Morin</surname></persName>
							<affiliation key="aff0">
								<orgName type="institution">SINTEF Digital</orgName>
								<address>
									<settlement>Oslo</settlement>
									<country key="NO">Norway</country>
								</address>
							</affiliation>
						</author>
						<title level="a" type="main">Implementing the MDETools&apos;18 challenge with ThingML ⋆</title>
					</analytic>
					<monogr>
						<imprint>
							<date/>
						</imprint>
					</monogr>
					<idno type="MD5">688370E07198E273FD3678B190DF2B38</idno>
				</biblStruct>
			</sourceDesc>
		</fileDesc>
		<encodingDesc>
			<appInfo>
				<application version="0.7.2" ident="GROBID" when="2023-03-24T15:18+0000">
					<desc>GROBID - A machine learning software for extracting information from scholarly documents</desc>
					<ref target="https://github.com/kermitt2/grobid"/>
				</application>
			</appInfo>
		</encodingDesc>
		<profileDesc>
			<textClass>
				<keywords>
					<term>Model-Driven Engineering</term>
					<term>Tool</term>
					<term>Reactive Systems</term>
				</keywords>
			</textClass>
			<abstract>
<div xmlns="http://www.tei-c.org/ns/1.0"><p>This paper presents a ThingML implementation of the MDE-Tools'18 challenge. ThingML is a textual modeling language that implements a sub-set of the UML (components and state-machines) and complements it with a first-class action language. ThingML also comes with a set of compilers targeting a large variety of platforms and programming languages. Using ThingML, we have been able to 1) fully model the MDETools'18 challenge, 2) automatically compile this specification it to two distinct programming languages, and 3) successfully execute the resulting programs and achieve reasonable results in the simulation.</p></div>
			</abstract>
		</profileDesc>
	</teiHeader>
	<text xml:lang="en">
		<body>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1">Introduction</head><p>This paper presents a ThingML <ref type="bibr" target="#b0">[1]</ref><ref type="bibr" target="#b1">[2]</ref><ref type="bibr" target="#b2">[3]</ref> implementation of the MDETools'18 challenge. ThingML is a textual modeling language that implements a sub-set of the UML (components and state-machines) and complements it with a firstclass action language. The MDETools'18 challenge being to implement a control system for a follower rover interacting with a simulated leader rover, we believe state-machines communicating through asynchronous message passing is an adequate paradigm, and ThingML a relevant MDE tool supporting this paradigm. ThingML employs a textual syntax based on XText, fully integrated in the Eclipse IDE, providing an advanced editor with syntax highlighting, error reporting and code completion. Code for multiple target platforms can easily be generated using the standard Eclipse build interface. A key advantage of ThingML is its first-class action language, which allows modeling fine-grained behavior (e.g. actions in states and transitions) in a platform-independent way. Still, ThingML also provides a "kick-down" mechanism for mixing ThingML code with platform-specific code in order to leverage existing libraries and frameworks to avoid over-modeling by forcing designer to remodel those libraries. The complete implementation of the challenge is publicly available on GitHub 1 . The remainder of this paper is organized as follows. Section 2 details how the challenge is modeled in ThingML. Section 3 presents how the platformindependent specifications from Section 2 can be specialized and compiled to different platforms. Section 4 concludes and discusses the strengths and weaknesses of ThingML when implementing this challenge.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2">Modeling the MDETools'18 Challenge with ThingML</head><p>The simulated environment of the posed challenge exposes two TCP ports for the external application (challenge solution) to 1) poll for the current state of the environment, and 2) send control signals to the follower rover. Not depicted in the figure, is a file containing parameters which describe both how the leader rover moves, the target distance for the follower rover, and the endpoints of the TCP ports.</p><p>The proposed solution to the problem, is an application consisting of: a) A settings parser, b) Communication with the simulator, c) State estimation, d) A control system, and e) A timer. Figure <ref type="figure" target="#fig_0">1</ref> shows how these parts are connected and interact with the simulated environment. A more detailed view into the actual components composing the application is given in Figure <ref type="figure" target="#fig_1">3</ref>. The following sections will detail each part. </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.1">Settings parser</head><p>The settings parser is implemented with a single component. It reads the lineformatted file of parameters, parses them into suitable ThingML datatypes and when the whole file is read, sends a message out to the listening components containing the parsed parameters. In the proposed solution, the following parameters are used:</p><p>-simulationIP, controlPort, observationPort: for the communication part that needs to open TCP sockets to the simulator. -minDistance, maxDistance: for the control system to calculate the target distance. -runTime: for the control system to know when it is done and apply the brakes.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.2">Communication</head><p>This part of the application is implemented with three components. There are two instances of a generic line-based TCP socket that 1) forwards ThingML messages containing a single string to the simulator as lines, and 2) reads lines coming from the simulator and sends them out as ThingML messages. The third component implements the communication protocol of the simulator, acting as the ThingML proxy to the simulator. It implements the parsing and formatting of strings and the ThingML messages shown in Listing 1.1, and uses two regions to handle the communication with both the leader and follower rovers concurrently, shown in Figure <ref type="figure">2</ref>.</p><p>Listing </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.3">State estimation</head><p>The simulated environment only provides the position of the leader and follower, the heading of the follower, and the distance between the leader and follower rovers. To implement a decent control system, derivatives of these quantities are also needed. This part therefore contains two components that estimate the first and second order derivatives, using a finite difference scheme with 2 nd order accuracy, one for each of the rovers. At a fixed time interval each estimator requests the current position of its assigned rover. When the response arrives, the last three position values are used to estimate the derivatives.</p><p>A third component buffers the received state estimates from each of the rover estimators, and calculates values that are passed on to the control system: Fig. <ref type="figure">2</ref>. Excerpt of the communicator thing statechart. Upon receiving the parsed settings from the settings parser, and opening observation and control sockets, the communicator enters the depicted composite state. The two parallel regions handle communications with the leader and follower rovers concurrently. As a command or request is received in the form of a ThingML message, it is formatted as a string and passed on to the appropriate socket. If a response is expected, an intermediate waiting state is entered until a string is received from the socket, which is then parsed and passed on as a ThingML message to listening components.</p><p>1. The angle from the follower to the leader, the heading. 2. The distance between the leader and follower. 3. The speed of the leader. 4. The speed of the rover, projected onto the speed of the leader. This is used to prevent the follower from going full in the wrong direction.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.4">Control system</head><p>The control system consists of three components responsible for controlling different aspects of the system, and a fourth component for coordinating and composing the final inputs to the follower rover. The implemented control components are:</p><p>1. Distance controller. A P-controller that tries to keep the follower at a distance of (minDistance + maxDistance) 2 from the leader. 2. Heading controller. A P-controller that tries to point the follower directly towards the leader. 3. Speed controller. A PI-controller with anti-windup, that tries to match the projected speed of the follower with the speed of the leader.</p><p>These control systems receive state estimates from the estimation component, and buffer the last received values. At a configurable time interval the control multiplexer component sends a message to the first controller with (0, 0) as the inputs for the left and right wheels of the follower. Each of the controllers add their own control input on top of the received input, and pass it on to the next controller, and finally back to the control multiplexer. When the control multiplexer gets the combined input from all the controllers back, it scales the values to make sure it is within the allowed range of [−100, 100], and sends it to the communication component to be passed to the simulated environment. </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.5">Timer</head><p>The timer is a single component that receives requests to start a countdown for a specific ID, and when the countdown has elapsed sends a notification to all listening components with the corresponding ID. Although the component is very simple, it is essential since the rest of system operates asynchronously without any notion of time.</p><p>ThingML comes with a rich platform-independent action language, and compilers targeting C (for microcontrollers and Linux), Java, JavaScript (Node.JS and Browser) and Go. This means that generating complete and executable code for multiple platforms, in many cases, comes at no extra cost to the developer. However, as very specialized functionality (like ad hoc communication protocols) are not included in the ThingML modeling language, some situations require platform specific models. There are three ways to accomplish this using ThingML:</p><p>1. Using plug-ins that come bundled with the ThingML compilers. These plugins are specialized for each target language, and generate code for exchanging ThingML messages across network protocols (such as MQTT and WebSockets) with other ThingML or legacy applications. 2. Using standard libraries that come bundled with ThingML. These libraries provide commonly used functions (e.g. mathematical functions or string formatting and parsing) as both platform independent abstract declarations, and platform specific concrete implementations. 3. Manually mix in platform specific code using the "kick-down" mechanism, or applying compiler specific options using annotations.</p><p>To demonstrate how platform independent and platform specific models are specified and mixed in ThingML, the proposed solution was implemented with models to generate code for both Java and Go. The final models consist of mainly platform independent components, while the following parts of the ThingML model is implemented in a platform specific way: a) Mathematical functions, b) String formatting and parsing, c) The timer component, d) Line-based messaging over TCP, and e) Reading the configuration file line-by-line.</p><p>The following sections first demonstrate how platform independent and specific models may be combined by showing the ThingML implementation of the configuration file parser, then compare the implementation of the proposed solution using the two languages.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.1">Example of Platform Specific Models Using ThingML</head><p>The settings parser component is responsible for converting a specially formatted file of parameters to ThingML datatypes, and notifying listening components about their values. Reading files and parsing strings are not functionalities that is supported in the ThingML action language directly, so this component requires platform specific implementations using the mechanisms provided by ThingML.</p><p>Listing 1.2 shows the platform independent partial (indicated by fragment) implementation of the component. This model defines the relatively simple behavior of the component. Once started, the ReadConfigFile function is called, which again is supposed to call HandleLine for each line in the file, and after all lines are read, the parsed parameters are sent out over the Loaded port.</p><p>The model uses two ways of defining platform independent behavior without the platform specific implementation. The ReadConfigFile function is declared as an abstract function, leaving all the details up to the final implementation of the component. The HandleLine function calls abstract functions declared in the platform independent String component from the ThingML Strings library, shown in Listing 1.4. To implement these functions, one may simply include the appropriate * Strings component from the library.</p><p>Listing 1.2. Platform independent partial implementation of the settings parser component. Some details have been left out to save space (...). The final implementation of the settings parser component for Java is shown in Listing 1.3. It includes the JavaStrings component from the Strings library that implements the abstract functions for Java (wrapping methods from the Java String class in a straightforward manner), while the ReadConfigFile is manually implemented with Java-code using the "kick-down" mechanism. The java import annotation instructs the ThingML Java compiler to include these additional imports at the top of the generated Java source files. </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.2">Evaluation of Controllers Generated Using Two Languages</head><p>To evaluate the performance of the proposed solution, and to ensure that the generated code for both Java and Go perform equally well and consistently, an experiment was conducted. The experiment consists of five scenarios corresponding to five randomly generated leader rover paths. For each scenario, both the generated Java and Go controllers were executed during five runs alongside the simulated environment. The resulting power input to the follower rover and the distance between the leader and follower rover were recorded over time, as well as the final percentage of time in the zone.</p><p>Table <ref type="table" target="#tab_2">1</ref> shows the final percentage of time in the zone for all runs of the experiment. Overall, the performance of the two languages are similar for each scenario, and quite consistent across the runs within each scenario. For a couple of runs, the Go controller performed significantly worse than the other runs of the same scenario (highlighted with gray cells). The reason for this is still unclear, but since it does not seem to happen for the Java, it might be a manifestation of a bug in the ThingML Go compiler, which warrants further investigation.</p><p>Figure <ref type="figure" target="#fig_3">4</ref> provides a more detailed view of the execution of the controllers for both Java and Go. It shows the power input to the follower rover and the distance between leader and follower rover over time for the two controllers, for randomly selected runs in a randomly selected scenario. In general, the two controllers produce quite similar input, and perform equally well. The slight differences are likely caused by timing differences (since the setup is not a hard real-time system), and potential floating point number inaccuracies. The jaggedness of the power input is probably a result of the sampling of position of the rovers from the simulated environment, either that the sampling rate is too high, the sampling time being non-uniform, or the low-order finite differentiation scheme implemented. As the controllers performed satisfactory, this issue has not been further investigated.  In this work, we have proposed a solution to the MDETools'18 Challenge problem using the ThingML modeling language and accompanying tools. Leveraging the ThingML language and tools, we were able to generate executable code in two languages (Java and Go) that in our experiments produced similar and reasonably good results. The resulting ThingML models for both languages consist of 767 lines of platform-independent code, and 71 (8%) and 88 (10%) lines of platform specific code for Java and Go respectively. In addition, 157 lines of code for new libraries has been written for the two languages that is to be contributed to the ThingML standard libraries.</p><p>This small amount of platform specific code, substantiates the claim that the ThingML modeling language is useful in practical applications, such as the posed challenge. Coupled with the wide range of platforms targeted by the ThingML compilers, it also means that generating code for suitable targets comes at little extra cost to the developer.</p><p>In terms of the control system implemented in the proposed solution of this work, the performance is far from optimal. However, as ThingML offers no specific support for control systems, the authors consider this as outside the main scope of this challenge, and leave further improvements for future work. Such improvements (such as limiting the rate of change of applied power to void wheel-spin) could with ease be implemented with platform independent models. Extending the proposed solution to other languages (e.g. C and JavaScript) is also reserved for future work.</p><p>During the work with solving the posed challenge, some bugs and shortcomings of the ThingML modeling language and tools was discovered, despite the already strong test suite in place for the compilers. Most have already been fixed and contributed to the official ThingML repository, while some (particularly related to the inconsistent behavior of the Go controller) requires further investigation, and will definitely be dealt with by the ThingML developers. As such, the posed challenge has both been a good exercise to assure the practicality of ThingML, as well as providing substantial input for the future development.</p></div><figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_0"><head>Fig. 1 .</head><label>1</label><figDesc>Fig. 1. Conceptual architecture of the proposed solution application. The direction of the arrows indicate the direction of flow of messages.</figDesc><graphic coords="2,134.77,382.14,345.82,132.18" type="bitmap" /></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_1"><head>Fig. 3 .</head><label>3</label><figDesc>Fig. 3. Detailed component diagram generated by the PlantUML ThingML compiler. The colored boxes indicate the parts of the system shown in the conceptual architecture in Figure 1, and described in sections 2.1-2.5 . For each component, a corresponding state machine defines the component behavior. The lines depict connectors between ports of the components, which indicate the flow of messages in the system.</figDesc><graphic coords="5,134.77,244.16,345.83,271.72" type="bitmap" /></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_2"><head>Listing 1 . 3 .</head><label>13</label><figDesc>Platform specific implementation of the settings parser for Java. thing JavaSettingsParser includes SettingsParser, JavaStrings @java_import ' import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException;' { function ReadConfigFile(path : String) do ' try (BufferedReader br = new BufferedReader(new ⤸ FileReader('&amp;path&amp;'))) { for (String line = br.readLine(); line != null; line = ⤸ br.readLine()) { ' HandleLine('line' as String) ' } } catch (IOException e) { System.err.println("Couldn't read config file: "+'&amp;path&amp;'); System.exit(1); } ' end } Listing 1.4. ThingML Strings library, showing both the platform independent declaration and the platform specific implementation for Java. Some details have been left out to save space (...). thing fragment Strings { abstract function ParseLong(s : String) : Long ... } thing fragment JavaStrings { function ParseLong(s : String) : Long do return ('Integer.parseInt('&amp;s&amp;')') as Long end ... }</figDesc></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" xml:id="fig_3"><head>Fig. 4 .</head><label>4</label><figDesc>Fig.4. Comparison of the power inputs for the Go and Java controllers, and the distance between leader and follower rover, for a a single execution.</figDesc></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0"><head></head><label></label><figDesc></figDesc><graphic coords="4,134.77,115.83,345.83,188.61" type="bitmap" /></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_0"><head></head><label></label><figDesc>1.1. The communication API</figDesc><table><row><cell>thing fragment CommunicatorMsgs {</cell></row><row><cell>message Ready()</cell></row><row><cell>message SimulationStarted()</cell></row><row><cell>message SetRoverLRPower(left : Integer, right : Integer)</cell></row><row><cell>message SetBrake(brake : Integer)</cell></row><row><cell>message GetRoverPosition()</cell></row><row><cell>message GetRoverCompass()</cell></row><row><cell>message RoverPosition(x : Double, y : Double)</cell></row><row><cell>message RoverCompass(phi : Double)</cell></row><row><cell>message LeaderStart()</cell></row><row><cell>message GetLeaderPosition()</cell></row><row><cell>message GetLeaderDistance()</cell></row><row><cell>message LeaderPosition(x : Double, y : Double)</cell></row><row><cell>message LeaderDistance(d : Double)</cell></row><row><cell>}</cell></row></table></figure>
<figure xmlns="http://www.tei-c.org/ns/1.0" type="table" xml:id="tab_2"><head>Table 1 .</head><label>1</label><figDesc>Resulting percentage of time in the zone for multiple runs of the simulation with both Go and Java controllers. Outliers are highlighted with gray cells.</figDesc><table><row><cell>Scenario:</cell><cell cols="6">Language: Run 1: Run 2: Run 3: Run 4: Run 5:</cell></row><row><cell cols="2">Scenario 1 Go</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell></row><row><cell></cell><cell>Java</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell></row><row><cell cols="2">Scenario 2 Go</cell><cell>69.2%</cell><cell>67.5%</cell><cell>70.0%</cell><cell>68.8%</cell><cell>68.8%</cell></row><row><cell></cell><cell>Java</cell><cell>70.0%</cell><cell>70.0%</cell><cell>70.0%</cell><cell>70.4%</cell><cell>73.3%</cell></row><row><cell cols="2">Scenario 3 Go</cell><cell>97.5%</cell><cell>98.3%</cell><cell>29.6%</cell><cell>97.5%</cell><cell>97.5%</cell></row><row><cell></cell><cell>Java</cell><cell>97.5%</cell><cell>97.5%</cell><cell>97.5%</cell><cell>97.0%</cell><cell>97.0%</cell></row><row><cell cols="2">Scenario 4 Go</cell><cell>100%</cell><cell>70.3%</cell><cell>100%</cell><cell>100%</cell><cell>97.9%</cell></row><row><cell></cell><cell>Java</cell><cell>95.8%</cell><cell>95.0%</cell><cell>96.3%</cell><cell>100%</cell><cell>100%</cell></row><row><cell cols="2">Scenario 5 Go</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell></row><row><cell></cell><cell>Java</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell><cell>100%</cell></row></table></figure>
		</body>
		<back>
			<div type="references">

				<listBibl>

<biblStruct xml:id="b0">
	<analytic>
		<title level="a" type="main">MDE to manage communications with and between resource-constrained systems</title>
		<author>
			<persName><forename type="first">Franck</forename><surname>Fleurey</surname></persName>
		</author>
		<author>
			<persName><forename type="first">Brice</forename><surname>Morin</surname></persName>
		</author>
		<author>
			<persName><forename type="first">Arnor</forename><surname>Solberg</surname></persName>
		</author>
		<author>
			<persName><forename type="first">Olivier</forename><surname>Barais</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">International Conference on Model Driven Engineering Languages and Systems</title>
				<imprint>
			<publisher>Springer</publisher>
			<date type="published" when="2011">2011</date>
			<biblScope unit="page" from="349" to="363" />
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b1">
	<analytic>
		<title level="a" type="main">ThingML: a language and code generation framework for heterogeneous targets</title>
		<author>
			<persName><forename type="first">Nicolas</forename><surname>Harrand</surname></persName>
		</author>
		<author>
			<persName><forename type="first">Franck</forename><surname>Fleurey</surname></persName>
		</author>
		<author>
			<persName><forename type="first">Brice</forename><surname>Morin</surname></persName>
		</author>
		<author>
			<persName><forename type="first">Knut</forename><forename type="middle">Eilif</forename><surname>Husa</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="m">Proceedings of the ACM/IEEE 19th International Conference on Model Driven Engineering Languages and Systems</title>
				<meeting>the ACM/IEEE 19th International Conference on Model Driven Engineering Languages and Systems</meeting>
		<imprint>
			<publisher>ACM</publisher>
			<date type="published" when="2016">2016</date>
			<biblScope unit="page" from="125" to="135" />
		</imprint>
	</monogr>
</biblStruct>

<biblStruct xml:id="b2">
	<analytic>
		<title level="a" type="main">Model-based Software Engineering to tame the IoT Jungle</title>
		<author>
			<persName><forename type="first">Brice</forename><surname>Morin</surname></persName>
		</author>
		<author>
			<persName><forename type="first">Nicolas</forename><surname>Harrand</surname></persName>
		</author>
		<author>
			<persName><forename type="first">Franck</forename><surname>Fleurey</surname></persName>
		</author>
	</analytic>
	<monogr>
		<title level="j">IEEE Software</title>
		<imprint>
			<biblScope unit="volume">34</biblScope>
			<biblScope unit="issue">1</biblScope>
			<biblScope unit="page" from="30" to="36" />
			<date type="published" when="2017">2017</date>
		</imprint>
	</monogr>
</biblStruct>

				</listBibl>
			</div>
		</back>
	</text>
</TEI>
