def send_request_to_change_parameters(
        self,  # Arguments are alphabetically sorted
        expect,
        frame_rate: float,
        output_directory: Path,
        real_time_factor: float,
        scenario: Path,
    ):
        """Send request to change scenario interpreter's parameters."""
        request = rcl_interfaces.srv.SetParameters.Request()

        request.parameters = [
            Parameter(
                name="intended_result",
                value=ParameterValue(type=ParameterType.PARAMETER_STRING,
                                     string_value=str(expect.name)),
            ),
            Parameter(
                name="osc_path",
                value=ParameterValue(type=ParameterType.PARAMETER_STRING,
                                     string_value=str(scenario)),
            ),
            Parameter(
                name="output_directory",
                value=ParameterValue(
                    type=ParameterType.PARAMETER_STRING,
                    string_value=str(output_directory),
                ),
            ),
            Parameter(
                name="local_real_time_factor",
                value=ParameterValue(type=ParameterType.PARAMETER_DOUBLE,
                                     double_value=real_time_factor),
            ),
            Parameter(
                name="local_frame_rate",
                value=ParameterValue(type=ParameterType.PARAMETER_DOUBLE,
                                     double_value=frame_rate),
            ),
        ]

        future = self.client_set_parameters.call_async(request)
        rclpy.spin_until_future_complete(self,
                                         future,
                                         timeout_sec=self.timeout_sec)
        return future
Ejemplo n.º 2
0
def _set_param(node_name, name, value, parameter_type=None):
    """
    Internal helper function for set_param.
    Attempts to set the given parameter in the target node with the desired value,
    deducing the parameter type if it's not specified.
    parameter_type allows forcing a type for the given value; this is useful to delete parameters.
    """
    parameter = Parameter()
    parameter.name = name
    if parameter_type is None:
        parameter.value = get_parameter_value(string_value=value)
    else:
        parameter.value = ParameterValue()
        parameter.value.type = parameter_type
        if parameter_type != ParameterType.PARAMETER_NOT_SET:
            setattr(parameter.value, _parameter_type_mapping[parameter_type])

    try:
        # call_get_parameters will fail if node does not exist.
        call_set_parameters(node=_node,
                            node_name=node_name,
                            parameters=[parameter])
    except:
        pass