Merge branch 'main' of github.com:HPCL-EI/RoboWaiter
This commit is contained in:
commit
02e3de9ccf
|
@ -33,6 +33,7 @@ def load(scene, ptml_path: str, behaviour_lib_path: str):
|
||||||
)
|
)
|
||||||
|
|
||||||
# noting fault, go next
|
# noting fault, go next
|
||||||
|
ptml_path = format_trans_to_bracket(ptml_path)
|
||||||
input_stream = FileStream(ptml_path, encoding="utf-8")
|
input_stream = FileStream(ptml_path, encoding="utf-8")
|
||||||
|
|
||||||
lexer = Lexer(input_stream)
|
lexer = Lexer(input_stream)
|
||||||
|
@ -50,3 +51,55 @@ def load(scene, ptml_path: str, behaviour_lib_path: str):
|
||||||
walker.walk(ptml, tree)
|
walker.walk(ptml, tree)
|
||||||
|
|
||||||
return ptml.bt_root
|
return ptml.bt_root
|
||||||
|
|
||||||
|
|
||||||
|
def format_trans_to_bracket(file_path: str) -> str:
|
||||||
|
"""_summary_
|
||||||
|
|
||||||
|
Args:
|
||||||
|
file_path (str): _description_
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
FileNotFoundError: _description_
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: the path tp temp file with '{}' form.
|
||||||
|
"""
|
||||||
|
import autopep8
|
||||||
|
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
raise FileNotFoundError("Given a fault ptml path: {}".format(file_path))
|
||||||
|
|
||||||
|
def counter_(input:str) -> int:
|
||||||
|
length = 0
|
||||||
|
for i in range(len(input)):
|
||||||
|
if input[i] == ' ':
|
||||||
|
length += 1
|
||||||
|
else:
|
||||||
|
if length % 4 != 0:
|
||||||
|
raise TabError('Tab length in ptml file should be 4.')
|
||||||
|
return length
|
||||||
|
|
||||||
|
with open(file_path, 'r') as file:
|
||||||
|
ptml_new = ''
|
||||||
|
ptml_tab = file.readlines()
|
||||||
|
|
||||||
|
level = 0
|
||||||
|
for i in ptml_tab:
|
||||||
|
new_level = counter_(i) // 4
|
||||||
|
if new_level == level:
|
||||||
|
ptml_new += i
|
||||||
|
elif new_level > level:
|
||||||
|
ptml_new += '{\n' + i
|
||||||
|
elif new_level < level:
|
||||||
|
ptml_new += '\n}' + i
|
||||||
|
level = new_level
|
||||||
|
ptml_new += '}'
|
||||||
|
|
||||||
|
import re
|
||||||
|
new_path = re.sub('/[a-zA-Z0-9_]*\.ptml', '/bracket_ptml.ptml',file_path)
|
||||||
|
with open(new_path, 'w+') as file:
|
||||||
|
file.write(ptml_new)
|
||||||
|
return new_path
|
||||||
|
|
||||||
|
# format_trans_to_bracket('/home/wu/RoboWaiter/robowaiter/behavior_tree/ptml/test/tab_test.ptml')
|
|
@ -0,0 +1,9 @@
|
||||||
|
selector
|
||||||
|
{
|
||||||
|
sequence
|
||||||
|
{
|
||||||
|
cond Chatting()
|
||||||
|
act DealChat()
|
||||||
|
|
||||||
|
} act At(Coffee,Table)
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
import os
|
import os
|
||||||
import py_trees as ptree
|
import py_trees as ptree
|
||||||
|
|
||||||
from robowaiter.scene.scene import Scene
|
# from robowaiter.scene.scene import Scene
|
||||||
from robowaiter.behavior_tree.ptml.ptmlCompiler import load
|
# from robowaiter.behavior_tree.ptml.ptmlCompiler import load
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from robowaiter import Robot, task_map
|
from robowaiter import Robot, task_map
|
||||||
|
@ -13,7 +13,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# create robot
|
# create robot
|
||||||
project_path = "../../../"
|
project_path = "../../../"
|
||||||
ptml_path = os.path.join(project_path, 'behavior_tree/ptml/test/Test.ptml')
|
ptml_path = os.path.join(project_path, 'behavior_tree/ptml/test/tab_test.ptml')
|
||||||
behavior_lib_path = os.path.join(project_path, 'behavior_lib')
|
behavior_lib_path = os.path.join(project_path, 'behavior_lib')
|
||||||
|
|
||||||
robot = Robot(ptml_path, behavior_lib_path)
|
robot = Robot(ptml_path, behavior_lib_path)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
selector
|
||||||
|
sequence
|
||||||
|
cond Chatting()
|
||||||
|
act DealChat()
|
||||||
|
act At(Coffee,Table)
|
Loading…
Reference in New Issue