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

Revision history [back]

click to hide/show revision 1
initial version

I was able to read by using basic python read file function for reading yaml file and then converted in to the dictionary and then used it to read the required parameter.
This issue I mentioned is for launch testing only. For regular node giving parameter from launch, 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.

I was able to read by using basic python read file function for reading yaml file and then converted in to the dictionary and then used it to read the required parameter.
This issue I mentioned is for launch testing only. For regular node giving parameter from launch, 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.

stream = open(config_path,'r') data_dict = yaml.load(stream, Loader = yaml.FullLoader) robot_name = data_dict['test_node']['ros__parameters']['robot_name'] spin_time = int(data_dict['test_node']['ros__parameters']['test_spin_time'])

I was able to read by using the basic python read file function for reading yaml the YAML file and then converted in converting it to the dictionary and then used using it to read the required parameter.
This issue I mentioned is for launch testing only. For regular node giving parameter from launch, 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.

Below is an example of how I solved it.

config_path = os.path.join(get_package_share_directory('pkg_name'), 'config/params.yaml')
stream = open(config_path,'r')
 data_dict = yaml.load(stream, Loader = yaml.FullLoader)
 robot_name = data_dict['test_node']['ros__parameters']['robot_name']
 spin_time = int(data_dict['test_node']['ros__parameters']['test_spin_time'])

int(data_dict['test_node']['ros__parameters']['test_spin_time'])

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 node nodes giving parameter 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 @Ijaniec recommendation.


Below is an example of how I solved it.

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

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 @Ijaniec @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'])