-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ros2 implementation based on ros2model
- Loading branch information
Showing
6 changed files
with
94 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,6 @@ | |
|
||
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) | ||
|
||
[![MELODIC build status](https://github.com/ipa320/ros-model-extractors/actions/workflows/build_melodic.yml/badge.svg)](https://github.com/ipa320/ros-model-extractors/actions/workflows/build_melodic.yml) | ||
[![NOETIC ros-model-extractors](https://github.com/ipa320/ros-model-extractors/actions/workflows/build_noetic.yml/badge.svg)](https://github.com/ipa320/ros-model-extractors/actions/workflows/build_noetic.yml) | ||
[![FOXY build status](https://github.com/ipa320/ros-model-extractors/actions/workflows/build_foxy.yml/badge.svg)](https://github.com/ipa320/ros-model-extractors/actions/workflows/build_foxy.yml) | ||
|
||
|
||
Technical Maintainer: [**ipa-nhg**](https://github.com/ipa-nhg/) (**Nadia Hammoudeh Garcia**, **Fraunhofer IPA**) - **[email protected]** | ||
|
||
This repository contains the HAROS framework plugin to automatically generate models according to the DSLs defined for RosModel. | ||
|
@@ -17,6 +12,7 @@ This package also contains a set of ROS containers where you can easily do the a | |
|
||
As related work you can read the following paper: [Bootstrapping MDE development from ROS manual code: Part 2—Model generation and leveraging models at runtime](https://link.springer.com/article/10.1007/s10270-021-00873-2?wt_mc=Internal.Event.1.SEM.ArticleAuthorOnlineFirst&utm_source=ArticleAuthorOnlineFirst&utm_medium=email&utm_content=AA_en_06082018&ArticleAuthorOnlineFirst_20210420) | ||
|
||
:bangbang: The updated version of the development is only being supported for ROS2, the RO1 implementation (old version) is available under [ros1 branch](https://github.com/ipa320/ros-model-extractors/tree/ros1) | ||
|
||
### HowTo Use the docker container to run the ros-model plugin for HAROS | ||
|
||
|
@@ -26,7 +22,7 @@ Build the HAROS docker image, for your desired ROS distro version: | |
|
||
``` | ||
cd path-to-ros-model-extractors-repo | ||
[sudo] docker build --tag=haros_ROSDISTRO -f ROSDISTRO/Dockerfile . | ||
[sudo] docker build --tag=haros_ROSDISTRO -f docker/ROSDISTRO/Dockerfile . | ||
``` | ||
|
||
Call the ros-model extractor plugin, remember you have to also clone the repository to be analysed: | ||
|
@@ -48,13 +44,8 @@ Additionally, the analysis offers the option to analyze all the nodes of a packa | |
``` | ||
|
||
Please check the available examples for the supported distros: | ||
|
||
- [ROS1 melodic](melodic/README.md) | ||
- [ROS1 noetic](noetic/README.md) | ||
- [ROS2 foxy](foxy/README.md) | ||
- [ROS2 humble](humble/README.md) | ||
|
||
ToDo: | ||
- Extractor of interfaces types (msgs, srvs and actions) | ||
- Parser for launch files and analysis of the full system | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
ros_code_analysis/ros_code_analysis/ros1_python_extractor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2024 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA) | ||
# | ||
# Nadia Hammoudeh Garcia | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from bonsai.analysis import CodeQuery, resolve_expression | ||
from ros_common_extractor import RosCommonExtractor | ||
import ros2model.core.metamodels.metamodel_ros as RosModelMetamodel | ||
|
||
class Ros1PythonExtractor(): | ||
def extract_primitives(node, parser, analysis): | ||
gs = parser.global_scope | ||
node.source_tree = parser.global_scope | ||
publishers=[] | ||
subscribers=[] | ||
serviceservers=[] | ||
serviceclients=[] | ||
actionservers=[] | ||
actionclients=[] | ||
parameters=[] | ||
|
||
msgs_list = [] | ||
pkgs_list = [] | ||
for imp_name in parser.imported_names_list: | ||
s = str(imp_name) | ||
if "msg" in s or "srv" in s: | ||
ss = s.split(".") | ||
if len(ss) < 2: | ||
continue | ||
if ss[-1] == "msg" or ss[-1] == "srv": | ||
pkgs_list.append(ss[0]) | ||
elif ss[1] == "msg" or ss[1] == "srv": | ||
msgs_list.append((ss[0], ss[2])) | ||
else: | ||
log.debug(("Python import with 'msg' or 'srv', " | ||
"but unable to process it: ") | ||
+ s) | ||
for call in CodeQuery(gs).all_calls.get(): | ||
if "rospy.Publisher" in str(call): | ||
if len(call.arguments) > 1: | ||
name = analysis._extract_topic(call, topic_pos=0) | ||
msg_type = analysis._extract_message_type(call, '', msgs_list, pkgs_list) | ||
pub = RosModelMetamodel.Publisher(name=name,type=msg_type.replace(".msg","")) | ||
publishers.append(pub) | ||
if "rospy.Subscriber" in str(call): | ||
if len(call.arguments) > 1: | ||
name = analysis._extract_topic(call, topic_pos=0) | ||
msg_type = analysis._extract_message_type(call, '', msgs_list, pkgs_list) | ||
sub = RosModelMetamodel.Subscriber(name=name,type=msg_type.replace(".msg","")) | ||
subscribers.append(sub) | ||
if "rospy.Service" in str(call): | ||
if len(call.arguments) > 1: | ||
name = analysis._extract_topic(call, topic_pos=0) | ||
srv_type = analysis._extract_message_type(call, '', msgs_list) | ||
ss = RosModelMetamodel.ServiceServer(name=name,type=srv_type.replace(".srv","").replace("Request","")) | ||
serviceservers.append(ss) | ||
if "rospy.ServiceProxy" in str(call): | ||
if len(call.arguments) > 1: | ||
name = analysis._extract_topic(call, topic_pos=0) | ||
srv_type = analysis._extract_message_type(call, '', msgs_list) | ||
sc = RosModelMetamodel.ServiceClient(name=name,type=srv_type.replace(".srv","").replace("Response","")) | ||
serviceclients.append(sc) | ||
if "rospy.set_param" in str(call): | ||
param_name = analysis._extract_topic(call, topic_pos=0) | ||
param_type = default_value = None | ||
default_value = resolve_expression(call.arguments[1]) | ||
param = RosModelMetamodel.Parameter(name=param_name,type=param_type,value=default_value) | ||
parameters.append(param) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters