I tried to use the service /turtlesim/set_parameters
[rcl_interfaces/srv/SetParameters
] to set the background of the turtlesim GUI. But I cannot get right the form of the request.
import rclpy
from rclpy.node import Node
from rcl_interfaces.srv import SetParameters
class SetParametersClient(Node):
def __init__(self):
super().__init__('set_parameters_client')
self.client = self.create_client(SetParameters, '/turtlesim/set_parameters')
while not self.client.wait_for_service(timeout_sec=1.0):
self.get_logger().info('Service not available, waiting again...')
def set_parameters(self, parameters):
request = SetParameters.Request()
request.parameters = parameters
future = self.client.call_async(request)
rclpy.spin_until_future_complete(self, future)
if future.result() is not None:
self.get_logger().info('Parameters set successfully')
else:
self.get_logger().error('Failed to set parameters')
def main(args=None):
rclpy.init(args=args)
set_params_client = SetParametersClient()
# Define the parameters to be set
parameters = [
{
"name": "background_r",
"value": 255.0 # Set red component to maximum value
},
{
"name": "background_g",
"value": 0.0 # Set green component to zero
},
{
"name": "background_b",
"value": 0.0 # Set blue component to zero
}
]
# Call the set_parameters service
set_params_client.set_parameters(parameters)
rclpy.shutdown()
if __name__ == '__main__':
main()
when I run the script, I got the following error message:
AssertionError: The 'parameters' field must be a set or sequence and each value of type 'Parameter'
How should I define the parameters to be set?