-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alberto Tudela <[email protected]>
- Loading branch information
Showing
12 changed files
with
387 additions
and
9 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,12 @@ jobs: | |
- name: Setup ROS 2 | ||
uses: ros-tooling/[email protected] | ||
with: | ||
required-ros-distributions: rolling | ||
required-ros-distributions: humble | ||
- name: Install dependencies | ||
uses: ros-tooling/[email protected] | ||
with: | ||
package-name: scitos2 | ||
target-ros2-distro: rolling | ||
vcs-repo-file-url: ./.github/repos.repos # Until nav2 is released in rolling | ||
target-ros2-distro: humble | ||
colcon-defaults: | | ||
{ | ||
"build": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
scitos2_behavior_tree/test/utils/test_behavior_tree_fixture.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) 2018 Intel Corporation | ||
// Copyright (c) 2020 Sarthak Mittal | ||
// | ||
// 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 UTILS__TEST_BEHAVIOR_TREE_FIXTURE_HPP_ | ||
#define UTILS__TEST_BEHAVIOR_TREE_FIXTURE_HPP_ | ||
|
||
#include <gtest/gtest.h> | ||
#include <memory> | ||
#include <set> | ||
|
||
#include "behaviortree_cpp_v3/bt_factory.h" | ||
#include "rclcpp/rclcpp.hpp" | ||
|
||
#include "test_transform_handler.hpp" | ||
#include "test_dummy_tree_node.hpp" | ||
|
||
namespace nav2_behavior_tree | ||
{ | ||
|
||
class BehaviorTreeTestFixture : public ::testing::Test | ||
{ | ||
public: | ||
static void SetUpTestCase() | ||
{ | ||
node_ = std::make_shared<rclcpp::Node>("test_behavior_tree_fixture"); | ||
transform_handler_ = std::make_shared<nav2_behavior_tree::TransformHandler>(node_); | ||
factory_ = std::make_shared<BT::BehaviorTreeFactory>(); | ||
|
||
config_ = new BT::NodeConfiguration(); | ||
|
||
// Create the blackboard that will be shared by all of the nodes in the tree | ||
config_->blackboard = BT::Blackboard::create(); | ||
// Put items on the blackboard | ||
config_->blackboard->set( | ||
"node", | ||
node_); | ||
config_->blackboard->set( | ||
"tf_buffer", | ||
transform_handler_->getBuffer()); | ||
config_->blackboard->set<std::chrono::milliseconds>( | ||
"server_timeout", | ||
std::chrono::milliseconds(20)); | ||
config_->blackboard->set<std::chrono::milliseconds>( | ||
"bt_loop_duration", | ||
std::chrono::milliseconds(10)); | ||
config_->blackboard->set("initial_pose_received", false); | ||
|
||
transform_handler_->activate(); | ||
transform_handler_->waitForTransform(); | ||
} | ||
|
||
static void TearDownTestCase() | ||
{ | ||
transform_handler_->deactivate(); | ||
delete config_; | ||
config_ = nullptr; | ||
transform_handler_.reset(); | ||
node_.reset(); | ||
factory_.reset(); | ||
} | ||
|
||
protected: | ||
static rclcpp::Node::SharedPtr node_; | ||
static std::shared_ptr<nav2_behavior_tree::TransformHandler> transform_handler_; | ||
static BT::NodeConfiguration * config_; | ||
static std::shared_ptr<BT::BehaviorTreeFactory> factory_; | ||
}; | ||
|
||
} // namespace nav2_behavior_tree | ||
|
||
rclcpp::Node::SharedPtr nav2_behavior_tree::BehaviorTreeTestFixture::node_ = nullptr; | ||
|
||
std::shared_ptr<nav2_behavior_tree::TransformHandler> | ||
nav2_behavior_tree::BehaviorTreeTestFixture::transform_handler_ = nullptr; | ||
|
||
BT::NodeConfiguration * nav2_behavior_tree::BehaviorTreeTestFixture::config_ = nullptr; | ||
|
||
std::shared_ptr<BT::BehaviorTreeFactory> | ||
nav2_behavior_tree::BehaviorTreeTestFixture::factory_ = nullptr; | ||
|
||
#endif // UTILS__TEST_BEHAVIOR_TREE_FIXTURE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2018 Intel Corporation | ||
// Copyright (c) 2020 Sarthak Mittal | ||
// | ||
// 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 UTILS__TEST_DUMMY_TREE_NODE_HPP_ | ||
#define UTILS__TEST_DUMMY_TREE_NODE_HPP_ | ||
|
||
#include <behaviortree_cpp_v3/basic_types.h> | ||
#include <behaviortree_cpp_v3/action_node.h> | ||
|
||
namespace nav2_behavior_tree | ||
{ | ||
|
||
/** | ||
* @brief A Dummy TreeNode to be used as a child for testing nodes | ||
* Returns the current status on tick without any execution logic | ||
*/ | ||
class DummyNode : public BT::ActionNodeBase | ||
{ | ||
public: | ||
DummyNode() | ||
: BT::ActionNodeBase("dummy", {}) | ||
{ | ||
} | ||
|
||
void changeStatus(BT::NodeStatus status) | ||
{ | ||
setStatus(status); | ||
} | ||
|
||
BT::NodeStatus executeTick() override | ||
{ | ||
return tick(); | ||
} | ||
|
||
BT::NodeStatus tick() override | ||
{ | ||
return status(); | ||
} | ||
|
||
void halt() override | ||
{ | ||
} | ||
}; | ||
|
||
} // namespace nav2_behavior_tree | ||
|
||
#endif // UTILS__TEST_DUMMY_TREE_NODE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2020 Sarthak Mittal | ||
// | ||
// 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 UTILS__TEST_SERVICE_HPP_ | ||
#define UTILS__TEST_SERVICE_HPP_ | ||
|
||
#include <string> | ||
#include <memory> | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
|
||
template<class ServiceT> | ||
class TestService : public rclcpp::Node | ||
{ | ||
public: | ||
explicit TestService( | ||
std::string service_name, | ||
const rclcpp::NodeOptions & options = rclcpp::NodeOptions()) | ||
: Node("test_service", options) | ||
{ | ||
using namespace std::placeholders; // NOLINT | ||
|
||
server_ = create_service<ServiceT>( | ||
service_name, | ||
std::bind(&TestService::handle_service, this, _1, _2, _3)); | ||
} | ||
|
||
std::shared_ptr<typename ServiceT::Request> getCurrentRequest() const | ||
{ | ||
return current_request_; | ||
} | ||
|
||
protected: | ||
virtual void handle_service( | ||
const std::shared_ptr<rmw_request_id_t> request_header, | ||
const std::shared_ptr<typename ServiceT::Request> request, | ||
const std::shared_ptr<typename ServiceT::Response> response) | ||
{ | ||
(void)request_header; | ||
(void)response; | ||
current_request_ = request; | ||
} | ||
|
||
private: | ||
typename rclcpp::Service<ServiceT>::SharedPtr server_; | ||
std::shared_ptr<typename ServiceT::Request> current_request_; | ||
}; | ||
|
||
#endif // UTILS__TEST_SERVICE_HPP_ |
Oops, something went wrong.