Skip to content

Commit

Permalink
Deal with ParameterUninitializedException for parameter service (#1033)
Browse files Browse the repository at this point in the history
* Deal with ParameterUninitializedException for parameter service

Signed-off-by: Barry Xu <barry.xu@sony.com>

* Enable all tests in test_parameter_client.py

Signed-off-by: Barry Xu <barry.xu@sony.com>

* Get empty value for ParameterUninitializedException

Signed-off-by: Barry Xu <barry.xu@sony.com>

Signed-off-by: Barry Xu <barry.xu@sony.com>
  • Loading branch information
Barry-Xu-2018 authored Nov 14, 2022
1 parent d2901dd commit e442ad2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions rclpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ if(BUILD_TESTING)
test/test_messages.py
test/test_node.py
test/test_parameter.py
test/test_parameter_client.py
test/test_publisher.py
test/test_qos.py
test/test_qos_event.py
Expand Down
4 changes: 2 additions & 2 deletions rclpy/rclpy/parameter_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from rcl_interfaces.msg import SetParametersResult
from rcl_interfaces.srv import DescribeParameters, GetParameters, GetParameterTypes
from rcl_interfaces.srv import ListParameters, SetParameters, SetParametersAtomically
from rclpy.exceptions import ParameterNotDeclaredException
from rclpy.exceptions import ParameterNotDeclaredException, ParameterUninitializedException
from rclpy.parameter import Parameter, PARAMETER_SEPARATOR_STRING
from rclpy.qos import qos_profile_parameters
from rclpy.validate_topic_name import TOPIC_SEPARATOR_STRING
Expand Down Expand Up @@ -80,7 +80,7 @@ def _get_parameters_callback(self, request, response):
for name in request.names:
try:
param = node.get_parameter(name)
except ParameterNotDeclaredException:
except (ParameterNotDeclaredException, ParameterUninitializedException):
response.values = node.get_parameters([])
return response
response.values.append(param.get_parameter_value())
Expand Down
21 changes: 21 additions & 0 deletions rclpy/test/test_parameter_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,24 @@ def test_load_parameter_file_atomically(self):
finally:
if os.path.exists(f.name):
os.unlink(f.name)

def test_get_uninitialized_parameter(self):
self.target_node.declare_parameter('uninitialized_parameter', Parameter.Type.STRING)

# The type in description should be STRING
future = self.client.describe_parameters(['uninitialized_parameter'])
self.executor.spin_until_future_complete(future)
results = future.result()
assert results is not None
assert len(results.descriptors) == 1
assert results.descriptors[0].type == ParameterType.PARAMETER_STRING
assert results.descriptors[0].name == 'uninitialized_parameter'

# The value should be empty
future = self.client.get_parameters(['uninitialized_parameter'])
self.executor.spin_until_future_complete(future)
results = future.result()
assert results is not None
assert results.values == []

self.target_node.undeclare_parameter('uninitialized_parameter')

0 comments on commit e442ad2

Please sign in to comment.