diff --git a/nav2_behavior_tree/plugins/action/back_up_action.cpp b/nav2_behavior_tree/plugins/action/back_up_action.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ae07ac4fcb668582675cad816df06216391ac34 --- /dev/null +++ b/nav2_behavior_tree/plugins/action/back_up_action.cpp @@ -0,0 +1,70 @@ +// Copyright (c) 2018 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NAV2_BEHAVIOR_TREE__BACK_UP_ACTION_HPP_ +#define NAV2_BEHAVIOR_TREE__BACK_UP_ACTION_HPP_ + +#include <string> +#include <memory> +#include <cmath> + +#include "nav2_behavior_tree/bt_action_node.hpp" +#include "nav2_msgs/action/back_up.hpp" + +namespace nav2_behavior_tree +{ + +class BackUpAction : public BtActionNode<nav2_msgs::action::BackUp> +{ +public: + BackUpAction( + const std::string & action_name, + const BT::NodeConfiguration & conf) + : BtActionNode<nav2_msgs::action::BackUp>(action_name, conf) + { + double dist; + getInput("backup_dist", dist); + double speed; + getInput("backup_speed", speed); + + // silently fix, vector direction determined by distance sign + if (speed < 0.0) { + speed *= -1.0; + } + + // Populate the input message + goal_.target.x = dist; + goal_.target.y = 0.0; + goal_.target.z = 0.0; + goal_.speed = speed; + } + + static BT::PortsList providedPorts() + { + return providedBasicPorts({ + BT::InputPort<double>("backup_dist", -0.15, "Distance to backup"), + BT::InputPort<double>("backup_speed", 0.025, "Speed at which to backup") + }); + } +}; + +} // namespace nav2_behavior_tree + +#include "behaviortree_cpp_v3/bt_factory.h" +BT_REGISTER_NODES(factory) +{ + factory.registerNodeType<nav2_behavior_tree::BackUpAction>("BackUp"); +} + +#endif // NAV2_BEHAVIOR_TREE__BACK_UP_ACTION_HPP_ diff --git a/nav2_behavior_tree/plugins/action/clear_costmap_service.cpp b/nav2_behavior_tree/plugins/action/clear_costmap_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..144244788fec42e7074e40d85db4d6a1a98c37c0 --- /dev/null +++ b/nav2_behavior_tree/plugins/action/clear_costmap_service.cpp @@ -0,0 +1,47 @@ +// Copyright (c) 2019 Samsung Research America +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NAV2_BEHAVIOR_TREE__CLEAR_COSTMAP_SERVICE_HPP_ +#define NAV2_BEHAVIOR_TREE__CLEAR_COSTMAP_SERVICE_HPP_ + +#include <string> +#include <memory> +#include <cmath> + +#include "nav2_behavior_tree/bt_service_node.hpp" +#include "nav2_msgs/srv/clear_entire_costmap.hpp" + +namespace nav2_behavior_tree +{ + +class ClearEntireCostmapService : public BtServiceNode<nav2_msgs::srv::ClearEntireCostmap> +{ +public: + ClearEntireCostmapService( + const std::string & service_node_name, + const BT::NodeConfiguration & conf) + : BtServiceNode<nav2_msgs::srv::ClearEntireCostmap>(service_node_name, conf) + { + } +}; + +} // namespace nav2_behavior_tree + +#include "behaviortree_cpp_v3/bt_factory.h" +BT_REGISTER_NODES(factory) +{ + factory.registerNodeType<nav2_behavior_tree::ClearEntireCostmapService>("ClearEntireCostmap"); +} + +#endif // NAV2_BEHAVIOR_TREE__CLEAR_COSTMAP_SERVICE_HPP_ diff --git a/nav2_behavior_tree/plugins/action/compute_path_to_pose_action.cpp b/nav2_behavior_tree/plugins/action/compute_path_to_pose_action.cpp new file mode 100644 index 0000000000000000000000000000000000000000..adc48af147443dae772294d7da9eadd5e139e353 --- /dev/null +++ b/nav2_behavior_tree/plugins/action/compute_path_to_pose_action.cpp @@ -0,0 +1,76 @@ +// Copyright (c) 2018 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NAV2_BEHAVIOR_TREE__COMPUTE_PATH_TO_POSE_ACTION_HPP_ +#define NAV2_BEHAVIOR_TREE__COMPUTE_PATH_TO_POSE_ACTION_HPP_ + +#include <memory> +#include <string> + +#include "nav2_msgs/action/compute_path_to_pose.hpp" +#include "nav_msgs/msg/path.h" +#include "nav2_behavior_tree/bt_action_node.hpp" + +namespace nav2_behavior_tree +{ + +class ComputePathToPoseAction : public BtActionNode<nav2_msgs::action::ComputePathToPose> +{ +public: + ComputePathToPoseAction( + const std::string & action_name, + const BT::NodeConfiguration & conf) + : BtActionNode<nav2_msgs::action::ComputePathToPose>(action_name, conf) + { + } + + void on_tick() override + { + getInput("goal", goal_.pose); + getInput("planner_property", goal_.planner_property); + } + + void on_success() override + { + setOutput("path", result_.result->path); + + if (first_time_) { + first_time_ = false; + } else { + config().blackboard->set("path_updated", true); + } + } + + static BT::PortsList providedPorts() + { + return providedBasicPorts({ + BT::OutputPort<nav_msgs::msg::Path>("path", "Path created by ComputePathToPose node"), + BT::InputPort<geometry_msgs::msg::PoseStamped>("goal", "Destination to plan to"), + BT::InputPort<std::string>("planner_property", "") + }); + } + +private: + bool first_time_{true}; +}; + +} // namespace nav2_behavior_tree + +#include "behaviortree_cpp_v3/bt_factory.h" +BT_REGISTER_NODES(factory) +{ + factory.registerNodeType<nav2_behavior_tree::ComputePathToPoseAction>("ComputePathToPose"); +} + +#endif // NAV2_BEHAVIOR_TREE__COMPUTE_PATH_TO_POSE_ACTION_HPP_ diff --git a/nav2_behavior_tree/plugins/action/follow_path_action.cpp b/nav2_behavior_tree/plugins/action/follow_path_action.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e138579e1b3474ef6899639d94a32b61377271bd --- /dev/null +++ b/nav2_behavior_tree/plugins/action/follow_path_action.cpp @@ -0,0 +1,73 @@ +// Copyright (c) 2018 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NAV2_BEHAVIOR_TREE__FOLLOW_PATH_ACTION_HPP_ +#define NAV2_BEHAVIOR_TREE__FOLLOW_PATH_ACTION_HPP_ + +#include <memory> +#include <string> + +#include "nav2_msgs/action/follow_path.hpp" +#include "nav2_behavior_tree/bt_action_node.hpp" + +namespace nav2_behavior_tree +{ + +class FollowPathAction : public BtActionNode<nav2_msgs::action::FollowPath> +{ +public: + FollowPathAction( + const std::string & action_name, + const BT::NodeConfiguration & conf) + : BtActionNode<nav2_msgs::action::FollowPath>(action_name, conf) + { + config().blackboard->set("path_updated", false); + } + + void on_tick() override + { + getInput("path", goal_.path); + } + + void on_server_timeout() override + { + // Check if the goal has been updated + if (config().blackboard->get<bool>("path_updated")) { + // Reset the flag in the blackboard + config().blackboard->set("path_updated", false); + + // Grab the new goal and set the flag so that we send the new goal to + // the action server on the next loop iteration + getInput("path", goal_.path); + goal_updated_ = true; + } + } + + static BT::PortsList providedPorts() + { + return providedBasicPorts({ + BT::InputPort<nav_msgs::msg::Path>("path", "Path to follow"), + }); + } +}; + +} // namespace nav2_behavior_tree + +#include "behaviortree_cpp_v3/bt_factory.h" +BT_REGISTER_NODES(factory) +{ + factory.registerNodeType<nav2_behavior_tree::FollowPathAction>("FollowPath"); +} + +#endif // NAV2_BEHAVIOR_TREE__FOLLOW_PATH_ACTION_HPP_ diff --git a/nav2_behavior_tree/plugins/action/navigate_to_pose_action.cpp b/nav2_behavior_tree/plugins/action/navigate_to_pose_action.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ad3ceac9468215e24c4d4a7975c65445df2d31b8 --- /dev/null +++ b/nav2_behavior_tree/plugins/action/navigate_to_pose_action.cpp @@ -0,0 +1,76 @@ +// Copyright (c) 2018 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NAV2_BEHAVIOR_TREE__NAVIGATE_TO_POSE_ACTION_HPP_ +#define NAV2_BEHAVIOR_TREE__NAVIGATE_TO_POSE_ACTION_HPP_ + +#include <memory> +#include <string> + +#include "geometry_msgs/msg/point.hpp" +#include "geometry_msgs/msg/quaternion.hpp" +#include "nav2_msgs/action/navigate_to_pose.hpp" +#include "nav2_behavior_tree/bt_action_node.hpp" +#include "nav2_behavior_tree/bt_conversions.hpp" + +namespace nav2_behavior_tree +{ + +class NavigateToPoseAction : public BtActionNode<nav2_msgs::action::NavigateToPose> +{ +public: + NavigateToPoseAction( + const std::string & action_name, + const BT::NodeConfiguration & conf) + : BtActionNode<nav2_msgs::action::NavigateToPose>(action_name, conf) + { + } + + void on_tick() override + { + // Use the position and orientation fields from the XML attributes to initialize the goal + geometry_msgs::msg::Point position; + geometry_msgs::msg::Quaternion orientation; + + bool have_position = getInput("position", position); + bool have_orientation = getInput("orientation", orientation); + + if (!have_position || !have_orientation) { + RCLCPP_ERROR(node_->get_logger(), + "NavigateToPoseAction: position or orientation not provided"); + } + + goal_.pose.pose.position = position; + goal_.pose.pose.orientation = orientation; + } + + // Any BT node that accepts parameters must provide a requiredNodeParameters method + static BT::PortsList providedPorts() + { + return providedBasicPorts({ + BT::InputPort<geometry_msgs::msg::Point>("position", "0;0;0", "Position"), + BT::InputPort<geometry_msgs::msg::Quaternion>("orientation", "0;0;0;0", "Orientation") + }); + } +}; + +} // namespace nav2_behavior_tree + +#include "behaviortree_cpp_v3/bt_factory.h" +BT_REGISTER_NODES(factory) +{ + factory.registerNodeType<nav2_behavior_tree::NavigateToPoseAction>("NavigateToPose"); +} + +#endif // NAV2_BEHAVIOR_TREE__NAVIGATE_TO_POSE_ACTION_HPP_ diff --git a/nav2_behavior_tree/plugins/action/random_crawl_action.cpp b/nav2_behavior_tree/plugins/action/random_crawl_action.cpp new file mode 100644 index 0000000000000000000000000000000000000000..86c8e48f9e0e65e4567c7f6d4b91e701aa3b3d4e --- /dev/null +++ b/nav2_behavior_tree/plugins/action/random_crawl_action.cpp @@ -0,0 +1,43 @@ +// Copyright (c) 2018 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NAV2_BEHAVIOR_TREE__RANDOM_CRAWL_ACTION_HPP_ +#define NAV2_BEHAVIOR_TREE__RANDOM_CRAWL_ACTION_HPP_ + +#include <string> + +#include "nav2_behavior_tree/bt_action_node.hpp" +#include "nav2_msgs/action/random_crawl.hpp" + +namespace nav2_behavior_tree +{ + +class RandomCrawlAction : public BtActionNode<nav2_msgs::action::RandomCrawl> +{ +public: + explicit RandomCrawlAction(const std::string & action_name) + : BtActionNode<nav2_msgs::action::RandomCrawl>(action_name) + { + } +}; + +} // namespace nav2_behavior_tree + +#include "behaviortree_cpp_v3/bt_factory.h" +BT_REGISTER_NODES(factory) +{ + factory.registerNodeType<nav2_behavior_tree::RandomCrawlAction>("RandomCrawl"); +} + +#endif // NAV2_BEHAVIOR_TREE__RANDOM_CRAWL_ACTION_HPP_ diff --git a/nav2_behavior_tree/plugins/action/reinitialize_global_localization_service.cpp b/nav2_behavior_tree/plugins/action/reinitialize_global_localization_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..edbde1af24a4d37e4eb97c975ba4b452619d0241 --- /dev/null +++ b/nav2_behavior_tree/plugins/action/reinitialize_global_localization_service.cpp @@ -0,0 +1,48 @@ +// Copyright (c) 2019 Samsung Research America +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NAV2_BEHAVIOR_TREE__REINITIALIZE_GLOBAL_LOCALIZATION_SERVICE_HPP_ +#define NAV2_BEHAVIOR_TREE__REINITIALIZE_GLOBAL_LOCALIZATION_SERVICE_HPP_ + +#include <string> +#include <memory> +#include <cmath> + +#include "nav2_behavior_tree/bt_service_node.hpp" +#include "std_srvs/srv/empty.hpp" + +namespace nav2_behavior_tree +{ + +class ReinitializeGlobalLocalizationService : public BtServiceNode<std_srvs::srv::Empty> +{ +public: + ReinitializeGlobalLocalizationService( + const std::string & service_node_name, + const BT::NodeConfiguration & conf) + : BtServiceNode<std_srvs::srv::Empty>(service_node_name, conf) + { + } +}; + +} // namespace nav2_behavior_tree + +#include "behaviortree_cpp_v3/bt_factory.h" +BT_REGISTER_NODES(factory) +{ + factory.registerNodeType<nav2_behavior_tree::ReinitializeGlobalLocalizationService>( + "ReinitializeGlobalLocalization"); +} + +#endif // NAV2_BEHAVIOR_TREE__REINITIALIZE_GLOBAL_LOCALIZATION_SERVICE_HPP_ diff --git a/nav2_behavior_tree/plugins/action/spin_action.cpp b/nav2_behavior_tree/plugins/action/spin_action.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ee8be2a65e4ef582ad8774c088c3ad40817d356 --- /dev/null +++ b/nav2_behavior_tree/plugins/action/spin_action.cpp @@ -0,0 +1,60 @@ +// Copyright (c) 2018 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NAV2_BEHAVIOR_TREE__SPIN_ACTION_HPP_ +#define NAV2_BEHAVIOR_TREE__SPIN_ACTION_HPP_ + +#include <string> +#include <memory> +#include <cmath> + +#include "nav2_behavior_tree/bt_action_node.hpp" +#include "nav2_msgs/action/spin.hpp" +#include "geometry_msgs/msg/quaternion.hpp" +#include "tf2/LinearMath/Quaternion.h" +#include "tf2_geometry_msgs/tf2_geometry_msgs.h" + +namespace nav2_behavior_tree +{ + +class SpinAction : public BtActionNode<nav2_msgs::action::Spin> +{ +public: + SpinAction( + const std::string & action_name, + const BT::NodeConfiguration & conf) + : BtActionNode<nav2_msgs::action::Spin>(action_name, conf) + { + double dist; + getInput("spin_dist", dist); + goal_.target_yaw = dist; + } + + static BT::PortsList providedPorts() + { + return providedBasicPorts({ + BT::InputPort<double>("spin_dist", 1.57, "Spin distance") + }); + } +}; + +} // namespace nav2_behavior_tree + +#include "behaviortree_cpp_v3/bt_factory.h" +BT_REGISTER_NODES(factory) +{ + factory.registerNodeType<nav2_behavior_tree::SpinAction>("Spin"); +} + +#endif // NAV2_BEHAVIOR_TREE__SPIN_ACTION_HPP_ diff --git a/nav2_behavior_tree/plugins/action/wait_action.cpp b/nav2_behavior_tree/plugins/action/wait_action.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aaf9bf6e128a13e2bc207038db1b0ca057e7d398 --- /dev/null +++ b/nav2_behavior_tree/plugins/action/wait_action.cpp @@ -0,0 +1,65 @@ +// Copyright (c) 2018 Samsung Research America +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NAV2_BEHAVIOR_TREE__WAIT_ACTION_HPP_ +#define NAV2_BEHAVIOR_TREE__WAIT_ACTION_HPP_ + +#include <string> +#include <memory> +#include <cmath> + +#include "nav2_behavior_tree/bt_action_node.hpp" +#include "nav2_msgs/action/wait.hpp" + +namespace nav2_behavior_tree +{ + +class WaitAction : public BtActionNode<nav2_msgs::action::Wait> +{ +public: + WaitAction( + const std::string & action_name, + const BT::NodeConfiguration & conf) + : BtActionNode<nav2_msgs::action::Wait>(action_name, conf) + { + int duration; + getInput("wait_duration", duration); + if (duration <= 0) { + RCLCPP_WARN(node_->get_logger(), "Wait duration is negative or zero " + "(%i). Setting to positive.", duration); + duration *= -1; + } + + goal_.time.sec = duration; + } + + // Any BT node that accepts parameters must provide a requiredNodeParameters method + static BT::PortsList providedPorts() + { + return providedBasicPorts({ + BT::InputPort<int>("wait_duration", 1, "Wait time") + }); + } +}; + +} // namespace nav2_behavior_tree + + +#include "behaviortree_cpp_v3/bt_factory.h" +BT_REGISTER_NODES(factory) +{ + factory.registerNodeType<nav2_behavior_tree::WaitAction>("Wait"); +} + +#endif // NAV2_BEHAVIOR_TREE__WAIT_ACTION_HPP_