ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ros2 param dump multiple nodes into a single .yaml file

asked 2022-04-24 21:47:42 -0500

Khalid Hersafril gravatar image

updated 2022-04-24 21:50:37 -0500

Using the ros2cli, where

ros2 param dump node_name

it will save the configuration of the node into a yaml file, however, with multiple nodes, running this recursively would only result in creating multiple yaml file. What I want to do is, to run this command for multiple nodes but only saving it into a single YAML File.

cli = f"ros2 node list"
proc = Popen(
            cli, 
            shell=True,
            stdout=PIPE,
            universal_newlines=True
        )
proc.wait()

node_list = proc.stdout.read().splitlines()

    for node in node_list:

        command = f"ros2 param dump {node}"

        proc = Popen(
                    command, 
                    shell=True,
                    stdout=PIPE,
                    universal_newlines=True
                )
        proc.wait()

Here, I made a really simple python script to do it for me but this would generate multiple YAML file as shown here.

yaml_test
├── ackermann_mux.yaml
├── cone_ground_truth.yaml
├── eufs_launcher.yaml
├── eufs_sim_rqt.yaml
├── gazebo.yaml
├── gps_controller.yaml
├── imu.yaml
├── joint_state_publisher.yaml
├── race_car.yaml
└── robot_state_publisher.yaml

Instead, I want it to be something like this

yaml_test
├── single_file.yaml

Inside the single_file.yaml would then look something like this:

/ackermann_mux:
  ros__parameters:
    config_file: /home/khalidowlwalid/eufs-master/install/ackermann_mux/share/ackermann_mux/config/ackermann_mux_topics.yaml
    loop_rate: 200
    max_dec: 99.0
    p_gain_breaking: 5.0
    qos_overrides:
      /parameter_events:
        publisher:
          depth: 1000
          durability: volatile
          history: keep_last
          reliability: reliable
    use_sim_time: false

/imu:
  ros__parameters:
    qos_overrides:
      /clock:
        subscription:
          depth: 1
          durability: volatile
          history: keep_last
          reliability: best_effort
      /parameter_events:
        publisher:
          depth: 1000
          durability: volatile
          history: keep_last
          reliability: reliable
    use_sim_time: true

with /ackermann_mux and /imu being two different nodes.

Is there any way I could possibly do this?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2022-04-25 02:34:46 -0500

aprotyas gravatar image

Since you already have the node names and you know that every output yaml file looks like [node-name].yaml, I reckon this something along the lines of this snippet should fit the bill:

file_names = (f'{node}.yaml' for node in node_list)
output_filename  = 'single_file.yaml'
with open(output_filename, 'w') as output_file:
    for file_name in file_names:
        with open(file_name) as input_file:
            output_file.write(input_file.read())

You could even just use this shell command:

cat file1.yaml file2.yaml ... > single_file.yaml

If you're looking for an API in ros2cli/ros2param, I don't think something like that exists. You could always file for a feature request to open discussion about it?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-04-24 21:47:42 -0500

Seen: 440 times

Last updated: Apr 25 '22