修复找不到sub_task_seq的Bug

This commit is contained in:
ChenXL97 2023-11-14 20:08:54 +08:00
parent 3e7f631f3c
commit 900ec490e9
13 changed files with 27 additions and 1094 deletions

View File

@ -36,15 +36,10 @@ class Bahavior(ptree.behaviour.Behaviour):
return ins_name
def __init__(self,*args):
self.name = Bahavior.get_ins_name(*args)
#get valid args
# self.valid_arg_list = []
# lines = self.valid_params.strip().splitlines()
# for line in lines:
# self.valid_arg_list.append((x.strip for x in line.split(",")))
ins_name = self.__class__.get_ins_name(*args)
self.args = args
super().__init__(self.name)
super().__init__(ins_name)
def _update(self) -> ptree.common.Status:
print("this is just a _base behavior node.")

View File

@ -187,7 +187,7 @@ class OptBTExpAlgorithm:
self.ptml_string += c_set_str
elif child.type == 'act':
if '(' not in child.content.name:
self.ptml_string += 'act '+child.content.name+"()\n"
self.ptml_string += 'act ' + child.content.name + "()\n"
else:
self.ptml_string += 'act ' + child.content.name + "\n"
elif isinstance(child, ControlBT):

View File

@ -10,7 +10,7 @@ import time
def print_action_data_table(goal,start,actions):
data = []
for a in actions:
data.append([a.name ,a.pre ,a.add ,a.del_set ,a.cost])
data.append([a.name , a.pre , a.add , a.del_set , a.cost])
data.append(["Goal" ,goal ," " ,"Start" ,start])
print(tabulate(data, headers=["Name", "Pre", "Add" ,"Del" ,"Cost"], tablefmt="fancy_grid")) # grid plain simple github fancy_grid

View File

@ -20,8 +20,10 @@ with open(file_path,'r',encoding="utf-8") as f:
def ask_llm(question):
if question in test_questions_dict:
return test_questions_dict[question]
ans = single_round(question)
ans = test_questions_dict[question]
else:
ans = single_round(question)
print(f"大模型输出: {ans}")
return ans

View File

@ -1 +1 @@
{"测试VLM做一杯咖啡": {"Answer": "测试VLM做一杯咖啡", "Goal": "{\"At(Coffee,Bar)\"}"}, "测试VLM前往桌子2": {"Answer": " 测试VLM前往桌子2", "Goal": "{\"At(Robot,Table2)\"}"}, "测试AEM": {"Answer": "测试AEM", "Goal": "{\"EnvExplored()\"}"}, "测试VLM倒一杯水": {"Answer": "测试VLM倒一杯水", "Goal": "{\"On(Water,WaterTable)\"}"}, "测试VLM开空调": {"Answer": "测试VLM开空调", "Goal": "{\"Is(AC,On)\"}"}, "测试VLM关空调": {"Answer": "测试VLM关空调", "Goal": "{\"Is(AC,Off)\"}"}, "测试VLM关大厅灯": {"Answer": "测试VLM关大厅灯", "Goal": "{\"Is(HallLight,Off)\"}"}, "测试VLM开大厅灯": {"Answer": "测试VLM开大厅灯", "Goal": "{\"Is(HallLight,On)\"}"}, "测试VLM关筒灯": {"Answer": "测试VLM关筒灯", "Goal": "{\"Is(TubeLight,Off)\"}"}, "测试VLM开筒灯": {"Answer": "测试VLM开筒灯", "Goal": "{\"Is(TubeLight,On)\"}"}, "测试VLM关窗帘": {"Answer": "测试VLM关窗帘", "Goal": "{\"Is(Curtain,Off)\"}"}, "测试VLM开窗帘": {"Answer": "测试VLM开窗帘", "Goal": "{\"Is(Curtain,On)\"}"}, "测试VLM拖地": {"Answer": "测试VLM拖地", "Goal": "{\"Is(Floor,Clean)\"}"}, "测试VLM擦桌子": {"Answer": "测试VLM擦桌子", "Goal": "{\"Is(Table1,Clean)\"}"}, "测试VLM整理椅子": {"Answer": "测试VLM整理椅子", "Goal": "{\"Is(Chairs,Clean)\"}"}, "测试VLM把冰红茶放到Table2": {"Answer": "测试VLM把冰红茶放到Table2", "Goal": "{\"On(BottledDrink,Table2)\"}"}}
{"测试VLM做一杯咖啡": {"Answer": "测试VLM做一杯咖啡", "Goal": "{\"At(Coffee,Bar)\"}"}, "测试VLN前往2号桌": {"Answer": " 测试VLN前往2号桌", "Goal": "{\"At(Robot,Table2)\"}"}, "测试AEM": {"Answer": "测试AEM", "Goal": "{\"EnvExplored()\"}"}, "测试VLM倒一杯水": {"Answer": "测试VLM倒一杯水", "Goal": "{\"On(Water,WaterTable)\"}"}, "测试VLM开空调": {"Answer": "测试VLM开空调", "Goal": "{\"Is(AC,On)\"}"}, "测试VLM关空调": {"Answer": "测试VLM关空调", "Goal": "{\"Is(AC,Off)\"}"}, "测试VLM关大厅灯": {"Answer": "测试VLM关大厅灯", "Goal": "{\"Is(HallLight,Off)\"}"}, "测试VLM开大厅灯": {"Answer": "测试VLM开大厅灯", "Goal": "{\"Is(HallLight,On)\"}"}, "测试VLM关筒灯": {"Answer": "测试VLM关筒灯", "Goal": "{\"Is(TubeLight,Off)\"}"}, "测试VLM开筒灯": {"Answer": "测试VLM开筒灯", "Goal": "{\"Is(TubeLight,On)\"}"}, "测试VLM关窗帘": {"Answer": "测试VLM关窗帘", "Goal": "{\"Is(Curtain,Off)\"}"}, "测试VLM开窗帘": {"Answer": "测试VLM开窗帘", "Goal": "{\"Is(Curtain,On)\"}"}, "测试VLM拖地": {"Answer": "测试VLM拖地", "Goal": "{\"Is(Floor,Clean)\"}"}, "测试VLM擦桌子": {"Answer": "测试VLM擦桌子", "Goal": "{\"Is(Table1,Clean)\"}"}, "测试VLM整理椅子": {"Answer": "测试VLM整理椅子", "Goal": "{\"Is(Chairs,Clean)\"}"}, "测试VLM把冰红茶放到Table2": {"Answer": "测试VLM把冰红茶放到Table2", "Goal": "{\"On(BottledDrink,Table2)\"}"}}

View File

@ -1,6 +1,6 @@
Question,Answer,Goal
测试VLM做一杯咖啡,测试VLM做一杯咖啡,"{""At(Coffee,Bar)""}"
测试VLM前往桌子2, 测试VLM前往桌子2,"{""At(Robot,Table2)""}"
测试VLN前往2号桌,测试VLN前往2号桌,"{""At(Robot,Table2)""}"
测试AEM,测试AEM,"{""EnvExplored()""}"
测试VLM倒一杯水,测试VLM倒一杯水,"{""On(Water,WaterTable)""}"
测试VLM开空调,测试VLM开空调,"{""Is(AC,On)""}"

1 Question Answer Goal
2 测试VLM:做一杯咖啡 测试VLM:做一杯咖啡 {"At(Coffee,Bar)"}
3 测试VLM:前往桌子2 测试VLN:前往2号桌 测试VLM:前往桌子2 测试VLN:前往2号桌 {"At(Robot,Table2)"}
4 测试AEM 测试AEM {"EnvExplored()"}
5 测试VLM:倒一杯水 测试VLM:倒一杯水 {"On(Water,WaterTable)"}
6 测试VLM:开空调 测试VLM:开空调 {"Is(AC,On)"}

View File

@ -32,7 +32,8 @@ class Robot(object):
def load_BT(self):
self.bt = load_bt_from_ptml(self.scene, self.ptml_path,self.behavior_lib_path)
sub_task_place_holder = find_node_by_name(self.bt.root,"SubTaskPlaceHolder")
sub_task_place_holder = find_node_by_name(self.bt.root,"SubTaskPlaceHolder()")
print(sub_task_place_holder)
if sub_task_place_holder:
sub_task_seq = sub_task_place_holder.parent
sub_task_seq.children.pop()
@ -44,12 +45,13 @@ class Robot(object):
def expand_sub_task_tree(self,goal):
if self.action_list is None:
self.action_list = self.collect_action_nodes()
print("\n--------------------")
print(f"首次运行行为树扩展算法,收集到{len(self.action_list)}个有效动作:")
for a in self.action_list:
if "Turn" in a.name:
print(a.name)
print(f"首次运行行为树扩展算法")
self.action_list = self.collect_action_nodes()
print(f"共收集到{len(self.action_list)}个实例化动作:")
# for a in self.action_list:
# if "Turn" in a.name:
# print(a.name)
print("--------------------\n")
@ -85,6 +87,7 @@ class Robot(object):
behavior_dict = load_behavior_tree_lib()
for cls in behavior_dict["act"].values():
if cls.can_be_expanded:
print(f"可扩展动作:{cls.__name__}, 存在{len(cls.valid_args)}个有效论域组合")
if cls.num_args == 0:
action_list.append(Action(name=cls.get_ins_name(),**cls.get_info()))
if cls.num_args == 1:
@ -94,7 +97,7 @@ class Robot(object):
for args in cls.valid_args:
action_list.append(Action(name=cls.get_ins_name(*args),**cls.get_info(*args)))
print(action_list)
# print(action_list)
# action_list = [
# Action(name='MakeCoffee', pre={'At(Robot,CoffeeMachine)'},
# add={'At(Coffee,Bar)'}, del_set=set(), cost=1),

View File

@ -22,7 +22,7 @@ class SceneVLN(Scene):
super().__init__(robot)
# 在这里加入场景中发生的事件, (事件发生的时间,事件函数)
self.event_list = [
(5, self.create_chat_event("测试VLN前往")),
(5, self.create_chat_event("测试VLN前往2号")),
]
def _reset(self):

View File

@ -129,7 +129,7 @@ def dot_tree(
root_name = str(root.id)
node_root = pydot.Node(
name=root_name,
label=get_node_label(root.name, root),
label=get_node_label(root.ins_name, root),
shape=node_shape,
style="filled",
fillcolor=node_colour,
@ -319,7 +319,7 @@ def render_dot_tree(root: behaviour.Behaviour,
root, visibility_level, collapse_decorators,
with_blackboard_variables=with_blackboard_variables,
with_qualified_names=with_qualified_names)
filename_wo_extension_to_convert = root.name if name is None else name
filename_wo_extension_to_convert = root.ins_name if name is None else name
filename_wo_extension = utilities.get_valid_filename(filename_wo_extension_to_convert)
filenames = {}
for extension, writer in {"dot": graph.write, "png": graph.write_png, "svg": graph.write_svg}.items():

View File

@ -1,7 +1,7 @@
import os
from robowaiter import Robot, task_map
TASK_NAME = 'VLM'
TASK_NAME = 'VLN'
# create robot
project_path = "./robowaiter"

File diff suppressed because it is too large Load Diff

View File

@ -183,7 +183,7 @@ class OptBTExpAlgorithm:
c_set_str = ', '.join(map(str, child.content)) + "\n"
self.ptml_string += c_set_str
elif child.type == 'act':
self.ptml_string += 'act '+child.content.name+"\n"
self.ptml_string += 'act ' + child.content.name + "\n"
elif isinstance(child, ControlBT):
if parnode.type == '?':
self.ptml_string += "selector{\n"

View File

@ -10,7 +10,7 @@ import time
def print_action_data_table(goal,start,actions):
data = []
for a in actions:
data.append([a.name ,a.pre ,a.add ,a.del_set ,a.cost])
data.append([a.name , a.pre , a.add , a.del_set , a.cost])
data.append(["Goal" ,goal ," " ,"Start" ,start])
print(tabulate(data, headers=["Name", "Pre", "Add" ,"Del" ,"Cost"], tablefmt="fancy_grid")) # grid plain simple github fancy_grid