Skip to content

Commit 6aa9eb6

Browse files
committed
Rebase from 'upstream'
1 parent fa7f099 commit 6aa9eb6

File tree

14 files changed

+231
-42
lines changed

14 files changed

+231
-42
lines changed

CHANGELOG.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@
22
Changelog for package behaviortree_cpp
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
3.8.7 (2024-06-26)
6+
------------------
7+
* Backport of some build-related flatbuffers changes (`#825 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/825>`_)
8+
* From flatbuffers upstream: Fix compiler error
9+
Original author of change: avaliente-bc
10+
Backport/update from upstream flatbuffers repository.
11+
Change taken from https://github.com/google/flatbuffers/pull/7227
12+
* From flatbuffers upstream: Fix include of string_view with C++17 abseil
13+
Original author of change: ocpalo
14+
Backport/update from upstream flatbuffers repository.
15+
Changes taken from https://github.com/google/flatbuffers/pull/7897.
16+
* Add in call to ament_export_targets. (`#826 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/826>`_)
17+
That way downstream ament packages can use this
18+
package as a CMake target.
19+
* Fixed `#810 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/810>`_ - halting of subsequent nodes in ReactiveSequence/Fallback (`#817 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/817>`_)
20+
* ReactiveSequence and ReactiveFallback will behave more similarly to 3.8
21+
* Reactive Sequence/Fallback defaulting to allow multiple async nodes
22+
---------
23+
Co-authored-by: Davide Faconti <[email protected]>
24+
Co-authored-by: Matej Vargovcik <[email protected]>
25+
* Merge pull request `#769 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/769>`_ from bi0ha2ard/fewer_boost_dependencies
26+
depend only on libboost-coroutine(-dev) for v3.8
27+
* fix(dependency): depend only on libboost-coroutine(-dev)
28+
At least on Ubuntu, boost-all-dev depends on openmpi, which depends on a
29+
fortran compiler and gcc. This is very heavy for Docker containers where
30+
only exec dependencies are really needed.
31+
* alternative to `#719 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/719>`_
32+
* fix issue `#725 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/725>`_ : SetBlackboard can copy entries
33+
* Contributors: Chris Lalancette, Davide Faconti, Felix, Lars Toenning, afrixs
34+
535
3.8.5 (2023-08-14)
636
------------------
737

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ if(ament_cmake_FOUND)
250250

251251
ament_export_include_directories(include)
252252
ament_export_libraries(${BEHAVIOR_TREE_LIBRARY})
253+
ament_export_targets(${BEHAVIOR_TREE_LIBRARY}Targets)
253254
ament_package()
254255
elseif(catkin_FOUND)
255256

include/behaviortree_cpp_v3/actions/set_blackboard_node.h

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ namespace BT
2626
* <SetBlackboard value="42" output_key="the_answer" />
2727
*
2828
* Will store the string "42" in the entry with key "the_answer".
29+
*
30+
* Alternatively, you can use it to copy one port inside another port:
31+
*
32+
* <SetBlackboard value="{src_port}" output_key="dst_port" />
33+
*
34+
* This will copy the type and content of {src_port} into {dst_port}
2935
*/
3036
class SetBlackboard : public SyncActionNode
3137
{
@@ -38,26 +44,45 @@ class SetBlackboard : public SyncActionNode
3844

3945
static PortsList providedPorts()
4046
{
41-
return {InputPort("value", "Value represented as a string. convertFromString must be "
42-
"implemented."),
47+
return {InputPort("value", "Value to be written int othe output_key"),
4348
BidirectionalPort("output_key", "Name of the blackboard entry where the "
44-
"value "
45-
"should be written")};
49+
"value should be written")};
4650
}
4751

4852
private:
4953
virtual BT::NodeStatus tick() override
5054
{
51-
std::string key, value;
52-
if (!getInput("output_key", key))
55+
std::string output_key;
56+
if (!getInput("output_key", output_key))
5357
{
5458
throw RuntimeError("missing port [output_key]");
5559
}
56-
if (!getInput("value", value))
60+
61+
const std::string value_str = config().input_ports.at("value");
62+
63+
if(isBlackboardPointer(value_str))
5764
{
58-
throw RuntimeError("missing port [value]");
65+
StringView stripped_key = stripBlackboardPointer(value_str);
66+
const auto input_key = std::string(stripped_key);
67+
std::shared_ptr<Blackboard::Entry> src_entry = config().blackboard->getEntry(input_key);
68+
std::shared_ptr<Blackboard::Entry> dst_entry = config().blackboard->getEntry(output_key);
69+
70+
if(!src_entry)
71+
{
72+
throw RuntimeError("Can't find the port referred by [value]");
73+
}
74+
if(!dst_entry)
75+
{
76+
config().blackboard->createEntry(output_key, src_entry->port_info);
77+
dst_entry = config().blackboard->getEntry(output_key);
78+
}
79+
dst_entry->value = src_entry->value;
80+
}
81+
else
82+
{
83+
config().blackboard->set(output_key, value_str);
5984
}
60-
setOutput("output_key", value);
85+
6186
return NodeStatus::SUCCESS;
6287
}
6388
};

include/behaviortree_cpp_v3/basic_types.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ using Optional = nonstd::expected<T, std::string>;
216216
* */
217217
using Result = Optional<void>;
218218

219-
const std::unordered_set<std::string> ReservedPortNames = {"ID", "name", "_description"};
219+
inline bool IsReservedPortname(StringView name)
220+
{
221+
return name == "ID" || name == "name" || name == "_description";
222+
}
223+
220224

221225
class PortInfo
222226
{
@@ -271,7 +275,7 @@ std::pair<std::string, PortInfo> CreatePort(PortDirection direction, StringView
271275
StringView description = {})
272276
{
273277
auto sname = static_cast<std::string>(name);
274-
if (ReservedPortNames.count(sname) != 0)
278+
if (IsReservedPortname(sname))
275279
{
276280
throw std::runtime_error("A port can not use a reserved name. See ReservedPortNames");
277281
}

include/behaviortree_cpp_v3/blackboard.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ class Blackboard
178178
createEntryImpl(key, info);
179179
}
180180

181-
private:
182181
struct Entry
183182
{
184183
Any value;
@@ -188,10 +187,18 @@ class Blackboard
188187
{}
189188

190189
Entry(Any&& other_any, const PortInfo& info) :
191-
value(std::move(other_any)), port_info(info)
190+
value(std::move(other_any)), port_info(info)
192191
{}
193192
};
194193

194+
std::shared_ptr<Entry> getEntry(const std::string& key) const
195+
{
196+
auto it = storage_.find(key);
197+
return it == storage_.end() ? std::shared_ptr<Entry>() : it->second;
198+
}
199+
200+
private:
201+
195202
std::shared_ptr<Entry> createEntryImpl(const std::string& key, const PortInfo& info);
196203

197204
mutable std::mutex mutex_;

include/behaviortree_cpp_v3/controls/reactive_fallback.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,19 @@ class ReactiveFallback : public ControlNode
3636
ReactiveFallback(const std::string& name) : ControlNode(name, {})
3737
{}
3838

39+
/** A ReactiveFallback is not supposed to have more than a single
40+
* anychronous node; if it does an exception is thrown.
41+
* You can disabled that check, if you know what you are doing.
42+
*/
43+
static void EnableException(bool enable);
44+
3945
private:
40-
virtual BT::NodeStatus tick() override;
46+
BT::NodeStatus tick() override;
47+
48+
void halt() override;
49+
50+
int running_child_ = -1;
51+
static bool throw_if_multiple_running;
4152
};
4253

4354
} // namespace BT

include/behaviortree_cpp_v3/controls/reactive_sequence.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,20 @@ class ReactiveSequence : public ControlNode
3636
ReactiveSequence(const std::string& name) : ControlNode(name, {})
3737
{}
3838

39+
/** A ReactiveSequence is not supposed to have more than a single
40+
* anychronous node; if it does an exception is thrown.
41+
* You can disabled that check, if you know what you are doing.
42+
*/
43+
static void EnableException(bool enable);
44+
3945
private:
40-
virtual BT::NodeStatus tick() override;
46+
BT::NodeStatus tick() override;
47+
48+
void halt() override;
49+
50+
int running_child_ = -1;
51+
52+
static bool throw_if_multiple_running;
4153
};
4254

4355
} // namespace BT

include/behaviortree_cpp_v3/flatbuffers/base.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,17 @@ namespace flatbuffers {
237237
}
238238
#define FLATBUFFERS_HAS_STRING_VIEW 1
239239
// Check for absl::string_view
240-
#elif __has_include("absl/strings/string_view.h")
241-
#include "absl/strings/string_view.h"
242-
namespace flatbuffers {
243-
typedef absl::string_view string_view;
244-
}
245-
#define FLATBUFFERS_HAS_STRING_VIEW 1
240+
#elif __has_include("absl/strings/string_view.h") && \
241+
__has_include("absl/base/config.h") && \
242+
(__cplusplus >= 201411)
243+
#include "absl/base/config.h"
244+
#if !defined(ABSL_USES_STD_STRING_VIEW)
245+
#include "absl/strings/string_view.h"
246+
namespace flatbuffers {
247+
typedef absl::string_view string_view;
248+
}
249+
#define FLATBUFFERS_HAS_STRING_VIEW 1
250+
#endif
246251
#endif
247252
#endif // __has_include
248253
#endif // !FLATBUFFERS_HAS_STRING_VIEW

include/behaviortree_cpp_v3/flatbuffers/stl_emulation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ class span FLATBUFFERS_FINAL_CLASS {
625625
private:
626626
// This is a naive implementation with 'count_' member even if (Extent != dynamic_extent).
627627
pointer const data_;
628-
const size_type count_;
628+
size_type count_;
629629
};
630630

631631
#if !defined(FLATBUFFERS_SPAN_MINIMAL)

package.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<package format="3">
33
<name>behaviortree_cpp_v3</name>
4-
<version>3.8.6</version>
4+
<version>3.8.7</version>
55
<description>
66
This package provides the Behavior Trees core library.
77
</description>
@@ -22,7 +22,8 @@
2222
<depend condition="$ROS_VERSION == 2">rclcpp</depend>
2323
<depend condition="$ROS_VERSION == 2">ament_index_cpp</depend>
2424

25-
<depend>boost</depend>
25+
<build_depend>libboost-coroutine-dev</build_depend>
26+
<exec_depend>libboost-coroutine</exec_depend>
2627
<depend>libzmq3-dev</depend>
2728
<depend>libncurses-dev</depend>
2829

src/controls/reactive_fallback.cpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@
1414

1515
namespace BT
1616
{
17+
18+
bool ReactiveFallback::throw_if_multiple_running = false;
19+
20+
void ReactiveFallback::EnableException(bool enable)
21+
{
22+
ReactiveFallback::throw_if_multiple_running = enable;
23+
}
24+
1725
NodeStatus ReactiveFallback::tick()
1826
{
1927
size_t failure_count = 0;
28+
if(status() == NodeStatus::IDLE)
29+
{
30+
running_child_ = -1;
31+
}
32+
setStatus(NodeStatus::RUNNING);
2033

2134
for (size_t index = 0; index < childrenCount(); index++)
2235
{
@@ -26,12 +39,23 @@ NodeStatus ReactiveFallback::tick()
2639
switch (child_status)
2740
{
2841
case NodeStatus::RUNNING: {
29-
30-
// reset the previous children, to make sure that they are in IDLE state
31-
// the next time we tick them
32-
for (size_t i = 0; i < index; i++)
42+
// reset the previous children, to make sure that they are
43+
// in IDLE state the next time we tick them
44+
for (size_t i = 0; i < childrenCount(); i++)
3345
{
34-
haltChild(i);
46+
if(i != index)
47+
{
48+
haltChild(i);
49+
}
50+
}
51+
if(running_child_ == -1)
52+
{
53+
running_child_ = int(index);
54+
}
55+
else if(throw_if_multiple_running && running_child_ != int(index))
56+
{
57+
throw LogicError("[ReactiveFallback]: only a single child can return RUNNING.\n"
58+
"This throw can be disabled with ReactiveFallback::EnableException(false)");
3559
}
3660
return NodeStatus::RUNNING;
3761
}
@@ -61,4 +85,10 @@ NodeStatus ReactiveFallback::tick()
6185
return NodeStatus::RUNNING;
6286
}
6387

88+
void ReactiveFallback::halt()
89+
{
90+
running_child_ = -1;
91+
ControlNode::halt();
92+
}
93+
6494
} // namespace BT

src/controls/reactive_sequence.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@
1414

1515
namespace BT
1616
{
17+
18+
bool ReactiveSequence::throw_if_multiple_running = false;
19+
20+
void ReactiveSequence::EnableException(bool enable)
21+
{
22+
ReactiveSequence::throw_if_multiple_running = enable;
23+
}
24+
1725
NodeStatus ReactiveSequence::tick()
1826
{
1927
size_t success_count = 0;
28+
if(status() == NodeStatus::IDLE)
29+
{
30+
running_child_ = -1;
31+
}
32+
setStatus(NodeStatus::RUNNING);
2033

2134
for (size_t index = 0; index < childrenCount(); index++)
2235
{
@@ -26,11 +39,23 @@ NodeStatus ReactiveSequence::tick()
2639
switch (child_status)
2740
{
2841
case NodeStatus::RUNNING: {
29-
// reset the previous children, to make sure that they are in IDLE state
30-
// the next time we tick them
31-
for (size_t i = 0; i < index; i++)
42+
// reset the previous children, to make sure that they are
43+
// in IDLE state the next time we tick them
44+
for (size_t i = 0; i < childrenCount(); i++)
3245
{
33-
haltChild(i);
46+
if(i != index)
47+
{
48+
haltChild(i);
49+
}
50+
}
51+
if(running_child_ == -1)
52+
{
53+
running_child_ = int(index);
54+
}
55+
else if(throw_if_multiple_running && running_child_ != int(index))
56+
{
57+
throw LogicError("[ReactiveSequence]: only a single child can return RUNNING.\n"
58+
"This throw can be disabled with ReactiveSequence::EnableException(false)");
3459
}
3560
return NodeStatus::RUNNING;
3661
}
@@ -59,4 +84,10 @@ NodeStatus ReactiveSequence::tick()
5984
return NodeStatus::RUNNING;
6085
}
6186

87+
void ReactiveSequence::halt()
88+
{
89+
running_child_ = -1;
90+
ControlNode::halt();
91+
}
92+
6293
} // namespace BT

0 commit comments

Comments
 (0)