Skip to content

A software program that translates XML-based code into executable python codes.

Notifications You must be signed in to change notification settings

TCC2021SeniorProject/ModelTranslator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation




Carthage compatible Carthage compatible Carthage compatible Carthage compatible Carthage compatible

MODEL TRANSLATOR


Translate XML model into Python code
Visit our website for full documentation »

View current process · Report Bug · Request Feature



TABLE OF CONTENTS

  1. About the Project
  2. Getting Started
  3. Current Features
  4. Usage/Application
  5. Roadmap
  6. Coding Style Convention
  7. License
  8. Contact


About The Project

This project will assist developers in implementing custom IoT systems.

Here's why you should use this:

  • Users who want to design automata system with UPPAAL
  • Users who want their modeled diagrams to run on a Rasberry Pi device
  • Users who want to test out IoT environment with the modeling tool (UPPAAL)

(back to top)

Tools Used With (Translator)


Getting Started

Prerequisites

Download UPPAAL to create your model

Demo Installation

  1. Clone the repo

    git clone https://github.com/TCC2021SeniorProject/ModelTranslator.git
  2. Download XML examples

  3. Run Main.py program

     cd ./MdoelTranslator/src

Current Features

  • The translator can handle the below features from UPPAAL

    • Identifies Start and End node by name (This feature will be changed to tag identification)
    • Change UPPAAL XML into abstract graph structure
    • Parse given global declaration from UPPAAL to variables
  • General features:

    • Handling multiple transitions
    • Identifiying classes, nodes, transitions
    • Handling system scripts
    • Handling sync broadcasting and respoding
    • Handling parameters
    • Access of gloabal fields
  • Template:

    • Stores every objects: transitions, nodes, local fields, etc.
  • Transition:

    • Select (name)
    • Guard (conditionals)
    • Assignment (variable update in local)
    • Sync
    • Conditional statement conversion(UPPAAL syntax -> Python syntax)
    • Locate linked node sources
  • Node

    • Node's name as function definition in Python
    • Transition's destination is a function call


Roadmap

For more plans, please see the plan documentation.

Current Tasks. (Due Jan 2022)

See current task list

  • Fully implement operational and conditional statement converter
    • Implement converter
    • Fix potential bugs & issues.
    • Identify variables.

  • Refactor packages(modules) structures to do only relative jobs
    • Object package only holds class data
    • Parser package holds only relavant modules
      • Components package only does parsing job
      • Syntax package only converts syntactical string
    • Translator package only translates objects into python scripts
    • Main.py only runs a root module of the packages.

  • Accept parameters on sender and on receiver
  • [-] Implement access of global variables from local field


Previous Tasks
    First Tasks

    First Task - Aug 2021 ~ Oct 2021

    • Update mark down documentation.
    • Create mock Python code output.
    • Make UPPAAL parser.
    • Program is able to traverse all the nodes through tranistion objects.
    • Program is able to identify the validity of the model.
    • Program is able to validate the node function (e.g. starting node, termination node, logic node, process node, etc)
    • Make Python code generator/converter.
    • Test simple diagram.

    Second Tasks

    Task 2 check list - Oct 2021 ~ Nov 2021.

    • Make complex diagram 1
    • Update(enhance) UPPAAL parser
    • Update(enhance) Python code generator/converter
    • Test complex diagram 1
    • Update (enhance) UPPAAL parser
    • Update (enhance) Python code generator/converter
    • Test complex diagram 1

See the open issues for a full list of proposed features (and known issues).

Testing schedules

    General testing Schedules

    • Test case 1 (Due Oct 9): Produce code from a simple model
    • Test case 2 (Due Oct 17): Model comparatively massive size diagram
    • Test case 3 (Due Oct 23): Build infinite loops / Redundant transitions.
    • Test case 4-1 (Due Nov 21): Change models to python codes that MCCD accepts.
    • Test case 4-2 (Due Jan 20): Create executable model.
    • Test case 7 (Due Feb 1): Create a web application version of translator.
    • Test case 8 (Due Feb 29): Check main control device can be postponed until specified device finishes its current job

Example of how software works


1. Build your own model in UPPAAL

Templates


Global declaration


System declaration


First template


Second template


Third template



2. XML input of UPPAAL model

Expand to see the code

  <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.1//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_2.dtd'>
<nta>
	<declaration>// Global declaration(s)
int[1,2] status;
int battery;
chan check_mode;
</declaration>
	<template>
		<name x="0" y="0">all_tran_example</name>
		<parameter>int &amp;mode, int &amp;charge</parameter>
		<declaration>// Place local declarations here.</declaration>
		<location id="id0" x="-1411" y="-425">
			<name x="-1428" y="-459">Idle</name>
		</location>
		<location id="id1" x="-1173" y="-425">
			<name x="-1190" y="-459">Run</name>
		</location>
		<location id="id2" x="-935" y="-425">
			<name x="-952" y="-459">Dock</name>
		</location>
		<init ref="id0"/>
		<transition>
			<source ref="id2"/>
			<target ref="id0"/>
			<label kind="assignment" x="-1207" y="-340">mode = 0</label>
			<nail x="-1020" y="-340"/>
			<nail x="-1360" y="-340"/>
		</transition>
		<transition>
			<source ref="id1"/>
			<target ref="id2"/>
			<label kind="guard" x="-1139" y="-425">mode == 4 || charge &lt; 10</label>
		</transition>
		<transition>
			<source ref="id0"/>
			<target ref="id1"/>
			<label kind="guard" x="-1377" y="-425">mode == 1 &amp;&amp; charge &gt; 10</label>
			<label kind="synchronisation" x="-1326" y="-442">check_mode?</label>
		</transition>
	</template>
	<template>
		<name>clean</name>
		<parameter>int &amp;mode</parameter>
		<location id="id3" x="-629" y="-272">
			<name x="-646" y="-306">Clean</name>
		</location>
		<location id="id4" x="-773" y="-272">
		</location>
		<init ref="id4"/>
		<transition>
			<source ref="id4"/>
			<target ref="id3"/>
			<label kind="guard" x="-748" y="-272">mode == 3</label>
			<label kind="synchronisation" x="-748" y="-289">check_mode!</label>
		</transition>
	</template>
	<template>
		<name>explore</name>
		<parameter>int &amp;mode</parameter>
		<location id="id5" x="-850" y="-493">
			<name x="-867" y="-527">Explore</name>
		</location>
		<location id="id6" x="-1020" y="-493">
		</location>
		<init ref="id6"/>
		<transition>
			<source ref="id6"/>
			<target ref="id5"/>
			<label kind="guard" x="-986" y="-493">mode == 2</label>
			<label kind="synchronisation" x="-986" y="-510">check_mode!</label>
		</transition>
	</template>
	<system>// Template instantiation(s)
Roomba = all_tran_example(status, battery);
// Processe(s) to be composed into a system(s)
system Roomba;
    </system>
	<queries>
		<query>
			<formula></formula>
			<comment></comment>
		</query>
	</queries>
</nta>



3. Auto-generated output in python:

    Expand to see the code

    import asyncio
    
    status = 0
    battery = 0
    check_mode = None #Channel variable
    
    class all_tran_example:
    	def __init__(self, mode, charge, ):
    		self.mode = mode
    		self.charge = charge
    
    	async def Dock(self):
    		await self.Idle()
    
    	async def Run(self):
    		if self.mode == 4 or self.charge < 10:
    			await self.Dock()
    
    	async def Idle(self):
    		if self.mode == 1 and self.charge > 10:
    			await self.Run()
    
    class clean:
    	def __init__(self, mode, ):
    		self.mode = mode
    
    	async def Clean(self):
    		exit()
    
    	async def default_init(self):
    		if self.mode == 3:
    			Roomba.Run()
    			await self.Clean()
    
    class explore:
    	def __init__(self, mode, ):
    		self.mode = mode
    
    	async def Explore(self):
    		exit()
    
    	async def default_init(self):
    		if self.mode == 2:
    			Roomba.Run()
    			await self.Explore()
    
    loop = asyncio.get_event_loop()
    
    Roomba = all_tran_example(status, battery)
    
    loop.run_until_complete(Roomba.Idle())
    



(back to top)

Process logic flow




(back to top)

File structure

├── data
├── docs
├── img
│   └── icon
├── README.md
└── src
    ├── main.py
    ├── objects
    │   ├── global_set.py
    │   ├── node.py
    │   ├── sync.py
    │   ├── system.py
    │   ├── template.py
    │   ├── transition.py
    │   └── variable.py
    ├── parser
    │   ├── components
    │   │   ├── declaration_parser.py
    │   │   ├── node_parser.py
    │   │   ├── system_parser.py
    │   │   └── transition_parser.py
    │   ├── syntax
    │   │   └── cpyparser.py
    │   ├── tag_set.py
    │   └── XML_parser.py
    └── translator
        ├── class_gen.py
        ├── function_gen.py
        ├── py_export.py
        └── script_gen.py

Valid model rule


+Rules before giving an input
  1. A model must be a valid model. The validity of the model can be checked in UPPAAL software. Any invalid UPPAAL model will cause a program crash.
  2. All variables must be defined. Any unidentified variables may cause errors either while using the software (translation) or executing output (Python code).
  3. All variable declarations must be valid, according to its template.
  4. Every node must have a unique identifier. Duplicate identifiers will result in overwriting of functions.

Usage/Application

For more examples, please refer to the Design Documentation.

(back to top)


To view the specific testing details, click here

MCCD refers to Main Control Center Device.

(back to top)

Coding Style Convention

See the following link: Style Guide for Python Code

Follow rules for better readability: Clean Code by Robert C. Martin

Getter first, setter later for function definitions

Only one thing in a function

Consider portability and readability

License

Currently, there is no license for this repo, meaning our team retains all rights to the source code and no one may reproduce, distribute, or create derivative works from our work.

This will not be permanent until the completion of the project.

(back to top)

Contact

Director

Dr. Siddhartha Bhattacharyya
Email: [email protected]

Developers

Sung-Jun Baek
Email: [email protected]
GitHub: MarcoBackman

Caelan Shoop
Email: [email protected]
GitHub: CCShoop

Cameron Wright
Email: [email protected]
GitHub: CameronWr

(back to top)

About

A software program that translates XML-based code into executable python codes.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages