-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added base of BT docking plugins Signed-off-by: Jakub Delicat <[email protected]> * Teste dock and undock plugins Signed-off-by: Jakub Delicat <[email protected]> * Removed test dock manager Signed-off-by: Jakub Delicat <[email protected]> * run precommit Signed-off-by: Jakub Delicat <[email protected]> * moved plugins Signed-off-by: Jakub Delicat <[email protected]> * changed names of files and classes | changed DockRobotAction to DockRobot Signed-off-by: Jakub Delicat <[email protected]> * Fixed copyright Signed-off-by: Jakub Delicat <[email protected]> * Changed timeouts | changed using Signed-off-by: Jakub Delicat <[email protected]> --------- Signed-off-by: Jakub Delicat <[email protected]>
- Loading branch information
Showing
8 changed files
with
765 additions
and
6 deletions.
There are no files selected for viewing
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
72 changes: 72 additions & 0 deletions
72
panther_manager/include/panther_manager/plugins/action/dock_robot_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,72 @@ | ||
// Copyright 2024 Husarion sp. z o.o. | ||
// | ||
// 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 PANTHER_MANAGER_PLUGINS_ACTION_DOCK_ROBOT_NODE_HPP_ | ||
#define PANTHER_MANAGER_PLUGINS_ACTION_DOCK_ROBOT_NODE_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <behaviortree_ros2/bt_action_node.hpp> | ||
|
||
#include <geometry_msgs/msg/pose_stamped.hpp> | ||
#include <opennav_docking_msgs/action/dock_robot.hpp> | ||
|
||
namespace panther_manager | ||
{ | ||
|
||
class DockRobot : public BT::RosActionNode<opennav_docking_msgs::action::DockRobot> | ||
{ | ||
using DockRobotAction = opennav_docking_msgs::action::DockRobot; | ||
using DockRobotActionResult = DockRobotAction::Result; | ||
|
||
public: | ||
DockRobot(const std::string & name, const BT::NodeConfig & conf, const BT::RosNodeParams & params) | ||
: RosActionNode<DockRobotAction>(name, conf, params) | ||
{ | ||
} | ||
|
||
bool setGoal(Goal & goal) override; | ||
|
||
void onHalt() override; | ||
|
||
BT::NodeStatus onResultReceived(const WrappedResult & wr) override; | ||
|
||
virtual BT::NodeStatus onFailure(BT::ActionNodeErrorCode error) override; | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return providedBasicPorts({ | ||
BT::InputPort<bool>("use_dock_id", true, "Whether to use the dock's ID or dock pose fields"), | ||
BT::InputPort<std::string>("dock_id", "Dock ID or name to use"), | ||
BT::InputPort<std::string>("dock_type", "The dock plugin type, if using dock pose"), | ||
BT::InputPort<float>( | ||
"max_staging_time", 1000.0, "Maximum time to navigate to the staging pose"), | ||
BT::InputPort<bool>( | ||
"navigate_to_staging_pose", true, "Whether to autonomously navigate to staging pose"), | ||
|
||
BT::OutputPort<DockRobotActionResult::_success_type>( | ||
"success", "If the action was successful"), | ||
BT::OutputPort<DockRobotActionResult::_error_code_type>( | ||
"error_code", "Contextual error code, if any"), | ||
BT::OutputPort<DockRobotActionResult::_num_retries_type>( | ||
"num_retries", "Number of retries attempted"), | ||
}); | ||
} | ||
}; | ||
|
||
} // namespace panther_manager | ||
|
||
#endif // PANTHER_MANAGER_PLUGINS_ACTION_DOCK_ROBOT_NODE_HPP_ |
67 changes: 67 additions & 0 deletions
67
panther_manager/include/panther_manager/plugins/action/undock_robot_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,67 @@ | ||
// Copyright 2024 Husarion sp. z o.o. | ||
// | ||
// 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 PANTHER_MANAGER_PLUGINS_ACTION_UNDOCK_ROBOT_NODE_HPP_ | ||
#define PANTHER_MANAGER_PLUGINS_ACTION_UNDOCK_ROBOT_NODE_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include <behaviortree_ros2/bt_action_node.hpp> | ||
|
||
#include <geometry_msgs/msg/pose_stamped.hpp> | ||
#include <opennav_docking_msgs/action/undock_robot.hpp> | ||
|
||
namespace panther_manager | ||
{ | ||
|
||
class UndockRobot : public BT::RosActionNode<opennav_docking_msgs::action::UndockRobot> | ||
{ | ||
using UndockRobotAction = opennav_docking_msgs::action::UndockRobot; | ||
using UndockRobotActionResult = UndockRobotAction::Result; | ||
|
||
public: | ||
UndockRobot( | ||
const std::string & name, const BT::NodeConfig & conf, const BT::RosNodeParams & params) | ||
: RosActionNode<UndockRobotAction>(name, conf, params) | ||
{ | ||
} | ||
|
||
bool setGoal(Goal & goal) override; | ||
|
||
void onHalt() override; | ||
|
||
BT::NodeStatus onResultReceived(const WrappedResult & wr) override; | ||
|
||
virtual BT::NodeStatus onFailure(BT::ActionNodeErrorCode error) override; | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return providedBasicPorts({ | ||
BT::InputPort<std::string>( | ||
"dock_type", "The dock plugin type, if not previous instance used for docking"), | ||
BT::InputPort<float>( | ||
"max_undocking_time", 30.0, "Maximum time to get back to the staging pose"), | ||
|
||
BT::OutputPort<UndockRobotActionResult::_success_type>( | ||
"success", "If the action was successful"), | ||
BT::OutputPort<UndockRobotActionResult::_error_code_type>("error_code", "Error code"), | ||
}); | ||
} | ||
}; | ||
|
||
} // namespace panther_manager | ||
|
||
#endif // PANTHER_MANAGER_PLUGINS_ACTION_UNDOCK_ROBOT_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,92 @@ | ||
// Copyright 2024 Husarion sp. z o.o. | ||
// | ||
// 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 "panther_manager/plugins/action/dock_robot_node.hpp" | ||
#include "panther_manager/behavior_tree_utils.hpp" | ||
|
||
namespace panther_manager | ||
{ | ||
|
||
bool DockRobot::setGoal(Goal & goal) | ||
{ | ||
if (!this->getInput<std::string>("dock_type", goal.dock_type) || goal.dock_type.empty()) { | ||
RCLCPP_ERROR_STREAM( | ||
this->logger(), GetLoggerPrefix(name()) << "Failed to get input [dock_type]"); | ||
return false; | ||
} | ||
|
||
if (!this->getInput<bool>("use_dock_id", goal.use_dock_id)) { | ||
goal.use_dock_id = false; | ||
RCLCPP_WARN_STREAM( | ||
this->logger(), GetLoggerPrefix(name()) | ||
<< "use_dock_id not set, using default value: " << goal.use_dock_id); | ||
} | ||
|
||
if ( | ||
(!this->getInput<std::string>("dock_id", goal.dock_id) || goal.dock_id.empty()) && | ||
goal.use_dock_id) { | ||
RCLCPP_ERROR_STREAM(this->logger(), GetLoggerPrefix(name()) << "Failed to get input [dock_id]"); | ||
return false; | ||
} | ||
|
||
if (!this->getInput<bool>("navigate_to_staging_pose", goal.navigate_to_staging_pose)) { | ||
goal.navigate_to_staging_pose = false; | ||
RCLCPP_WARN_STREAM( | ||
this->logger(), GetLoggerPrefix(name()) << "navigate_to_staging_pose not set, using default " | ||
"value: " | ||
<< goal.navigate_to_staging_pose); | ||
} | ||
|
||
if ( | ||
!this->getInput<float>("max_staging_time", goal.max_staging_time) && | ||
goal.navigate_to_staging_pose) { | ||
RCLCPP_ERROR_STREAM( | ||
this->logger(), GetLoggerPrefix(name()) << "Failed to get input [max_staging_time]"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
BT::NodeStatus DockRobot::onResultReceived(const WrappedResult & wr) | ||
{ | ||
const auto & result = wr.result; | ||
|
||
this->setOutput("success", result->success); | ||
this->setOutput("error_code", result->error_code); | ||
this->setOutput("num_retries", result->num_retries); | ||
|
||
if (result->success) { | ||
return BT::NodeStatus::SUCCESS; | ||
} | ||
|
||
return BT::NodeStatus::FAILURE; | ||
} | ||
|
||
BT::NodeStatus DockRobot::onFailure(BT::ActionNodeErrorCode error) | ||
{ | ||
RCLCPP_ERROR_STREAM( | ||
this->logger(), GetLoggerPrefix(name()) << ": onFailure with error: " << toStr(error)); | ||
return BT::NodeStatus::FAILURE; | ||
} | ||
|
||
void DockRobot::onHalt() | ||
{ | ||
RCLCPP_INFO_STREAM(this->logger(), GetLoggerPrefix(name()) << ": onHalt"); | ||
} | ||
|
||
} // namespace panther_manager | ||
|
||
#include "behaviortree_ros2/plugins.hpp" | ||
CreateRosNodePlugin(panther_manager::DockRobot, "DockRobot"); |
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,67 @@ | ||
// Copyright 2024 Husarion sp. z o.o. | ||
// | ||
// 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 "panther_manager/plugins/action/undock_robot_node.hpp" | ||
#include "panther_manager/behavior_tree_utils.hpp" | ||
|
||
namespace panther_manager | ||
{ | ||
|
||
bool UndockRobot::setGoal(Goal & goal) | ||
{ | ||
if (!this->getInput<std::string>("dock_type", goal.dock_type) || goal.dock_type.empty()) { | ||
RCLCPP_ERROR_STREAM( | ||
this->logger(), GetLoggerPrefix(name()) << "Failed to get input [dock_type]"); | ||
return false; | ||
} | ||
|
||
if (!this->getInput<float>("max_undocking_time", goal.max_undocking_time)) { | ||
RCLCPP_ERROR_STREAM( | ||
this->logger(), GetLoggerPrefix(name()) << "Failed to get input [max_undocking_time]"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
BT::NodeStatus UndockRobot::onResultReceived(const WrappedResult & wr) | ||
{ | ||
const auto & result = wr.result; | ||
|
||
this->setOutput("success", result->success); | ||
this->setOutput("error_code", result->error_code); | ||
|
||
if (result->success) { | ||
return BT::NodeStatus::SUCCESS; | ||
} | ||
|
||
return BT::NodeStatus::FAILURE; | ||
} | ||
|
||
BT::NodeStatus UndockRobot::onFailure(BT::ActionNodeErrorCode error) | ||
{ | ||
RCLCPP_ERROR_STREAM( | ||
this->logger(), GetLoggerPrefix(name()) << ": onFailure with error: " << toStr(error)); | ||
return BT::NodeStatus::FAILURE; | ||
} | ||
|
||
void UndockRobot::onHalt() | ||
{ | ||
RCLCPP_INFO_STREAM(this->logger(), GetLoggerPrefix(name()) << ": onHalt"); | ||
} | ||
|
||
} // namespace panther_manager | ||
|
||
#include "behaviortree_ros2/plugins.hpp" | ||
CreateRosNodePlugin(panther_manager::UndockRobot, "UndockRobot"); |
Oops, something went wrong.