diff --git a/rclpy/rclpy/lifecycle/node.py b/rclpy/rclpy/lifecycle/node.py index 596687621..3458a176c 100644 --- a/rclpy/rclpy/lifecycle/node.py +++ b/rclpy/rclpy/lifecycle/node.py @@ -126,9 +126,11 @@ def __init__( # this doesn't only checks, but also imports some stuff we need later check_is_valid_srv_type(srv_type) + clock = self.get_clock() + with self.handle: self._state_machine: _rclpy.LifecycleStateMachine = _rclpy.LifecycleStateMachine( - self.handle, enable_communication_interface) + self.handle, clock.handle, enable_communication_interface) if enable_communication_interface: self._service_change_state = Service( self._state_machine.service_change_state, diff --git a/rclpy/src/rclpy/lifecycle.cpp b/rclpy/src/rclpy/lifecycle.cpp index e9f0a79a9..2f1ad98f5 100644 --- a/rclpy/src/rclpy/lifecycle.cpp +++ b/rclpy/src/rclpy/lifecycle.cpp @@ -34,6 +34,7 @@ #include #include +#include "clock.hpp" #include "destroyable.hpp" #include "exceptions.hpp" #include "lifecycle.hpp" @@ -49,8 +50,8 @@ class LifecycleStateMachine : public rclpy::Destroyable, { public: LifecycleStateMachine( - rclpy::Node & node, bool enable_com_interface) - : node_(node) + rclpy::Node & node, rclpy::Clock & clock, bool enable_com_interface) + : node_(node), clock_(clock) { state_machine_ = std::shared_ptr( new rcl_lifecycle_state_machine_t(rcl_lifecycle_get_zero_initialized_state_machine()), @@ -70,6 +71,7 @@ class LifecycleStateMachine : public rclpy::Destroyable, rcl_ret_t ret = rcl_lifecycle_state_machine_init( state_machine_.get(), node_.rcl_ptr(), + clock_.rcl_ptr(), ROSIDL_GET_MSG_TYPE_SUPPORT(lifecycle_msgs, msg, TransitionEvent), ROSIDL_GET_SRV_TYPE_SUPPORT(lifecycle_msgs, srv, ChangeState), ROSIDL_GET_SRV_TYPE_SUPPORT(lifecycle_msgs, srv, GetState), @@ -268,6 +270,7 @@ class LifecycleStateMachine : public rclpy::Destroyable, private: rclpy::Node node_; + rclpy::Clock clock_; std::shared_ptr srv_change_state_; std::shared_ptr srv_get_state_; std::shared_ptr srv_get_available_states_; @@ -307,7 +310,7 @@ define_lifecycle_api(py::module m) { py::class_>( m, "LifecycleStateMachine") - .def(py::init()) + .def(py::init()) .def_property_readonly( "initialized", &LifecycleStateMachine::is_initialized, "Check if state machine is initialized.")