Skip to content

Commit 960cb75

Browse files
Merge pull request #584 from BehaviorTree/v4.3
V4.3
2 parents 8cec462 + 36e0e72 commit 960cb75

35 files changed

+944
-575
lines changed

CHANGELOG.rst

+16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
Changelog for package behaviortree_cpp
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
Forthcoming
6+
-----------
7+
* use PImpl in multiple classes
8+
* updated FileLogger2
9+
* better error messages
10+
* blackboard refactoring to fix buggy _autoremap
11+
* improved support for default values
12+
* fix error and add nodiscard
13+
* Fix `#580 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/580>`_ : more informative error when not specializing BT::toStr
14+
* add builtin models to WriteTreeToXML
15+
* add simple example to generate logs
16+
* add Sleep Node
17+
* Fix `#271 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/271>`_: better error message
18+
* remove EOL ros2 from CI
19+
* Contributors: Davide Faconti
20+
521
4.2.1 (2023-06-07)
622
------------------
723
* Fix `#570 <https://github.com/BehaviorTree/BehaviorTree.CPP/issues/570>`_: string_view set in blackboard

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.16.3) # version on Ubuntu Focal
22

3-
project(behaviortree_cpp VERSION 4.2.0 LANGUAGES C CXX)
3+
project(behaviortree_cpp VERSION 4.3.0 LANGUAGES C CXX)
44

55
set(CMAKE_CONFIG_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake")
66
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CONFIG_PATH}")

README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
![License MIT](https://img.shields.io/github/license/BehaviorTree/BehaviorTree.CPP?color=blue)
2-
![Version](https://img.shields.io/badge/version-4.2-blue.svg)
2+
![Version](https://img.shields.io/badge/version-4.3-blue.svg)
33
[![conan Ubuntu](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/cmake_ubuntu.yml/badge.svg)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/cmake_ubuntu.yml)
44
[![conan Windows](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/cmake_windows.yml/badge.svg)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions/workflows/cmake_windows.yml)
55
[![ros1](https://github.com/BehaviorTree/BehaviorTree.CPP/workflows/ros1/badge.svg?branch=master)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions?query=workflow%3Aros1)
66
[![ros2](https://github.com/BehaviorTree/BehaviorTree.CPP/workflows/ros2/badge.svg?branch=master)](https://github.com/BehaviorTree/BehaviorTree.CPP/actions?query=workflow%3Aros2)
77

8-
# BehaviorTree.CPP 4.2
8+
# BehaviorTree.CPP 4.3
99

1010
<p align="center"><img width=350 src="animated.svg"></p>
1111

@@ -99,11 +99,9 @@ You can contact the main author dfaconti@aurynrobotics.com to discuss your use c
9999

100100
The MIT License (MIT)
101101

102-
Copyright (c) 2014-2018 Michele Colledanchise
103-
104-
Copyright (c) 2018-2019 Davide Faconti, Eurecat
105-
106102
Copyright (c) 2019-2023 Davide Faconti
103+
Copyright (c) 2018-2019 Davide Faconti, Eurecat
104+
Copyright (c) 2014-2018 Michele Colledanchise
107105

108106
Permission is hereby granted, free of charge, to any person obtaining a copy
109107
of this software and associated documentation files (the "Software"), to deal

examples/t12_groot_howto.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int main()
7373
BT::FileLogger2 logger2(tree, "t12_logger2.btlog");
7474
// SQLite logger can save multiple sessions into the same database
7575
bool append_to_database = true;
76-
BT::SqliteLogger sqlite_logger(tree, "t12_sqlitelog.btsql", append_to_database);
76+
BT::SqliteLogger sqlite_logger(tree, "t12_sqlitelog.db3", append_to_database);
7777

7878
while(1)
7979
{

include/behaviortree_cpp/action_node.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class SyncActionNode : public ActionNodeBase
7878
class SimpleActionNode : public SyncActionNode
7979
{
8080
public:
81-
typedef std::function<NodeStatus(TreeNode&)> TickFunctor;
81+
using TickFunctor = std::function<NodeStatus(TreeNode&)>;
8282

8383
// You must provide the function to call when tick() is invoked
8484
SimpleActionNode(const std::string& name, TickFunctor tick_functor,

include/behaviortree_cpp/basic_types.h

+45-22
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,21 @@ NodeType convertFromString<NodeType>(StringView str);
130130
template <> [[nodiscard]]
131131
PortDirection convertFromString<PortDirection>(StringView str);
132132

133-
typedef std::function<Any(StringView)> StringConverter;
133+
using StringConverter = std::function<Any(StringView)>;
134134

135-
typedef std::unordered_map<const std::type_info*, StringConverter> StringConvertersMap;
135+
using StringConvertersMap = std::unordered_map<const std::type_info*, StringConverter>;
136136

137137
// helper function
138138
template <typename T> [[nodiscard]]
139139
inline StringConverter GetAnyFromStringFunctor()
140140
{
141-
return [](StringView str) { return Any(convertFromString<T>(str)); };
141+
if constexpr(std::is_constructible_v<StringView, T>)
142+
{
143+
return [](StringView str) { return Any(str); };
144+
}
145+
else {
146+
return [](StringView str) { return Any(convertFromString<T>(str)); };
147+
}
142148
}
143149

144150
template <> [[nodiscard]]
@@ -152,10 +158,17 @@ inline StringConverter GetAnyFromStringFunctor<void>()
152158
template<typename T> [[nodiscard]]
153159
std::string toStr(const T& value)
154160
{
155-
static_assert(std::is_arithmetic_v<T>,
156-
"You need a template specialization of BT::toStr() and "
157-
"it must be consistent with the implementation of BT::convertFromString");
158-
return std::to_string(value);
161+
if constexpr(!std::is_arithmetic_v<T>)
162+
{
163+
throw LogicError(
164+
StrCat("Function BT::toStr<T>() not specialized for type [",
165+
BT::demangle(typeid(T)), "],",
166+
"Implement it consistently with BT::convertFromString<T>(), "
167+
"or provide at dummy version that returns an empty string.")
168+
);
169+
} else {
170+
return std::to_string(value);
171+
}
159172
}
160173

161174
template <> [[nodiscard]]
@@ -250,11 +263,11 @@ class PortInfo
250263
};
251264

252265
PortInfo(PortDirection direction = PortDirection::INOUT) :
253-
_type(direction), _type_info(typeid(AnyTypeAllowed))
266+
type_(direction), type_info_(typeid(AnyTypeAllowed))
254267
{}
255268

256269
PortInfo(PortDirection direction, std::type_index type_info, StringConverter conv) :
257-
_type(direction), _type_info(type_info), _converter(conv)
270+
type_(direction), type_info_(type_info), converter_(conv)
258271
{}
259272

260273
[[nodiscard]] PortDirection direction() const;
@@ -274,28 +287,38 @@ class PortInfo
274287

275288
void setDescription(StringView description);
276289

277-
void setDefaultValue(StringView default_value_as_string);
290+
template <typename T>
291+
void setDefaultValue(const T& default_value) {
292+
default_value_ = Any(default_value);
293+
try{
294+
default_value_str_ = BT::toStr(default_value);
295+
}
296+
catch(LogicError&) {}
297+
}
278298

279299
[[nodiscard]] const std::string& description() const;
280300

281-
[[nodiscard]] std::optional<std::string> defaultValue() const;
301+
[[nodiscard]] const Any& defaultValue() const;
302+
303+
[[nodiscard]] const std::string& defaultValueString() const;
282304

283305
[[nodiscard]] bool isStronglyTyped() const
284306
{
285-
return _type_info != typeid(AnyTypeAllowed);
307+
return type_info_ != typeid(AnyTypeAllowed);
286308
}
287309

288310
[[nodiscard]] const StringConverter& converter() const
289311
{
290-
return _converter;
312+
return converter_;
291313
}
292314

293315
private:
294-
PortDirection _type;
295-
std::type_index _type_info;
296-
StringConverter _converter;
316+
PortDirection type_;
317+
std::type_index type_info_;
318+
StringConverter converter_;
297319
std::string description_;
298-
std::optional<std::string> default_value_;
320+
Any default_value_;
321+
std::string default_value_str_;
299322
};
300323

301324
template <typename T = PortInfo::AnyTypeAllowed> [[nodiscard]]
@@ -355,7 +378,7 @@ inline std::pair<std::string, PortInfo> InputPort(StringView name, const T& defa
355378
StringView description)
356379
{
357380
auto out = CreatePort<T>(PortDirection::INPUT, name, description);
358-
out.second.setDefaultValue(BT::toStr(default_value));
381+
out.second.setDefaultValue(default_value);
359382
return out;
360383
}
361384

@@ -365,12 +388,12 @@ inline std::pair<std::string, PortInfo> BidirectionalPort(StringView name,
365388
StringView description)
366389
{
367390
auto out = CreatePort<T>(PortDirection::INOUT, name, description);
368-
out.second.setDefaultValue(BT::toStr(default_value));
391+
out.second.setDefaultValue(default_value);
369392
return out;
370393
}
371394
//----------
372395

373-
typedef std::unordered_map<std::string, PortInfo> PortsList;
396+
using PortsList = std::unordered_map<std::string, PortInfo>;
374397

375398
template <typename T, typename = void>
376399
struct has_static_method_providedPorts : std::false_type
@@ -398,8 +421,8 @@ inline PortsList
398421
return {};
399422
}
400423

401-
typedef std::chrono::high_resolution_clock::time_point TimePoint;
402-
typedef std::chrono::high_resolution_clock::duration Duration;
424+
using TimePoint = std::chrono::high_resolution_clock::time_point;
425+
using Duration = std::chrono::high_resolution_clock::duration;
403426

404427
} // namespace BT
405428

include/behaviortree_cpp/behavior_tree.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void applyRecursiveVisitor(TreeNode* root_node,
6464
*/
6565
void printTreeRecursively(const TreeNode* root_node, std::ostream& stream = std::cout);
6666

67-
typedef std::vector<std::pair<uint16_t, uint8_t>> SerializedTreeStatus;
67+
using SerializedTreeStatus = std::vector<std::pair<uint16_t, uint8_t>>;
6868

6969
/**
7070
* @brief buildSerializedStatusSnapshot can be used to create a buffer that can be stored

0 commit comments

Comments
 (0)