Skip to content

Commit 44f2322

Browse files
final touch
1 parent 4dcd00f commit 44f2322

File tree

6 files changed

+46
-22
lines changed

6 files changed

+46
-22
lines changed

CMakeLists.txt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,24 @@ catkin_package(
5151

5252
include_directories( include ${catkin_INCLUDE_DIRS})
5353

54-
5554
######################################################
5655
# LIBRARIES
5756

58-
add_library(behaviortree_ros
59-
src/loggers/rosout_logger.cpp
60-
src/bt_service_node.cpp
61-
)
62-
63-
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})
57+
#header only for the time being
6458

59+
#add_library(behaviortree_ros ... )
60+
#target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})
6561

6662
######################################################
6763
# TESTS
6864

6965
add_executable(test_bt test/test_bt.cpp)
7066
add_dependencies(test_bt ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
71-
target_link_libraries(test_bt ${catkin_LIBRARIES} ${PROJECT_NAME})
67+
target_link_libraries(test_bt ${catkin_LIBRARIES} )
7268

7369
add_executable(test_server test/test_server.cpp)
7470
add_dependencies(test_server ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
75-
target_link_libraries(test_server ${catkin_LIBRARIES} ${PROJECT_NAME})
71+
target_link_libraries(test_server ${catkin_LIBRARIES} )
7672

7773
######################################################
7874
# INSTALL

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ to develop Behavior Trees in C++.
66
The library is not particularly opinionated about the way Actions and Conditions should be created; this gives
77
more freedom to the developer, but can also be confusing for those people which are getting started with it.
88

9-
[BehaviorTree.ROS](https://github.com/BehaviorTree/BehaviorTree.ROS) provides some practical examples and
10-
utilities related to [ROS (the Robotic Operative System)](http://www.ros.org).
9+
Consequently, many people in the [ROS](http://www.ros.org) community asked for examples and guidelines;
10+
this repository try to provide some basic examples.
11+
12+
Currently, two wrappers are provided:
13+
14+
- [RosServiceNode](include/behaviortree_ros/bt_service_node.h), which can be used to call
15+
[ROS Services](http://wiki.ros.org/Services)
16+
17+
- [RosActionNode](include/behaviortree_ros/bt_service_node.h) that, similarly, is a wrapper around
18+
[actionlib::SimpleActionClient](http://wiki.ros.org/actionlib).
19+
1120

12-
ROS users can use this library or look at the way Nodes are implemented to implmenent their own version.

include/behaviortree_ros/bt_action_node.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
namespace BT
2525
{
2626

27+
/** Helper Node to call an actionlib::SimpleActionClient<>
28+
* inside a BT::ActionNode.
29+
*
30+
* Note that the user must implement the methods:
31+
*
32+
* - sendGoal
33+
* - onResult
34+
* - onFailedRequest
35+
* - halt (optionally)
36+
*
37+
*/
2738
template<class ActionT>
2839
class RosActionNode : public BT::ActionNodeBase
2940
{
@@ -48,6 +59,8 @@ class RosActionNode : public BT::ActionNodeBase
4859

4960
virtual ~RosActionNode() = default;
5061

62+
/// These ports will be added automatically if this Node is
63+
/// registered using RegisterRosAction<DeriveClass>()
5164
static PortsList providedPorts()
5265
{
5366
return {
@@ -56,13 +69,15 @@ class RosActionNode : public BT::ActionNodeBase
5669
};
5770
}
5871

72+
/// Method called when the Action makes a transition from IDLE to RUNNING.
73+
/// If it return false, the entire action is immediately aborted, it returns
74+
/// FAILURE and no request is sent to the server.
5975
virtual bool sendGoal(GoalType& goal) = 0;
6076

6177
/// Method (to be implemented by the user) to receive the reply.
6278
/// User can decide which NodeStatus it will return (SUCCESS or FAILURE).
6379
virtual NodeStatus onResult( const ResultType& res) = 0;
6480

65-
6681
enum FailureCause{
6782
MISSING_SERVER = 0,
6883
ABORTED_BY_SERVER = 1,
@@ -75,6 +90,10 @@ class RosActionNode : public BT::ActionNodeBase
7590
return NodeStatus::FAILURE;
7691
}
7792

93+
/// If you override this method, you MUST call this implementation invoking:
94+
///
95+
/// BaseClass::halt()
96+
///
7897
virtual void halt() override
7998
{
8099
if( status() == NodeStatus::RUNNING )
@@ -92,7 +111,6 @@ class RosActionNode : public BT::ActionNodeBase
92111

93112
BT::NodeStatus tick() override
94113
{
95-
96114
unsigned msec = getInput<unsigned>("timeout").value();
97115
ros::Duration timeout(static_cast<double>(msec) * 1e-3);
98116

@@ -112,7 +130,6 @@ class RosActionNode : public BT::ActionNodeBase
112130
{
113131
return NodeStatus::FAILURE;
114132
}
115-
116133
action_client_->sendGoal(goal);
117134
}
118135

include/behaviortree_ros/bt_service_node.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
namespace BT
2525
{
2626

27+
/**
28+
* Base Action to implement a ROS Service
29+
*/
2730
template<class ServiceT>
2831
class RosServiceNode : public BT::SyncActionNode
2932
{
@@ -34,23 +37,26 @@ class RosServiceNode : public BT::SyncActionNode
3437

3538
public:
3639

37-
using ServiceType = ServiceT;
38-
using RequestType = typename ServiceT::Request;
40+
using BaseClass = RosServiceNode<ServiceT>;
41+
using ServiceType = ServiceT;
42+
using RequestType = typename ServiceT::Request;
3943
using ResponseType = typename ServiceT::Response;
4044

4145
RosServiceNode() = delete;
4246

4347
virtual ~RosServiceNode() = default;
4448

49+
/// These ports will be added automatically if this Node is
50+
/// registered using RegisterRosAction<DeriveClass>()
4551
static PortsList providedPorts()
4652
{
4753
return {
4854
InputPort<std::string>("service_name", "name of the ROS service"),
49-
InputPort<unsigned>("timeout", 100, "timeout to connect (milliseconds)")
55+
InputPort<unsigned>("timeout", 100, "timeout to connect to server (milliseconds)")
5056
};
5157
}
5258

53-
/// User must implement this method
59+
/// User must implement this method.
5460
virtual void sendRequest(RequestType& request) = 0;
5561

5662
/// Method (to be implemented by the user) to receive the reply.

src/bt_action_node.cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/bt_service_node.cpp

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)