Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
lifecycle_service_client.hpp
1 // Copyright (c) 2019 Intel Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NAV2_UTIL__LIFECYCLE_SERVICE_CLIENT_HPP_
16 #define NAV2_UTIL__LIFECYCLE_SERVICE_CLIENT_HPP_
17 
18 #include <chrono>
19 #include <memory>
20 #include <string>
21 
22 #include "lifecycle_msgs/srv/change_state.hpp"
23 #include "lifecycle_msgs/srv/get_state.hpp"
24 #include "nav2_util/service_client.hpp"
25 #include "nav2_util/node_utils.hpp"
26 
27 namespace nav2_util
28 {
29 
32 {
33 public:
34  explicit LifecycleServiceClient(const std::string & lifecycle_node_name);
36  const std::string & lifecycle_node_name,
37  rclcpp::Node::SharedPtr parent_node);
38 
40 
44  const uint8_t transition, // takes a lifecycle_msgs::msg::Transition id
45  const std::chrono::seconds timeout);
46 
48  bool change_state(std::uint8_t transition);
49 
51 
54  uint8_t get_state(const std::chrono::seconds timeout = std::chrono::seconds(2));
55 
56 protected:
57  rclcpp::Node::SharedPtr node_;
60 };
61 
62 } // namespace nav2_util
63 
64 #endif // NAV2_UTIL__LIFECYCLE_SERVICE_CLIENT_HPP_
Helper functions to interact with a lifecycle node.
uint8_t get_state(const std::chrono::seconds timeout=std::chrono::seconds(2))
Get the current state as a lifecycle_msgs::msg::State id value.
bool change_state(const uint8_t transition, const std::chrono::seconds timeout)
Trigger a state change.