Skip to content
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ if __name__ == '__main__':

while result == NodeStatus.ACTIVE:
result = count.tick()
print result
print(result)
time.sleep(0.1)
```

Expand All @@ -172,7 +172,7 @@ if __name__ == '__main__':

for i in range(0, 10):
result = repeat.tick()
print result
print(result)
time.sleep(0.1)
```

Expand Down Expand Up @@ -203,7 +203,7 @@ if __name__ == '__main__':

while result == NodeStatus.ACTIVE:
result = finish_counts.tick()
print result
print(result)
time.sleep(0.1)
```
Here is also an example of how to use the blackboard to set node parameters.
Expand Down
15 changes: 9 additions & 6 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
# License for the specific language governing permissions and limitations
# under the License.

from __future__ import absolute_import
from __future__ import print_function
import time

from task_behavior_engine.branch import Sequencer
from task_behavior_engine.decorator import Repeat
from task_behavior_engine.tree import Blackboard
from task_behavior_engine.tree import Node
from task_behavior_engine.tree import NodeStatus
from six.moves import range


class Count(Node):
Expand Down Expand Up @@ -78,28 +81,28 @@ def cleanup(self, nodedata):

if __name__ == '__main__':

print "Running example 1 -- using a node"
print("Running example 1 -- using a node")

count = Count(name="count_index")
result = NodeStatus(NodeStatus.ACTIVE)

while result == NodeStatus.ACTIVE:
result = count.tick()
print result
print(result)
time.sleep(0.1)

print "Running example 2 (10 times) -- using a decorator"
print("Running example 2 (10 times) -- using a decorator")

count = Count(name="count_index")
repeat = Repeat(name="repeat_count", child=count)
result = NodeStatus(NodeStatus.ACTIVE)

for i in range(0, 10):
result = repeat.tick()
print result
print(result)
time.sleep(0.1)

print "Running example 3 -- using a behavior"
print("Running example 3 -- using a behavior")

b = Blackboard()

Expand All @@ -121,5 +124,5 @@ def cleanup(self, nodedata):

while result == NodeStatus.ACTIVE:
result = finish_counts.tick()
print result
print(result)
time.sleep(0.1)
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD

from __future__ import absolute_import
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

# fetch values from package.xml
setup_args = generate_distutils_setup(
packages=['task_behavior_engine',],
package_dir={'': 'src'})
package_dir={'': 'src'},
classifiers=[
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3'
],
install_requires=[
'six'
],
)

setup(**setup_args)
5 changes: 3 additions & 2 deletions src/task_behavior_engine/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# under the License.


from __future__ import absolute_import
import logging
import random

from tree import Behavior
from tree import NodeStatus
from .tree import Behavior
from .tree import NodeStatus

logger = logging.getLogger(__name__)

Expand Down
5 changes: 3 additions & 2 deletions src/task_behavior_engine/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.

from __future__ import absolute_import
import logging

from tree import Decorator
from tree import NodeStatus
from .tree import Decorator
from .tree import NodeStatus

logger = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions src/task_behavior_engine/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# under the License.


from __future__ import absolute_import
from task_behavior_engine.tree import Node
from task_behavior_engine.tree import NodeStatus

Expand Down
9 changes: 5 additions & 4 deletions src/task_behavior_engine/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# under the License.


from __future__ import absolute_import
import logging
import threading
import uuid
Expand All @@ -32,13 +33,13 @@ def __init__(self):
self._locks = {}

def __contains__(self, key):
return key in self._data.keys()
return key in list(self._data.keys())

def __getattr__(self, name):
""" Override getattr to be thread safe. """
if name[0] == '_':
return object.__getattr__(self, name)
if not name in self._locks.keys():
if not name in list(self._locks.keys()):
self._locks[name] = threading.Lock()

with self._locks[name]:
Expand All @@ -51,7 +52,7 @@ def __setattr__(self, name, value):
if name[0] == '_':
return object.__setattr__(self, name, value)

if not name in self._locks.keys():
if not name in list(self._locks.keys()):
self._locks[name] = threading.Lock()

self._locks[name].acquire()
Expand Down Expand Up @@ -79,7 +80,7 @@ def get_data(self, key, default=None):
@param default (None) The default value
@throws KeyError if key not found and default not set
"""
if not key in self._data.keys():
if not key in list(self._data.keys()):
self._data[key] = default
return self._data[key]

Expand Down
1 change: 1 addition & 0 deletions test/test_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from __future__ import absolute_import
from nose.tools import assert_equal

from task_behavior_engine.branch import All
Expand Down
1 change: 1 addition & 0 deletions test/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# under the License.


from __future__ import absolute_import
from nose.tools import assert_equal

from task_behavior_engine.decorator import Fail
Expand Down
11 changes: 6 additions & 5 deletions test/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from __future__ import absolute_import
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_raises
Expand Down Expand Up @@ -46,10 +47,10 @@ def test_assignment(self):
def test_keys(self):
nd = NodeData()
nd.key1 = "first key"
assert_equal(nd.keys(), ['key1'])
assert_equal(list(nd.keys()), ['key1'])
nd.key2 = "second key"
assert_equal(True, 'key2' in nd.keys())
assert_equal(True, 'key1' in nd.keys())
assert_equal(True, 'key2' in list(nd.keys()))
assert_equal(True, 'key1' in list(nd.keys()))

def test_get_data(self):
nd = NodeData()
Expand Down Expand Up @@ -138,7 +139,7 @@ def test_node_memory(self):
assert_equal(b._get_node_memory("uuid"), {})
# test unknown uuid memory
memory = b._get_node_memory("test_uuid")
assert_equal(memory.keys(), ['node_data', 'remapping'])
assert_equal(list(memory.keys()), ['node_data', 'remapping'])
# test _get_node_memory
memory['test_memory'] = 'test'
memory = b._get_node_memory("test_uuid")
Expand All @@ -149,7 +150,7 @@ def test_memory(self):
# test manually set memory
node_memory = {'node_data': {'test_memory': 'test'}, 'remapping': {}}
node_data = b._get_node_data(node_memory)
assert_equal(node_data.keys(), ['test_memory'])
assert_equal(list(node_data.keys()), ['test_memory'])
# test non-existing memory
assert_raises(KeyError, b.get, 'test', 'node_scope')
# test save
Expand Down