Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
goal_updated_condition.cpp
1 // Copyright (c) 2020 Aitor Miguel Blanco
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 #include <string>
16 #include <vector>
17 #include "nav2_behavior_tree/plugins/condition/goal_updated_condition.hpp"
18 
19 namespace nav2_behavior_tree
20 {
21 
22 GoalUpdatedCondition::GoalUpdatedCondition(
23  const std::string & condition_name,
24  const BT::NodeConfiguration & conf)
25 : BT::ConditionNode(condition_name, conf)
26 {}
27 
29 {
30  if (!BT::isStatusActive(status())) {
31  BT::getInputOrBlackboard("goals", goals_);
32  BT::getInputOrBlackboard("goal", goal_);
33  return BT::NodeStatus::FAILURE;
34  }
35 
36  std::vector<geometry_msgs::msg::PoseStamped> current_goals;
37  geometry_msgs::msg::PoseStamped current_goal;
38  BT::getInputOrBlackboard("goals", current_goals);
39  BT::getInputOrBlackboard("goal", current_goal);
40 
41  if (goal_ != current_goal || goals_ != current_goals) {
42  goal_ = current_goal;
43  goals_ = current_goals;
44  return BT::NodeStatus::SUCCESS;
45  }
46 
47  return BT::NodeStatus::FAILURE;
48 }
49 
50 } // namespace nav2_behavior_tree
51 
52 #include "behaviortree_cpp/bt_factory.h"
53 BT_REGISTER_NODES(factory)
54 {
55  factory.registerNodeType<nav2_behavior_tree::GoalUpdatedCondition>("GoalUpdated");
56 }
A BT::ConditionNode that returns SUCCESS when goal is updated on the blackboard and FAILURE otherwise...
BT::NodeStatus tick() override
The main override required by a BT action.