-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support setting parameters atomically #727
base: rolling
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,10 @@ def load_parameter_file(*, node, node_name, parameter_file, use_wildcard): | |
parameters = list(parameter_dict_from_yaml_file(parameter_file, use_wildcard).values()) | ||
rclpy.spin_until_future_complete(node, future) | ||
response = future.result() | ||
if response is None: | ||
raise RuntimeError('Exception while calling service of node ' | ||
f'{node_name}: {future.exception()}') | ||
|
||
assert len(response.results) == len(parameters), 'Not all parameters set' | ||
for i in range(0, len(response.results)): | ||
result = response.results[i] | ||
|
@@ -66,6 +70,26 @@ def load_parameter_file(*, node, node_name, parameter_file, use_wildcard): | |
print(msg, file=sys.stderr) | ||
|
||
|
||
def load_parameter_file_atomically(*, node, node_name, parameter_file, use_wildcard): | ||
client = AsyncParameterClient(node, node_name) | ||
ready = client.wait_for_services(timeout_sec=5.0) | ||
if not ready: | ||
raise RuntimeError('Wait for service timed out') | ||
future = client.load_parameter_file_atomically(parameter_file, use_wildcard) | ||
parameters = list(parameter_dict_from_yaml_file(parameter_file, use_wildcard).values()) | ||
rclpy.spin_until_future_complete(node, future) | ||
response = future.result() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
if response is None: | ||
raise RuntimeError('Exception while calling service of node ' | ||
f'{node_name}: {future.exception()}') | ||
|
||
if response.result.successful: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
msg = 'Set parameters {} successful'.format(' '.join([i.name for i in parameters])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this whole operation is atomic, and user knows parameters as input, so i am not sure if we need print all parameters again here. probably this command prints the result only? |
||
if response.result.reason: | ||
msg += ': ' + response.result.reason | ||
print(msg) | ||
|
||
|
||
def call_describe_parameters(*, node, node_name, parameter_names=None): | ||
client = AsyncParameterClient(node, node_name) | ||
ready = client.wait_for_services(timeout_sec=5.0) | ||
|
@@ -96,6 +120,18 @@ def call_get_parameters(*, node, node_name, parameter_names): | |
return response | ||
|
||
|
||
def call_set_parameters_atomically(*, node, node_name, parameters): | ||
client = AsyncParameterClient(node, node_name) | ||
client.wait_for_services(timeout_sec=5.0) | ||
future = client.set_parameters_atomically(parameters) | ||
rclpy.spin_until_future_complete(node, future) | ||
response = future.result() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
if response is None: | ||
raise RuntimeError('Exception while calling service of node ' | ||
f'{node_name}: {future.exception()}') | ||
return response | ||
|
||
|
||
def call_set_parameters(*, node, node_name, parameters): | ||
client = AsyncParameterClient(node, node_name) | ||
ready = client.wait_for_services(timeout_sec=5.0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this call will raise exception if there is an actual exception.