Skip to content

Commit fc041fe

Browse files
committed
remove code duplication and fix mutex deadlock
1 parent 8abc277 commit fc041fe

File tree

7 files changed

+20
-134
lines changed

7 files changed

+20
-134
lines changed

CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,12 @@ list(APPEND BT_SOURCE
9999
src/actions/sleep_node.cpp
100100

101101
src/decorators/delay_node.cpp
102+
src/decorators/entry_updated_nodes.cpp
102103
src/decorators/inverter_node.cpp
103104
src/decorators/repeat_node.cpp
104105
src/decorators/retry_node.cpp
105-
src/decorators/timeout_node.cpp
106-
src/decorators/skip_unless_updated.cpp
107106
src/decorators/subtree_node.cpp
108-
src/decorators/wait_update.cpp
107+
src/decorators/timeout_node.cpp
109108

110109
src/controls/if_then_else_node.cpp
111110
src/controls/fallback_node.cpp

include/behaviortree_cpp/behavior_tree.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
#include "behaviortree_cpp/decorators/run_once_node.h"
3434
#include "behaviortree_cpp/decorators/subtree_node.h"
3535
#include "behaviortree_cpp/decorators/loop_node.h"
36-
#include "behaviortree_cpp/decorators/skip_unless_updated.h"
37-
#include "behaviortree_cpp/decorators/wait_update.h"
36+
#include "behaviortree_cpp/decorators/entry_updated_nodes.h"
3837

3938
#include "behaviortree_cpp/actions/always_success_node.h"
4039
#include "behaviortree_cpp/actions/always_failure_node.h"

include/behaviortree_cpp/decorators/skip_unless_updated.h renamed to include/behaviortree_cpp/decorators/entry_updated_nodes.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@
1616

1717
namespace BT
1818
{
19-
2019
/**
21-
* @brief The SkipUnlessUpdated checks the Timestamp in an entry
20+
* @brief The EntryUpdatedNode checks the Timestamp in an entry
2221
* to determine if the value was updated since the last time (true,
2322
* the first time).
2423
*
25-
* If it is, the child will be executed, otherwise SKIPPED is returned.
24+
* If it is, the child will be executed, otherwise [if_not_updated] value is returned.
2625
*/
27-
class SkipUnlessUpdated : public DecoratorNode
26+
class EntryUpdatedNode : public DecoratorNode
2827
{
2928
public:
30-
SkipUnlessUpdated(const std::string& name, const NodeConfig& config);
29+
EntryUpdatedNode(const std::string& name, const NodeConfig& config,
30+
NodeStatus if_not_updated);
3131

32-
~SkipUnlessUpdated() override = default;
32+
~EntryUpdatedNode() override = default;
3333

3434
static PortsList providedPorts()
3535
{
36-
return { InputPort<BT::Any>("entry", "Skip this branch unless the blackboard value "
37-
"was updated") };
36+
return { InputPort<BT::Any>("entry", "Entry to check") };
3837
}
3938

4039
private:
4140
int64_t sequence_id_ = -1;
4241
std::string entry_key_;
4342
bool still_executing_child_ = false;
43+
NodeStatus if_not_updated_;
4444

4545
NodeStatus tick() override;
4646

include/behaviortree_cpp/decorators/wait_update.h

-49
This file was deleted.

src/bt_factory.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ BehaviorTreeFactory::BehaviorTreeFactory() : _p(new PImpl)
9595
registerNodeType<LoopNode<double>>("LoopDouble");
9696
registerNodeType<LoopNode<std::string>>("LoopString");
9797

98-
registerNodeType<SkipUnlessUpdated>("SkipUnlessUpdated");
99-
registerNodeType<WaitValueUpdate>("WaitValueUpdate");
98+
registerNodeType<EntryUpdatedNode>("SkipUnlessUpdated", NodeStatus::SKIPPED);
99+
registerNodeType<EntryUpdatedNode>("WaitValueUpdate", NodeStatus::RUNNING);
100100

101101
for(const auto& it : _p->builders)
102102
{

src/decorators/skip_unless_updated.cpp renamed to src/decorators/entry_updated_nodes.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
* 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.
1111
*/
1212

13-
#include "behaviortree_cpp/decorators/skip_unless_updated.h"
13+
#include "behaviortree_cpp/decorators/entry_updated_nodes.h"
1414

1515
namespace BT
1616
{
1717

18-
SkipUnlessUpdated::SkipUnlessUpdated(const std::string& name, const NodeConfig& config)
19-
: DecoratorNode(name, config)
18+
EntryUpdatedNode::EntryUpdatedNode(const std::string& name, const NodeConfig& config,
19+
NodeStatus if_not_updated)
20+
: DecoratorNode(name, config), if_not_updated_(if_not_updated)
2021
{
2122
const auto entry_str = config.input_ports.at("entry");
2223
StringView stripped_key;
@@ -30,7 +31,7 @@ SkipUnlessUpdated::SkipUnlessUpdated(const std::string& name, const NodeConfig&
3031
}
3132
}
3233

33-
NodeStatus SkipUnlessUpdated::tick()
34+
NodeStatus EntryUpdatedNode::tick()
3435
{
3536
// continue executing an asynchronous child
3637
if(still_executing_child_)
@@ -46,7 +47,7 @@ NodeStatus SkipUnlessUpdated::tick()
4647
auto seq = static_cast<int64_t>(entry->sequence_id);
4748
if(seq == sequence_id_)
4849
{
49-
return NodeStatus::SKIPPED;
50+
return if_not_updated_;
5051
}
5152
sequence_id_ = seq;
5253
}
@@ -56,7 +57,7 @@ NodeStatus SkipUnlessUpdated::tick()
5657
return status;
5758
}
5859

59-
void SkipUnlessUpdated::halt()
60+
void EntryUpdatedNode::halt()
6061
{
6162
still_executing_child_ = false;
6263
}

src/decorators/wait_update.cpp

-64
This file was deleted.

0 commit comments

Comments
 (0)