-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parse rossystem, add qos and parameters
- Loading branch information
Showing
10 changed files
with
326 additions
and
8 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
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,42 @@ | ||
# | ||
# Copyright 2023 Fraunhofer IPA | ||
# | ||
# 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 pathlib import Path | ||
|
||
from ros2model.core.generator.generator_core import GeneratorCore | ||
import typing as t | ||
from ament_index_python import get_package_share_directory | ||
|
||
Template_Folder = Path(__file__).parent.parent.parent.parent.resolve() / "templates" | ||
Template = Path(Template_Folder / "rossystem.rossystem.j2") | ||
|
||
Template_Folder_ROS = Path(get_package_share_directory("ros2model") + "/templates") | ||
Template_ROS = Path(Template_Folder_ROS / "rossystem.rossystem.j2") | ||
|
||
|
||
class SystemGenerator(GeneratorCore): | ||
def __init__(self, template_path=None) -> None: | ||
if template_path != None: | ||
self.template_path = Path(template_path).resolve() | ||
elif Template_ROS.is_file(): | ||
self.template_path = Template | ||
elif Template.is_file(): | ||
self.template_path = Template | ||
else: | ||
raise FileNotFoundError( | ||
f"Can't find template either from {Template.absolute().as_posix()} or {Template_ROS.absolute().as_posix()}" | ||
) | ||
super().__init__(self.template_path, ".rossystem") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from ros2model.api.runtime_parser.rosmodel_runtime_parser import ( | ||
save_to_file, | ||
get_node_graph_names, | ||
parse, | ||
) | ||
import ros2model.core.metamodels.metamodel_ros as ROSModel | ||
from pathlib import Path | ||
|
||
|
||
class RuntimeRossystem(ROSModel.Rossystem): | ||
pass | ||
|
||
def __init__(self, *, system: ROSModel.Rossystem, **data): | ||
super().__init__(name=system.name, **data) | ||
|
||
def get_nodes(self): | ||
nodes = get_node_graph_names() | ||
for n in nodes: | ||
print("node name: ", n.namespace, n.name, n.full_name) | ||
parsed_node = parse( | ||
ROSModel.GraphName( | ||
name=n.name, namespace=n.namespace, full_name=n.full_name | ||
) | ||
) | ||
self.nodes.append(parsed_node) | ||
|
||
|
||
def name_system_file(grapg_name: ROSModel.GraphName): | ||
n = grapg_name.name.replace("/", "_") | ||
file_name = f"{grapg_name.namespace}__{n}" | ||
return file_name | ||
|
||
|
||
def main(result_file_path): | ||
system_name = Path(result_file_path).name | ||
system = RuntimeRossystem(system=ROSModel.Rossystem(name=system_name)) | ||
system.get_nodes() | ||
save_to_file( | ||
result_path, | ||
system_name, | ||
system, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
result_path = "./test.rossystem" | ||
main(result_path) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from pathlib import Path | ||
|
||
from ros2cli.node.strategy import add_arguments | ||
|
||
from ros2model.verb import VerbExtension | ||
from ros2model.api.model_generator.system_generator import SystemGenerator | ||
import ros2model.api.runtime_parser.rossystem_runtime_parser as RuntimeParser | ||
import ros2model.core.metamodels.metamodel_ros as ROSModel | ||
|
||
|
||
class RuntimeVerb(VerbExtension): | ||
"""Create .rossystem for a runtime system""" | ||
|
||
def add_arguments(self, parser, cli_name): | ||
add_arguments(parser) | ||
|
||
parser.add_argument( | ||
"-o", | ||
"--output_file", | ||
default=".", | ||
required=False, | ||
help="The system model file path.", | ||
) | ||
|
||
parser.add_argument( | ||
"--include_hidden_nodes", | ||
action="store_true", | ||
required=False, | ||
help="Consider hidden nodes.", | ||
) | ||
|
||
parser.add_argument( | ||
"--include_hidden_interfaces", | ||
action="store_true", | ||
required=False, | ||
help="Consider hidden topics, services or actions.", | ||
) | ||
|
||
def main(self, *, args): | ||
output_file = Path(args.output_file) | ||
system_name = output_file.name | ||
if output_file.is_absolute() != True: | ||
output_file = output_file.resolve() | ||
|
||
generator = SystemGenerator() | ||
|
||
system = RuntimeParser.RuntimeRossystem( | ||
system=ROSModel.Rossystem(name=system_name) | ||
) | ||
system.get_nodes() | ||
|
||
generator.generate_a_file( | ||
model=system, | ||
output_dir=output_file.parent, | ||
filename=system_name, | ||
) |
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
Oops, something went wrong.