forked from ros-navigation/navigation2
-
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.
standalone assisted teleop (ros-navigation#2904)
* standalone assisted teleop * added in action message * code review * moved to behavior server * added assisted teleop bt node * revert * added bt node for assisted teleop * lint fix * added cancel assisted teleop node * code review * working * cleanup * updated feeback * code review * update compute velocity * cleanup * lint fixes * cleanup * test fix * starting to add tests for assisted teleop * fixed tests * undo * fixed test * is_recovery * adjust abort result based on recovery or not * code review * added preempt velocity * working preempt assisted teleop test * completed assisted teleop tests * code review * undo * code review * remove sleep * topic rename * missing comma * added comma :( * added comma Co-authored-by: Steve Macenski <[email protected]>
- Loading branch information
1 parent
344ac1c
commit 2b34405
Showing
30 changed files
with
1,622 additions
and
2 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
70 changes: 70 additions & 0 deletions
70
nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/assisted_teleop_action.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,70 @@ | ||
// Copyright (c) 2022 Joshua Wallace | ||
// | ||
// 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__PLUGINS__ACTION__ASSISTED_TELEOP_ACTION_HPP_ | ||
#define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__ASSISTED_TELEOP_ACTION_HPP_ | ||
|
||
#include <string> | ||
|
||
#include "nav2_behavior_tree/bt_action_node.hpp" | ||
#include "nav2_msgs/action/assisted_teleop.hpp" | ||
|
||
namespace nav2_behavior_tree | ||
{ | ||
|
||
/** | ||
* @brief A nav2_behavior_tree::BtActionNode class that wraps nav2_msgs::action::AssistedTeleop | ||
*/ | ||
class AssistedTeleopAction : public BtActionNode<nav2_msgs::action::AssistedTeleop> | ||
{ | ||
public: | ||
/** | ||
* @brief A constructor for nav2_behavior_tree::nav2_msgs::action::AssistedTeleop | ||
* @param xml_tag_name Name for the XML tag for this node | ||
* @param action_name Action name this node creates a client for | ||
* @param conf BT node configuration | ||
*/ | ||
AssistedTeleopAction( | ||
const std::string & xml_tag_name, | ||
const std::string & action_name, | ||
const BT::NodeConfiguration & conf); | ||
|
||
/** | ||
* @brief Function to perform some user-defined operation on tick | ||
*/ | ||
void on_tick() override; | ||
|
||
BT::NodeStatus on_aborted() override; | ||
|
||
/** | ||
* @brief Creates list of BT ports | ||
* @return BT::PortsList Containing basic ports along with node-specific ports | ||
*/ | ||
static BT::PortsList providedPorts() | ||
{ | ||
return providedBasicPorts( | ||
{ | ||
BT::InputPort<double>("time_allowance", 10.0, "Allowed time for running assisted teleop"), | ||
BT::InputPort<bool>("is_recovery", false, "If true the recovery count will be incremented") | ||
}); | ||
} | ||
|
||
private: | ||
bool is_recovery_; | ||
}; | ||
|
||
} // namespace nav2_behavior_tree | ||
|
||
#endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__ASSISTED_TELEOP_ACTION_HPP_ |
59 changes: 59 additions & 0 deletions
59
nav2_behavior_tree/include/nav2_behavior_tree/plugins/action/assisted_teleop_cancel_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,59 @@ | ||
// Copyright (c) 2022 Joshua Wallace | ||
// | ||
// 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__PLUGINS__ACTION__ASSISTED_TELEOP_CANCEL_NODE_HPP_ | ||
#define NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__ASSISTED_TELEOP_CANCEL_NODE_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "nav2_msgs/action/assisted_teleop.hpp" | ||
|
||
#include "nav2_behavior_tree/bt_cancel_action_node.hpp" | ||
|
||
namespace nav2_behavior_tree | ||
{ | ||
|
||
/** | ||
* @brief A nav2_behavior_tree::BtActionNode class that wraps nav2_msgs::action::BackUp | ||
*/ | ||
class AssistedTeleopCancel : public BtCancelActionNode<nav2_msgs::action::AssistedTeleop> | ||
{ | ||
public: | ||
/** | ||
* @brief A constructor for nav2_behavior_tree::BackUpAction | ||
* @param xml_tag_name Name for the XML tag for this node | ||
* @param action_name Action name this node creates a client for | ||
* @param conf BT node configuration | ||
*/ | ||
AssistedTeleopCancel( | ||
const std::string & xml_tag_name, | ||
const std::string & action_name, | ||
const BT::NodeConfiguration & conf); | ||
|
||
/** | ||
* @brief Creates list of BT ports | ||
* @return BT::PortsList Containing basic ports along with node-specific ports | ||
*/ | ||
static BT::PortsList providedPorts() | ||
{ | ||
return providedBasicPorts( | ||
{ | ||
}); | ||
} | ||
}; | ||
|
||
} // namespace nav2_behavior_tree | ||
|
||
#endif // NAV2_BEHAVIOR_TREE__PLUGINS__ACTION__ASSISTED_TELEOP_CANCEL_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
62 changes: 62 additions & 0 deletions
62
nav2_behavior_tree/plugins/action/assisted_teleop_action.cpp
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,62 @@ | ||
// Copyright (c) 2022 Joshua Wallace | ||
// | ||
// 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 <string> | ||
#include <memory> | ||
|
||
#include "nav2_behavior_tree/plugins/action/assisted_teleop_action.hpp" | ||
|
||
namespace nav2_behavior_tree | ||
{ | ||
|
||
AssistedTeleopAction::AssistedTeleopAction( | ||
const std::string & xml_tag_name, | ||
const std::string & action_name, | ||
const BT::NodeConfiguration & conf) | ||
: BtActionNode<nav2_msgs::action::AssistedTeleop>(xml_tag_name, action_name, conf) | ||
{ | ||
double time_allowance; | ||
getInput("time_allowance", time_allowance); | ||
getInput("is_recovery", is_recovery_); | ||
|
||
// Populate the input message | ||
goal_.time_allowance = rclcpp::Duration::from_seconds(time_allowance); | ||
} | ||
|
||
void AssistedTeleopAction::on_tick() | ||
{ | ||
if (is_recovery_) { | ||
increment_recovery_count(); | ||
} | ||
} | ||
|
||
BT::NodeStatus AssistedTeleopAction::on_aborted() | ||
{ | ||
return is_recovery_ ? BT::NodeStatus::FAILURE : BT::NodeStatus::SUCCESS; | ||
} | ||
|
||
} // namespace nav2_behavior_tree | ||
|
||
#include "behaviortree_cpp_v3/bt_factory.h" | ||
BT_REGISTER_NODES(factory) | ||
{ | ||
BT::NodeBuilder builder = | ||
[](const std::string & name, const BT::NodeConfiguration & config) | ||
{ | ||
return std::make_unique<nav2_behavior_tree::AssistedTeleopAction>( | ||
name, "assisted_teleop", config); | ||
}; | ||
|
||
factory.registerBuilder<nav2_behavior_tree::AssistedTeleopAction>("AssistedTeleop", builder); | ||
} |
47 changes: 47 additions & 0 deletions
47
nav2_behavior_tree/plugins/action/assisted_teleop_cancel_node.cpp
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,47 @@ | ||
// Copyright (c) 2022 Joshua Wallace | ||
// | ||
// 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 <string> | ||
#include <memory> | ||
|
||
#include "std_msgs/msg/string.hpp" | ||
|
||
#include "nav2_behavior_tree/plugins/action/assisted_teleop_cancel_node.hpp" | ||
|
||
namespace nav2_behavior_tree | ||
{ | ||
|
||
AssistedTeleopCancel::AssistedTeleopCancel( | ||
const std::string & xml_tag_name, | ||
const std::string & action_name, | ||
const BT::NodeConfiguration & conf) | ||
: BtCancelActionNode<nav2_msgs::action::AssistedTeleop>(xml_tag_name, action_name, conf) | ||
{ | ||
} | ||
|
||
} // namespace nav2_behavior_tree | ||
|
||
#include "behaviortree_cpp_v3/bt_factory.h" | ||
BT_REGISTER_NODES(factory) | ||
{ | ||
BT::NodeBuilder builder = | ||
[](const std::string & name, const BT::NodeConfiguration & config) | ||
{ | ||
return std::make_unique<nav2_behavior_tree::AssistedTeleopCancel>( | ||
name, "assisted_teleop", config); | ||
}; | ||
|
||
factory.registerBuilder<nav2_behavior_tree::AssistedTeleopCancel>( | ||
"CancelAssistedTeleop", builder); | ||
} |
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
Oops, something went wrong.