Skip to content

Commit cc77171

Browse files
committed
backporting changes from v4.x
1 parent d23578b commit cc77171

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+156
-191
lines changed

include/behaviortree_cpp_v3/action_node.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ namespace BT
2525
{
2626

2727
// IMPORTANT: Actions which returned SUCCESS or FAILURE will not be ticked
28-
// again unless setStatus(IDLE) is called first.
28+
// again unless resetStatus() is called first.
2929
// Keep this in mind when writing your custom Control and Decorator nodes.
3030

31-
3231
/**
3332
* @brief The ActionNodeBase is the base class to use to create any kind of action.
3433
* A particular derived class is free to override executeTick() as needed.
@@ -64,9 +63,7 @@ class SyncActionNode : public ActionNodeBase
6463

6564
/// You don't need to override this
6665
virtual void halt() override final
67-
{
68-
setStatus(NodeStatus::IDLE);
69-
}
66+
{ }
7067
};
7168

7269
/**
@@ -140,7 +137,7 @@ class AsyncActionNode : public ActionNodeBase
140137
std::exception_ptr exptr_;
141138
std::atomic_bool halt_requested_;
142139
std::future<void> thread_handle_;
143-
std::mutex m_;
140+
std::mutex mutex_;
144141
};
145142

146143
/**

include/behaviortree_cpp_v3/actions/always_failure_node.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
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-
#ifndef ACTION_ALWAYS_FAILURE_NODE_H
14-
#define ACTION_ALWAYS_FAILURE_NODE_H
13+
#pragma once
1514

1615
#include "behaviortree_cpp_v3/action_node.h"
1716

@@ -37,4 +36,3 @@ class AlwaysFailureNode : public SyncActionNode
3736
};
3837
}
3938

40-
#endif

include/behaviortree_cpp_v3/actions/always_success_node.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
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-
#ifndef ACTION_ALWAYS_SUCCESS_NODE_H
14-
#define ACTION_ALWAYS_SUCCESS_NODE_H
13+
#pragma once
1514

1615
#include "behaviortree_cpp_v3/action_node.h"
1716

@@ -37,4 +36,3 @@ class AlwaysSuccessNode : public SyncActionNode
3736
};
3837
}
3938

40-
#endif

include/behaviortree_cpp_v3/actions/pop_from_queue.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2018-2022 Davide Faconti, Eurecat - All Rights Reserved
1+
/* Copyright (C) 2022 Davide Faconti - All Rights Reserved
22
*
33
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
44
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
@@ -10,9 +10,7 @@
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-
14-
#ifndef BEHAVIORTREE_POPFROMQUEUE_HPP
15-
#define BEHAVIORTREE_POPFROMQUEUE_HPP
13+
#pragma once
1614

1715
#include <list>
1816
#include <mutex>
@@ -145,4 +143,3 @@ class QueueSize : public SyncActionNode
145143

146144
}
147145

148-
#endif // BEHAVIORTREE_POPFROMQUEUE_HPP

include/behaviortree_cpp_v3/basic_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ enum class NodeStatus
4040
FAILURE
4141
};
4242

43+
inline bool StatusCompleted(const NodeStatus& status)
44+
{
45+
return status == NodeStatus::SUCCESS ||
46+
status == NodeStatus::FAILURE;
47+
}
48+
4349
enum class PortDirection{
4450
INPUT,
4551
OUTPUT,

include/behaviortree_cpp_v3/behavior_tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ inline NodeType getType()
8989
return NodeType::UNDEFINED;
9090
// clang-format on
9191
}
92+
9293
}
9394

9495
#endif // BEHAVIOR_TREE_H

include/behaviortree_cpp_v3/blackboard.h

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Blackboard
5151
const Any* getAny(const std::string& key) const
5252
{
5353
std::unique_lock<std::mutex> lock(mutex_);
54-
54+
// search first if this port was remapped
5555
if( auto parent = parent_bb_.lock())
5656
{
5757
auto remapping_it = internal_to_external_.find(key);
@@ -67,7 +67,7 @@ class Blackboard
6767
Any* getAny(const std::string& key)
6868
{
6969
std::unique_lock<std::mutex> lock(mutex_);
70-
70+
// search first if this port was remapped
7171
if( auto parent = parent_bb_.lock())
7272
{
7373
auto remapping_it = internal_to_external_.find(key);
@@ -118,39 +118,33 @@ class Blackboard
118118
{
119119
std::unique_lock<std::mutex> lock_entry(entry_mutex_);
120120
std::unique_lock<std::mutex> lock(mutex_);
121-
auto it = storage_.find(key);
122121

123-
if( auto parent = parent_bb_.lock())
122+
// search first if this port was remapped.
123+
// Change the parent_bb_ in that case
124+
auto remapping_it = internal_to_external_.find(key);
125+
if( remapping_it != internal_to_external_.end())
124126
{
125-
auto remapping_it = internal_to_external_.find(key);
126-
if( remapping_it != internal_to_external_.end())
127+
const auto& remapped_key = remapping_it->second;
128+
if( auto parent = parent_bb_.lock())
127129
{
128-
const auto& remapped_key = remapping_it->second;
129-
if( it == storage_.end() ) // virgin entry
130-
{
131-
auto parent_info = parent->portInfo(remapped_key);
132-
if( parent_info )
133-
{
134-
storage_.emplace( key, Entry( *parent_info ) );
135-
}
136-
else{
137-
storage_.emplace( key, Entry( PortInfo() ) );
138-
}
139-
}
140130
parent->set( remapped_key, value );
141131
return;
142132
}
143133
}
144134

145-
if( it != storage_.end() ) // already there. check the type
135+
// check local storage
136+
auto it = storage_.find(key);
137+
if( it != storage_.end() )
146138
{
147139
const PortInfo& port_info = it->second.port_info;
148140
auto& previous_any = it->second.value;
149-
const auto locked_type = port_info.type();
141+
const auto previous_type = port_info.type();
150142

151-
Any temp(value);
143+
Any new_value(value);
152144

153-
if( locked_type && *locked_type != typeid(T) && *locked_type != temp.type() )
145+
if( previous_type &&
146+
*previous_type != typeid(T) &&
147+
*previous_type != new_value.type() )
154148
{
155149
bool mismatching = true;
156150
if( std::is_constructible<StringView, T>::value )
@@ -159,7 +153,7 @@ class Blackboard
159153
if( any_from_string.empty() == false)
160154
{
161155
mismatching = false;
162-
temp = std::move( any_from_string );
156+
new_value = std::move( any_from_string );
163157
}
164158
}
165159

@@ -168,11 +162,11 @@ class Blackboard
168162
debugMessage();
169163

170164
throw LogicError( "Blackboard::set() failed: once declared, the type of a port shall not change. "
171-
"Declared type [", demangle( locked_type ),
172-
"] != current type [", demangle( typeid(T) ),"]" );
165+
"Declared type [", BT::demangle(previous_type),
166+
"] != current type [", BT::demangle(typeid(T)),"]" );
173167
}
174168
}
175-
previous_any = std::move(temp);
169+
previous_any = std::move(new_value);
176170
}
177171
else{ // create for the first time without any info
178172
storage_.emplace( key, Entry( Any(value), PortInfo() ) );
@@ -201,7 +195,7 @@ class Blackboard
201195
// done using the value.
202196
std::mutex& entryMutex()
203197
{
204-
return entry_mutex_;
198+
return entry_mutex_;
205199
}
206200

207201
private:

include/behaviortree_cpp_v3/bt_parser.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
#ifndef PARSING_BT_H
2-
#define PARSING_BT_H
1+
/* Copyright (C) 2022 Davide Faconti - All Rights Reserved
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4+
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5+
* 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:
6+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9+
* 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,
10+
* 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.
11+
*/
12+
13+
14+
#pragma once
315

416
#include "behaviortree_cpp_v3/bt_factory.h"
517
#include "behaviortree_cpp_v3/blackboard.h"
@@ -32,4 +44,3 @@ class Parser
3244

3345
}
3446

35-
#endif // PARSING_BT_H

include/behaviortree_cpp_v3/condition_node.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ class ConditionNode : public LeafNode
2626
virtual ~ConditionNode() override = default;
2727

2828
//Do nothing
29-
virtual void halt() override final
30-
{
31-
setStatus(NodeStatus::IDLE);
32-
}
29+
virtual void halt() override final {}
3330

3431
virtual NodeType type() const override final
3532
{

include/behaviortree_cpp_v3/control_node.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
* 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.
1212
*/
1313

14-
#ifndef CONTROLNODE_H
15-
#define CONTROLNODE_H
14+
#pragma once
1615

1716
#include <vector>
1817
#include "behaviortree_cpp_v3/tree_node.h"
@@ -57,4 +56,3 @@ class ControlNode : public TreeNode
5756
};
5857
}
5958

60-
#endif

0 commit comments

Comments
 (0)