diff --git a/nexus_integration_tests/config/system_bts/main.xml b/nexus_integration_tests/config/system_bts/main.xml deleted file mode 100644 index 3f96eaf..0000000 --- a/nexus_integration_tests/config/system_bts/main.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/nexus_integration_tests/config/system_bts/pick_and_place.xml b/nexus_integration_tests/config/system_bts/pick_and_place.xml index 07a7e78..8e69348 100644 --- a/nexus_integration_tests/config/system_bts/pick_and_place.xml +++ b/nexus_integration_tests/config/system_bts/pick_and_place.xml @@ -2,14 +2,30 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nexus_integration_tests/launch/control_center.launch.py b/nexus_integration_tests/launch/control_center.launch.py index c92b133..6cf6e8b 100644 --- a/nexus_integration_tests/launch/control_center.launch.py +++ b/nexus_integration_tests/launch/control_center.launch.py @@ -126,7 +126,7 @@ def launch_setup(context, *args, **kwargs): { "bt_path": ( FindPackageShare("nexus_integration_tests"), - "/config/system_bts", + "/config/system_bts/pick_and_place.xml", ), "remap_task_types": """{ diff --git a/nexus_system_orchestrator/CMakeLists.txt b/nexus_system_orchestrator/CMakeLists.txt index d3459bb..e474698 100644 --- a/nexus_system_orchestrator/CMakeLists.txt +++ b/nexus_system_orchestrator/CMakeLists.txt @@ -19,7 +19,6 @@ set(CMAKE_CXX_FLAGS "-Wall -Wpedantic") add_library(${PROJECT_NAME}_plugin SHARED src/bid_transporter.cpp - src/execute_task.cpp src/for_each_task.cpp src/send_signal.cpp src/system_orchestrator.cpp diff --git a/nexus_system_orchestrator/src/execute_task.cpp b/nexus_system_orchestrator/src/execute_task.cpp deleted file mode 100644 index fbf626a..0000000 --- a/nexus_system_orchestrator/src/execute_task.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2023 Johnson & Johnson - * - * 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. - * - */ - -#include "execute_task.hpp" - -namespace nexus::system_orchestrator { - -BT::NodeStatus ExecuteTask::onStart() -{ - auto task = this->getInput("task"); - if (!task) - { - RCLCPP_ERROR( - this->_ctx->node.get_logger(), "%s: [task] port is required", - this->name().c_str()); - return BT::NodeStatus::FAILURE; - } - - auto workcell = this->getInput("workcell"); - if (!workcell) - { - RCLCPP_ERROR( - this->_ctx->node.get_logger(), "%s: [workcell] port is required", - this->name().c_str()); - return BT::NodeStatus::FAILURE; - } - - // Remap the BT filename to load if one is provided. - std::string bt_name = task->type; - auto it = _ctx->task_remaps->find(task->type); - if (it != _ctx->task_remaps->end()) - { - RCLCPP_DEBUG( - _ctx->node.get_logger(), - "[ExecuteTask] Loading remapped BT [%s] for original task type [%s]", - it->second.c_str(), - task->type.c_str() - ); - bt_name = it->second; - } - std::filesystem::path task_bt_path(this->_bt_path / (bt_name + ".xml")); - if (!std::filesystem::is_regular_file(task_bt_path)) - { - RCLCPP_ERROR( - this->_ctx->node.get_logger(), "%s: no behavior tree to execute task type [%s]", - this->name().c_str(), task->type.c_str()); - return BT::NodeStatus::FAILURE; - } - - this->_bt = std::make_unique(this->_bt_factory->createTreeFromFile( - task_bt_path)); - this->_bt->rootBlackboard()->set("task", *task); - this->_bt->rootBlackboard()->set("workcell", *workcell); - - return BT::NodeStatus::RUNNING; -} - -BT::NodeStatus ExecuteTask::onRunning() -{ - return this->_bt->tickRoot(); -} - -void ExecuteTask::onHalted() -{ - this->_bt->haltTree(); -} - -} diff --git a/nexus_system_orchestrator/src/execute_task.hpp b/nexus_system_orchestrator/src/execute_task.hpp deleted file mode 100644 index c3ce603..0000000 --- a/nexus_system_orchestrator/src/execute_task.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2023 Johnson & Johnson - * - * 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 NEXUS_SYSTEM_ORCHESTRATOR__EXECUTE_TASK_HPP -#define NEXUS_SYSTEM_ORCHESTRATOR__EXECUTE_TASK_HPP - -#include "context.hpp" - -#include - -#include -#include - -#include - -namespace nexus::system_orchestrator { - -/** - * Searches for a behavior tree to execute a task and run it as a sub tree. - * - * The behavior tree used is based on the task type after remapping and the - * filename of the behavior tree without extension. - * - * Input Ports: - * task |nexus_orchestrator_msgs::msg::WorkcellTask| The task to execute. - * workcell |std::string| Workcell to execute on. - */ -class ExecuteTask : public BT::StatefulActionNode -{ -public: using Task = nexus_orchestrator_msgs::msg::WorkcellTask; - -public: static BT::PortsList providedPorts() - { - return { BT::InputPort("task"), - BT::InputPort("workcell") }; - } - -public: ExecuteTask(const std::string& name, - const BT::NodeConfiguration& config, - std::shared_ptr ctx, - std::filesystem::path bt_path, - std::shared_ptr bt_factory) - : BT::StatefulActionNode(name, config), _ctx(std::move(ctx)), _bt_path(std::move( - bt_path)), - _bt_factory(std::move(bt_factory)) {} - -protected: BT::NodeStatus onStart() override; - -protected: BT::NodeStatus onRunning() override; - -protected: void onHalted() override; - -private: std::shared_ptr _ctx; -private: std::filesystem::path _bt_path; -private: std::shared_ptr _bt_factory; -private: std::unique_ptr _bt; -}; - -} - -#endif diff --git a/nexus_system_orchestrator/src/system_orchestrator.cpp b/nexus_system_orchestrator/src/system_orchestrator.cpp index bd972e2..754b608 100644 --- a/nexus_system_orchestrator/src/system_orchestrator.cpp +++ b/nexus_system_orchestrator/src/system_orchestrator.cpp @@ -20,7 +20,6 @@ #include "bid_transporter.hpp" #include "context.hpp" #include "exceptions.hpp" -#include "execute_task.hpp" #include "for_each_task.hpp" #include "job.hpp" #include "send_signal.hpp" @@ -71,20 +70,19 @@ SystemOrchestrator::SystemOrchestrator(const rclcpp::NodeOptions& options) ParameterDescriptor desc; desc.read_only = true; desc.description = - "Path to a directory containing behavior trees. Each file in the directory should be a behavior tree xml, the file name denotes the task type for that behavior tree. In addition, there must be a file named \"main.xml\" which will be used to perform the work order."; + "Path to a behavior tree."; this->_bt_path = this->declare_parameter("bt_path", "", desc); if (this->_bt_path.empty()) { throw std::runtime_error("param [bt_path] is required"); } - // check if "main.xml" exists - const auto main_bt = this->_bt_path / "main.xml"; - if (!std::filesystem::exists(main_bt) || - !std::filesystem::is_regular_file(main_bt)) + // check if behavior tree exists + if (!std::filesystem::exists(this->_bt_path) || + !std::filesystem::is_regular_file(this->_bt_path)) { throw std::runtime_error( - "path specified in [bt_path] param must contain \"main.xml\""); + "path specified in [bt_path] param must point to a file"); } } @@ -491,21 +489,13 @@ BT::Tree SystemOrchestrator::_create_bt(const WorkOrderActionType::Goal& wo, this->get_logger(), ctx); }); - bt_factory->registerBuilder("ExecuteTask", - [this, ctx, bt_factory](const std::string& name, - const BT::NodeConfiguration& config) - { - return std::make_unique(name, config, ctx, this->_bt_path, - bt_factory); - }); - bt_factory->registerBuilder("SendSignal", [ctx](const std::string& name, const BT::NodeConfiguration& config) { return std::make_unique(name, config, ctx); }); - return bt_factory->createTreeFromFile(this->_bt_path / "main.xml"); + return bt_factory->createTreeFromFile(this->_bt_path); } void SystemOrchestrator::_create_job(const WorkOrderActionType::Goal& goal)