Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configure and cleanup transitions to lifecycle manager and client #4371

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ class LifecycleManager : public rclcpp::Node
* @return true or false
*/
bool startup();
/**
* @brief Configures the managed nodes.
* @return true or false
*/
bool configure();
/**
* @brief Cleanups the managed nodes
* @return true or false
*/
bool cleanup();
/**
* @brief Deactivate, clean up and shut down all the managed nodes.
* @return true or false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ class LifecycleManagerClient
* @return true or false
*/
bool reset(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
/**
* @brief Make configure service call
* @return true or false
*/
bool configure(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
/**
* @brief Make cleanup service call
* @return true or false
*/
bool cleanup(const std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1));
/**
* @brief Check if lifecycle node manager server is active
* @return ACTIVE or INACTIVE or TIMEOUT
Expand Down
34 changes: 34 additions & 0 deletions nav2_lifecycle_manager/src/lifecycle_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ LifecycleManager::managerCallback(
case ManageLifecycleNodes::Request::STARTUP:
response->success = startup();
break;
case ManageLifecycleNodes::Request::CONFIGURE:
response->success = configure();
break;
case ManageLifecycleNodes::Request::CLEANUP:
response->success = cleanup();
break;
case ManageLifecycleNodes::Request::RESET:
response->success = reset();
break;
Expand Down Expand Up @@ -319,6 +325,34 @@ LifecycleManager::startup()
return true;
}

bool
LifecycleManager::configure()
{
message("Configuring managed nodes...");
if (!changeStateForAllNodes(Transition::TRANSITION_CONFIGURE)) {
RCLCPP_ERROR(get_logger(), "Failed to configure all requested nodes. Aborting bringup.");
managed_nodes_state_ = NodeState::UNKNOWN;
return false;
}
message("Managed nodes are now configured");
managed_nodes_state_ = NodeState::INACTIVE;
return true;
}

bool
LifecycleManager::cleanup()
{
message("Cleaning up managed nodes...");
if (!changeStateForAllNodes(Transition::TRANSITION_CLEANUP)) {
RCLCPP_ERROR(get_logger(), "Failed to cleanup all requested nodes. Aborting cleanup.");
managed_nodes_state_ = NodeState::UNKNOWN;
return false;
}
message("Managed nodes have been cleaned up");
managed_nodes_state_ = NodeState::UNCONFIGURED;
return true;
}

bool
LifecycleManager::shutdown()
{
Expand Down
12 changes: 12 additions & 0 deletions nav2_lifecycle_manager/src/lifecycle_manager_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ LifecycleManagerClient::reset(const std::chrono::nanoseconds timeout)
return callService(ManageLifecycleNodes::Request::RESET, timeout);
}

bool
LifecycleManagerClient::configure(const std::chrono::nanoseconds timeout)
{
return callService(ManageLifecycleNodes::Request::CONFIGURE, timeout);
}

bool
LifecycleManagerClient::cleanup(const std::chrono::nanoseconds timeout)
{
return callService(ManageLifecycleNodes::Request::CLEANUP, timeout);
}

SystemStatus
LifecycleManagerClient::is_active(const std::chrono::nanoseconds timeout)
{
Expand Down
2 changes: 2 additions & 0 deletions nav2_lifecycle_manager/test/test_lifecycle_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ TEST(LifecycleClientTest, BasicTest)
client.is_active(std::chrono::nanoseconds(1000000000)));
EXPECT_TRUE(client.resume());
EXPECT_TRUE(client.reset());
EXPECT_TRUE(client.configure());
EXPECT_TRUE(client.cleanup());
EXPECT_TRUE(client.shutdown());
}

Expand Down
2 changes: 2 additions & 0 deletions nav2_msgs/srv/ManageLifecycleNodes.srv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ uint8 PAUSE = 1
uint8 RESUME = 2
uint8 RESET = 3
uint8 SHUTDOWN = 4
uint8 CONFIGURE = 5
uint8 CLEANUP = 6

uint8 command
---
Expand Down
Loading