Skip to content

Commit

Permalink
fix merge - update to btcpp 4
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryLeMasurier committed Apr 3, 2024
1 parent c5d833a commit af8a2aa
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 911 deletions.
91 changes: 50 additions & 41 deletions include/behaviortree_cpp/behavior_tree.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
* Copyright (C) 2018-2020 Davide Faconti, Eurecat - All Rights Reserved
* Copyright (C) 2018-2023 Davide Faconti - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Expand All @@ -11,38 +11,44 @@
* 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.
*/

#ifndef BEHAVIOR_TREE_H
#define BEHAVIOR_TREE_H

#include "behaviortree_cpp_v3/controls/parallel_node.h"
#include "behaviortree_cpp_v3/controls/reactive_sequence.h"
#include "behaviortree_cpp_v3/controls/reactive_fallback.h"
#include "behaviortree_cpp_v3/controls/fallback_node.h"
#include "behaviortree_cpp_v3/controls/sequence_node.h"
#include "behaviortree_cpp_v3/controls/sequence_star_node.h"
#include "behaviortree_cpp_v3/controls/switch_node.h"
#include "behaviortree_cpp_v3/controls/manual_node.h"
#include "behaviortree_cpp_v3/controls/if_then_else_node.h"
#include "behaviortree_cpp_v3/controls/while_do_else_node.h"

#include "behaviortree_cpp_v3/action_node.h"
#include "behaviortree_cpp_v3/condition_node.h"

#include "behaviortree_cpp_v3/decorators/inverter_node.h"
#include "behaviortree_cpp_v3/decorators/retry_node.h"
#include "behaviortree_cpp_v3/decorators/repeat_node.h"
#include "behaviortree_cpp_v3/decorators/subtree_node.h"

#include "behaviortree_cpp_v3/actions/always_success_node.h"
#include "behaviortree_cpp_v3/actions/always_failure_node.h"
#include "behaviortree_cpp_v3/actions/set_blackboard_node.h"

#include "behaviortree_cpp_v3/decorators/force_success_node.h"
#include "behaviortree_cpp_v3/decorators/force_failure_node.h"
#include "behaviortree_cpp_v3/decorators/keep_running_until_failure_node.h"
#include "behaviortree_cpp_v3/decorators/blackboard_precondition.h"
#include "behaviortree_cpp_v3/decorators/timeout_node.h"
#include "behaviortree_cpp_v3/decorators/delay_node.h"
#pragma once

#include "behaviortree_cpp/controls/parallel_node.h"
#include "behaviortree_cpp/controls/parallel_all_node.h"
#include "behaviortree_cpp/controls/reactive_sequence.h"
#include "behaviortree_cpp/controls/reactive_fallback.h"
#include "behaviortree_cpp/controls/fallback_node.h"
#include "behaviortree_cpp/controls/sequence_node.h"
#include "behaviortree_cpp/controls/sequence_with_memory_node.h"
#include "behaviortree_cpp/controls/switch_node.h"
#include "behaviortree_cpp/controls/if_then_else_node.h"
#include "behaviortree_cpp/controls/while_do_else_node.h"

#include "behaviortree_cpp/action_node.h"
#include "behaviortree_cpp/condition_node.h"

#include "behaviortree_cpp/decorators/inverter_node.h"
#include "behaviortree_cpp/decorators/retry_node.h"
#include "behaviortree_cpp/decorators/repeat_node.h"
#include "behaviortree_cpp/decorators/run_once_node.h"
#include "behaviortree_cpp/decorators/subtree_node.h"
#include "behaviortree_cpp/decorators/loop_node.h"

#include "behaviortree_cpp/actions/always_success_node.h"
#include "behaviortree_cpp/actions/always_failure_node.h"
#include "behaviortree_cpp/actions/script_condition.h"
#include "behaviortree_cpp/actions/script_node.h"
#include "behaviortree_cpp/actions/set_blackboard_node.h"
#include "behaviortree_cpp/actions/test_node.h"
#include "behaviortree_cpp/actions/sleep_node.h"
#include "behaviortree_cpp/actions/unset_blackboard_node.h"

#include "behaviortree_cpp/decorators/force_success_node.h"
#include "behaviortree_cpp/decorators/force_failure_node.h"
#include "behaviortree_cpp/decorators/keep_running_until_failure_node.h"
#include "behaviortree_cpp/decorators/script_precondition.h"
#include "behaviortree_cpp/decorators/timeout_node.h"
#include "behaviortree_cpp/decorators/delay_node.h"

#include <iostream>

Expand All @@ -60,14 +66,15 @@ void applyRecursiveVisitor(const TreeNode* root_node,
const std::function<void(const TreeNode*)>& visitor);

//Call the visitor for each node of the tree, given a root.
void applyRecursiveVisitor(TreeNode* root_node, const std::function<void(TreeNode*)>& visitor);
void applyRecursiveVisitor(TreeNode* root_node,
const std::function<void(TreeNode*)>& visitor);

/**
* Debug function to print the hierarchy of the tree. Prints to std::cout by default.
*/
void printTreeRecursively(const TreeNode* root_node, std::ostream& stream = std::cout);

typedef std::vector<std::pair<uint16_t, uint8_t>> SerializedTreeStatus;
using SerializedTreeStatus = std::vector<std::pair<uint16_t, uint8_t>>;

/**
* @brief buildSerializedStatusSnapshot can be used to create a buffer that can be stored
Expand All @@ -85,16 +92,18 @@ void buildSerializedStatusSnapshot(const TreeNode* root_node,
template <typename T>
inline NodeType getType()
{
// clang-format off
// clang-format off
if( std::is_base_of<ActionNodeBase, T>::value ) return NodeType::ACTION;
if( std::is_base_of<ConditionNode, T>::value ) return NodeType::CONDITION;
if( std::is_base_of<SubtreeNode, T>::value ) return NodeType::SUBTREE;
if( std::is_base_of<SubtreePlusNode, T>::value ) return NodeType::SUBTREE;
if( std::is_base_of<SubTreeNode, T>::value ) return NodeType::SUBTREE;
if( std::is_base_of<DecoratorNode, T>::value ) return NodeType::DECORATOR;
if( std::is_base_of<ControlNode, T>::value ) return NodeType::CONTROL;
return NodeType::UNDEFINED;
// clang-format on
}
// clang-format on
}

#endif // BEHAVIOR_TREE_H
const char* LibraryVersionString();

int LibraryVersionNumber();

} // namespace BT
7 changes: 3 additions & 4 deletions include/behaviortree_cpp/bt_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ class BehaviorTreeFactory
auto manifest = CreateManifest<T>(ID);
registerBuilder(manifest, builder);
}

/**
/**
* @brief registerSimpleAction help you register nodes of type SimpleActionNode.
*
* @param ID registration ID
Expand All @@ -245,7 +245,6 @@ class BehaviorTreeFactory
void registerSimpleAction(const std::string& ID,
const std::function<bool(TreeNode&)>& tick_bool_functor,
PortsList ports = {});

/**
* @brief registerSimpleAction help you register nodes of type SimpleActionNode.
*
Expand Down Expand Up @@ -567,4 +566,4 @@ void ImportTreeFromJSON(const nlohmann::json& json, BT::Tree& tree);

} // namespace BT

#endif // BT_FACTORY_H
#endif // BT_FACTORY_H
60 changes: 32 additions & 28 deletions include/behaviortree_cpp/control_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,54 @@
* 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.
*/

#ifndef CONTROLNODE_H
#define CONTROLNODE_H
#pragma once

#include <vector>
#include "behaviortree_cpp_v3/tree_node.h"
#include "behaviortree_cpp/tree_node.h"

namespace BT
{
class ControlNode : public TreeNode
{
protected:
std::vector<TreeNode*> children_nodes_;
protected:
std::vector<TreeNode*> children_nodes_;

public:
ControlNode(const std::string& name, const NodeConfiguration& config);
public:
ControlNode(const std::string& name, const NodeConfig& config);

virtual ~ControlNode() override = default;
virtual ~ControlNode() override = default;

/// The method used to add nodes to the children vector
void addChild(TreeNode* child);
/// The method used to add nodes to the children vector
void addChild(TreeNode* child);

size_t childrenCount() const;
void insertChildAfter(TreeNode* child, TreeNode* sibling);

const std::vector<TreeNode*>& children() const;
size_t childrenCount() const;

const TreeNode* child(size_t index) const
{
return children().at(index);
}
const std::vector<TreeNode*>& children() const;

virtual void halt() override;
const TreeNode* child(size_t index) const
{
return children().at(index);
}

void haltChildren();
virtual void halt() override;

[[deprecated( "deprecated: please use explicitly haltChildren() or haltChild(i)")]]
void haltChildren(size_t first);
/// same as resetChildren()
void haltChildren();

void haltChild(size_t i);
[[deprecated("deprecated: please use explicitly haltChildren() or haltChild(i)")]] void
haltChildren(size_t first);

virtual NodeType type() const override final
{
return NodeType::CONTROL;
}
};
}
void haltChild(size_t i);

virtual NodeType type() const override final
{
return NodeType::CONTROL;
}

#endif
/// Set the status of all children to IDLE.
/// also send a halt() signal to all RUNNING children
void resetChildren();
};
} // namespace BT
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/controls/sequence_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ class SequenceNode : public ControlNode
virtual BT::NodeStatus tick() override;
};

} // namespace BT
} // namespace BT
16 changes: 8 additions & 8 deletions include/behaviortree_cpp/decorators/retry_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ class RetryNode : public DecoratorNode

virtual void halt() override;

private:
int max_attempts_;
int try_count_;
bool all_skipped_ = true;

bool is_retrying() const {
return try_count_ > 0;
return try_count_ > 0;
}

int n_th_retry() const {
return try_count_;
return try_count_;
}

private:
int max_attempts_;
int try_count_;
bool all_skipped_ = true;

bool read_parameter_from_ports_;
static constexpr const char* NUM_ATTEMPTS = "num_attempts";

Expand All @@ -85,4 +85,4 @@ class [[deprecated("RetryUntilSuccesful was a typo and deprecated, use "
virtual ~RetryNodeTypo() override = default;
};

} // namespace BT
} // namespace BT
2 changes: 1 addition & 1 deletion include/behaviortree_cpp/loggers/bt_cout_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ class StdCoutLogger : public StatusChangeLogger

} // namespace BT

#endif // BT_COUT_LOGGER_H
#endif // BT_COUT_LOGGER_H
40 changes: 20 additions & 20 deletions include/behaviortree_cpp/tree_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,6 @@ class TreeNode
[[nodiscard]] static Expected<StringView> getRemappedKey(StringView port_name,
StringView remapped_port);

void setParent(TreeNode *parent) {
parent_ = parent;
}

TreeNode* getParent() const {
return parent_;
}

std::string short_description() const {
std::string str = name();
if (str.empty()) {
str = config().uid;
}
return str;
}

/// Notify that the tree should be ticked again()
void emitWakeUpSignal();

Expand Down Expand Up @@ -336,6 +320,22 @@ class TreeNode
}
}

void setParent(TreeNode *parent) {
parent_ = parent;
}

TreeNode* getParent() const {
return parent_;
}

std::string short_description() const {
std::string str = name();
if (str.empty()) {
str = config().uid;
}
return str;
}

protected:
friend class BehaviorTreeFactory;
friend class DecoratorNode;
Expand Down Expand Up @@ -377,12 +377,12 @@ class TreeNode
Expected<NodeStatus> checkPreConditions();
void checkPostConditions(NodeStatus status);

TreeNode *parent_;
bool failed_ = false;

/// The method used to interrupt the execution of a RUNNING node.
/// Only Async nodes that may return RUNNING should implement it.
virtual void halt() = 0;

TreeNode *parent_;
bool failed_ = false;
};

//-------------------------------------------------------
Expand Down Expand Up @@ -575,4 +575,4 @@ inline void assignDefaultRemapping(NodeConfig& config)
}
}

} // namespace BT
} // namespace BT
Loading

0 comments on commit af8a2aa

Please sign in to comment.