Nav2 Navigation Stack - kilted  kilted
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 
28 namespace nav2_util
29 {
30 
33 {
34 public:
35  explicit LifecycleServiceClient(
36  const std::string & lifecycle_node_name);
38  const std::string & lifecycle_node_name,
39  rclcpp::Node::SharedPtr parent_node);
40 
42 
45  bool change_state(
46  const uint8_t transition, // takes a lifecycle_msgs::msg::Transition id
47  const std::chrono::milliseconds transition_timeout = std::chrono::milliseconds(-1),
48  const std::chrono::milliseconds wait_for_service_timeout = std::chrono::milliseconds(5000));
49 
51 
54  uint8_t get_state(const std::chrono::milliseconds timeout = std::chrono::milliseconds(2000));
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.
bool change_state(const uint8_t transition, const std::chrono::milliseconds transition_timeout=std::chrono::milliseconds(-1), const std::chrono::milliseconds wait_for_service_timeout=std::chrono::milliseconds(5000))
Trigger a state change.
uint8_t get_state(const std::chrono::milliseconds timeout=std::chrono::milliseconds(2000))
Get the current state as a lifecycle_msgs::msg::State id value.