Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
check_stop_status_action.hpp
1 // Copyright (c) 2024 Angsa Robotics
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_BEHAVIOR_TREE__PLUGINS__ACTION__CHECK_STOP_STATUS_ACTION_HPP_
16 #define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__CHECK_STOP_STATUS_ACTION_HPP_
17 
18 #include <memory>
19 #include <string>
20 
21 #include "nav2_ros_common/lifecycle_node.hpp"
22 #include "behaviortree_cpp/action_node.h"
23 #include "behaviortree_cpp/json_export.h"
24 #include "nav_msgs/msg/odometry.hpp"
25 #include "nav2_util/odometry_utils.hpp"
26 #include "nav2_behavior_tree/bt_utils.hpp"
27 #include "nav2_behavior_tree/json_utils.hpp"
28 
29 using namespace std::chrono_literals; // NOLINT
30 
31 namespace nav2_behavior_tree
32 {
33 
42 class CheckStopStatus : public BT::ActionNodeBase
43 {
44 public:
51  const std::string & xml_tag_name,
52  const BT::NodeConfiguration & conf);
53 
58  static BT::PortsList providedPorts()
59  {
60  // Register JSON definitions for the types used in the ports
61  BT::RegisterJsonDefinition<std::chrono::milliseconds>();
62 
63  return {
64  BT::InputPort<double>(
65  "velocity_threshold", 0.01,
66  "Velocity threshold below which robot is considered stopped"),
67  BT::InputPort<std::chrono::milliseconds>(
68  "duration_stopped", 1000,
69  "Duration (ms) the velocity must remain below the threshold"),
70  };
71  }
72 
73 private:
77  void halt() override {}
82  BT::NodeStatus tick() override;
83 
84  double velocity_threshold_;
85  std::chrono::milliseconds duration_stopped_;
86  rclcpp::Time stopped_stamp_;
87  std::shared_ptr<nav2_util::OdomSmoother> odom_smoother_;
88  nav2::LifecycleNode::SharedPtr node_;
89 };
90 
91 } // namespace nav2_behavior_tree
92 
93 #endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__CHECK_STOP_STATUS_ACTION_HPP_
A nav2_behavior_tree::ActionNodeBase class that checks if the robot has been stopped for a specified ...
static BT::PortsList providedPorts()
Creates list of BT ports.