Ejemplo n.º 1
0
def test_set_param_with_node():
    lc = MockContext()
    node = Node(package='asd',
                executable='bsd',
                name='my_node',
                namespace='my_ns',
                parameters=[{
                    'asd': 'bsd'
                }])
    set_param = SetParameter(name='my_param', value='my_value')
    set_param.execute(lc)
    node._perform_substitutions(lc)
    actual_command = [
        perform_substitutions(lc, item) for item in node.cmd
        if type(item[0]) == TextSubstitution
    ]
    assert actual_command.count('--params-file') == 1
    assert actual_command.count('-p') == 1

    param_cmdline_index = actual_command.index('-p') + 1
    param_cmdline = actual_command[param_cmdline_index]
    assert param_cmdline == 'my_param:=my_value'

    param_file_index = actual_command.index('--params-file') + 1
    param_file_path = actual_command[param_file_index]
    assert os.path.isfile(param_file_path)
    with open(param_file_path, 'r') as h:
        expanded_parameters_dict = yaml.load(h, Loader=yaml.FullLoader)
        assert expanded_parameters_dict == {
            '/my_ns/my_node': {
                'ros__parameters': {
                    'asd': 'bsd'
                }
            }
        }
Ejemplo n.º 2
0
def test_set_param_with_node():
    lc = MockContext()
    node = Node(
        package='asd',
        executable='bsd',
        name='my_node',
        namespace='my_ns',
        parameters=[{'asd': 'bsd'}]
    )
    set_param = SetParameter(name='my_param', value='my_value')
    set_param.execute(lc)
    node._perform_substitutions(lc)
    expanded_parameter_files = node._Node__expanded_parameter_files
    assert len(expanded_parameter_files) == 2
    with open(expanded_parameter_files[0], 'r') as h:
        expanded_parameters_dict = yaml.load(h, Loader=yaml.FullLoader)
        assert expanded_parameters_dict == {
            '/my_ns/my_node': {
                'ros__parameters': {'my_param': 'my_value'}
            }
        }
    with open(expanded_parameter_files[1], 'r') as h:
        expanded_parameters_dict = yaml.load(h, Loader=yaml.FullLoader)
        assert expanded_parameters_dict == {
            '/my_ns/my_node': {
                'ros__parameters': {'asd': 'bsd'}
            }
        }
Ejemplo n.º 3
0
def test_set_param_is_scoped():
    lc = LaunchContext()
    push_conf = PushLaunchConfigurations()
    pop_conf = PopLaunchConfigurations()
    set_param = SetParameter(name='my_param', value='my_value')

    push_conf.execute(lc)
    set_param.execute(lc)
    assert lc.launch_configurations == {'ros_params': {'my_param': 'my_value'}}
    pop_conf.execute(lc)
    assert lc.launch_configurations == {}
Ejemplo n.º 4
0
def test_set_param_is_scoped():
    lc = LaunchContext()
    push_conf = PushLaunchConfigurations()
    pop_conf = PopLaunchConfigurations()
    set_param = SetParameter(name='my_param', value='my_value')

    push_conf.execute(lc)
    set_param.execute(lc)
    assert lc.launch_configurations['global_params'] == [('my_param',
                                                          'my_value')]
    pop_conf.execute(lc)
    assert lc.launch_configurations == {}
Ejemplo n.º 5
0
def test_set_param(params_to_set, expected_result):
    set_parameter_actions = []
    for name, value in params_to_set:
        set_parameter_actions.append(SetParameter(name=name, value=value))
    lc = MockContext()
    for set_param in set_parameter_actions:
        set_param.execute(lc)
    assert lc.launch_configurations['global_params'] == expected_result
Ejemplo n.º 6
0
def test_set_param(params_to_set, expected_result):
    set_parameter_actions = []
    for dicts in params_to_set:
        for name, value in dicts.items():
            set_parameter_actions.append(SetParameter(name=name, value=value))
    lc = MockContext()
    for set_param in set_parameter_actions:
        set_param.execute(lc)
    assert lc.launch_configurations == {'ros_params': expected_result}
def launch_setup(context, *args, **kwargs):
    # use_sim_time
    set_use_sim_time = SetParameter(name="use_sim_time", value=LaunchConfiguration("use_sim_time"))

    # vehicle_info
    vehicle_description_pkg = FindPackageShare(
        [LaunchConfiguration("vehicle_model"), "_description"]
    ).perform(context)

    load_vehicle_info = IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            [FindPackageShare("vehicle_info_util"), "/launch/vehicle_info.launch.py"]
        ),
        launch_arguments={
            "vehicle_info_param_file": [vehicle_description_pkg, "/config/vehicle_info.param.yaml"]
        }.items(),
    )

    return [
        set_use_sim_time,
        load_vehicle_info,
    ]
Ejemplo n.º 8
0
def test_set_param_with_composable_node():
    lc = MockContext()
    node_description = ComposableNode(
        package='asd',
        plugin='my_plugin',
        name='my_node',
        namespace='my_ns',
        parameters=[{'asd': 'bsd'}]
    )
    set_param_1 = SetParameter(name='my_param', value='my_value')
    set_param_2 = SetParameter(name='asd', value='csd')
    set_param_1.execute(lc)
    set_param_2.execute(lc)
    request = get_composable_node_load_request(node_description, lc)
    parameters = request.parameters
    assert len(parameters) == 3
    assert parameters[0].name == 'my_param'
    assert parameters[0].value.string_value == 'my_value'
    assert parameters[1].name == 'asd'
    assert parameters[1].value.string_value == 'csd'
    assert parameters[2].name == 'asd'
    assert parameters[2].value.string_value == 'bsd'

    lc = MockContext()
    node_description = ComposableNode(
        package='asd',
        plugin='my_plugin',
        name='my_node',
        namespace='my_ns',
    )
    set_param = SetParameter(name='my_param', value='my_value')
    set_param.execute(lc)
    request = get_composable_node_load_request(node_description, lc)
    parameters = request.parameters
    assert len(parameters) == 1
    assert parameters[0].name == 'my_param'
    assert parameters[0].value.string_value == 'my_value'
def launch_setup(context, *args, **kwargs):
    vehicle_param_file = LaunchConfiguration(
        "vehicle_info_param_file").perform(context)
    with open(vehicle_param_file, "r") as f:
        vehicle_param = yaml.safe_load(f)["/**"]["ros__parameters"]
    return [SetParameter(name=k, value=v) for (k, v) in vehicle_param.items()]