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

Add roseus_bt package #681

Draft
wants to merge 164 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
ba636be
Add roseus_bt package
Affonso-Gui Jun 16, 2021
126683f
(roseus_bt) Parse to service files
Affonso-Gui Jun 16, 2021
ece138e
(roseus_bt) Add EusActionNode and EusConditionNode
Affonso-Gui Jun 16, 2021
3a74a07
(roseus_bt) Add euslisp roseus_bt package and utilities
Affonso-Gui Jun 16, 2021
ab76394
(roseus_bt) Parse header
Affonso-Gui Jun 16, 2021
9c9a8e1
(roseus_bt) Parse action classes
Affonso-Gui Jun 16, 2021
f1dc08a
(roseus_bt) Parse condition classes
Affonso-Gui Jun 16, 2021
1157cda
(roseus_bt) Parse main function
Affonso-Gui Jun 16, 2021
05592d8
(roseus_bt) Fix namespace of eus nodes
Affonso-Gui Jun 16, 2021
cc3466c
(roseus_bt) Add generate_cpp_file
Affonso-Gui Jun 16, 2021
0450ccb
(roseus_bt) Add generate_cmake_lists
Affonso-Gui Jun 17, 2021
885b32c
(roseus_bt) Add generate_package_xml
Affonso-Gui Jun 17, 2021
f8705a4
(roseus_bt) Change action/service file generator
Affonso-Gui Jun 17, 2021
9499451
(roseus_bt) Keep xml_filename in class variable
Affonso-Gui Jun 17, 2021
7bc0ac4
(roseus_bt) Fix comment in xml_parser.h
Affonso-Gui Jun 17, 2021
6476df2
(roseus_bt) Add create_bt_package executable
Affonso-Gui Jun 17, 2021
b88633f
(roseus_bt) Fix compilation errors
Affonso-Gui Jun 17, 2021
bfc608c
(roseus_bt) Remove test executable
Affonso-Gui Jun 18, 2021
ce849dc
(roseus_bt) Print warnings on non-global lambda-closures
Affonso-Gui Jun 18, 2021
1a7086a
(roseus_bt) Copy model file and use absolute path
Affonso-Gui Jun 18, 2021
cb61d50
(roseus_bt) Add roseus_bt:spin
Affonso-Gui Jun 20, 2021
e466a7f
(roseus_bt) Add generate_eus_action_server
Affonso-Gui Jun 20, 2021
77b300b
(roseus_bt) Add generate_eus_condition_server
Affonso-Gui Jun 20, 2021
1e33fb5
(roseus_bt) Add separate template generator class
Affonso-Gui Jun 20, 2021
ca34f7a
(roseus_bt) Replace const char* with std::string
Affonso-Gui Jun 20, 2021
3ba47f1
(roseus_bt) Use external symbol roseus_bt:spin in template
Affonso-Gui Jun 20, 2021
bf26571
(roseus_bt) Add command line arguments
Affonso-Gui Jun 20, 2021
9be78d7
(roseus_bt) Fix bugs in euslisp file generation
Affonso-Gui Jun 20, 2021
b4e7fb4
(roseus_bt) Query before overwriting files
Affonso-Gui Jun 20, 2021
7cd9bf9
(roseus_bt) Use const strings on function arguments
Affonso-Gui Jun 20, 2021
902158f
(roseus_bt) Add subscriber nodes
Affonso-Gui Jun 21, 2021
a821fa0
(roseus_bt) Add roseus_bt/eus_nodes.h header file
Affonso-Gui Jun 21, 2021
781309e
(roseus_bt) Add eus-like function names
Affonso-Gui Jun 30, 2021
c7f6155
(roseus_bt) Add comments on roseus_bt:set-output usage
Affonso-Gui Jun 30, 2021
95422cf
(roseus_bt) Add hyphen-spelled package nickname
Affonso-Gui Jun 30, 2021
bad10a7
(roseus_bt) Add maybe_push_message_package as common utility
Affonso-Gui Jun 30, 2021
27c0631
(roseus_bt) Don't write eus files if not needed
Affonso-Gui Jun 30, 2021
ab0511b
(roseus_bt) Skip copy_xml_file if source is equal to destination
Affonso-Gui Jun 30, 2021
cbb489f
(roseus_bt) Use model filename as default executable name
Affonso-Gui Jul 6, 2021
68d377b
(roseus_bt) Allow to assign multiple model files
Affonso-Gui Jul 6, 2021
59bddd6
(roseus_bt) Add euslisp sample files
Affonso-Gui Jul 6, 2021
fb280c1
(roseus_bt) Update euslisp sample task
Affonso-Gui Jul 7, 2021
d693401
(roseus_bt) Add sample model files
Affonso-Gui Jul 7, 2021
eb52e53
(roseus_bt) Suppress return value on eus_condition_server template
Affonso-Gui Jul 7, 2021
343c65d
(roseus_bt) Avoid extra newline after comment on eus_action_server te…
Affonso-Gui Jul 7, 2021
f772296
(roseus_bt) Fix bug on server_name/service_name formatting
Affonso-Gui Jul 7, 2021
c1459a7
(roseus_bt) Search in all BehaviorTrees for server_name/service_name
Affonso-Gui Jul 7, 2021
c2c20a8
(roseus_bt) Update target xml_filename location
Affonso-Gui Jul 7, 2021
1eea29f
(roseus_bt) Avoid extra newlines after registering on cpp main function
Affonso-Gui Jul 7, 2021
c3bffa7
(roseus_bt) Ensure valid package name
Affonso-Gui Jul 7, 2021
39445fa
(roseus_bt) Use different IDs when initializing demo task with broom …
Affonso-Gui Jul 8, 2021
b16da76
(roseus_bt) Add create_bt_tutorials executable
Affonso-Gui Jul 8, 2021
b1bc0fe
(roseus_bt) Rename function port_node_to_message_description -> forma…
Affonso-Gui Jul 8, 2021
000dd51
(roseus_bt) Add load guard in package_generator.h
Affonso-Gui Jul 8, 2021
36b30db
(roseus_bt) Only split euslisp server files for reactive conditions
Affonso-Gui Jul 8, 2021
d4e7919
(roseus_bt) Ensure newline after load_files in eus_server_template
Affonso-Gui Jul 8, 2021
d79cdc6
(roseus_bt) Wait for topic message on t04_subscriber
Affonso-Gui Jul 8, 2021
87a36b6
(roseus_bt) Add roseus_bt.rosinstall
Affonso-Gui Jul 8, 2021
44df06c
(roseus_bt) Add README files
Affonso-Gui Jul 9, 2021
c370e30
(roseus_bt) Move server_name/service_name definition to node pallete
Affonso-Gui Jul 9, 2021
e5db899
(roseus_bt) Avoid pushing duplicates on collect_eus_actions/conditions
Affonso-Gui Jul 9, 2021
3f974d6
(roseus_bt) Verify the xml file syntax
Affonso-Gui Jul 9, 2021
95e8165
(roseus_bt) Fix bug when dealing with multiple duplicated nodes
Affonso-Gui Jul 10, 2021
be7ab31
(roseus_bt) Add t07_xacro tutorial
Affonso-Gui Jul 10, 2021
9f0f950
(roseus_bt) Spell check README.md
Affonso-Gui Jul 10, 2021
2f803d3
(roseus_bt) Verify root and TreeNodesModel in check_xml_file
Affonso-Gui Jul 10, 2021
65d3197
(roseus_bt) Add custom exceptions
Affonso-Gui Jul 12, 2021
fd92d43
(roseus_bt) Add logging
Affonso-Gui Jul 12, 2021
27a7856
(roseus_bt) Declare template as static member variable
Affonso-Gui Jul 12, 2021
1597bdf
(roseus_bt) Downgrade cmake minimum required version
Affonso-Gui Aug 13, 2021
8ccc544
(roseus_bt) Update README title case
Affonso-Gui Aug 13, 2021
4948e55
(roseus_bt) Update .rosinstall
Affonso-Gui Aug 16, 2021
8838b28
(roseus_bt) Fix trailing whitespace in nodes.l
Affonso-Gui Aug 16, 2021
40ce988
(roseus_bt) Add checks for accept-cb
Affonso-Gui Aug 16, 2021
e28f234
(roseus_bt) Add additional checks for local context on global callbacks
Affonso-Gui Aug 24, 2021
2409bce
(roseus_bt) Add groupname option to condition servers
Affonso-Gui Sep 12, 2022
63f6458
(roseus_bt) Use classes instead of macros
Affonso-Gui Sep 21, 2021
8105c81
(roseus_bt) Call set-succeeded from the :execute-cb method
Affonso-Gui Sep 22, 2021
8045e9c
(roseus_bt) Use :is-active to evaluate ongoing requests
Affonso-Gui Sep 22, 2021
8583059
(roseus_bt) Use trace level on verbose option
Affonso-Gui Oct 8, 2021
bfa3001
(roseus_bt) Format tracing messages
Affonso-Gui Oct 8, 2021
d1bc757
(roseus_bt) Add port name to trace log
Affonso-Gui Oct 8, 2021
e733a9c
(roseus_bt) Fix fmt::format indexing in format_node_body
Affonso-Gui Oct 8, 2021
14e4aa2
(roseus_bt) Add monitor-groupname for separate goal and cancel handlers
Affonso-Gui Sep 22, 2021
32a8b39
(roseus_bt) Add groupname option to condition nodes
Affonso-Gui Feb 24, 2022
8676dba
(roseus_bt) Check server connections at init time
Affonso-Gui Apr 18, 2022
f51eac5
(roseus_bt) Stablish persistent connection with service client at ini…
Affonso-Gui Apr 18, 2022
a911c03
(roseus_bt) Add sleep in sample task loop
Affonso-Gui Apr 18, 2022
d663eb6
(roseus_bt) Increase default spin rate
Affonso-Gui Apr 18, 2022
737a1ff
(roseus_bt) Update RetryUntilSuccessful name
Affonso-Gui Apr 18, 2022
208884e
(roseus_bt) Add rosbridgecpp submodule
Affonso-Gui Apr 18, 2022
198c8c5
(roseus_bt) Add eus_remote_action_node.h
Affonso-Gui Apr 18, 2022
18bb4b3
(roseus_bt) Add EusRemoteAction generation code
Affonso-Gui Apr 18, 2022
6e28861
(roseus_bt) Add t08_multimaster
Affonso-Gui Apr 18, 2022
1596dfe
(roseus_bt) Add ws_action_client base
Affonso-Gui Apr 21, 2022
f3b208a
(roseus_bt) Subscribe remote action results
Affonso-Gui Apr 21, 2022
c59c4bd
(roseus_bt) Enable halting remote actions
Affonso-Gui Apr 21, 2022
1d90c68
(roseus_bt) Fix message type parameter in EusRemoteActionNode
Affonso-Gui Apr 25, 2022
ff65a78
(roseus_bt) Enable input and output ports in remote actions
Affonso-Gui Apr 25, 2022
f143e74
(roseus_bt) Allow to set host_name and host_port dynamically
Affonso-Gui Apr 25, 2022
d6ef47a
(roseus_bt) Add EusRemoteCondition node
Affonso-Gui Apr 25, 2022
06fab19
(roseus_bt) Indent
Affonso-Gui Apr 25, 2022
5d50b72
(roseus_bt) Reduce duplicate formatting functions
Affonso-Gui Apr 25, 2022
e80a9e9
(roseus_bt) Add default file logger
Affonso-Gui Apr 25, 2022
3db2c3d
(roseus_bt) Add 'update_field_name' to set output ports once at a time
Affonso-Gui Apr 25, 2022
270e90b
(roseus_bt) Move #DEBUG definition to generated files
Affonso-Gui Apr 25, 2022
f7669e0
(roseus_bt) Add generate_eus_remote_action_server and generate_eus_re…
Affonso-Gui Apr 25, 2022
c959c6c
(roseus_bt) Split euslisp files for each host
Affonso-Gui Apr 25, 2022
481c7e6
(roseus_bt) Enable splitting eus files in tutorials
Affonso-Gui Apr 25, 2022
7ca191b
(roseus_bt) Fix file splitting with mixed remote and local nodes
Affonso-Gui Apr 25, 2022
4b9c6d9
(roseus_bt) Enable non-ROS input ports in remote nodes
Affonso-Gui Apr 26, 2022
4bee738
(roseus_bt) Avoid unnecessary declarations at sendGoal and sendRequest
Affonso-Gui Apr 26, 2022
1744d50
(roseus_bt) Update t08_multimaster
Affonso-Gui Apr 26, 2022
6a90f15
(roseus_bt) Add submodule directory
Affonso-Gui Apr 26, 2022
daa8747
(roseus_bt) Update submodules at build time
Affonso-Gui Apr 26, 2022
778ee2b
(roseus_bt) Add basic_types.h
Affonso-Gui Apr 27, 2022
b9c5f07
(roseus_bt) Change subscriber port names
Affonso-Gui Apr 28, 2022
613a6ac
(roseus_bt) Allow to set default topic_name at Subscriber nodes
Affonso-Gui Apr 28, 2022
96cb683
(roseus_bt) Add RemoteSubscriber
Affonso-Gui Apr 28, 2022
d1942b3
(roseus_bt) Fix bug in convertFromString
Affonso-Gui Apr 28, 2022
18ceee0
(roseus_bt) Explicitly add subscriber and subtree ports in model files
Affonso-Gui Apr 28, 2022
27009c9
(roseus_bt) Fix typo in warning
Affonso-Gui May 27, 2022
ed42794
(roseus_bt) Log and return final tree status on completion
Affonso-Gui May 27, 2022
2cd501a
(roseus_bt) Add received_port in Subscriber nodes to differentiate re…
Affonso-Gui May 27, 2022
1598955
(roseus_bt) Update samples to use received_port in subscribers
Affonso-Gui May 27, 2022
4da49e2
(roseus_bt) Update the subscriber documentation
Affonso-Gui May 27, 2022
d1800ff
(roseus_bt) Update the remote tutorial documentation
Affonso-Gui May 27, 2022
3cdfbb5
(roseus_bt) Update create_bt_tutorials help description
Affonso-Gui Sep 26, 2022
ab0d723
(roseus_bt) Always wait for result in RemoteCondition
Affonso-Gui Oct 10, 2022
1369d4a
(roseus_bt) Fix misspell: SetUInt -> SetUint
Affonso-Gui Oct 10, 2022
dee8c05
(roseus_bt) Generate server launch files
Affonso-Gui Oct 20, 2022
71f15f8
(roseus_bt) Force hyphens in euslisp file names
Affonso-Gui Oct 20, 2022
3b4af65
(roseus_bt) Add CopyDocument class to avoid unnecessary dumping and p…
Affonso-Gui Oct 21, 2022
d30d92c
(roseus_bt) Allow to parse to basic ros types in remote action
Affonso-Gui Oct 21, 2022
e9afe58
(roseus_bt) Add command line arguments for initializing blackboard va…
Affonso-Gui Oct 21, 2022
4bf6c95
(roseus_bt) Standardize namespaces and loadguards
Affonso-Gui Oct 21, 2022
d1783d1
(roseus_bt) Add positional argument check and negative number support…
Affonso-Gui Oct 21, 2022
b01a68e
(roseus_bt) Add implicit blackboard conversions for int8, int16, and …
Affonso-Gui Oct 21, 2022
87f0415
(roseus_bt) Decrease sleep time in remote nodes
Affonso-Gui Oct 22, 2022
6fcf2b7
(roseus_bt) Use CopyDocument in remote subscriber
Affonso-Gui Oct 23, 2022
e060aec
(roseus_bt) Inform topic type in remote subscribers
Affonso-Gui Oct 23, 2022
6e9e6f8
(roseus_bt) Add single variable constructor in CopyDocument
Affonso-Gui Oct 23, 2022
32c1b46
(roseus_bt) Avoid duplicated header generation
Affonso-Gui Oct 23, 2022
d7d3045
(roseus_bt) Drop support for type unsafe message_field subscriber option
Affonso-Gui Oct 23, 2022
16160ab
(roseus_bt) Increase server unregister_timeout (https://github.com/kn…
Affonso-Gui Oct 23, 2022
afdd325
(roseus_bt) Remove comma separation in package.xml generator
Affonso-Gui Oct 25, 2022
b24d3a3
(roseus_bt) Enforce '/' on remote topics
Affonso-Gui Oct 25, 2022
a79dd92
(roseus_bt) Raise runtime errors when blackboard entry is not found
Affonso-Gui Oct 25, 2022
6635d14
(roseus_bt) Initialize subscriber ports
Affonso-Gui Oct 25, 2022
bf49aa1
(roseus_bt) Better euslisip function formatting with underscores
Affonso-Gui Nov 7, 2022
90f3074
(roseus_bt) Avoid CMake errors on bloom release
Affonso-Gui Nov 11, 2022
c2da0cc
(roseus_bt) define result_ member as Document to avoid having the all…
Affonso-Gui Nov 14, 2022
a27c275
(roseus_bt) Throw errors on failed requests
Affonso-Gui Nov 15, 2022
3ba0a24
(roseus_bt) Throw errors on failed remote service calls
Affonso-Gui Nov 15, 2022
60680a6
(roseus_bt) Throttle actions/status topic for performance
Affonso-Gui Nov 11, 2022
f56ce1b
(roseus_bt) Timeout cancel and check result in remote actions
Affonso-Gui Nov 21, 2022
1134d32
remove ros args in parse_command_line
knorth55 Nov 21, 2022
b4b52b8
add common_argument_mapping.h
knorth55 Nov 21, 2022
4fb75ed
add rosparam_argument_mapping.h
knorth55 Nov 21, 2022
914eedf
(roseus_bt) Remove unused imports and minor style changes in argument…
Affonso-Gui Nov 21, 2022
75eaf4e
(roseus_bt) Add optional timeout parameter to the action template
Affonso-Gui Nov 21, 2022
dbb2453
(roseus_bt) Use ros::package::getPath when loading model file
Affonso-Gui Nov 21, 2022
53b82f0
(roseus_bt) Set timeout as an argument in cancelGoal()
Affonso-Gui Nov 22, 2022
26865cc
(roseus_bt) Use SubTreePlus instead of SubTree
Affonso-Gui Nov 25, 2022
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule ".travis"]
path = .travis
url = https://github.com/jsk-ros-pkg/jsk_travis
[submodule "roseus_bt/include/rosbridgecpp"]
path = roseus_bt/include/rosbridgecpp
url = https://github.com/ppianpak/rosbridgecpp
49 changes: 49 additions & 0 deletions roseus_bt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 2.8.3)
project(roseus_bt)

SET(Boost_USE_STATIC_LIBS ON)

find_package(catkin REQUIRED COMPONENTS
cmake_modules
roscpp
behaviortree_ros
)

find_package(TinyXML2 REQUIRED)
find_package(Boost REQUIRED COMPONENTS log)
find_package(fmt)

catkin_package(
INCLUDE_DIRS include
LIBRARIES
CATKIN_DEPENDS
DEPENDS TinyXML2 fmt
)

# git submodule update
# only when not in bloom build
if (NOT $ENV{DH_OPTIONS})
find_package(Git QUIET)
option(GIT_SUBMODULE "Check submodules during build" ON)
if(Git_FOUND AND GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --remote include/rosbridgecpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(WARNING "git submodule update failed with ${GIT_SUBMOD_RESULT}")
message(WARNING "please update submodules manually with: git submodule update --init --remote include/rosbridgecpp")
endif()
endif()
endif()

include_directories( include ${catkin_INCLUDE_DIRS} ${TinyXML2_INCUDE_DIRS})


add_executable(create_bt_package src/create_bt_package.cpp)
add_dependencies(create_bt_package ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(create_bt_package ${catkin_LIBRARIES} ${TinyXML2_LIBRARIES} ${Boost_LIBRARIES} fmt::fmt)

add_executable(create_bt_tutorials src/create_bt_tutorials.cpp)
add_dependencies(create_bt_tutorials ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(create_bt_tutorials ${catkin_LIBRARIES} ${TinyXML2_LIBRARIES} ${Boost_LIBRARIES} fmt::fmt)
49 changes: 49 additions & 0 deletions roseus_bt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# roseus_bt

Generate glue code for connecting your roseus projects to [BehaviorTree.CPP](https://github.com/BehaviorTree/BehaviorTree.CPP), [BehaviorTree.ROS](https://github.com/BehaviorTree/BehaviorTree.ROS) and [Groot](https://github.com/BehaviorTree/Groot).

## What are behavior trees

Behavior Trees are a control structure used to better organize and design the logical flow of an application. When compared to State Machines they tend to display increased modularity (because there are no direct connections between the execution nodes) and reactivity (because the tree formulation includes implicit transitions).

BehaviorTree.CPP documentation page: [https://www.behaviortree.dev/bt_basics](https://www.behaviortree.dev/bt_basics)

Behavior Tree in Robotics and AI: [https://arxiv.org/pdf/1709.00084.pdf](https://arxiv.org/pdf/1709.00084.pdf)

## Quick Setup

Clone related directories
```bash
mkdir ~/catkin_ws/src -p
cd ~/catkin_ws/src
wget https://raw.githubusercontent.com/Affonso-Gui/jsk_roseus/roseus_bt/roseus_bt/roseus_bt.rosinstall -O .rosinstall
wstool update
```

Install dependencies
```bash
rosdep install -yr --ignore-src --from-paths BehaviorTree.ROS Groot jsk_roseus/roseus_bt
```

Build & source
```bash
cd ~/catkin_ws/
catkin build roseus_bt groot
source ~/catkin_ws/devel/setup.bash
```

## Run

The following command creates a new ros package with all the necessary glue code for running roseus code on the BehaviorTree.CPP engine.

```bash
cd ~/catkin_ws/src
rosrun roseus_bt create_bt_package my_package path/to/model.xml
catkin build my_package
```

For more information on how to compose the model file and use the package check the [tutorials](https://github.com/Affonso-Gui/jsk_roseus/tree/roseus_bt/roseus_bt/sample) and the [BehaviorTree.CPP documentation](https://www.behaviortree.dev/bt_basics).

## Samples

Follow instructions at the [tutorial page](https://github.com/Affonso-Gui/jsk_roseus/tree/roseus_bt/roseus_bt/sample).
140 changes: 140 additions & 0 deletions roseus_bt/euslisp/nodes.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
(unless (find-package "ROSEUS_BT")
(make-package "ROSEUS_BT" :nicknames (list "ROSEUS-BT")))

(in-package "ROSEUS_BT")

(export '(action-node condition-node spin-once spin))
;; import relevant ros::simple-action-server symbols
(import '(ros::name-space ros::status ros::execute-cb
ros::goal ros::goal-id))

(defvar *action-list*)
(defvar *condition-list*)


;; utility
(defun get-fn-sym (fn)
(when (functionp fn)
(cond
((symbolp fn) fn)
((and (listp fn) (memq (car fn) '(lambda lambda-closure)))
(cadr fn))
((derivedp fn compiled-code)
(send fn :name))
(t nil))))

(defun check-fn-closure (fn)
(when (and (consp fn)
(eql (car fn) 'lambda-closure)
(or (not (zerop (third fn)))
(not (zerop (fourth fn)))))
(let ((name (get-fn-sym fn)))
(if name
(ros::ros-warn
(format nil "Possibly harmful lambda-closure in #'~A! Try using '~A instead."
name
name))
(ros::ros-warn
(format nil "Possibly harmful lambda context in ~A! Reseting to 0..."
(append (subseq fn 0 5) '(...)))
(setf (third fn) 0)
(setf (fourth fn) 0))))))


;; classes
(defclass action-node :super ros::simple-action-server :slots (monitor-groupname))
(defmethod action-node
(:init (ns spec &key execute-cb preempt-cb accept-cb groupname
((:monitor-groupname monitor-gn)))
(check-fn-closure execute-cb)
(check-fn-closure preempt-cb)
(check-fn-closure accept-cb)

(send-super :init ns spec
:execute-cb execute-cb
:preempt-cb preempt-cb
:accept-cb accept-cb
:groupname groupname)
(when monitor-gn
(setq monitor-groupname monitor-gn)
(ros::create-nodehandle monitor-groupname)
;; resubscribe /cancel on separate handler
(ros::subscribe (format nil "~A/cancel" ns)
actionlib_msgs::GoalID #'send self :cancel-callback 50
:groupname monitor-groupname))

;; Publishing the status topic is required to make a
;; connection with the action client, but doing so on
;; high frequencies is slow. Throttle it to 5Hz.
(ros::create-timer 0.2 #'(lambda (event) (send self :publish-status))
:groupname groupname)

(push self *action-list*)
(if *condition-list*
(ros::ros-warn "Actions and Conditions detected in the same node! Start two separate nodes when reactivity is required."))
self)
(:publish-status ()
(let ((msg (instance actionlib_msgs::GoalStatusArray :init)))
(when goal-id
(send msg :status_list
(list (instance actionlib_msgs::goalstatus :init
:goal_id goal-id
:status status
:text (ros::goal-status-to-string status)))))
(send msg :header :seq (send self :next-seq-id))
(send msg :header :stamp (ros::time-now))
(ros::publish (format nil "~A/status" name-space) msg)))
(:execute-cb ()
(when (and goal execute-cb)
(let ((res (funcall execute-cb self goal)))
(when (send self :is-active)
(send self :set-succeeded
(send self :result :success (not (not res))))))))
(:set-output (name val)
(let ((msg (send self :feedback (intern (string-upcase name) *keyword-package*) val)))
(send msg :feedback :update_field_name name)
(send self :publish-feedback msg)))
(:ok ()
(send self :spin-monitor)
(not (send self :is-preempt-requested)))
(:spin-monitor ()
(if monitor-groupname
(ros::spin-once monitor-groupname)
(send self :spin-once))))


(defclass condition-node :super propertied-object :slots (execute-cb groupname))
(defmethod condition-node
(:init (ns spec &key ((:execute-cb exec-cb)) ((:groupname gn)))
(check-fn-closure exec-cb)
(setq execute-cb exec-cb)
(setq groupname gn)
(if groupname
(ros::advertise-service ns spec #'send self :request-cb :groupname groupname)
(ros::advertise-service ns spec #'send self :request-cb))
(push self *condition-list*)
(if *action-list*
(ros::ros-warn "Actions and Conditions detected in the same node! Start two separate nodes when reacitivity is required."))
self)
(:request-cb (msg)
(let ((response (send msg :response)))
(send response :success (not (not (funcall execute-cb self msg))))
response))
(:spin-once ()
(if groupname
(ros::spin-once groupname)
(ros::spin-once))))


;; functions
(defun spin-once ()
(dolist (cc *condition-list*)
(send cc :spin-once))
(dolist (ac *action-list*)
(send ac :spin-once)
(send ac :execute-cb)))

(defun spin ()
(while t
(spin-once)
(ros::sleep)))
1 change: 1 addition & 0 deletions roseus_bt/include/rosbridgecpp
Submodule rosbridgecpp added at cb87f6
54 changes: 54 additions & 0 deletions roseus_bt/include/roseus_bt/basic_types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "roseus_bt/basic_types.h"

namespace roseus_bt
{

std::string toStr(NodeType type)
{
switch (type)
{
case NodeType::ACTION:
return "Action";
case NodeType::CONDITION:
return "Condition";
case NodeType::DECORATOR:
return "Decorator";
case NodeType::CONTROL:
return "Control";
case NodeType::SUBTREE:
return "SubTree";
case NodeType::SUBSCRIBER:
return "Subscriber";
case NodeType::REMOTE_SUBSCRIBER:
return "RemoteSubscriber";
case NodeType::REMOTE_ACTION:
return "RemoteAction";
case NodeType::REMOTE_CONDITION:
return "RemoteCondition";
default:
return "Undefined";
}
}

NodeType convertFromString(BT::StringView str)
{
if( str == "Action" ) return NodeType::ACTION;
if( str == "Condition" ) return NodeType::CONDITION;
if( str == "Control" ) return NodeType::CONTROL;
if( str == "Decorator" ) return NodeType::DECORATOR;
if( str == "SubTree" || str == "SubTreePlus" ) return NodeType::SUBTREE;
if( str == "Subscriber" ) return NodeType::SUBSCRIBER;
if( str == "RemoteAction" ) return NodeType::REMOTE_ACTION;
if( str == "RemoteCondition" ) return NodeType::REMOTE_CONDITION;
if( str == "RemoteSubscriber" ) return NodeType::REMOTE_SUBSCRIBER;
return NodeType::UNDEFINED;
}

std::ostream& operator<<(std::ostream& os, const NodeType& type)
{
os << toStr(type);
return os;
}


} // namespace roseus_bt
30 changes: 30 additions & 0 deletions roseus_bt/include/roseus_bt/basic_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef BEHAVIOR_TREE_ROSEUS_BT_EUS_NODE_TYPE_HPP_
#define BEHAVIOR_TREE_ROSEUS_BT_EUS_NODE_TYPE_HPP_

#include <behaviortree_cpp_v3/basic_types.h>


namespace roseus_bt
{

enum class NodeType
{
UNDEFINED = 0,
ACTION,
CONDITION,
CONTROL,
DECORATOR,
SUBTREE,
SUBSCRIBER,
REMOTE_ACTION,
REMOTE_CONDITION,
REMOTE_SUBSCRIBER,
};

std::string toStr(NodeType type);
NodeType convertFromString(BT::StringView str);
std::ostream& operator<<(std::ostream& os, const NodeType& type);

} // namespace roseus_bt

#endif // BEHAVIOR_TREE_ROSEUS_BT_EUS_NODE_TYPE_HPP_
41 changes: 41 additions & 0 deletions roseus_bt/include/roseus_bt/bt_exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef BEHAVIOR_TREE_ROSEUS_BT_BT_EXCEPTIONS_
#define BEHAVIOR_TREE_ROSEUS_BT_BT_EXCEPTIONS_

#include <string>
#include <stdexcept>
#include <fmt/format.h>

namespace RoseusBT
{

class BTError: public std::exception {
public:
BTError(std::string message): message(message) {}

const char* what() const noexcept {
return message.c_str();
}

std::string message;
};

class InvalidOutputPort: public BTError {
public:
InvalidOutputPort() : BTError("Condition Node only accepts input ports!") {};
};

class InvalidPackageName: public BTError {
public:
InvalidPackageName(std::string name) :
BTError(fmt::format("Package name {} does not follow naming conventions", name)) {};
};

class InvalidInput: public BTError {
public:
InvalidInput() : BTError("Invalid Input") {};
};


} // namespace RoseusBT

#endif // BEHAVIOR_TREE_ROSEUS_BT_BT_EXCEPTIONS_
Loading