forked from BehaviorTree/BehaviorTree.CPP
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new decorators using the entry sequence, added
- Loading branch information
1 parent
22f1b62
commit 3a9784f
Showing
9 changed files
with
237 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Copyright (C) 2024 Davide Faconti - All Rights Reserved | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "behaviortree_cpp/decorator_node.h" | ||
|
||
namespace BT | ||
{ | ||
|
||
/** | ||
* @brief The SkipUnlessUpdated 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. | ||
*/ | ||
class SkipUnlessUpdated : public DecoratorNode | ||
{ | ||
public: | ||
SkipUnlessUpdated(const std::string& name, const NodeConfig& config); | ||
|
||
~SkipUnlessUpdated() override = default; | ||
|
||
static PortsList providedPorts() | ||
{ | ||
return { InputPort<BT::Any>("entry", "Skip this branch unless the blackboard value " | ||
"was updated") }; | ||
} | ||
|
||
private: | ||
int64_t sequence_id_ = -1; | ||
std::string entry_key_; | ||
bool still_executing_child_ = false; | ||
|
||
NodeStatus tick() override; | ||
|
||
void halt() override; | ||
}; | ||
|
||
} // namespace BT |
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,49 @@ | ||
/* Copyright (C) 2024 Davide Faconti - All Rights Reserved | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "behaviortree_cpp/decorator_node.h" | ||
|
||
namespace BT | ||
{ | ||
/** | ||
* @brief The WaitValueUpdate 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 RUNNING is returned. | ||
*/ | ||
class WaitValueUpdate : public DecoratorNode | ||
{ | ||
public: | ||
WaitValueUpdate(const std::string& name, const NodeConfig& config); | ||
|
||
~WaitValueUpdate() override = default; | ||
|
||
static PortsList providedPorts() | ||
{ | ||
return { InputPort<BT::Any>("entry", "Sleep until the entry in the blackboard is " | ||
"updated") }; | ||
} | ||
|
||
private: | ||
int64_t sequence_id_ = -1; | ||
std::string entry_key_; | ||
bool still_executing_child_ = false; | ||
|
||
NodeStatus tick() override; | ||
|
||
void halt() override; | ||
}; | ||
|
||
} // namespace BT |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* Copyright (C) 2024 Davide Faconti - All Rights Reserved | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "behaviortree_cpp/decorators/skip_unless_updated.h" | ||
|
||
namespace BT | ||
{ | ||
|
||
SkipUnlessUpdated::SkipUnlessUpdated(const std::string& name, const NodeConfig& config) | ||
: DecoratorNode(name, config) | ||
{ | ||
const auto entry_str = config.input_ports.at("entry"); | ||
StringView stripped_key; | ||
if(isBlackboardPointer(entry_str, &stripped_key)) | ||
{ | ||
entry_key_ = stripped_key; | ||
} | ||
else | ||
{ | ||
entry_key_ = entry_str; | ||
} | ||
} | ||
|
||
NodeStatus SkipUnlessUpdated::tick() | ||
{ | ||
// continue executing an asynchronous child | ||
if(still_executing_child_) | ||
{ | ||
auto status = child()->executeTick(); | ||
still_executing_child_ = (status == NodeStatus::RUNNING); | ||
return status; | ||
} | ||
|
||
auto entry = config().blackboard->getEntry(entry_key_); | ||
std::unique_lock lk(entry->entry_mutex); | ||
auto seq = static_cast<int64_t>(entry->sequence_id); | ||
if(seq == sequence_id_) | ||
{ | ||
return NodeStatus::SKIPPED; | ||
} | ||
sequence_id_ = seq; | ||
|
||
auto status = child()->executeTick(); | ||
still_executing_child_ = (status == NodeStatus::RUNNING); | ||
return status; | ||
} | ||
|
||
void SkipUnlessUpdated::halt() | ||
{ | ||
still_executing_child_ = false; | ||
} | ||
|
||
} // namespace BT |
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,64 @@ | ||
/* Copyright (C) 2024 Davide Faconti - All Rights Reserved | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "behaviortree_cpp/decorators/wait_update.h" | ||
|
||
namespace BT | ||
{ | ||
|
||
WaitValueUpdate::WaitValueUpdate(const std::string& name, const NodeConfig& config) | ||
: DecoratorNode(name, config) | ||
{ | ||
const auto entry_str = config.input_ports.at("entry"); | ||
StringView stripped_key; | ||
if(isBlackboardPointer(entry_str, &stripped_key)) | ||
{ | ||
entry_key_ = stripped_key; | ||
} | ||
else | ||
{ | ||
entry_key_ = entry_str; | ||
} | ||
} | ||
|
||
NodeStatus WaitValueUpdate::tick() | ||
{ | ||
// continue executing an asynchronous child | ||
if(still_executing_child_) | ||
{ | ||
auto status = child()->executeTick(); | ||
still_executing_child_ = (status == NodeStatus::RUNNING); | ||
return status; | ||
} | ||
|
||
auto entry = config().blackboard->getEntry(entry_key_); | ||
std::unique_lock lk(entry->entry_mutex); | ||
auto seq = static_cast<int64_t>(entry->sequence_id); | ||
if(seq == sequence_id_) | ||
{ | ||
return NodeStatus::RUNNING; | ||
} | ||
sequence_id_ = seq; | ||
|
||
auto status = child()->executeTick(); | ||
still_executing_child_ = (status == NodeStatus::RUNNING); | ||
return status; | ||
} | ||
|
||
void WaitValueUpdate::halt() | ||
{ | ||
still_executing_child_ = false; | ||
} | ||
|
||
} // namespace BT |