From f637e871bad2fa5ce4207036e1f7ddffffe10e26 Mon Sep 17 00:00:00 2001 From: ChenXL97 <908926798@qq.com> Date: Sat, 18 Nov 2023 14:51:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E9=A1=BE=E5=AE=A2=E9=A2=86?= =?UTF-8?q?=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robowaiter/behavior_lib/act/DealChat.py | 5 +++++ robowaiter/behavior_lib/act/DelSubTree.py | 2 ++ robowaiter/behavior_lib/act/GreetCustomer.py | 2 ++ robowaiter/behavior_lib/act/ServeCustomer.py | 5 ++--- .../cond/{Chatting.py => CustomerChatting.py} | 2 +- robowaiter/behavior_lib/cond/FocusingCustomer.py | 16 ++++++++++++++++ .../{DetectCustomer.py => NewCustomerComing.py} | 2 +- robowaiter/robot/Default.ptml | 11 ++++++++--- robowaiter/robot/robot.py | 3 +-- robowaiter/scene/scene.py | 3 ++- robowaiter/scene/tasks/VLM/VLN_greet_lead.py | 8 +------- 11 files changed, 41 insertions(+), 18 deletions(-) rename robowaiter/behavior_lib/cond/{Chatting.py => CustomerChatting.py} (96%) create mode 100644 robowaiter/behavior_lib/cond/FocusingCustomer.py rename robowaiter/behavior_lib/cond/{DetectCustomer.py => NewCustomerComing.py} (93%) diff --git a/robowaiter/behavior_lib/act/DealChat.py b/robowaiter/behavior_lib/act/DealChat.py index fa4cf11..a47ea66 100644 --- a/robowaiter/behavior_lib/act/DealChat.py +++ b/robowaiter/behavior_lib/act/DealChat.py @@ -16,6 +16,11 @@ class DealChat(Act): self.create_sub_task(sentence) return ptree.common.Status.RUNNING + self.scene.state["attention"]["customer"] = name + self.scene.state["serve_state"] = { + "last_chat_time": self.scene.time, + } + self.chat_history += sentence + '\n' diff --git a/robowaiter/behavior_lib/act/DelSubTree.py b/robowaiter/behavior_lib/act/DelSubTree.py index 9c43c00..f139eed 100644 --- a/robowaiter/behavior_lib/act/DelSubTree.py +++ b/robowaiter/behavior_lib/act/DelSubTree.py @@ -9,6 +9,8 @@ class DelSubTree(Act): super().__init__(*args) def _update(self) -> ptree.common.Status: + self.scene.state["attention"] = {} + sub_task_tree = self.parent self.scene.sub_task_seq.children.remove(sub_task_tree) return Status.RUNNING \ No newline at end of file diff --git a/robowaiter/behavior_lib/act/GreetCustomer.py b/robowaiter/behavior_lib/act/GreetCustomer.py index 9297dd4..94ac629 100644 --- a/robowaiter/behavior_lib/act/GreetCustomer.py +++ b/robowaiter/behavior_lib/act/GreetCustomer.py @@ -28,4 +28,6 @@ class GreetCustomer(Act): customer_name = self.scene.state['attention']['customer'] self.scene.state['greeted_customers'].add(customer_name) + + return ptree.common.Status.RUNNING diff --git a/robowaiter/behavior_lib/act/ServeCustomer.py b/robowaiter/behavior_lib/act/ServeCustomer.py index 1b4312e..0c9f888 100644 --- a/robowaiter/behavior_lib/act/ServeCustomer.py +++ b/robowaiter/behavior_lib/act/ServeCustomer.py @@ -3,9 +3,6 @@ from robowaiter.behavior_lib._base.Act import Act from robowaiter.algos.navigator.navigate import Navigator class ServeCustomer(Act): - can_be_expanded = False - num_args = 0 - valid_args = () def __init__(self, *args): super().__init__(*args) @@ -20,6 +17,8 @@ class ServeCustomer(Act): return info def _update(self) -> ptree.common.Status: + # if self.scene.time - self.scene.state["serve_state"]["last_chat_time"] > 10: + # self.chat_bubble goal = Act.place_xyz_dic['Bar'] self.scene.walk_to(goal[0]-5,goal[1], 180, 180, 0) diff --git a/robowaiter/behavior_lib/cond/Chatting.py b/robowaiter/behavior_lib/cond/CustomerChatting.py similarity index 96% rename from robowaiter/behavior_lib/cond/Chatting.py rename to robowaiter/behavior_lib/cond/CustomerChatting.py index ec83aa2..5d26c85 100644 --- a/robowaiter/behavior_lib/cond/Chatting.py +++ b/robowaiter/behavior_lib/cond/CustomerChatting.py @@ -2,7 +2,7 @@ import py_trees as ptree from typing import Any from robowaiter.behavior_lib._base.Cond import Cond -class Chatting(Cond): +class CustomerChatting(Cond): def __init__(self): diff --git a/robowaiter/behavior_lib/cond/FocusingCustomer.py b/robowaiter/behavior_lib/cond/FocusingCustomer.py new file mode 100644 index 0000000..9420c1e --- /dev/null +++ b/robowaiter/behavior_lib/cond/FocusingCustomer.py @@ -0,0 +1,16 @@ +import py_trees as ptree +from typing import Any +from robowaiter.behavior_lib._base.Cond import Cond + +class FocusingCustomer(Cond): + + def __init__(self): + super().__init__() + + + def _update(self) -> ptree.common.Status: + # if self.scene.status? + if "customer" in self.scene.state['attention']: + return ptree.common.Status.SUCCESS + else: + return ptree.common.Status.FAILURE diff --git a/robowaiter/behavior_lib/cond/DetectCustomer.py b/robowaiter/behavior_lib/cond/NewCustomerComing.py similarity index 93% rename from robowaiter/behavior_lib/cond/DetectCustomer.py rename to robowaiter/behavior_lib/cond/NewCustomerComing.py index 7595f63..a77c190 100644 --- a/robowaiter/behavior_lib/cond/DetectCustomer.py +++ b/robowaiter/behavior_lib/cond/NewCustomerComing.py @@ -3,7 +3,7 @@ from typing import Any from robowaiter.behavior_lib._base.Cond import Cond import itertools -class DetectCustomer(Cond): +class NewCustomerComing(Cond): can_be_expanded = False num_params = 0 valid_args = () diff --git a/robowaiter/robot/Default.ptml b/robowaiter/robot/Default.ptml index e1a98fa..b498f75 100644 --- a/robowaiter/robot/Default.ptml +++ b/robowaiter/robot/Default.ptml @@ -2,9 +2,8 @@ selector { sequence { - cond Chatting() + cond CustomerChatting() act DealChat() - } sequence { @@ -16,7 +15,12 @@ selector } sequence { - cond DetectCustomer() + cond FocusingCustomer() + act ServeCustomer() + } + sequence + { + cond NewCustomerComing() selector { cond At(Robot,Bar) @@ -24,4 +28,5 @@ selector } act GreetCustomer() } + } \ No newline at end of file diff --git a/robowaiter/robot/robot.py b/robowaiter/robot/robot.py index bc79121..40af1af 100644 --- a/robowaiter/robot/robot.py +++ b/robowaiter/robot/robot.py @@ -41,7 +41,6 @@ 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()") - print(sub_task_place_holder) if sub_task_place_holder: sub_task_seq = sub_task_place_holder.parent sub_task_seq.children.pop() @@ -53,7 +52,7 @@ class Robot(object): def expand_sub_task_tree(self,goal): if self.action_list is None: - print("\n--------------------") + print("\n\n--------------------") print(f"首次运行行为树扩展算法") self.action_list = self.collect_action_nodes() print(f"共收集到{len(self.action_list)}个实例化动作:") diff --git a/robowaiter/scene/scene.py b/robowaiter/scene/scene.py index 6d15ef4..4acb354 100644 --- a/robowaiter/scene/scene.py +++ b/robowaiter/scene/scene.py @@ -69,7 +69,8 @@ class Scene: "customer_mem":{}, "served_mem":{}, "greeted_customers":set(), - "attention":{} + "attention":{}, + "serve_state":{}, } """ status: diff --git a/robowaiter/scene/tasks/VLM/VLN_greet_lead.py b/robowaiter/scene/tasks/VLM/VLN_greet_lead.py index 6d4c090..39ac481 100644 --- a/robowaiter/scene/tasks/VLM/VLN_greet_lead.py +++ b/robowaiter/scene/tasks/VLM/VLN_greet_lead.py @@ -32,12 +32,6 @@ class SceneVLM(Scene): def _step(self): - # self.control_walker( - # [self.walker_control_generator(walkerID=0, autowalk=False, speed=200, X=60, Y=520, Yaw=180)]) - # time.sleep(3) - # cont = self.status.walkers[0].name+":请问可以带我去空位上嘛?我想晒太阳。" - # self.control_robot_action(0,3,cont) - # 如果机器人不在 吧台 # if "At(Robot,Bar)" not in self.state['condition_set']: @@ -50,7 +44,7 @@ class SceneVLM(Scene): # if int(self.status.location.X)!=247 or int(self.status.location.X)!=520: self.walker_followed = True self.control_walker( - [self.walker_control_generator(walkerID=0, autowalk=False, speed=100, X=end[0], Y=end[1], Yaw=-90)]) + [self.walker_control_generator(walkerID=0, autowalk=False, speed=300, X=end[0], Y=end[1], Yaw=-90)]) cont = self.status.walkers[0].name+"谢谢!" self.control_robot_action(0,3,cont)