Skip to content

Commit b3b33e1

Browse files
committed
Merge branch 'master' of github.com:BehaviorTree/BehaviorTree.CPP
2 parents 80a581f + ca6ee34 commit b3b33e1

File tree

10 files changed

+194
-125
lines changed

10 files changed

+194
-125
lines changed

CHANGELOG.rst

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

5+
4.0.2 (2023-02-17)
6+
------------------
7+
* fix issue `#501 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/501>`_
8+
* fix issue `#505 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/505>`_
9+
* solve issue `#506 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/506>`_
10+
* prevent useless exception catcking
11+
* fix issue `#507 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/507>`_
12+
* adding the uid to the log to uniquely identify the nodes (`#502 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/502>`_)
13+
* fix in SharedLibrary and cosmetic changes to the code
14+
* using tinyxml ErrorStr() instead of ErrorName() to get more info about missing file (`#497 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/497>`_)
15+
* Fixed use of ros_pkg for ROS1 applications (`#483 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/483>`_)
16+
* Fix error message StdCoutLogger -> MinitraceLogger (`#495 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/495>`_)
17+
* Fix boost dependency in package.xml (`#493 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/493>`_)
18+
Co-authored-by: Bart Keulen <[email protected]>
19+
* support Enums in string conversion
20+
* fix issue 489
21+
* updated example. Demonstrate pass by reference
22+
* lexy updated
23+
* rename haltChildren to resetChildren
24+
* revert `#329 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/329>`_
25+
* Merge branch 'master' of github.com:BehaviorTree/BehaviorTree.CPP
26+
* Small improvements (`#479 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/479>`_)
27+
* Make message for allowed port names more explicit
28+
Also throw an exception for unknown port direction rather than using
29+
`PortDirection::INOUT`.
30+
* Small code improvements
31+
* Remove code without effect
32+
* Fix some renaming for V4 (`#480 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/480>`_)
33+
* Define NodeConfiguration for BT3 compatibility (`#477 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/477>`_)
34+
* Implement `#404 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/404>`_ to solve `#435 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/435>`_ (gtest not found)
35+
* fix issue `#474 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/474>`_ Make libraries dependencies private
36+
* fix issue `#413 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/413>`_ (Delay logic)
37+
* change suggested in `#444 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/444>`_
38+
* add XML converter
39+
* Add CodeQL workflow (`#471 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/471>`_)
40+
* Update README.md
41+
* Contributors: Ana, Bart Keulen, Christian Henkel, Davide Faconti, Gaël Écorchard, Jorge, Mahmoud Farshbafdoustar, Norawit Nangsue
42+
543
4.0.1 (2022-11-19)
644
------------------
745
* version 4.X

include/behaviortree_cpp/bt_factory.h

Lines changed: 30 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ inline NodeBuilder CreateBuilder(Args... args)
4040
}
4141

4242
template <typename T>
43-
inline TreeNodeManifest CreateManifest(const std::string& ID,
44-
PortsList portlist = getProvidedPorts<T>())
43+
inline TreeNodeManifest CreateManifest(const std::string& ID, PortsList portlist)
4544
{
4645
return {getType<T>(), ID, portlist, {}};
4746
}
@@ -300,40 +299,53 @@ class BehaviorTreeFactory
300299
const std::string& ID,
301300
const NodeConfig& config) const;
302301

303-
/** registerNodeType is the method to use to register your custom TreeNode.
304-
*
305-
* It accepts only classed derived from either ActionNodeBase, DecoratorNode,
306-
* ControlNode or ConditionNode.
307-
*/
302+
/** registerNodeType where you explicitly pass the list of ports.
303+
* Doesn't require the implementation of static method providedPorts()
304+
*/
308305
template <typename T, typename... ExtraArgs>
309-
void registerNodeType(const std::string& ID, ExtraArgs... args)
306+
void registerNodeType(const std::string& ID, const PortsList& ports, ExtraArgs... args)
310307
{
311308
static_assert(std::is_base_of<ActionNodeBase, T>::value ||
312-
std::is_base_of<ControlNode, T>::value ||
313-
std::is_base_of<DecoratorNode, T>::value ||
314-
std::is_base_of<ConditionNode, T>::value,
309+
std::is_base_of<ControlNode, T>::value ||
310+
std::is_base_of<DecoratorNode, T>::value ||
311+
std::is_base_of<ConditionNode, T>::value,
315312
"[registerNode]: accepts only classed derived from either "
316313
"ActionNodeBase, "
317314
"DecoratorNode, ControlNode or ConditionNode");
318315

319-
static_assert(!std::is_abstract<T>::value, "[registerNode]: Some methods are pure "
320-
"virtual. "
321-
"Did you override the methods tick() and "
322-
"halt()?");
323-
324316
constexpr bool default_constructable =
325317
std::is_constructible<T, const std::string&>::value;
326318
constexpr bool param_constructable =
327319
std::is_constructible<T, const std::string&, const NodeConfig&,
328320
ExtraArgs...>::value;
329-
constexpr bool has_static_ports_list = has_static_method_providedPorts<T>::value;
330321

331322
// clang-format off
323+
static_assert(!std::is_abstract<T>::value,
324+
"[registerNode]: Some methods are pure virtual. "
325+
"Did you override the methods tick() and halt()?");
326+
332327
static_assert(default_constructable || param_constructable,
333328
"[registerNode]: the registered class must have at least one of these two constructors:\n"
334329
" (const std::string&, const NodeConfig&) or (const std::string&)\n"
335330
"Check also if the constructor is public!)");
331+
// clang-format on
332+
333+
registerBuilder(CreateManifest<T>(ID, ports), CreateBuilder<T>(args...));
334+
}
335+
336+
/** registerNodeType is the method to use to register your custom TreeNode.
337+
*
338+
* It accepts only classed derived from either ActionNodeBase, DecoratorNode,
339+
* ControlNode or ConditionNode.
340+
*/
341+
template <typename T, typename... ExtraArgs>
342+
void registerNodeType(const std::string& ID, ExtraArgs... args)
343+
{
344+
constexpr bool param_constructable =
345+
std::is_constructible<T, const std::string&, const NodeConfig&, ExtraArgs...>::value;
346+
constexpr bool has_static_ports_list = has_static_method_providedPorts<T>::value;
336347

348+
// clang-format off
337349
static_assert(!(param_constructable && !has_static_ports_list),
338350
"[registerNode]: you MUST implement the static method:\n"
339351
" PortsList providedPorts();\n");
@@ -343,52 +355,7 @@ class BehaviorTreeFactory
343355
"you MUST add a constructor with signature:\n"
344356
"(const std::string&, const NodeParameters&)\n");
345357
// clang-format on
346-
347-
registerBuilder(CreateManifest<T>(ID), CreateBuilder<T>(args...));
348-
}
349-
350-
template <typename T>
351-
void registerNodeType(const std::string& ID, PortsList ports)
352-
{
353-
static_assert(std::is_base_of<ActionNodeBase, T>::value ||
354-
std::is_base_of<ControlNode, T>::value ||
355-
std::is_base_of<DecoratorNode, T>::value ||
356-
std::is_base_of<ConditionNode, T>::value,
357-
"[registerNode]: accepts only classed derived from either "
358-
"ActionNodeBase, "
359-
"DecoratorNode, ControlNode or ConditionNode");
360-
361-
static_assert(!std::is_abstract<T>::value, "[registerNode]: Some methods are pure "
362-
"virtual. "
363-
"Did you override the methods tick() and "
364-
"halt()?");
365-
366-
constexpr bool default_constructable =
367-
std::is_constructible<T, const std::string&>::value;
368-
constexpr bool param_constructable =
369-
std::is_constructible<T, const std::string&, const NodeConfig&>::value;
370-
constexpr bool has_static_ports_list = has_static_method_providedPorts<T>::value;
371-
372-
static_assert(default_constructable || param_constructable, "[registerNode]: the "
373-
"registered class must "
374-
"have at "
375-
"least one of these two "
376-
"constructors: (const "
377-
"std::string&, const "
378-
"NodeConfig&) or (const "
379-
"std::string&).");
380-
381-
static_assert(!has_static_ports_list, "[registerNode]: ports are passed to this node "
382-
"explicitly. The static method"
383-
"providedPorts() should be removed to avoid "
384-
"ambiguities\n");
385-
386-
static_assert(param_constructable, "[registerNode]: since this node has ports, "
387-
"you MUST add a constructor sign signature (const "
388-
"std::string&, const "
389-
"NodeParameters&)\n");
390-
391-
registerBuilder(CreateManifest<T>(ID, ports), CreateBuilder<T>());
358+
registerNodeType<T>(ID, getProvidedPorts<T>(), args...);
392359
}
393360

394361
/// All the builders. Made available mostly for debug purposes.

include/behaviortree_cpp/decorators/subtree_node.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,15 @@ namespace BT
5050
class SubTreeNode : public DecoratorNode
5151
{
5252
public:
53-
SubTreeNode(const std::string& instance_name);
53+
SubTreeNode(const std::string& name, const NodeConfig& config);
5454

5555
virtual ~SubTreeNode() override = default;
5656

57+
static PortsList providedPorts();
58+
5759
private:
5860
virtual BT::NodeStatus tick() override;
5961

60-
static PortsList providedPorts()
61-
{
62-
return {InputPort<bool>("_autoremap", false,
63-
"If true, all the ports with the same name will be "
64-
"remapped")};
65-
}
66-
6762
virtual NodeType type() const override final
6863
{
6964
return NodeType::SUBTREE;

include/behaviortree_cpp/scripting/operators.hpp

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -157,40 +157,49 @@ struct ExprBinaryArithmetic : ExprBase
157157
return Any(lv / rv);
158158
default: {}
159159
}
160-
try {
161-
int64_t li = lhs_v.cast<int64_t>();
162-
int64_t ri = rhs_v.cast<int64_t>();
163-
switch (op)
164-
{
165-
case bit_and:
160+
161+
if(op == bit_and || op == bit_or || op == bit_xor)
162+
{
163+
try {
164+
int64_t li = lhs_v.cast<int64_t>();
165+
int64_t ri = rhs_v.cast<int64_t>();
166+
switch (op)
167+
{
168+
case bit_and:
166169
return Any(static_cast<double>(li & ri));
167-
case bit_or:
170+
case bit_or:
168171
return Any(static_cast<double>(li | ri));
169-
case bit_xor:
172+
case bit_xor:
170173
return Any(static_cast<double>(li ^ ri));
171-
default: {}
174+
default: {}
175+
}
176+
}
177+
catch(...)
178+
{
179+
throw std::runtime_error("Binary operators are not allowed if "
180+
"one of the operands is not an integer");
172181
}
173-
}
174-
catch(...)
175-
{
176-
throw std::runtime_error("Binary operators are not allowed if one of the operands is an integer");
177182
}
178183

179-
try {
180-
auto lb = lhs_v.cast<bool>();
181-
auto rb = rhs_v.cast<bool>();
182-
switch (op)
183-
{
184-
case logic_or:
184+
if(op == logic_or || op == logic_and)
185+
{
186+
try {
187+
auto lb = lhs_v.cast<bool>();
188+
auto rb = rhs_v.cast<bool>();
189+
switch (op)
190+
{
191+
case logic_or:
185192
return Any(static_cast<double>(lb || rb));
186-
case logic_and:
193+
case logic_and:
187194
return Any(static_cast<double>(lb && rb));
188-
default: {}
195+
default: {}
196+
}
197+
}
198+
catch(...)
199+
{
200+
throw std::runtime_error("Logic operators are not allowed if "
201+
"one of the operands is not castable to bool");
189202
}
190-
}
191-
catch(...)
192-
{
193-
throw std::runtime_error("Logic operators are not allowed if one of the operands is not castable to bool");
194203
}
195204
}
196205
else if(rhs_v.isType<SimpleString>() && lhs_v.isType<SimpleString>() && op == plus)

include/behaviortree_cpp/utils/convert_impl.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ void convertNumber( const SRC& source, DST& target )
142142
// casting to/from floating points might cause truncation.
143143
else if constexpr( std::is_floating_point<SRC>::value || std::is_floating_point<DST>::value )
144144
{
145-
checkTruncation<SRC,DST>(source);
145+
bool both_float = std::is_floating_point<SRC>::value && std::is_floating_point<DST>::value;
146+
// to avoid being too pedantic, let's accept casting between double and float
147+
if(!both_float){
148+
checkTruncation<SRC,DST>(source);
149+
}
146150
target = static_cast<DST>(source);
147151
}
148152
}

include/behaviortree_cpp/utils/simple_string.hpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,23 @@ class SimpleString {
114114
return std::strcmp(data(), other.data()) > 0;
115115
}
116116

117-
bool isSOO() const { return !(_storage.soo.capacity_left & IS_LONG_BIT); }
117+
bool isSOO() const {
118+
return !(_storage.soo.capacity_left & IS_LONG_BIT);
119+
}
118120

119121
private:
120-
constexpr static std::size_t CAPACITY = sizeof(void *) * 2 - 1;
122+
123+
struct String {
124+
char *data;
125+
std::size_t size;
126+
};
127+
128+
constexpr static std::size_t CAPACITY = std::max(size_t(15), sizeof(String) - 1);
121129
constexpr static std::size_t IS_LONG_BIT = 1 << 7;
122-
constexpr static std::size_t LONG_MASK = ~(uint32_t(0));
130+
constexpr static std::size_t LONG_MASK = (~std::size_t(0)) >> 1;
123131

124132
union {
125-
struct String {
126-
char *data;
127-
std::size_t size;
128-
} str;
133+
String str;
129134

130135
struct SOO {
131136
char data[CAPACITY];

package.xml

Lines changed: 1 addition & 1 deletion
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</name>
4-
<version>4.0.1</version>
4+
<version>4.0.2</version>
55
<description>
66
This package provides the Behavior Trees core library.
77
</description>

src/decorators/subtree_node.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
#include "behaviortree_cpp/decorators/subtree_node.h"
22

3-
BT::SubTreeNode::SubTreeNode(const std::string& instance_name) :
4-
DecoratorNode(instance_name, {})
3+
BT::SubTreeNode::SubTreeNode(const std::string& name,
4+
const NodeConfig &config) :
5+
DecoratorNode(name, config)
56
{
67
setRegistrationID("SubTree");
78
}
89

10+
BT::PortsList BT::SubTreeNode::providedPorts()
11+
{
12+
auto port = PortInfo(PortDirection::INPUT, typeid(bool),
13+
GetAnyFromStringFunctor<bool>());
14+
port.setDefaultValue("false");
15+
port.setDescription("If true, all the ports with the same name "
16+
"will be remapped");
17+
18+
return {{"_autoremap", port}};
19+
}
20+
921
BT::NodeStatus BT::SubTreeNode::tick()
1022
{
1123
NodeStatus prev_status = status();

0 commit comments

Comments
 (0)