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

How to provide parameters for test node in launch testing using yaml file file

asked 2022-06-27 13:48:26 -0500

Flash gravatar image

updated 2022-06-27 14:00:16 -0500

Hi,
I am working with launch testing to test my pkgs and for this I am using launch testing. The problem I am having is that I am unable to provide parameters to my test node usingparams.yaml file.
As mentioned in this link I can set parameter one by one I guess but I want to know if it's possible to set multiple parameters using YAML or any another method.
Any help is appreciated.
Thanks,

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-06-27 14:28:55 -0500

Flash gravatar image

updated 2022-06-28 10:02:53 -0500

I was able to read by using the basic python read file function for reading the YAML file and then converting it to the dictionary and then using it to read the required parameter.
This issue I mentioned is for launch testing only. For regular nodes giving parameters from launch, the file works perfectly.
I am not sure if this is the right way to do it but it seems like the easiest way to do it. If anyone still has a better idea or way please share it.


Updated my solution using @ljaniec recommendation.


Below is an example of how I solved it.

config_path = os.path.join(get_package_share_directory('pkg_name'), 'config/params.yaml')
with open(config_path) as stream:
    data_dict = yaml.load(stream, Loader = yaml.SafeLoader)
    robot_name = data_dict['test_node']['ros__parameters']['robot_name']
    spin_time = int(data_dict['test_node']['ros__parameters']['test_spin_time'])
edit flag offensive delete link more

Comments

1

Suggestion - using with open(config_path) as stream: would be better there (exception handling, cleaner code, with statement also ensures proper acquisition and release of resources).

ljaniec gravatar image ljaniec  ( 2022-06-28 07:06:44 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-06-27 13:48:26 -0500

Seen: 184 times

Last updated: Jun 28 '22