|
@@ -5,74 +5,73 @@ import launch_ros.actions
|
|
|
from launch.substitutions import EnvironmentVariable
|
|
|
from launch_ros.actions import ComposableNodeContainer
|
|
|
from launch_ros.descriptions import ComposableNode
|
|
|
+import yaml
|
|
|
+import tempfile
|
|
|
+
|
|
|
+def rewrite_yaml_config(yaml_filename,ns):
|
|
|
+ rewritten_yaml = tempfile.NamedTemporaryFile(mode='w', delete=False)
|
|
|
+ data = yaml.safe_load(open(yaml_filename, 'r'))
|
|
|
+ data = {ns: data}
|
|
|
+ yaml.dump(data, rewritten_yaml)
|
|
|
+ rewritten_yaml.close()
|
|
|
+ return rewritten_yaml.name
|
|
|
+
|
|
|
+def get_camera_list_from_yaml(yaml_file)->str:
|
|
|
+ try:
|
|
|
+ with open(yaml_file, 'r') as file:
|
|
|
+ data = yaml.safe_load(file)
|
|
|
+ camera_list = list(data.keys())
|
|
|
+ return camera_list
|
|
|
+ except FileNotFoundError:
|
|
|
+ print(f"Error: File '{yaml_file}' not found.")
|
|
|
+ return None
|
|
|
+ except yaml.YAMLError as e:
|
|
|
+ print(f"Error parsing YAML file '{yaml_file}': {e}")
|
|
|
+ return None
|
|
|
|
|
|
def generate_launch_description():
|
|
|
- config = os.path.join(
|
|
|
+ origin_config = os.path.join(
|
|
|
get_package_share_directory('saturn_controller'),
|
|
|
'config',
|
|
|
'saturn_controller.yaml'
|
|
|
)
|
|
|
- print(f"config:{config}" )
|
|
|
|
|
|
- # 创建组件容器
|
|
|
- container = ComposableNodeContainer(
|
|
|
- name='rclcpp_components',
|
|
|
- namespace='nav',
|
|
|
- package='rclcpp_components',
|
|
|
- executable='component_container',
|
|
|
- composable_node_descriptions=[
|
|
|
- # 添加你的组件
|
|
|
- ComposableNode(
|
|
|
- package='saturn_controller',
|
|
|
- plugin='saturn_ros2::SaturnController',
|
|
|
- name='saturn_controller',
|
|
|
- namespace='nav',
|
|
|
- parameters=[config]
|
|
|
- # remappings=[
|
|
|
- # ('input_topic', 'new_input_topic'),
|
|
|
- # ('output_topic', 'new_output_topic')
|
|
|
- # ]
|
|
|
- )
|
|
|
- ],
|
|
|
- output='screen'
|
|
|
- )
|
|
|
+ origin_list = get_camera_list_from_yaml(origin_config)
|
|
|
+
|
|
|
+ # robot_name = os.getenv('ROBOT_NAME', '')
|
|
|
+ model_name = 'nav'
|
|
|
|
|
|
- return launch.LaunchDescription([container])
|
|
|
+ ld = launch.LaunchDescription()
|
|
|
+ for name in origin_list:
|
|
|
+ config = rewrite_yaml_config(origin_config, model_name)
|
|
|
+ # if robot_name != '':
|
|
|
+ # config = rewrite_yaml_config(config,robot_name)
|
|
|
+
|
|
|
+ # namespace = robot_name + '/' + model_name
|
|
|
+ namespace = model_name
|
|
|
+ print(f"namespace:{namespace}" )
|
|
|
+ # 创建组件容器
|
|
|
+ container = ComposableNodeContainer(
|
|
|
+ name='rclcpp_components',
|
|
|
+ namespace=namespace,
|
|
|
+ package='rclcpp_components',
|
|
|
+ executable='component_container',
|
|
|
+ composable_node_descriptions=[
|
|
|
+ # 添加你的组件
|
|
|
+ ComposableNode(
|
|
|
+ package='saturn_controller',
|
|
|
+ plugin='saturn_ros2::SaturnController',
|
|
|
+ name='saturn_controller',
|
|
|
+ namespace=namespace,
|
|
|
+ parameters=[config]
|
|
|
+ # remappings=[
|
|
|
+ # ('input_topic', 'new_input_topic'),
|
|
|
+ # ('output_topic', 'new_output_topic')
|
|
|
+ # ]
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ output='screen'
|
|
|
+ )
|
|
|
+ ld.add_action(container)
|
|
|
|
|
|
-# def generate_launch_description():
|
|
|
-#
|
|
|
-# robot_name = EnvironmentVariable('ROBOT_NAME', default_value='')
|
|
|
-#
|
|
|
-# # print("Robot name: " + robot_name)
|
|
|
-#
|
|
|
-# config = os.path.join(
|
|
|
-# get_package_share_directory('saturn_controller'),
|
|
|
-# 'config',
|
|
|
-# 'saturn_controller.yaml'
|
|
|
-# )
|
|
|
-# print(R"config:{config}" )
|
|
|
-#
|
|
|
-# component_manager_node = launch_ros.actions.Node(
|
|
|
-# package='rclcpp_components',
|
|
|
-# executable='component_container',
|
|
|
-# name='component_container',
|
|
|
-# namespace = robot_name,
|
|
|
-# output='screen'
|
|
|
-# )
|
|
|
-#
|
|
|
-# composable_node = launch_ros.actions.LoadComposableNodes(
|
|
|
-# target_container='/component_container',
|
|
|
-# composable_node_descriptions=[
|
|
|
-# launch_ros.descriptions.ComposableNode(
|
|
|
-# package='saturn_controller',
|
|
|
-# plugin='saturn_ros2::SaturnController',
|
|
|
-# parameters=[config],
|
|
|
-# name='saturn_controller'
|
|
|
-# ),
|
|
|
-# ]
|
|
|
-# )
|
|
|
-#
|
|
|
-# return launch.LaunchDescription([
|
|
|
-# component_manager_node,
|
|
|
-# composable_node
|
|
|
-# ])
|
|
|
+ return ld
|