Skip to content

Commit

Permalink
remove code duplication and fix mutex deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Apr 24, 2024
1 parent 8abc277 commit fc041fe
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 134 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ list(APPEND BT_SOURCE
src/actions/sleep_node.cpp

src/decorators/delay_node.cpp
src/decorators/entry_updated_nodes.cpp
src/decorators/inverter_node.cpp
src/decorators/repeat_node.cpp
src/decorators/retry_node.cpp
src/decorators/timeout_node.cpp
src/decorators/skip_unless_updated.cpp
src/decorators/subtree_node.cpp
src/decorators/wait_update.cpp
src/decorators/timeout_node.cpp

src/controls/if_then_else_node.cpp
src/controls/fallback_node.cpp
Expand Down
3 changes: 1 addition & 2 deletions include/behaviortree_cpp/behavior_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
#include "behaviortree_cpp/decorators/run_once_node.h"
#include "behaviortree_cpp/decorators/subtree_node.h"
#include "behaviortree_cpp/decorators/loop_node.h"
#include "behaviortree_cpp/decorators/skip_unless_updated.h"
#include "behaviortree_cpp/decorators/wait_update.h"
#include "behaviortree_cpp/decorators/entry_updated_nodes.h"

#include "behaviortree_cpp/actions/always_success_node.h"
#include "behaviortree_cpp/actions/always_failure_node.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@

namespace BT
{

/**
* @brief The SkipUnlessUpdated checks the Timestamp in an entry
* @brief The EntryUpdatedNode checks the Timestamp in an entry
* to determine if the value was updated since the last time (true,
* the first time).
*
* If it is, the child will be executed, otherwise SKIPPED is returned.
* If it is, the child will be executed, otherwise [if_not_updated] value is returned.
*/
class SkipUnlessUpdated : public DecoratorNode
class EntryUpdatedNode : public DecoratorNode
{
public:
SkipUnlessUpdated(const std::string& name, const NodeConfig& config);
EntryUpdatedNode(const std::string& name, const NodeConfig& config,
NodeStatus if_not_updated);

~SkipUnlessUpdated() override = default;
~EntryUpdatedNode() override = default;

static PortsList providedPorts()
{
return { InputPort<BT::Any>("entry", "Skip this branch unless the blackboard value "
"was updated") };
return { InputPort<BT::Any>("entry", "Entry to check") };
}

private:
int64_t sequence_id_ = -1;
std::string entry_key_;
bool still_executing_child_ = false;
NodeStatus if_not_updated_;

NodeStatus tick() override;

Expand Down
49 changes: 0 additions & 49 deletions include/behaviortree_cpp/decorators/wait_update.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/bt_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ BehaviorTreeFactory::BehaviorTreeFactory() : _p(new PImpl)
registerNodeType<LoopNode<double>>("LoopDouble");
registerNodeType<LoopNode<std::string>>("LoopString");

registerNodeType<SkipUnlessUpdated>("SkipUnlessUpdated");
registerNodeType<WaitValueUpdate>("WaitValueUpdate");
registerNodeType<EntryUpdatedNode>("SkipUnlessUpdated", NodeStatus::SKIPPED);
registerNodeType<EntryUpdatedNode>("WaitValueUpdate", NodeStatus::RUNNING);

for(const auto& it : _p->builders)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "behaviortree_cpp/decorators/skip_unless_updated.h"
#include "behaviortree_cpp/decorators/entry_updated_nodes.h"

namespace BT
{

SkipUnlessUpdated::SkipUnlessUpdated(const std::string& name, const NodeConfig& config)
: DecoratorNode(name, config)
EntryUpdatedNode::EntryUpdatedNode(const std::string& name, const NodeConfig& config,
NodeStatus if_not_updated)
: DecoratorNode(name, config), if_not_updated_(if_not_updated)
{
const auto entry_str = config.input_ports.at("entry");
StringView stripped_key;
Expand All @@ -30,7 +31,7 @@ SkipUnlessUpdated::SkipUnlessUpdated(const std::string& name, const NodeConfig&
}
}

NodeStatus SkipUnlessUpdated::tick()
NodeStatus EntryUpdatedNode::tick()
{
// continue executing an asynchronous child
if(still_executing_child_)
Expand All @@ -46,7 +47,7 @@ NodeStatus SkipUnlessUpdated::tick()
auto seq = static_cast<int64_t>(entry->sequence_id);
if(seq == sequence_id_)
{
return NodeStatus::SKIPPED;
return if_not_updated_;
}
sequence_id_ = seq;
}
Expand All @@ -56,7 +57,7 @@ NodeStatus SkipUnlessUpdated::tick()
return status;
}

void SkipUnlessUpdated::halt()
void EntryUpdatedNode::halt()
{
still_executing_child_ = false;
}
Expand Down
64 changes: 0 additions & 64 deletions src/decorators/wait_update.cpp

This file was deleted.

0 comments on commit fc041fe

Please sign in to comment.