Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion rclpy/rclpy/lifecycle/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions rclpy/src/rclpy/lifecycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <tuple>
#include <vector>

#include "clock.hpp"
#include "destroyable.hpp"
#include "exceptions.hpp"
#include "lifecycle.hpp"
Expand All @@ -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<rcl_lifecycle_state_machine_t>(
new rcl_lifecycle_state_machine_t(rcl_lifecycle_get_zero_initialized_state_machine()),
Expand All @@ -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),
Expand Down Expand Up @@ -268,6 +270,7 @@ class LifecycleStateMachine : public rclpy::Destroyable,

private:
rclpy::Node node_;
rclpy::Clock clock_;
std::shared_ptr<rclpy::Service> srv_change_state_;
std::shared_ptr<rclpy::Service> srv_get_state_;
std::shared_ptr<rclpy::Service> srv_get_available_states_;
Expand Down Expand Up @@ -307,7 +310,7 @@ define_lifecycle_api(py::module m)
{
py::class_<LifecycleStateMachine, Destroyable, std::shared_ptr<LifecycleStateMachine>>(
m, "LifecycleStateMachine")
.def(py::init<Node &, bool>())
.def(py::init<Node &, Clock &, bool>())
.def_property_readonly(
"initialized", &LifecycleStateMachine::is_initialized,
"Check if state machine is initialized.")
Expand Down