Translate XML model into Python code
Visit our website for full documentation »
View current process
·
Report Bug
·
Request Feature
- About the Project
- Getting Started
- Current Features
- Usage/Application
- Roadmap
- Coding Style Convention
- License
- Contact
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)
Download UPPAAL to create your model
-
Clone the repo
git clone https://github.com/TCC2021SeniorProject/ModelTranslator.git
-
Download XML examples
-
Run Main.py program
cd ./MdoelTranslator/src
-
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
For more plans, please see the plan documentation.
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
- 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.
First Tasks
See the open issues for a full list of proposed features (and known issues).
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
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 &mode, int &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 < 10</label>
</transition>
<transition>
<source ref="id0"/>
<target ref="id1"/>
<label kind="guard" x="-1377" y="-425">mode == 1 && charge > 10</label>
<label kind="synchronisation" x="-1326" y="-442">check_mode?</label>
</transition>
</template>
<template>
<name>clean</name>
<parameter>int &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 &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>
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())
├── 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
+Rules before giving an input
- 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.
- All variables must be defined. Any unidentified variables may cause errors either while using the software (translation) or executing output (Python code).
- All variable declarations must be valid, according to its template.
- Every node must have a unique identifier. Duplicate identifiers will result in overwriting of functions.
For more examples, please refer to the Design Documentation.
To view the specific testing details, click here
MCCD refers to Main Control Center Device.
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
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.
Dr. Siddhartha Bhattacharyya
Email: [email protected]
Sung-Jun Baek
Email: [email protected]
GitHub: MarcoBackman
Caelan Shoop
Email: [email protected]
GitHub: CCShoop
Cameron Wright
Email: [email protected]
GitHub: CameronWr