19 #include "nav2_util/geometry_utils.hpp"
21 #include "nav2_behavior_tree/plugins/action/check_stop_status_action.hpp"
23 namespace nav2_behavior_tree
27 const std::string & name,
28 const BT::NodeConfiguration & conf)
29 : BT::ActionNodeBase(name, conf),
30 velocity_threshold_(0.01),
31 duration_stopped_(1000ms),
32 stopped_stamp_(rclcpp::Time(0, 0, RCL_ROS_TIME))
34 node_ = config().blackboard->get<nav2::LifecycleNode::SharedPtr>(
"node");
35 odom_smoother_ = config().blackboard->get<std::shared_ptr<nav2_util::OdomSmoother>>(
39 inline BT::NodeStatus CheckStopStatus::tick()
41 getInput(
"velocity_threshold", velocity_threshold_);
42 getInput(
"duration_stopped", duration_stopped_);
44 auto twist = odom_smoother_->getRawTwistStamped();
47 if (twist.header.stamp.sec == 0 && twist.header.stamp.nanosec == 0) {
48 twist.header.stamp = node_->get_clock()->now();
51 if (abs(twist.twist.linear.x) < velocity_threshold_ &&
52 abs(twist.twist.linear.y) < velocity_threshold_ &&
53 abs(twist.twist.angular.z) < velocity_threshold_)
55 if (stopped_stamp_ == rclcpp::Time(0, 0, RCL_ROS_TIME)) {
56 stopped_stamp_ = rclcpp::Time(twist.header.stamp);
59 if (node_->get_clock()->now() - stopped_stamp_ > rclcpp::Duration(duration_stopped_)) {
60 stopped_stamp_ = rclcpp::Time(0, 0, RCL_ROS_TIME);
61 return BT::NodeStatus::SUCCESS;
63 return BT::NodeStatus::RUNNING;
67 stopped_stamp_ = rclcpp::Time(0, 0, RCL_ROS_TIME);
68 return BT::NodeStatus::FAILURE;
74 #include "behaviortree_cpp/bt_factory.h"
75 BT_REGISTER_NODES(factory)
A nav2_behavior_tree::ActionNodeBase class that checks if the robot has been stopped for a specified ...
CheckStopStatus(const std::string &xml_tag_name, const BT::NodeConfiguration &conf)
A constructor for nav2_behavior_tree::CheckStopStatus.