Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the while loop with an if statement because placing a while s… #908

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ list(APPEND BT_SOURCE
src/controls/if_then_else_node.cpp
src/controls/fallback_node.cpp
src/controls/parallel_node.cpp
src/controls/reactive_parallel_node.cpp
src/controls/parallel_all_node.cpp
src/controls/reactive_sequence.cpp
src/controls/reactive_fallback.cpp
Expand Down
124 changes: 62 additions & 62 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
include_directories( ../sample_nodes )

set(CMAKE_DEBUG_POSTFIX "")

function(CompileExample name)
add_executable(${name} ${name}.cpp )
target_link_libraries(${name} ${BTCPP_LIBRARY} bt_sample_nodes )
endfunction()


# The plugin libdummy_nodes.so can be linked statically or
# loaded dynamically at run-time.
add_executable(t01_first_tree_static t01_build_your_first_tree.cpp )
target_compile_definitions(t01_first_tree_static PRIVATE "MANUAL_STATIC_LINKING")
target_link_libraries(t01_first_tree_static ${BTCPP_LIBRARY} bt_sample_nodes )

add_executable(t01_first_tree_dynamic t01_build_your_first_tree.cpp )
target_link_libraries(t01_first_tree_dynamic ${BTCPP_LIBRARY} )

CompileExample("t02_basic_ports")
CompileExample("t03_generic_ports")
CompileExample("t04_reactive_sequence")
CompileExample("t05_crossdoor")
CompileExample("t06_subtree_port_remapping")
CompileExample("t07_load_multiple_xml")
CompileExample("t08_additional_node_args")
CompileExample("t09_scripting")
CompileExample("t10_observer")

if(BTCPP_GROOT_INTERFACE)
CompileExample("t11_groot_howto")
endif()

CompileExample("t12_default_ports")
CompileExample("t13_access_by_ref")
CompileExample("t14_subtree_model")
CompileExample("t15_nodes_mocking")
CompileExample("t16_global_blackboard")
CompileExample("t17_blackboard_backup")
CompileExample("t18_waypoints")

CompileExample("ex01_wrap_legacy")
CompileExample("ex02_runtime_ports")

if(BTCPP_SQLITE_LOGGING)
CompileExample("ex03_sqlite_log")
endif()


############ Create plugin and executor in folder plugin_example ##########

# library must be SHARED
add_library(test_plugin_action SHARED plugin_example/plugin_action.cpp )
# you must set the definition BT_PLUGIN_EXPORT
target_compile_definitions(test_plugin_action PRIVATE BT_PLUGIN_EXPORT )
# remove the "lib" prefix. Name of the file will be test_plugin_action.so
set_target_properties(test_plugin_action PROPERTIES PREFIX "")
# link dependencies as usual
target_link_libraries(test_plugin_action ${BTCPP_LIBRARY} )

add_executable(test_plugin_executor plugin_example/plugin_executor.cpp )
target_link_libraries(test_plugin_executor ${BTCPP_LIBRARY})
# include_directories( ../sample_nodes )

# set(CMAKE_DEBUG_POSTFIX "")

# function(CompileExample name)
# add_executable(${name} ${name}.cpp )
# target_link_libraries(${name} ${BTCPP_LIBRARY} bt_sample_nodes )
# endfunction()


# # The plugin libdummy_nodes.so can be linked statically or
# # loaded dynamically at run-time.
# add_executable(t01_first_tree_static t01_build_your_first_tree.cpp )
# target_compile_definitions(t01_first_tree_static PRIVATE "MANUAL_STATIC_LINKING")
# target_link_libraries(t01_first_tree_static ${BTCPP_LIBRARY} bt_sample_nodes )

# add_executable(t01_first_tree_dynamic t01_build_your_first_tree.cpp )
# target_link_libraries(t01_first_tree_dynamic ${BTCPP_LIBRARY} )

# CompileExample("t02_basic_ports")
# CompileExample("t03_generic_ports")
# CompileExample("t04_reactive_sequence")
# CompileExample("t05_crossdoor")
# CompileExample("t06_subtree_port_remapping")
# CompileExample("t07_load_multiple_xml")
# CompileExample("t08_additional_node_args")
# CompileExample("t09_scripting")
# CompileExample("t10_observer")

# if(BTCPP_GROOT_INTERFACE)
# CompileExample("t11_groot_howto")
# endif()

# CompileExample("t12_default_ports")
# CompileExample("t13_access_by_ref")
# CompileExample("t14_subtree_model")
# CompileExample("t15_nodes_mocking")
# CompileExample("t16_global_blackboard")
# CompileExample("t17_blackboard_backup")
# CompileExample("t18_waypoints")

# CompileExample("ex01_wrap_legacy")
# CompileExample("ex02_runtime_ports")

# if(BTCPP_SQLITE_LOGGING)
# CompileExample("ex03_sqlite_log")
# endif()


# ############ Create plugin and executor in folder plugin_example ##########

# # library must be SHARED
# add_library(test_plugin_action SHARED plugin_example/plugin_action.cpp )
# # you must set the definition BT_PLUGIN_EXPORT
# target_compile_definitions(test_plugin_action PRIVATE BT_PLUGIN_EXPORT )
# # remove the "lib" prefix. Name of the file will be test_plugin_action.so
# set_target_properties(test_plugin_action PROPERTIES PREFIX "")
# # link dependencies as usual
# target_link_libraries(test_plugin_action ${BTCPP_LIBRARY} )

# add_executable(test_plugin_executor plugin_example/plugin_executor.cpp )
# target_link_libraries(test_plugin_executor ${BTCPP_LIBRARY})
84 changes: 84 additions & 0 deletions include/behaviortree_cpp/controls/reactive_parallel_node.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
* Copyright (C) 2018-2022 Davide Faconti, Eurecat - 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,
* 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:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* 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,
* 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.
*/

#pragma once

#include <set>
#include "behaviortree_cpp/control_node.h"

namespace BT
{
/**
* @brief The ReactiveParallelNode execute all its children
* __concurrently__, but not in separate threads!
*
* Even if this may look similar to ReactiveSequence,
* this Control Node is the __only__ one that can have
* multiple children RUNNING at the same time.
*
* It is more powerful than ParallelNode in checking conditions because even if a child already returns SUCCESS,
* it will still tick that child again before moving on to other children.
*
* It also differs from ParallelNode in that it will tick all children before deciding whether THRESHOLD_SUCCESS
* or THRESHOLD_FAILURE has been reached.
*
* The Node is completed either when the THRESHOLD_SUCCESS
* or THRESHOLD_FAILURE number is reached (both configured using ports).
*
* If any of the thresholds is reached, and other children are still running,
* they will be halted.
*
* Note that threshold indexes work as in Python:
* https://www.i2tutorials.com/what-are-negative-indexes-and-why-are-they-used/
*
* Therefore -1 is equivalent to the number of children.
*/
class ReactiveParallelNode : public ControlNode
{
public:
ReactiveParallelNode(const std::string& name);

ReactiveParallelNode(const std::string& name, const NodeConfig& config);

static PortsList providedPorts()
{
return { InputPort<int>(THRESHOLD_SUCCESS, -1,
"number of children that need to succeed to trigger a "
"SUCCESS"),
InputPort<int>(THRESHOLD_FAILURE, 1,
"number of children that need to fail to trigger a "
"FAILURE") };
}

~ReactiveParallelNode() override = default;

virtual void halt() override;

size_t successThreshold() const;
size_t failureThreshold() const;
void setSuccessThreshold(int threshold);
void setFailureThreshold(int threshold);

private:
int success_threshold_;
int failure_threshold_;

bool read_parameter_from_ports_;
static constexpr const char* THRESHOLD_SUCCESS = "success_count";
static constexpr const char* THRESHOLD_FAILURE = "failure_count";

virtual BT::NodeStatus tick() override;

};

} // namespace BT
72 changes: 36 additions & 36 deletions sample_nodes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
include_directories( ../include )
# include_directories( ../include )

# compile as static libraries
# # compile as static libraries

set(CMAKE_DEBUG_POSTFIX "")
# set(CMAKE_DEBUG_POSTFIX "")

add_library(bt_sample_nodes STATIC
crossdoor_nodes.cpp
dummy_nodes.cpp
movebase_node.cpp )
# add_library(bt_sample_nodes STATIC
# crossdoor_nodes.cpp
# dummy_nodes.cpp
# movebase_node.cpp )

target_link_libraries(bt_sample_nodes PRIVATE ${BTCPP_LIBRARY})
set_target_properties(bt_sample_nodes PROPERTIES ARCHIVE_OUTPUT_DIRECTORY
${BTCPP_LIB_DESTINATION} )
# target_link_libraries(bt_sample_nodes PRIVATE ${BTCPP_LIBRARY})
# set_target_properties(bt_sample_nodes PROPERTIES ARCHIVE_OUTPUT_DIRECTORY
# ${BTCPP_LIB_DESTINATION} )

# to create a plugin, compile them in this way instead
# # to create a plugin, compile them in this way instead

add_library(crossdoor_nodes_dyn SHARED crossdoor_nodes.cpp )
target_link_libraries(crossdoor_nodes_dyn PRIVATE ${BTCPP_LIBRARY})
target_compile_definitions(crossdoor_nodes_dyn PRIVATE BT_PLUGIN_EXPORT )
set_target_properties(crossdoor_nodes_dyn PROPERTIES LIBRARY_OUTPUT_DIRECTORY
${BTCPP_BIN_DESTINATION} )
# add_library(crossdoor_nodes_dyn SHARED crossdoor_nodes.cpp )
# target_link_libraries(crossdoor_nodes_dyn PRIVATE ${BTCPP_LIBRARY})
# target_compile_definitions(crossdoor_nodes_dyn PRIVATE BT_PLUGIN_EXPORT )
# set_target_properties(crossdoor_nodes_dyn PROPERTIES LIBRARY_OUTPUT_DIRECTORY
# ${BTCPP_BIN_DESTINATION} )

add_library(dummy_nodes_dyn SHARED dummy_nodes.cpp )
target_link_libraries(dummy_nodes_dyn PRIVATE ${BTCPP_LIBRARY})
target_compile_definitions(dummy_nodes_dyn PRIVATE BT_PLUGIN_EXPORT)
set_target_properties(dummy_nodes_dyn PROPERTIES LIBRARY_OUTPUT_DIRECTORY
${BTCPP_BIN_DESTINATION} )
# add_library(dummy_nodes_dyn SHARED dummy_nodes.cpp )
# target_link_libraries(dummy_nodes_dyn PRIVATE ${BTCPP_LIBRARY})
# target_compile_definitions(dummy_nodes_dyn PRIVATE BT_PLUGIN_EXPORT)
# set_target_properties(dummy_nodes_dyn PROPERTIES LIBRARY_OUTPUT_DIRECTORY
# ${BTCPP_BIN_DESTINATION} )


add_library(movebase_node_dyn SHARED movebase_node.cpp )
target_link_libraries(movebase_node_dyn PRIVATE ${BTCPP_LIBRARY})
target_compile_definitions(movebase_node_dyn PRIVATE BT_PLUGIN_EXPORT )
set_target_properties(movebase_node_dyn PROPERTIES LIBRARY_OUTPUT_DIRECTORY
${BTCPP_BIN_DESTINATION} )
# add_library(movebase_node_dyn SHARED movebase_node.cpp )
# target_link_libraries(movebase_node_dyn PRIVATE ${BTCPP_LIBRARY})
# target_compile_definitions(movebase_node_dyn PRIVATE BT_PLUGIN_EXPORT )
# set_target_properties(movebase_node_dyn PROPERTIES LIBRARY_OUTPUT_DIRECTORY
# ${BTCPP_BIN_DESTINATION} )

######################################################
# INSTALL plugins for other packages to load
# ######################################################
# # INSTALL plugins for other packages to load

INSTALL(TARGETS
crossdoor_nodes_dyn
dummy_nodes_dyn
movebase_node_dyn
LIBRARY DESTINATION share/${PROJECT_NAME}/bt_plugins
ARCHIVE DESTINATION share/${PROJECT_NAME}/bt_plugins
RUNTIME DESTINATION share/${PROJECT_NAME}/bt_plugins
)
# INSTALL(TARGETS
# crossdoor_nodes_dyn
# dummy_nodes_dyn
# movebase_node_dyn
# LIBRARY DESTINATION share/${PROJECT_NAME}/bt_plugins
# ARCHIVE DESTINATION share/${PROJECT_NAME}/bt_plugins
# RUNTIME DESTINATION share/${PROJECT_NAME}/bt_plugins
# )
Loading