|  | 
|  | 1 | +// Copyright (c) 2024 Open Navigation LLC | 
|  | 2 | +// Copyright (c) 2024 Alberto J. Tudela Roldán | 
|  | 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__ACTION__FOLLOW_OBJECT_ACTION_HPP_ | 
|  | 17 | +#define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__FOLLOW_OBJECT_ACTION_HPP_ | 
|  | 18 | + | 
|  | 19 | +#include <string> | 
|  | 20 | +#include <memory> | 
|  | 21 | +#include <vector> | 
|  | 22 | + | 
|  | 23 | +#include "nav2_behavior_tree/bt_action_node.hpp" | 
|  | 24 | +#include "nav2_msgs/action/follow_object.hpp" | 
|  | 25 | + | 
|  | 26 | + | 
|  | 27 | +namespace nav2_behavior_tree | 
|  | 28 | +{ | 
|  | 29 | + | 
|  | 30 | +/** | 
|  | 31 | + * @brief nav2_behavior_tree::BtActionNode class that wraps nav2_msgs/FollowObject | 
|  | 32 | + */ | 
|  | 33 | +class FollowObjectAction | 
|  | 34 | +  : public nav2_behavior_tree::BtActionNode<nav2_msgs::action::FollowObject> | 
|  | 35 | +{ | 
|  | 36 | +  using Action = nav2_msgs::action::FollowObject; | 
|  | 37 | +  using ActionResult = Action::Result; | 
|  | 38 | + | 
|  | 39 | +public: | 
|  | 40 | +  /** | 
|  | 41 | +   * @brief A constructor for nav2_behavior_tree::FollowObjectAction | 
|  | 42 | +   * @param xml_tag_name Name for the XML tag for this node | 
|  | 43 | +   * @param action_name Action name this node creates a client for | 
|  | 44 | +   * @param conf BT node configuration | 
|  | 45 | +   */ | 
|  | 46 | +  FollowObjectAction( | 
|  | 47 | +    const std::string & xml_tag_name, | 
|  | 48 | +    const std::string & action_name, | 
|  | 49 | +    const BT::NodeConfiguration & conf); | 
|  | 50 | + | 
|  | 51 | +  /** | 
|  | 52 | +   * @brief Function to perform some user-defined operation on tick | 
|  | 53 | +   */ | 
|  | 54 | +  void on_tick() override; | 
|  | 55 | + | 
|  | 56 | +  /** | 
|  | 57 | +   * @brief Function to perform some user-defined operation upon successful completion of the action | 
|  | 58 | +   */ | 
|  | 59 | +  BT::NodeStatus on_success() override; | 
|  | 60 | + | 
|  | 61 | +  /** | 
|  | 62 | +   * @brief Function to perform some user-defined operation upon abortion of the action | 
|  | 63 | +   */ | 
|  | 64 | +  BT::NodeStatus on_aborted() override; | 
|  | 65 | + | 
|  | 66 | +  /** | 
|  | 67 | +   * @brief Function to perform some user-defined operation upon cancellation of the action | 
|  | 68 | +   */ | 
|  | 69 | +  BT::NodeStatus on_cancelled() override; | 
|  | 70 | + | 
|  | 71 | +  /** | 
|  | 72 | +   * @brief Creates list of BT ports | 
|  | 73 | +   * @return BT::PortsList Containing basic ports along with node-specific ports | 
|  | 74 | +   */ | 
|  | 75 | +  static BT::PortsList providedPorts() | 
|  | 76 | +  { | 
|  | 77 | +    return providedBasicPorts( | 
|  | 78 | +      { | 
|  | 79 | +        BT::InputPort<std::string>( | 
|  | 80 | +          "pose_topic", "dynamic_pose", "Topic to publish the pose of the object to follow"), | 
|  | 81 | +        BT::InputPort<std::string>( | 
|  | 82 | +          "tracked_frame", "Target frame to follow (Optional, used if pose_topic is not set)"), | 
|  | 83 | +        BT::InputPort<float>( | 
|  | 84 | +          "max_duration", 0.0, "The maximum duration to follow the object (Optional)"), | 
|  | 85 | + | 
|  | 86 | +        BT::OutputPort<ActionResult::_total_elapsed_time_type>( | 
|  | 87 | +          "total_elapsed_time", "Total elapsed time"), | 
|  | 88 | +        BT::OutputPort<ActionResult::_error_code_type>( | 
|  | 89 | +          "error_code_id", "Error code"), | 
|  | 90 | +        BT::OutputPort<std::string>( | 
|  | 91 | +          "error_msg", "Error message"), | 
|  | 92 | +      }); | 
|  | 93 | +  } | 
|  | 94 | +}; | 
|  | 95 | + | 
|  | 96 | +}  // namespace nav2_behavior_tree | 
|  | 97 | + | 
|  | 98 | +#endif  // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__FOLLOW_OBJECT_ACTION_HPP_ | 
0 commit comments