Skip to content
Snippets Groups Projects
Commit e5174dfc authored by Alejandro Lopez Gestoso's avatar Alejandro Lopez Gestoso
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 2.8.3)
project(iri_behaviortree)
add_compile_options(-std=c++11)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS behaviortree_cpp_v3)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()
################################################
## Declare ROS messages, services and actions ##
################################################
## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET
## * If MSG_DEP_SET isn't empty the following dependencies might have been
## pulled in transitively but can be declared for certainty nonetheless:
## * add a build_depend tag for "message_generation"
## * add a run_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
## * add "message_generation" and every package in MSG_DEP_SET to
## find_package(catkin REQUIRED COMPONENTS ...)
## * add "message_runtime" and every package in MSG_DEP_SET to
## catkin_package(CATKIN_DEPENDS ...)
## * uncomment the add_*_files sections below as needed
## and list every .msg/.srv/.action file to be processed
## * uncomment the generate_messages entry below
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )
## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )
## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# std_msgs # Or other packages containing msgs
# )
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if you package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS behaviortree_cpp_v3
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(include)
include_directories(${catkin_INCLUDE_DIRS})
## Declare a cpp library
# add_library(iri_behaviortree
# src/${PROJECT_NAME}/iri_behaviortree.cpp
# )
add_library(${PROJECT_NAME} src/iri_async_action.cpp src/iri_bt_factory.cpp)
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})
## Declare a cpp executable
# add_executable(iri_behaviortree_node src/iri_behaviortree_node.cpp)
## Add cmake target dependencies of the executable/library
## as an example, message headers may need to be generated before nodes
# add_dependencies(iri_behaviortree_node iri_behaviortree_generate_messages_cpp)
## Specify libraries to link a library or executable target against
#############
## Install ##
#############
# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# install(PROGRAMS
# scripts/my_python_script
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark executables and/or libraries for installation
# install(TARGETS iri_behaviortree iri_behaviortree_node
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
## Mark cpp header files for installation
# install(DIRECTORY include
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )
## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )
#############
## Testing ##
#############
## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_iri_behaviortree.cpp)
# if(TARGET ${PROJECT_NAME}-test)
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()
## Add folders to be run by python nosetests
# catkin_add_nosetests(test)
#ifndef IRI_BEHAVIOR_TREE_ACTION
#define IRI_BEHAVIOR_TREE_ACTION
#include "behaviortree_cpp/action_node.h"
#include "behaviortree_cpp/leaf_node.h"
/**
* @brief The IriAsyncActionNode is an ActionNode that
* explicitly prevents the status RUNNING.
* The user should simply provide a callback with this signature
*
* BT::NodeStatus functionName(TreeNode&)
*
* This avoids the hassle of inheriting from a ActionNode.
*
* Using lambdas or std::bind it is easy to pass a pointer to a method.
* IriSimpleActionNode is executed synchronously and does not support halting.
* NodeParameters aren't supported.
*/
class IriAsyncActionNode : public BT::ActionNodeBase
{
public:
typedef std::function<BT::NodeStatus(BT::TreeNode&)> TickFunctor;
IriAsyncActionNode(const std::string& name, TickFunctor tick_functor, const BT::NodeConfiguration& config);
~IriAsyncActionNode() override = default;
/// throws if the derived class return RUNNING.
virtual BT::NodeStatus executeTick() override;
/// You don't need to override this
virtual void halt() override final
{
setStatus(BT::NodeStatus::IDLE);
}
protected:
virtual BT::NodeStatus tick() override final;
TickFunctor tick_functor_;
};
#endif
\ No newline at end of file
#ifndef IRI_BT_FACTORY_H
#define IRI_BT_FACTORY_H
#include "behaviortree_cpp/bt_factory.h"
#include "iri_async_action.h"
class IriBehaviorTreeFactory : public BT::BehaviorTreeFactory
{
public:
IriBehaviorTreeFactory()
{
}
/**
* @brief registerIriSimpleAction help you register nodes of type IriAsyncActionNode.
*
* @param ID registration ID
* @param tick_functor the callback to be invoked in the tick() method.
* @param ports if your IriAsyncActionNode requires ports, provide the list here.
*
* */
void registerIriAsyncAction(const std::string& ID,
const IriAsyncActionNode::TickFunctor& tick_functor,
BT::PortsList ports = {});
};
#endif
\ No newline at end of file
<?xml version="1.0"?>
<package>
<name>iri_behaviortree</name>
<version>0.0.0</version>
<description>The iri_behaviortree package</description>
<!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="jane.doe@example.com">Jane Doe</maintainer> -->
<maintainer email="labrobotica@iri.upc.edu">labrobotica</maintainer>
<!-- One license tag required, multiple allowed, one license per tag -->
<!-- Commonly used license strings: -->
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
<license>LGPL</license>
<!-- Url tags are optional, but mutiple are allowed, one per tag -->
<!-- Optional attribute type can be: website, bugtracker, or repository -->
<!-- Example: -->
<url type="website">http://wiki.ros.org/iri_ros_tool</url>
<!-- Author tags are optional, mutiple are allowed, one per tag -->
<!-- Authors do not have to be maintianers, but could be -->
<!-- Example: -->
<!-- <author email="jane.doe@example.com">Jane Doe</author> -->
<author email="shernand@iri.upc.edu">Sergi Hernandez</author>
<!-- The *_depend tags are used to specify dependencies -->
<!-- Dependencies can be catkin packages or system dependencies -->
<!-- Examples: -->
<!-- Use build_depend for packages you need at compile time: -->
<!-- <build_depend>message_generation</build_depend> -->
<build_depend>behaviortree_cpp_v3</build_depend>
<!-- Use buildtool_depend for build tool packages: -->
<!-- <buildtool_depend>catkin</buildtool_depend> -->
<!-- Use run_depend for packages you need at runtime: -->
<!-- <run_depend>message_runtime</run_depend> -->
<run_depend>behaviortree_cpp_v3</run_depend>
<!-- Use test_depend for packages you need only for testing: -->
<!-- <test_depend>gtest</test_depend> -->
<buildtool_depend>catkin</buildtool_depend>
<!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here -->
</export>
</package>
#include "iri_async_action.h"
IriAsyncActionNode::IriAsyncActionNode(const std::string& name,
IriAsyncActionNode::TickFunctor tick_functor,
const BT::NodeConfiguration& config):
ActionNodeBase(name, config), tick_functor_(std::move(tick_functor))
{}
BT::NodeStatus IriAsyncActionNode::executeTick()
{
auto stat = BT::ActionNodeBase::executeTick();
return stat;
}
BT::NodeStatus IriAsyncActionNode::tick()
{
BT::NodeStatus prev_status = status();
if (prev_status == BT::NodeStatus::IDLE)
{
setStatus(BT::NodeStatus::RUNNING);
prev_status = BT::NodeStatus::RUNNING;
}
BT::NodeStatus status = tick_functor_(*this);
if (status != prev_status)
{
setStatus(status);
}
return status;
}
\ No newline at end of file
#include "iri_bt_factory.h"
void IriBehaviorTreeFactory::registerIriAsyncAction(const std::string& ID,
const IriAsyncActionNode::TickFunctor& tick_functor,
BT::PortsList ports)
{
BT::NodeBuilder builder = [tick_functor, ID](const std::string& name, const BT::NodeConfiguration& config) {
return std::make_unique<IriAsyncActionNode>(name, tick_functor, config);
};
BT::TreeNodeManifest manifest = { BT::NodeType::ACTION, ID, std::move(ports) };
registerBuilder(manifest, builder);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment