Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
is_battery_low_condition.hpp
1 // Copyright (c) 2020 Sarthak Mittal
2 // Copyright (c) 2019 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__IS_BATTERY_LOW_CONDITION_HPP_
17 #define NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__IS_BATTERY_LOW_CONDITION_HPP_
18 
19 #include <string>
20 #include <memory>
21 #include <mutex>
22 
23 #include "rclcpp/rclcpp.hpp"
24 #include "sensor_msgs/msg/battery_state.hpp"
25 #include "behaviortree_cpp_v3/condition_node.h"
26 
27 namespace nav2_behavior_tree
28 {
29 
34 class IsBatteryLowCondition : public BT::ConditionNode
35 {
36 public:
43  const std::string & condition_name,
44  const BT::NodeConfiguration & conf);
45 
46  IsBatteryLowCondition() = delete;
47 
52  BT::NodeStatus tick() override;
53 
58  static BT::PortsList providedPorts()
59  {
60  return {
61  BT::InputPort<double>("min_battery", "Minimum battery percentage/voltage"),
62  BT::InputPort<std::string>(
63  "battery_topic", std::string("/battery_status"), "Battery topic"),
64  BT::InputPort<bool>(
65  "is_voltage", false, "If true voltage will be used to check for low battery"),
66  };
67  }
68 
69 private:
74  void batteryCallback(sensor_msgs::msg::BatteryState::SharedPtr msg);
75 
76  rclcpp::Node::SharedPtr node_;
77  rclcpp::CallbackGroup::SharedPtr callback_group_;
78  rclcpp::executors::SingleThreadedExecutor callback_group_executor_;
79  rclcpp::Subscription<sensor_msgs::msg::BatteryState>::SharedPtr battery_sub_;
80  std::string battery_topic_;
81  double min_battery_;
82  bool is_voltage_;
83  bool is_battery_low_;
84 };
85 
86 } // namespace nav2_behavior_tree
87 
88 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__CONDITION__IS_BATTERY_LOW_CONDITION_HPP_
A BT::ConditionNode that listens to a battery topic and returns SUCCESS when battery is low and FAILU...
static BT::PortsList providedPorts()
Creates list of BT ports.
BT::NodeStatus tick() override
The main override required by a BT action.