Skip to content
Gianluca Prato edited this page Apr 15, 2020 · 7 revisions

The CPSwarm Code Generator is one of the component of the CPSwarm Workbench and is responsible to translate design-level modelled behaviours into concrete, executable code. Such executable code rely on a set of libraries and functionalities, that can be executed by the robot and whose APIs are equivalent among the different supported platforms, called CPSwarm Abstraction Library.

Contents

  1. Concepts
  2. Components
  3. SCXML Extension

1. Concepts

The current implementation of CPSwarm Code Generator supports the generation of code starting from the description of an algorithm in the form of a Finite State Machine (FSM). This state machine can be provided as input to the Code Generator using a standard data format called SCXML. More specifically, the generated state machine implementation relies on the SMACH library, a Python-based project that let easily implement and execute State Machine-designed algorithm. The choice has fallen to this library not only for his extreme simplicity and scalability, but also for his direct integration with ROS.

Due to the very schematic and repeatable structure that all algorithms defined using a FSM have, the template-based technique has been selected as the most proper approach to complete the code generation task. Indeed, the template-based generation pattern applies to all the cases in which simple translation between the high-level algorithm specification and the target runtime environment is possible. In other words, template-based generation applies whenever it is possible to define a simple set of target-templates to be filled with data extracted from the algorithm specification.

2. Components

A template-based code generator can be described by his 4 main components:

  • The template engine: also known as template processor or template parser, it is software designed to combine templates with a data model to produce any kind of formatted output (in our case in source). In this implementation of the CPSwarm Code Generator the code generation process is driven by a Java-based template engine called Velocity. This tool was chosen because of his powerful and simple template language called Velocity Template Language (VLT).

  • The runtime input (or data): this part corresponds to the set of information needed to produce the output. In order to be correctly processed by the Code Generator, the data has to conform to a specific data format such as SCXML. The Apache Commons SCXML library has been used to parse the SCXML input files and extract the data.

  • The templates: a template is text file and it is usually composed by a static part that appears in the output “as it is” and a dynamic part written with a template meta-code. This code contains all the directives that are processed at runtime (together with the input data) by the template engine to produce the final source code, also called output.

  • The output: the source code that is produced as final result of the generation task.

3. SCXML - CPSwarm Extension

As already stated above, the current implementation of the CPSwarm Code Generator accepts as input a formal description of the state machine behavior in the SCXML standard format. SCXML was selected among other possible languages (such as Amazon States Language or RoboChart) for his high flexibility and adaptability to different working context. In fact, in order to capture specific aspects related to the CPS domain, the language has been slightly adapted for code generator purposes. The detailed description of this extension is presented here.

Clone this wiki locally