Add lifecycle timers - #2261
Add lifecycle timers#2261carmiac wants to merge 6 commits into
Conversation
Signed-off-by: Adam Milner <[email protected]>
Signed-off-by: Adam Milner <[email protected]>
Signed-off-by: Adam Milner <[email protected]>
|
This pull request has been mentioned on ROS Discourse. There might be relevant details there: https://discourse.ros.org/t/lifecycle-node-improvements/32706/1 |
clalancette
left a comment
There was a problem hiding this comment.
This generally looks good to me, but can you please add some unit tests as well?
Signed-off-by: Adam Milner <[email protected]>
Signed-off-by: Adam Milner <[email protected]>
4a6eb23 to
22f26cd
Compare
Signed-off-by: Adam Milner <[email protected]>
3b9db53 to
fe6cbec
Compare
| CallbackT callback, | ||
| rclcpp::CallbackGroup::SharedPtr group = nullptr); | ||
|
|
||
| /// Create a lifecycle timer that uses the node clock to drive the callback. |
There was a problem hiding this comment.
we should also have an API to create a timer with a custom clock
There was a problem hiding this comment.
I'm not sure whether that makes sense. Sure, the underlying https://github.com/ros2/rclcpp/blob/rolling/rclcpp/include/rclcpp/create_timer.hpp has support for that, but the rclcpp::Node already has a Clock that is accessed via get_clock. Giving the ability to create a timer based off another clock means that this particular timer will (possibly) run at a different rate from the rest of the Node. While I can imagine some uses for that, it is kind of strange.
Further, it doesn't look like we expose that kind of functionality from https://github.com/ros2/rclcpp/blob/rolling/rclcpp/include/rclcpp/node.hpp . And I don't really want LifecycleNode to "get ahead" of Node (we already have the opposite problem).
To me, adding that in is an orthogonal discussion, and if we are going to do it we should do it for both Node and LifecycleNode.
| std::chrono::nanoseconds period, | ||
| FunctorT && callback, | ||
| rclcpp::Context::SharedPtr context, | ||
| bool autostart = true) |
There was a problem hiding this comment.
by default, autostart true means time starts immediately. that means timer callback will be called after creation w/o activating the lifecycle node? i was thinking that timer should not be called until node becomes to active status.
| void on_activate() override | ||
| { | ||
| SimpleManagedEntity::on_activate(); | ||
| if (autostart_) { |
There was a problem hiding this comment.
what is user application creates the LifecycleTimer with autostart false after on_activate? timer will not be activated even the node is active status. i think that would not be what user expects.
| EXPECT_TRUE(timer_->is_activated()); | ||
| EXPECT_TRUE(wall_timer_->is_activated()); |
There was a problem hiding this comment.
not only checking with is_activated, but also needs to check timer_called_ and wall_timer_called_.
| EXPECT_EQ(State::PRIMARY_STATE_UNCONFIGURED, node_->get_current_state().id()); | ||
| node_->trigger_transition( | ||
| rclcpp_lifecycle::Transition(Transition::TRANSITION_CONFIGURE), ret); | ||
| ASSERT_EQ(success, ret); |
There was a problem hiding this comment.
i think we need to check if timer_called_ and wall_timer_called_ are false here.
| EXPECT_EQ(timer_called_, false); | ||
| EXPECT_EQ(wall_timer_called_, false); |
There was a problem hiding this comment.
i think there probably are failing since the timer will autostart w/o state checking.
This adds lifecycle timers which start when the node activates and cancel when the node deactivates. There is a demo available at https://github.com/carmiac/demos/blob/lifecycle_timer/lifecycle/src/lifecycle_timer.cpp