Skip to content

Commit

Permalink
add info about shutdown
Browse files Browse the repository at this point in the history
Signed-off-by: M. Fatih Cırıt <[email protected]>
  • Loading branch information
xmfcx committed Dec 7, 2024
1 parent 103d185 commit 797edc0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions common/autoware_node/include/autoware/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@

namespace autoware::node
{
using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;

class Node : public rclcpp_lifecycle::LifecycleNode
{
public:
AUTOWARE_NODE_PUBLIC
explicit Node(
const std::string & node_name, const std::string & ns = "",
const rclcpp::NodeOptions & options = rclcpp::NodeOptions());

protected:
CallbackReturn on_shutdown(const rclcpp_lifecycle::State & state) override;
};
} // namespace autoware::node

Expand Down
11 changes: 10 additions & 1 deletion common/autoware_node/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ Node::Node(
: LifecycleNode(node_name, ns, options)
{
RCLCPP_DEBUG(
get_logger(), "Node %s constructor was called.", get_node_base_interface()->get_fully_qualified_name());
get_logger(), "Node %s constructor was called.",
get_node_base_interface()->get_fully_qualified_name());
}

CallbackReturn Node::on_shutdown(const rclcpp_lifecycle::State & state)
{
RCLCPP_DEBUG(
get_logger(), "Node %s shutdown was called with state %s.",
get_node_base_interface()->get_fully_qualified_name(), state.label().c_str());
return CallbackReturn::SUCCESS;
}
} // namespace autoware::node
11 changes: 10 additions & 1 deletion common/autoware_test_node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ros2 launch autoware_test_node autoware_test_node.launch.xml

### Lifecycle control

Information on Lifecycle nodes can be found [here](https://design.ros2.org/articles/node_lifecycle.html).

Output a list of nodes with lifecycle:

```console
Expand Down Expand Up @@ -41,4 +43,11 @@ Shutdown the node:
```console
$ ros2 lifecycle set /test_ns1/test_node1 shutdown
Transitioning successful
```
```

```console
$ ros2 lifecycle get /test_ns1/test_node1
finalized [4]
```

The node will remain alive in the `finalized` state until it is killed by the user.

0 comments on commit 797edc0

Please sign in to comment.