Skip to content

Commit

Permalink
Merge pull request #34 from fmessmer/feature/sync_flexbe
Browse files Browse the repository at this point in the history
Feature/sync flexbe
  • Loading branch information
fmessmer authored Jul 20, 2023
2 parents 2d56a6b + 36e786a commit 243ecd3
Show file tree
Hide file tree
Showing 27 changed files with 150 additions and 20 deletions.
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015, DARPA Robotics Challenge Team ViGIR
Copyright (c) 2015-2023, DARPA Robotics Challenge Team ViGIR
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand All @@ -25,4 +25,3 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
> should use the https://github.com/FlexBE site, which will be the one-stop
> shop for all things FlexBE going forward.


FlexBE is a high-level behavior engine coordinating the capabilities of a robot in order to solve complex tasks.
Behaviors are modeled as hierarchical state machines where states correspond to active actions and transitions describe the reaction to outcomes.
Main advantage over similar approaches is the good operator integration and extensive user interface.
Expand All @@ -20,14 +18,14 @@ The user interface features a runtime control interface as well as a graphical e

Please refer to the FlexBE Homepage ([flexbe.github.io](http://flexbe.github.io)) for further information, tutorials, application examples, and much more.

![FlexBE CI](https://github.com/team-vigir/flexbe_behavior_engine/workflows/FlexBE%20CI/badge.svg)
![FlexBE CI](https://github.com/FlexBE/flexbe_behavior_engine/workflows/FlexBE%20CI/badge.svg)

## Installation

Execute the following commands to install FlexBE:

roscd && cd ../src
git clone https://github.com/team-vigir/flexbe_behavior_engine.git
git clone https://github.com/FlexBE/flexbe_behavior_engine.git

Furthermore, create your own repository for behavior development (contains examples):

Expand Down
8 changes: 8 additions & 0 deletions flexbe_behavior_engine/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package flexbe_behavior_engine
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1.4.0 (2023-05-18)
------------------
* Updates for Melodic and Noetic releases on github.com/FlexBE
* [flexbe_core] Merge pull request #153 from omercans/fix/set-current-state-of-cc-to-none-on-forced-exit
* [flexbe_core] Merge pull request #154 from duwke/patch-1 - Check topic availability before returning last_msg
* [flexbe_states] Merge pull request #160 from cpswarm/fix_namespace - namespace fix for topic lookup with rostopic in subscriber state
* [flexbe_core] Merge pull request #163 from LoyVanBeek/fix/nested_sm_userdata - Fix nested state machine userdata
* [flexbe_onboard] Merge pull request #165 from HannesBachter/feature/get_userdata - get userdata by service

1.3.1 (2020-12-11)
------------------
Expand Down
4 changes: 2 additions & 2 deletions flexbe_behavior_engine/package.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0"?>
<package format="2">
<name>flexbe_behavior_engine</name>
<version>1.3.1</version>
<version>1.4.0</version>
<description>
A meta-package to aggregate all the FlexBE packages
</description>

<maintainer email="[email protected]">Philipp Schillinger</maintainer>
<maintainer email="[email protected]">Alireza Hosseini</maintainer>
<maintainer email="[email protected]">David Conner</maintainer>
<license>BSD</license>

<url>http://ros.org/wiki/flexbe</url>
Expand Down
7 changes: 7 additions & 0 deletions flexbe_core/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package flexbe_core
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1.4.0 (2023-05-18)
------------------
* Updates for Melodic and Noetic releases on github.com/FlexBE
* [flexbe_core] Fix handling of boolean behavior args
* [flexbe_core] Merge pull request #153 from omercans/fix/set-current-state-of-cc-to-none-on-forced-exit
* [flexbe_core] Merge pull request #154 from duwke/patch-1 - Check topic availability before returning last_msg
* [flexbe_core] Merge pull request #163 from LoyVanBeek/fix/nested_sm_userdata - Fix nested state machine userdata

1.3.1 (2020-12-11)
------------------
Expand Down
2 changes: 1 addition & 1 deletion flexbe_core/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>flexbe_core</name>
<version>1.3.1</version>
<version>1.4.0</version>
<description>
flexbe_core provides the core components for the FlexBE behavior engine.
</description>
Expand Down
17 changes: 17 additions & 0 deletions flexbe_core/src/flexbe_core/proxy/proxy_action_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ def get_result(self, topic):
@param topic: The topic of interest.
"""
return ProxyActionClient._result.get(topic)

def get_goal_status_text(self, topic):
"""
Returns the result status text if any.
@type topic: string
@param topic: The topic of interest.
"""

if (not topic in ProxyActionClient._clients):
return "Failed to get status text: Invalid action topic = [" + topic +"]"

try:
status = ProxyActionClient._clients[topic].get_goal_status_text()
return status
except:
return "Failed to retrieve goal status text for topic = [" + topic +"]"

def remove_result(self, topic):
"""
Expand Down
4 changes: 3 additions & 1 deletion flexbe_core/src/flexbe_core/proxy/proxy_subscriber_cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def has_msg(self, topic):
@type topic: string
@param topic: The topic of interest.
"""
return ProxySubscriberCached._topics[topic]['last_msg'] is not None
if self.is_available(topic):
return ProxySubscriberCached._topics[topic]['last_msg'] is not None
return False

def has_buffered(self, topic):
"""
Expand Down
3 changes: 3 additions & 0 deletions flexbe_input/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package flexbe_input
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1.4.0 (2023-05-18)
------------------
* Updates for Melodic and Noetic releases on github.com/FlexBE

1.3.1 (2020-12-11)
------------------
Expand Down
2 changes: 1 addition & 1 deletion flexbe_input/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>flexbe_input</name>
<version>1.3.1</version>
<version>1.4.0</version>
<description>
flexbe_input enables to send data to onboard behavior when required.
</description>
Expand Down
3 changes: 3 additions & 0 deletions flexbe_mirror/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package flexbe_mirror
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1.4.0 (2023-05-18)
------------------
* Updates for Melodic and Noetic releases on github.com/FlexBE

1.3.1 (2020-12-11)
------------------
Expand Down
2 changes: 1 addition & 1 deletion flexbe_mirror/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>flexbe_mirror</name>
<version>1.3.1</version>
<version>1.4.0</version>
<description>
flexbe_mirror implements functionality to remotely mirror an executed behavior.
</description>
Expand Down
4 changes: 4 additions & 0 deletions flexbe_msgs/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package flexbe_msgs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1.4.0 (2023-05-18)
------------------
* Updates for Melodic and Noetic releases on github.com/FlexBE
* [flexbe_msgs] Merge pull request #165 from HannesBachter/feature/get_userdata - get userdata by service

1.3.1 (2020-12-11)
------------------
Expand Down
2 changes: 1 addition & 1 deletion flexbe_msgs/package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<package format="2">
<name>flexbe_msgs</name>
<version>1.3.1</version>
<version>1.4.0</version>
<description>
flexbe_msgs provides the messages used by FlexBE.
</description>
Expand Down
4 changes: 4 additions & 0 deletions flexbe_onboard/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package flexbe_onboard
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1.4.0 (2023-05-18)
------------------
* Updates for Melodic and Noetic releases on github.com/FlexBE
* [flexbe_onboard] Merge pull request #165 from HannesBachter/feature/get_userdata - get userdata by service

1.3.1 (2020-12-11)
------------------
Expand Down
2 changes: 1 addition & 1 deletion flexbe_onboard/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>flexbe_onboard</name>
<version>1.3.1</version>
<version>1.4.0</version>
<description>
flexbe_onboard implements the robot-side of the behavior engine from where all behaviors are started.
</description>
Expand Down
17 changes: 16 additions & 1 deletion flexbe_onboard/test/test_onboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class TestOnboard(unittest.TestCase):

def __init__(self, name):
print("Initializing TestOnboard ...")
super(TestOnboard, self).__init__(name)
self.sub = ProxySubscriberCached({
'flexbe/status': BEStatus,
Expand All @@ -23,10 +24,13 @@ def __init__(self, name):
# make sure that behaviors can be imported
data_folder = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, data_folder)
print(f"Using {data_folder} ...")
# run onboard and add custom test behaviors to onboard lib
print(f"Create onboard instance ...")
self.onboard = FlexbeOnboard()
self.lib = self.onboard._behavior_lib
self.lib._add_behavior_manifests(data_folder)
print(f"Done adding behavior manifests from {data_folder}")

def assertStatus(self, expected, timeout):
""" Assert that the expected onboard status is received before the timeout. """
Expand All @@ -39,14 +43,17 @@ def assertStatus(self, expected, timeout):
msg = self.sub.get_last_msg('flexbe/status')
self.sub.remove_last_msg('flexbe/status')
self.assertEqual(msg.code, expected)
print(f"Successfully received status {msg}")
return msg

def test_onboard_behaviors(self):
print("Creating start_behavior publisher ...")
behavior_pub = rospy.Publisher('flexbe/start_behavior', BehaviorSelection, queue_size=1)
rospy.sleep(0.5) # wait for publisher

# wait for the initial status message
self.assertStatus(BEStatus.READY, 1)
print("Behavior engine is ready!")

# send simple behavior request without checksum
be_id, _ = self.lib.find_behavior("Test Behavior Log")
Expand All @@ -55,8 +62,10 @@ def test_onboard_behaviors(self):
request.autonomy_level = 255
behavior_pub.publish(request)
self.assertStatus(BEStatus.ERROR, 2)
print(f"Correctly detected checksum issue!")

# send valid simple behavior request
print(f"Correctly set checksum and send request ...")
with open(self.lib.get_sourcecode_filepath(be_id)) as f:
request.behavior_checksum = zlib.adler32(f.read().encode()) & 0x7fffffff
self.sub.enable_buffer('flexbe/log')
Expand All @@ -67,9 +76,11 @@ def test_onboard_behaviors(self):
while self.sub.has_buffered('flexbe/log'):
behavior_logs.append(self.sub.get_from_buffer('flexbe/log').text)
self.assertIn('Test data', behavior_logs)
print(f"Correctly recived update!")

# send valid complex behavior request
be_id, _ = self.lib.find_behavior("Test Behavior Complex")
print(f"Send complex request ...")
request = BehaviorSelection()
request.behavior_id = be_id
request.autonomy_level = 255
Expand All @@ -87,15 +98,19 @@ def test_onboard_behaviors(self):
content = content.replace(replace, by)
request.behavior_checksum = zlib.adler32(content.encode()) & 0x7fffffff
behavior_pub.publish(request)
print("Wait for status updates ...")
self.assertStatus(BEStatus.STARTED, 1)
result = self.assertStatus(BEStatus.FINISHED, 3)
self.assertEqual(result.args[0], 'finished')
print("Successful update, now check logs ...")

behavior_logs = []
while self.sub.has_buffered('flexbe/log'):
behavior_logs.append(self.sub.get_from_buffer('flexbe/log').text)
self.assertIn('value_2', behavior_logs)

# send the same behavior with different parameters
print(f"Send complex request with different parameters ...")
request.arg_keys = ['param', 'invalid']
request.arg_values = ['value_1', 'should be ignored']
request.input_keys = []
Expand All @@ -108,7 +123,7 @@ def test_onboard_behaviors(self):
while self.sub.has_buffered('flexbe/log'):
behavior_logs.append(self.sub.get_from_buffer('flexbe/log').text)
self.assertIn('value_1', behavior_logs)

print("Success!")

if __name__ == '__main__':
rospy.init_node('test_flexbe_onboard')
Expand Down
3 changes: 3 additions & 0 deletions flexbe_states/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package flexbe_states
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1.4.0 (2023-05-18)
------------------
* Updates for Melodic and Noetic releases on github.com/FlexBE

1.3.1 (2020-12-11)
------------------
Expand Down
2 changes: 1 addition & 1 deletion flexbe_states/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>flexbe_states</name>
<version>1.3.1</version>
<version>1.4.0</version>
<description>
flexbe_states provides a collection of predefined states.
Feel free to add new states.
Expand Down
8 changes: 6 additions & 2 deletions flexbe_states/src/flexbe_states/subscriber_state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
import rospy
import rostopic
from flexbe_core import EventState, Logger

Expand Down Expand Up @@ -53,8 +54,11 @@ def on_enter(self, userdata):
self._sub.remove_last_msg(self._topic)

def _connect(self):
msg_type, msg_topic, _ = rostopic.get_topic_class(self._topic)
if msg_topic == self._topic:
global_topic = self._topic
if global_topic[0] != '/':
global_topic = rospy.get_namespace() + global_topic
msg_type, msg_topic, _ = rostopic.get_topic_class(global_topic)
if msg_topic == global_topic:
self._sub = ProxySubscriberCached({self._topic: msg_type})
self._connected = True
return True
Expand Down
46 changes: 46 additions & 0 deletions flexbe_states/src/flexbe_states/user_data_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python

from flexbe_core import EventState, Logger

'''
Created on 14-Feb-2018
@author: David Conner
'''

class UserDataState(EventState):
'''
Implements a state that defines user data
-- data type Data for given user data
#> data User data
<= done Created the user data
'''


def __init__(self, data ):
'''
Constructor
'''
super(UserDataState, self).__init__( output_keys=["data"], outcomes=["done"])

self._my_data = data
self._return_code = None

def execute(self, userdata):
'''
Execute this state
'''
return self._return_code


def on_enter(self, userdata):

try:
# Add the user data
userdata.data = self._my_data
self._return_code = 'done'
except:
raise ValueError('UserDataState %s - invalid data ' % self.name)
1 change: 1 addition & 0 deletions flexbe_states/tests/run_tests.launch
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$(arg path)/log_state_msg.test
$(arg path)/operator_decision_state_suggested.test
$(arg path)/subscriber_state_unavailable.test
$(arg path)/user_data_state.test
$(arg path)/wait_state_short.test
" />
Expand Down
10 changes: 10 additions & 0 deletions flexbe_states/tests/user_data_state.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
path: flexbe_states.user_data_state
class: UserDataState

params:
data: "Test data"

output:
data: "Test data"

outcome: done
Loading

0 comments on commit 243ecd3

Please sign in to comment.