Skip to content

Commit 8457ae5

Browse files
authored
Merge pull request #1 from convince-project/dev
Update with HL-SCXML and topics
2 parents eda4824 + 9834a2f commit 8457ae5

File tree

25 files changed

+1155
-222
lines changed

25 files changed

+1155
-222
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ target_sources( ${PROJECT_NAME} PRIVATE
2727
${CMAKE_CURRENT_SOURCE_DIR}/src/Data.cpp
2828
${CMAKE_CURRENT_SOURCE_DIR}/src/strManipulation.cpp
2929
${CMAKE_CURRENT_SOURCE_DIR}/src/Replacer.cpp
30+
${CMAKE_CURRENT_SOURCE_DIR}/src/Translator.cpp
3031
${CMAKE_CURRENT_SOURCE_DIR}/src/ExtractFromXML.cpp
3132
${CMAKE_CURRENT_SOURCE_DIR}/src/ExtractFromElement.cpp
3233
)

README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> Please access the documentation via [convince-project.github.io/model2code](https://convince-project.github.io/model2code/)
44
5-
MODEL2CODE is a tool that generates CPP code from a SCXML model.
5+
MODEL2CODE is a tool that generates a ROS package with C++ code from a ROS-flavoured SCXML model.
66

77
## Installation
88

@@ -12,37 +12,45 @@ MODEL2CODE has been tested on Ubuntu 22.04 with Python 3.10.12.
1212

1313
MODEL2CODE requires the following dependencies:
1414

15-
* [TinyXML2](https://github.com/leethomason/tinyxml2/) (Tested with v10.0.0)
15+
* [TinyXML2](https://github.com/leethomason/tinyxml2/) (Tested with v10.0.0) for XML file handling.
1616

1717
To install see [TinyXML2 Installation](https://github.com/leethomason/tinyxml2/tree/master?tab=readme-ov-file#building-tinyxml-2---using-vcpkg)
1818

1919
## Compiling
20-
To compile the code run the following commands
20+
To compile the code run the following commands:
2121
```
2222
git clone https://github.com/convince-project/model2code.git
23-
cd model2code/code
23+
cd model2code
2424
mkdir build
2525
cd build
2626
cmake ../code
2727
make install
2828
```
2929

3030
## Execution
31-
To run the `model2code` tool you need three different files:
32-
- An SCXML file with your state machine
33-
- An XML file with the definition of your model
34-
- An XML file with the definition of your interfaces
35-
- A directory containing the templates of the files to generate
31+
To run the `model2code` tool, you will need the following:
32+
- An SCXML file with the state machine of the model;
33+
- An XML file defining the model of your project;
34+
- An XML file defining the interfaces of your project;
35+
- A directory containing templates for the files to be generated.
3636

3737
To run the `model2code` tool use the following command
3838
```
39-
model2code --input_filename "input_filename.scxml" --model_filename "model_filename.scxml" --interface_filename "interface_filename.scxml" --output_path "path/to/output/directory" --template_path "path/to/template_skill/directory"
39+
model2code --input_filename "input_model.scxml" --model_filename "project_model_definition.xml" --interface_filename "interface_definition.xml" --output_path "path/to/output/directory" --template_path "path/to/template_skill/directory"
4040
```
41-
replace `input_filename.scxml`, `model_filename.scxml`, `interface_filename.scxml`, `path/to/output/directory` and `path/to/template_skill/directory` with your needs.
42-
By default the `path/to/output/directory` is set to the location of `input_filename.scxml` and `path/to/template_skill/directory` is set to the 'templates/skills/template_skill' directory of this repository.
41+
replace `input_model.scxml`, `project_model_definition.scxml`, `interface_definition.scxml`, `path/to/output/directory` and `path/to/template_skill/directory` with your needs.
42+
43+
By default the `path/to/output/directory` is set to the location of `input_model.scxml`, and `path/to/template_skill/directory` is set to the 'templates/skills/template_skill' directory of this repository.
44+
45+
Example XML files with the required structure for defining the project's model and interfaces are available in the `template/specifications` folder.
4346

4447
## Run examples
4548
To run an example of MODEL2CODE go to the main directory and run the following commands:
49+
Example 1:
50+
```
51+
model2code --input_filename "tutorials/skills/first_tutorial_skill/src/FirstTutorialSkill.scxml" --model_filename "templates/specifications/full-model.xml" --interface_filename "templates/specifications/interfaces.xml" --output_path "tutorials/skills/first_tutorial_skill"
4652
```
47-
model2code --input_filename "templates/skills/first_template_skill/src/FirstTemplateSkillSM.scxml" --model_filename "templates/specifications/full-model.xml" --interface_filename "templates/specifications/interfaces.xml"
53+
Example 2:
4854
```
55+
model2code --input_filename "tutorials/skills/second_tutorial_skill/src/SecondTutorialSkill.scxml" --model_filename "templates/specifications/full-model.xml" --interface_filename "templates/specifications/interfaces.xml"
56+
```

docs/source/index.rst

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
11
CONVINCE model2code Documentation
22
==================================
3-
The tool is developed as part of the CONVINCE project and is mainly used to generate skill-level code starting from an SCXML model.
3+
The model2code tool is developed as part of the CONVINCE project and is used to generate skill-level code from the high-level SCXML model of a skill.
44

5-
The inputs of the program are:
5+
Program inputs:
66

7-
- an SCXML model that describes the behavior of the skill,
8-
- an XML file that describes the full model of the program, which includes the behavior tree, the skills and the components used in the system,
9-
- an XML file that describes the interfaces used between behavior tree and skills, and between skills and components,
10-
- a directory containing the templates of the files to generate.
7+
- An SCXML model that describes the behavior of the skill,
8+
- An XML file that outlines the full model of the program, including the behavior tree, skills, and components used in the system.
9+
- An XML file that specifies the interfaces between the behavior tree and skills, as well as between skills and components.
10+
- A directory containing templates for the files to be generated.
1111

12-
The output of the program is composed of:
12+
Program outputs:
1313

14-
- a C++ file that contains the code of the skill,
15-
- a header file that contains the declaration of the skill,
16-
- a main C++ file that contains the main function of the skill,
17-
- a package.xml file that contains the information of the ROS package,
18-
- a CMakeLists.txt file that includes the generated files.
14+
- A C++ file containing skill code.
15+
- A header file declaring the skill.
16+
- A main C++ file that includes the main function of the skill.
17+
- A package.xml file with information about the ROS package.
18+
- A CMakeLists.txt file that incorporates the generated files.
1919

20-
The output above is only if the data model is ECMAscript, otherwise, you will need to add the parameter ``--datamodel_mode`` to generate the C++ data model files.
21-
In this case, you will get 2 additional files:
2220

23-
- a C++ file that contains the code of the data model,
24-
- a header file that contains the declaration of the data model.
21+
Required parameters:
2522

23+
- ``--input_filename``: The path to the SCXML file that describes the behavior of the skill.
24+
- ``--model_filename``: The path to the XML file that describes the full model of the program.
25+
- ``--interface_filename``: The path to the XML file that describes the interfaces used.
2626

27-
The parameters required to run the program are:
27+
By default, the program generates the code in the same directory as the SCXML file specified by the ``--input_filename`` parameter. However, you can select a different output directory by using the ``--output_path`` parameter.
2828

29-
- ``--input_filename`` : the path to the SCXML file that describes the behavior of the skill,
30-
- ``--model_filename`` : the path to the XML file that describes the full model of the program,
31-
- ``--interface_filename`` : the path to the XML file that describes the interfaces used.
29+
Additionally, the program uses files from the ``templates`` directory by default to generate the code, but you can specify a different directory with the ``--templates_path`` parameter.
3230

33-
By default the program will generate the code in the directory where the SCXML file passed by the parameter ``--input_filename`` is located, but you can specify a different directory by using the parameter ``--output_path``.
34-
35-
The skills generated are based on a behavior tree structure and will have a ROS2 tick service in case they are a condition a ROS2 tick and halt services in case they are an action.
31+
The generated skills are based on a behavior tree structure. Skills defined as conditions will have a ROS2 tick service, while skills defined as actions will have both tick and halt services.
3632

3733
Contents
3834
----------
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct eventDataStr{
6868

6969
struct fileDataStr{
7070
std::string inputFileName;
71+
std::string inputFileNameGeneration;
7172
std::string interfaceFileName;
7273
std::string modelFileName;
7374
std::string outputPath;
@@ -80,8 +81,11 @@ struct fileDataStr{
8081
std::string outputDatamodelFileNameCPP;
8182
std::string outputFileNameH;
8283
std::string outputFileNameCPP;
84+
std::string outputFileTranslatedSM;
8385
bool debug_mode;
8486
bool datamodel_mode;
87+
bool translate_mode;
88+
bool generate_mode;
8589
};
8690

8791
struct templateFileDataStr{
@@ -103,6 +107,11 @@ struct savedCodeStr{
103107
std::string interfaceCMake;
104108
std::string packageCMake;
105109
std::string interfaceXML;
110+
std::string topicSubscriptionC;
111+
std::string topicCallbackC;
112+
std::string topicSubscriptionH;
113+
std::string topicCallbackH;
114+
std::string topicInterfaceH;
106115
};
107116

108117
struct cppCodeStr
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @param fileData file data structure passed by reference from which the event data is extracted
1919
* @param eventData event data structure passed by reference where the event data is stored
2020
*/
21-
void getEventData(fileDataStr fileData, eventDataStr& eventData);
21+
bool getEventData(fileDataStr fileData, eventDataStr& eventData);
2222

2323
/**
2424
* @brief Get the Event Data from the vector of event elements
@@ -27,7 +27,7 @@ void getEventData(fileDataStr fileData, eventDataStr& eventData);
2727
* @param elementsTransition vector of transition event elements
2828
* @param elementsSend vector of send event elements
2929
*/
30-
void getEventsVecData(fileDataStr fileData, const std::vector<tinyxml2::XMLElement*> elementsTransition, const std::vector<tinyxml2::XMLElement*> elementsSend);
30+
bool getEventsVecData(fileDataStr fileData, const std::vector<tinyxml2::XMLElement*> elementsTransition, const std::vector<tinyxml2::XMLElement*> elementsSend);
3131

3232
/**
3333
* @brief function to keep or delete the sections of the code related to the Command Tick event
@@ -95,6 +95,9 @@ void replaceEventCode(std::map <std::string, std::string>& codeMap);
9595
*/
9696
bool readTemplates(templateFileDataStr& templateFileData, std::map <std::string, std::string>& codeMap);
9797

98+
99+
bool createDirectory(const std::string& path);
100+
98101
/**
99102
* @brief main function to get the code from template files and replace the placeholders with the data from the input file
100103
*

include/Translator.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-FileCopyrightText: 2024 Humanoid Sensing and Perception, Istituto Italiano di Tecnologia
2+
// SPDX-License-Identifier: APACHE-2.0
3+
4+
/**
5+
* @file Translator.h
6+
* @brief This file contains the functions to translate the High-Level CONVINCE XML to the compilable SCXML used for code generation.
7+
* @version 0.1
8+
* @date 2024-09-18
9+
*
10+
*/
11+
#include "Replacer.h"
12+
#include <fstream>
13+
14+
/**
15+
* @brief Deletes a specific attribute of a given XML element
16+
*
17+
* @param element element from which to delete the attribute
18+
* @param attribute attribute name to be deleted
19+
* @return bool
20+
*/
21+
bool deleteElementAttribute(tinyxml2::XMLElement* element, const std::string& attribute);
22+
23+
/**
24+
* @brief Deletes a specific attribute from all elements in a vector
25+
*
26+
* @param elements vector of elements from which to delete the attribute
27+
* @param attribute attribute name to be deleted
28+
* @return bool Returns true if at least one attribute was successfully deleted, false otherwise
29+
*/
30+
bool deleteElementAttributeFromVector(std::vector<tinyxml2::XMLElement*>& elements, const std::string& attribute);
31+
32+
/**
33+
* @brief
34+
*
35+
* @param
36+
*/
37+
bool readHLXMLFile(tinyxml2::XMLDocument& doc, const std::string fileName);
38+
39+
/**
40+
* @brief
41+
*
42+
* @param
43+
*/
44+
bool Translator(fileDataStr& fileData);
File renamed without changes.

0 commit comments

Comments
 (0)