Skip to content

Commit bed714f

Browse files
authored
Avoid exception in Node constructor when use override for 'use_sim_time' (#896)
Signed-off-by: Artem Shumov <[email protected]>
1 parent 1b8cacf commit bed714f

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

rclpy/rclpy/node.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,7 @@ def __init__(
207207
self._parameter_overrides.update({p.name: p for p in parameter_overrides})
208208

209209
# Clock that has support for ROS time.
210-
# Note: parameter overrides and parameter event publisher need to be ready at this point
211-
# to be able to declare 'use_sim_time' if it was not declared yet.
212210
self._clock = ROSClock()
213-
self._time_source = TimeSource(node=self)
214-
self._time_source.attach_clock(self._clock)
215211

216212
if automatically_declare_parameters_from_overrides:
217213
self.declare_parameters(
@@ -222,6 +218,12 @@ def __init__(
222218
ignore_override=True,
223219
)
224220

221+
# Init a time source.
222+
# Note: parameter overrides and parameter event publisher need to be ready at this point
223+
# to be able to declare 'use_sim_time' if it was not declared yet.
224+
self._time_source = TimeSource(node=self)
225+
self._time_source.attach_clock(self._clock)
226+
225227
if start_parameter_services:
226228
self._parameter_service = ParameterService(self)
227229

rclpy/test/test_create_node.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from rclpy.exceptions import InvalidNamespaceException
2020
from rclpy.exceptions import InvalidNodeNameException
21+
from rclpy.parameter import Parameter
2122

2223

2324
class TestCreateNode(unittest.TestCase):
@@ -71,6 +72,16 @@ def test_create_node_invalid_namespace(self):
7172
with self.assertRaisesRegex(InvalidNamespaceException, 'must not contain characters'):
7273
rclpy.create_node(node_name, namespace=namespace, context=self.context)
7374

75+
def test_create_node_with_parameter_overrides(self):
76+
node_name = 'create_node_with_parameter_overrides_test'
77+
rclpy.create_node(
78+
node_name, context=self.context,
79+
automatically_declare_parameters_from_overrides=True,
80+
parameter_overrides=[
81+
Parameter('use_sim_time', Parameter.Type.BOOL, True)
82+
]
83+
).destroy_node()
84+
7485

7586
if __name__ == '__main__':
7687
unittest.main()

0 commit comments

Comments
 (0)