实现事件驱动的场景
This commit is contained in:
parent
02e3de9ccf
commit
98852e6276
|
@ -6,4 +6,5 @@ gym==0.21.0
|
|||
grpcio==1.53.0
|
||||
requests
|
||||
urllib3
|
||||
tabulate
|
||||
tabulate
|
||||
autopep8
|
|
@ -2,6 +2,7 @@ import py_trees as ptree
|
|||
from typing import Any
|
||||
from robowaiter.behavior_lib._base.Act import Act
|
||||
from robowaiter.llm_client.ask_llm import ask_llm
|
||||
from robowaiter.behavior_tree.utils import load_bt_from_ptml,print_tree_from_root
|
||||
|
||||
class DealChat(Act):
|
||||
def __init__(self):
|
||||
|
@ -16,9 +17,12 @@ class DealChat(Act):
|
|||
self.scene.chat_bubble(f"开始测试VLN")
|
||||
self.scene.state['sub_task_list'].append(("At(Robot, Table)",))
|
||||
|
||||
|
||||
answer = ask_llm(chat)
|
||||
print(f"机器人回答:{answer}")
|
||||
self.scene.chat_bubble(f"机器人回答:{answer}")
|
||||
|
||||
return ptree.common.Status.RUNNING
|
||||
|
||||
|
||||
def create_sub_task(goal):
|
||||
pass
|
|
@ -7,16 +7,5 @@ class ExploreEnv(Act):
|
|||
def __init__(self, *args):
|
||||
super().__init__(*args)
|
||||
|
||||
def setup(self, **kwargs: Any) -> None:
|
||||
return super().setup(**kwargs)
|
||||
|
||||
def initialise(self) -> None:
|
||||
return super().initialise()
|
||||
|
||||
def _update(self) -> ptree.common.Status:
|
||||
print('Start checking IsChatting...')
|
||||
return ptree.common.Status.SUCCESS
|
||||
|
||||
def terminate(self, new_status: ptree.common.Status) -> None:
|
||||
return super().terminate(new_status)
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
selector
|
||||
selector
|
||||
cond HasMap()
|
||||
act ExploreEnv()
|
||||
sequence
|
||||
cond Chatting()
|
||||
act DealChat()
|
||||
sequence
|
||||
cond HasSubTask()
|
||||
sequence
|
||||
cond At(Robot,Table)
|
||||
cond At(Robot,Table)
|
|
@ -1,9 +1,20 @@
|
|||
selector
|
||||
{
|
||||
sequence
|
||||
selector
|
||||
{
|
||||
cond HasMap()
|
||||
act ExploreEnv()
|
||||
|
||||
} sequence
|
||||
{
|
||||
cond Chatting()
|
||||
act DealChat()
|
||||
|
||||
} act At(Coffee,Table)
|
||||
}
|
||||
} sequence
|
||||
{
|
||||
cond HasSubTask()
|
||||
sequence
|
||||
{
|
||||
cond At(Robot,Table)
|
||||
|
||||
} cond At(Robot,Table)}
|
|
@ -13,7 +13,7 @@ if __name__ == '__main__':
|
|||
|
||||
# create robot
|
||||
project_path = "../../../"
|
||||
ptml_path = os.path.join(project_path, 'behavior_tree/ptml/test/tab_test.ptml')
|
||||
ptml_path = os.path.join(project_path, 'behavior_tree/ptml/test/Default.ptml')
|
||||
behavior_lib_path = os.path.join(project_path, 'behavior_lib')
|
||||
|
||||
robot = Robot(ptml_path, behavior_lib_path)
|
||||
|
|
|
@ -3,13 +3,27 @@ ordering=out;
|
|||
graph [fontname="times-roman"];
|
||||
node [fontname="times-roman"];
|
||||
edge [fontname="times-roman"];
|
||||
selector_4aUN4FAA [fillcolor=cyan, fontcolor=black, fontsize=9, label=selector_4aUN4FAA, shape=octagon, style=filled];
|
||||
sequence_BNun8ZFM [fillcolor=orange, fontcolor=black, fontsize=9, label=sequence_BNun8ZFM, shape=box, style=filled];
|
||||
selector_4aUN4FAA -> sequence_BNun8ZFM;
|
||||
Selector [fillcolor=cyan, fontcolor=black, fontsize=9, label=Selector, shape=octagon, style=filled];
|
||||
"Selector*" [fillcolor=cyan, fontcolor=black, fontsize=9, label="Selector*", shape=octagon, style=filled];
|
||||
Selector -> "Selector*";
|
||||
HasMap [fillcolor=gray, fontcolor=black, fontsize=9, label=HasMap, shape=ellipse, style=filled];
|
||||
"Selector*" -> HasMap;
|
||||
ExploreEnv [fillcolor=gray, fontcolor=black, fontsize=9, label=ExploreEnv, shape=ellipse, style=filled];
|
||||
"Selector*" -> ExploreEnv;
|
||||
Sequence [fillcolor=orange, fontcolor=black, fontsize=9, label=Sequence, shape=box, style=filled];
|
||||
Selector -> Sequence;
|
||||
Chatting [fillcolor=gray, fontcolor=black, fontsize=9, label=Chatting, shape=ellipse, style=filled];
|
||||
sequence_BNun8ZFM -> Chatting;
|
||||
Sequence -> Chatting;
|
||||
DealChat [fillcolor=gray, fontcolor=black, fontsize=9, label=DealChat, shape=ellipse, style=filled];
|
||||
sequence_BNun8ZFM -> DealChat;
|
||||
"At(Coffee,Table)" [fillcolor=gray, fontcolor=black, fontsize=9, label="At(Coffee,Table)", shape=ellipse, style=filled];
|
||||
selector_4aUN4FAA -> "At(Coffee,Table)";
|
||||
Sequence -> DealChat;
|
||||
"Sequence*" [fillcolor=orange, fontcolor=black, fontsize=9, label="Sequence*", shape=box, style=filled];
|
||||
Selector -> "Sequence*";
|
||||
HasSubTask [fillcolor=gray, fontcolor=black, fontsize=9, label=HasSubTask, shape=ellipse, style=filled];
|
||||
"Sequence*" -> HasSubTask;
|
||||
"Sequence**" [fillcolor=orange, fontcolor=black, fontsize=9, label="Sequence**", shape=box, style=filled];
|
||||
"Sequence*" -> "Sequence**";
|
||||
"At(Robot,Table)" [fillcolor=gray, fontcolor=black, fontsize=9, label="At(Robot,Table)", shape=ellipse, style=filled];
|
||||
"Sequence**" -> "At(Robot,Table)";
|
||||
"At(Robot,Table)*" [fillcolor=gray, fontcolor=black, fontsize=9, label="At(Robot,Table)*", shape=ellipse, style=filled];
|
||||
"Sequence*" -> "At(Robot,Table)*";
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 34 KiB |
|
@ -4,64 +4,148 @@
|
|||
<!-- Generated by graphviz version 9.0.0 (20230911.1827)
|
||||
-->
|
||||
<!-- Title: pastafarianism Pages: 1 -->
|
||||
<svg width="233pt" height="188pt"
|
||||
viewBox="0.00 0.00 232.96 188.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 184)">
|
||||
<svg width="584pt" height="260pt"
|
||||
viewBox="0.00 0.00 583.62 260.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 256)">
|
||||
<title>pastafarianism</title>
|
||||
<polygon fill="white" stroke="none" points="-4,4 -4,-184 228.96,-184 228.96,4 -4,4"/>
|
||||
<!-- selector_4aUN4FAA -->
|
||||
<polygon fill="white" stroke="none" points="-4,4 -4,-256 579.62,-256 579.62,4 -4,4"/>
|
||||
<!-- Selector -->
|
||||
<g id="node1" class="node">
|
||||
<title>selector_4aUN4FAA</title>
|
||||
<polygon fill="cyan" stroke="black" points="181.38,-154.54 181.38,-169.46 146.4,-180 96.92,-180 61.94,-169.46 61.94,-154.54 96.92,-144 146.4,-144 181.38,-154.54"/>
|
||||
<text text-anchor="middle" x="121.66" y="-159.07" font-family="Times New Roman,serif" font-size="9.00">selector_4aUN4FAA</text>
|
||||
<title>Selector</title>
|
||||
<polygon fill="cyan" stroke="black" points="255.05,-226.54 255.05,-241.46 238.35,-252 214.74,-252 198.05,-241.46 198.05,-226.54 214.74,-216 238.35,-216 255.05,-226.54"/>
|
||||
<text text-anchor="middle" x="226.55" y="-231.07" font-family="Times New Roman,serif" font-size="9.00">Selector</text>
|
||||
</g>
|
||||
<!-- sequence_BNun8ZFM -->
|
||||
<!-- Selector* -->
|
||||
<g id="node2" class="node">
|
||||
<title>sequence_BNun8ZFM</title>
|
||||
<polygon fill="orange" stroke="black" points="114.29,-108 15.04,-108 15.04,-72 114.29,-72 114.29,-108"/>
|
||||
<text text-anchor="middle" x="64.66" y="-87.08" font-family="Times New Roman,serif" font-size="9.00">sequence_BNun8ZFM</text>
|
||||
<title>Selector*</title>
|
||||
<polygon fill="cyan" stroke="black" points="140.93,-154.54 140.93,-169.46 122.55,-180 96.55,-180 78.17,-169.46 78.17,-154.54 96.55,-144 122.55,-144 140.93,-154.54"/>
|
||||
<text text-anchor="middle" x="109.55" y="-159.07" font-family="Times New Roman,serif" font-size="9.00">Selector*</text>
|
||||
</g>
|
||||
<!-- selector_4aUN4FAA->sequence_BNun8ZFM -->
|
||||
<!-- Selector->Selector* -->
|
||||
<g id="edge1" class="edge">
|
||||
<title>selector_4aUN4FAA->sequence_BNun8ZFM</title>
|
||||
<path fill="none" stroke="black" d="M107.57,-143.7C101.01,-135.64 93.08,-125.89 85.82,-116.98"/>
|
||||
<polygon fill="black" stroke="black" points="88.57,-114.82 79.55,-109.28 83.15,-119.24 88.57,-114.82"/>
|
||||
<title>Selector->Selector*</title>
|
||||
<path fill="none" stroke="black" d="M206.44,-220.97C188.24,-210.08 161.19,-193.89 140.28,-181.39"/>
|
||||
<polygon fill="black" stroke="black" points="142.26,-178.49 131.88,-176.36 138.67,-184.5 142.26,-178.49"/>
|
||||
</g>
|
||||
<!-- At(Coffee,Table) -->
|
||||
<!-- Sequence -->
|
||||
<g id="node5" class="node">
|
||||
<title>At(Coffee,Table)</title>
|
||||
<ellipse fill="gray" stroke="black" cx="178.66" cy="-90" rx="46.3" ry="18"/>
|
||||
<text text-anchor="middle" x="178.66" y="-87.08" font-family="Times New Roman,serif" font-size="9.00">At(Coffee,Table)</text>
|
||||
<title>Sequence</title>
|
||||
<polygon fill="orange" stroke="black" points="253.55,-180 199.55,-180 199.55,-144 253.55,-144 253.55,-180"/>
|
||||
<text text-anchor="middle" x="226.55" y="-159.07" font-family="Times New Roman,serif" font-size="9.00">Sequence</text>
|
||||
</g>
|
||||
<!-- selector_4aUN4FAA->At(Coffee,Table) -->
|
||||
<!-- Selector->Sequence -->
|
||||
<g id="edge4" class="edge">
|
||||
<title>selector_4aUN4FAA->At(Coffee,Table)</title>
|
||||
<path fill="none" stroke="black" d="M135.75,-143.7C142.48,-135.44 150.66,-125.39 158.06,-116.3"/>
|
||||
<polygon fill="black" stroke="black" points="160.57,-118.76 164.17,-108.8 155.14,-114.34 160.57,-118.76"/>
|
||||
<title>Selector->Sequence</title>
|
||||
<path fill="none" stroke="black" d="M226.55,-215.7C226.55,-208.41 226.55,-199.73 226.55,-191.54"/>
|
||||
<polygon fill="black" stroke="black" points="230.05,-191.62 226.55,-181.62 223.05,-191.62 230.05,-191.62"/>
|
||||
</g>
|
||||
<!-- Sequence* -->
|
||||
<g id="node8" class="node">
|
||||
<title>Sequence*</title>
|
||||
<polygon fill="orange" stroke="black" points="417.55,-180 363.55,-180 363.55,-144 417.55,-144 417.55,-180"/>
|
||||
<text text-anchor="middle" x="390.55" y="-159.07" font-family="Times New Roman,serif" font-size="9.00">Sequence*</text>
|
||||
</g>
|
||||
<!-- Selector->Sequence* -->
|
||||
<g id="edge7" class="edge">
|
||||
<title>Selector->Sequence*</title>
|
||||
<path fill="none" stroke="black" d="M250.05,-222.97C276.94,-211.49 321.36,-192.53 353.05,-179"/>
|
||||
<polygon fill="black" stroke="black" points="354.05,-182.38 361.88,-175.24 351.31,-175.94 354.05,-182.38"/>
|
||||
</g>
|
||||
<!-- HasMap -->
|
||||
<g id="node3" class="node">
|
||||
<title>HasMap</title>
|
||||
<ellipse fill="gray" stroke="black" cx="28.55" cy="-90" rx="28.55" ry="18"/>
|
||||
<text text-anchor="middle" x="28.55" y="-87.08" font-family="Times New Roman,serif" font-size="9.00">HasMap</text>
|
||||
</g>
|
||||
<!-- Selector*->HasMap -->
|
||||
<g id="edge2" class="edge">
|
||||
<title>Selector*->HasMap</title>
|
||||
<path fill="none" stroke="black" d="M92.37,-146.15C81.09,-136.4 66.14,-123.48 53.54,-112.6"/>
|
||||
<polygon fill="black" stroke="black" points="55.87,-109.99 46.02,-106.1 51.3,-115.28 55.87,-109.99"/>
|
||||
</g>
|
||||
<!-- ExploreEnv -->
|
||||
<g id="node4" class="node">
|
||||
<title>ExploreEnv</title>
|
||||
<ellipse fill="gray" stroke="black" cx="109.55" cy="-90" rx="34.32" ry="18"/>
|
||||
<text text-anchor="middle" x="109.55" y="-87.08" font-family="Times New Roman,serif" font-size="9.00">ExploreEnv</text>
|
||||
</g>
|
||||
<!-- Selector*->ExploreEnv -->
|
||||
<g id="edge3" class="edge">
|
||||
<title>Selector*->ExploreEnv</title>
|
||||
<path fill="none" stroke="black" d="M109.55,-143.7C109.55,-136.41 109.55,-127.73 109.55,-119.54"/>
|
||||
<polygon fill="black" stroke="black" points="113.05,-119.62 109.55,-109.62 106.05,-119.62 113.05,-119.62"/>
|
||||
</g>
|
||||
<!-- Chatting -->
|
||||
<g id="node3" class="node">
|
||||
<g id="node6" class="node">
|
||||
<title>Chatting</title>
|
||||
<ellipse fill="gray" stroke="black" cx="27.66" cy="-18" rx="27.66" ry="18"/>
|
||||
<text text-anchor="middle" x="27.66" y="-15.07" font-family="Times New Roman,serif" font-size="9.00">Chatting</text>
|
||||
<ellipse fill="gray" stroke="black" cx="189.55" cy="-90" rx="27.66" ry="18"/>
|
||||
<text text-anchor="middle" x="189.55" y="-87.08" font-family="Times New Roman,serif" font-size="9.00">Chatting</text>
|
||||
</g>
|
||||
<!-- sequence_BNun8ZFM->Chatting -->
|
||||
<g id="edge2" class="edge">
|
||||
<title>sequence_BNun8ZFM->Chatting</title>
|
||||
<path fill="none" stroke="black" d="M55.52,-71.7C51.27,-63.67 46.13,-53.95 41.43,-45.05"/>
|
||||
<polygon fill="black" stroke="black" points="44.67,-43.69 36.9,-36.48 38.48,-46.96 44.67,-43.69"/>
|
||||
<!-- Sequence->Chatting -->
|
||||
<g id="edge5" class="edge">
|
||||
<title>Sequence->Chatting</title>
|
||||
<path fill="none" stroke="black" d="M217.4,-143.7C213.16,-135.67 208.02,-125.95 203.32,-117.05"/>
|
||||
<polygon fill="black" stroke="black" points="206.56,-115.69 198.79,-108.48 200.37,-118.96 206.56,-115.69"/>
|
||||
</g>
|
||||
<!-- DealChat -->
|
||||
<g id="node4" class="node">
|
||||
<g id="node7" class="node">
|
||||
<title>DealChat</title>
|
||||
<ellipse fill="gray" stroke="black" cx="102.66" cy="-18" rx="29.44" ry="18"/>
|
||||
<text text-anchor="middle" x="102.66" y="-15.07" font-family="Times New Roman,serif" font-size="9.00">DealChat</text>
|
||||
<ellipse fill="gray" stroke="black" cx="264.55" cy="-90" rx="29.44" ry="18"/>
|
||||
<text text-anchor="middle" x="264.55" y="-87.08" font-family="Times New Roman,serif" font-size="9.00">DealChat</text>
|
||||
</g>
|
||||
<!-- sequence_BNun8ZFM->DealChat -->
|
||||
<g id="edge3" class="edge">
|
||||
<title>sequence_BNun8ZFM->DealChat</title>
|
||||
<path fill="none" stroke="black" d="M74.06,-71.7C78.31,-63.87 83.43,-54.44 88.15,-45.73"/>
|
||||
<polygon fill="black" stroke="black" points="91.22,-47.41 92.92,-36.95 85.07,-44.07 91.22,-47.41"/>
|
||||
<!-- Sequence->DealChat -->
|
||||
<g id="edge6" class="edge">
|
||||
<title>Sequence->DealChat</title>
|
||||
<path fill="none" stroke="black" d="M235.94,-143.7C240.19,-135.87 245.31,-126.44 250.04,-117.73"/>
|
||||
<polygon fill="black" stroke="black" points="253.11,-119.41 254.8,-108.95 246.96,-116.07 253.11,-119.41"/>
|
||||
</g>
|
||||
<!-- HasSubTask -->
|
||||
<g id="node9" class="node">
|
||||
<title>HasSubTask</title>
|
||||
<ellipse fill="gray" stroke="black" cx="348.55" cy="-90" rx="36.54" ry="18"/>
|
||||
<text text-anchor="middle" x="348.55" y="-87.08" font-family="Times New Roman,serif" font-size="9.00">HasSubTask</text>
|
||||
</g>
|
||||
<!-- Sequence*->HasSubTask -->
|
||||
<g id="edge8" class="edge">
|
||||
<title>Sequence*->HasSubTask</title>
|
||||
<path fill="none" stroke="black" d="M380.17,-143.7C375.42,-135.78 369.69,-126.23 364.41,-117.44"/>
|
||||
<polygon fill="black" stroke="black" points="367.45,-115.69 359.3,-108.92 361.45,-119.3 367.45,-115.69"/>
|
||||
</g>
|
||||
<!-- Sequence** -->
|
||||
<g id="node10" class="node">
|
||||
<title>Sequence**</title>
|
||||
<polygon fill="orange" stroke="black" points="461.55,-108 403.55,-108 403.55,-72 461.55,-72 461.55,-108"/>
|
||||
<text text-anchor="middle" x="432.55" y="-87.08" font-family="Times New Roman,serif" font-size="9.00">Sequence**</text>
|
||||
</g>
|
||||
<!-- Sequence*->Sequence** -->
|
||||
<g id="edge9" class="edge">
|
||||
<title>Sequence*->Sequence**</title>
|
||||
<path fill="none" stroke="black" d="M400.93,-143.7C405.61,-135.9 411.24,-126.51 416.45,-117.83"/>
|
||||
<polygon fill="black" stroke="black" points="419.36,-119.78 421.51,-109.4 413.36,-116.18 419.36,-119.78"/>
|
||||
</g>
|
||||
<!-- At(Robot,Table)* -->
|
||||
<g id="node12" class="node">
|
||||
<title>At(Robot,Table)*</title>
|
||||
<ellipse fill="gray" stroke="black" cx="527.55" cy="-90" rx="48.08" ry="18"/>
|
||||
<text text-anchor="middle" x="527.55" y="-87.08" font-family="Times New Roman,serif" font-size="9.00">At(Robot,Table)*</text>
|
||||
</g>
|
||||
<!-- Sequence*->At(Robot,Table)* -->
|
||||
<g id="edge11" class="edge">
|
||||
<title>Sequence*->At(Robot,Table)*</title>
|
||||
<path fill="none" stroke="black" d="M417.94,-147C438.66,-136.42 467.35,-121.76 490.18,-110.1"/>
|
||||
<polygon fill="black" stroke="black" points="491.54,-113.33 498.85,-105.66 488.36,-107.09 491.54,-113.33"/>
|
||||
</g>
|
||||
<!-- At(Robot,Table) -->
|
||||
<g id="node11" class="node">
|
||||
<title>At(Robot,Table)</title>
|
||||
<ellipse fill="gray" stroke="black" cx="432.55" cy="-18" rx="45.41" ry="18"/>
|
||||
<text text-anchor="middle" x="432.55" y="-15.07" font-family="Times New Roman,serif" font-size="9.00">At(Robot,Table)</text>
|
||||
</g>
|
||||
<!-- Sequence**->At(Robot,Table) -->
|
||||
<g id="edge10" class="edge">
|
||||
<title>Sequence**->At(Robot,Table)</title>
|
||||
<path fill="none" stroke="black" d="M432.55,-71.7C432.55,-64.41 432.55,-55.73 432.55,-47.54"/>
|
||||
<polygon fill="black" stroke="black" points="436.05,-47.62 432.55,-37.62 429.05,-47.62 436.05,-47.62"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 7.5 KiB |
|
@ -30,7 +30,7 @@ def ask_llm(question):
|
|||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
return result['choices'][0]['message']['content']
|
||||
return result['choices'][0]['message']['content'].strip()
|
||||
else:
|
||||
return "大模型请求失败:", response.status_code
|
||||
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
selector{
|
||||
selector{
|
||||
cond HasMap()
|
||||
act ExploreEnv
|
||||
}
|
||||
sequence{
|
||||
selector
|
||||
// selector
|
||||
// cond HasMap()
|
||||
// act ExploreEnv()
|
||||
sequence
|
||||
cond Chatting()
|
||||
act DealChat()
|
||||
}
|
||||
sequence{
|
||||
sequence
|
||||
cond HasSubTask()
|
||||
sequence{
|
||||
sequence
|
||||
act SubTaskPlaceHolder()
|
||||
}
|
||||
cond At(Talb,ea)
|
||||
}
|
||||
}
|
||||
cond At(Talb,ea)
|
|
@ -0,0 +1,18 @@
|
|||
selector
|
||||
// selector
|
||||
// cond HasMap()
|
||||
// act ExploreEnv()
|
||||
{
|
||||
sequence
|
||||
{
|
||||
cond Chatting()
|
||||
act DealChat()
|
||||
|
||||
} sequence
|
||||
{
|
||||
cond HasSubTask()
|
||||
sequence
|
||||
{
|
||||
act SubTaskPlaceHolder()
|
||||
|
||||
} cond At(Talb,ea)}
|
|
@ -2,6 +2,8 @@ import os
|
|||
import py_trees as ptree
|
||||
|
||||
from robowaiter.behavior_tree.utils import load_bt_from_ptml,find_node_by_name,print_tree_from_root
|
||||
import io
|
||||
import contextlib
|
||||
|
||||
class Robot(object):
|
||||
scene = None
|
||||
|
@ -13,15 +15,18 @@ class Robot(object):
|
|||
|
||||
self.next_response_time = self.response_frequency
|
||||
self.step_num = 0
|
||||
self.last_tick_output = ""
|
||||
|
||||
def set_scene(self,scene):
|
||||
self.scene = scene
|
||||
|
||||
def load_BT(self):
|
||||
self.bt = load_bt_from_ptml(self.scene, self.ptml_path,self.behavior_lib_path)
|
||||
sub_task_seq = find_node_by_name(self.bt.root,"SubTaskPlaceHolder").parent
|
||||
sub_task_seq.children.pop()
|
||||
self.scene.sub_task_seq = sub_task_seq
|
||||
sub_task_place_holder = find_node_by_name(self.bt.root,"SubTaskPlaceHolder")
|
||||
if sub_task_place_holder:
|
||||
sub_task_seq = sub_task_place_holder.parent
|
||||
sub_task_seq.children.pop()
|
||||
self.scene.sub_task_seq = sub_task_seq
|
||||
|
||||
|
||||
def step(self):
|
||||
|
@ -29,11 +34,24 @@ class Robot(object):
|
|||
self.next_response_time += self.response_frequency
|
||||
self.step_num += 1
|
||||
|
||||
print(f"==== step: {self.step_num}, time:{self.scene.time:f}s ======")
|
||||
# 创建一个StringIO对象
|
||||
output = io.StringIO()
|
||||
|
||||
self.bt.tick()
|
||||
# 将print输出重定向到StringIO对象
|
||||
with contextlib.redirect_stdout(output):
|
||||
self.bt.tick()
|
||||
|
||||
print("\n")
|
||||
# 获取StringIO对象中的字符串值
|
||||
contents = output.getvalue()
|
||||
output.close()
|
||||
|
||||
if contents != self.last_tick_output:
|
||||
print(f"==== time:{self.scene.time:f}s ======")
|
||||
|
||||
print(contents)
|
||||
|
||||
print("\n")
|
||||
self.last_tick_output = contents
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
|
@ -33,6 +33,7 @@ def image_extract(camera_data):
|
|||
|
||||
class Scene:
|
||||
robot = None
|
||||
event_list = []
|
||||
|
||||
default_state = {
|
||||
"map": {
|
||||
|
@ -107,9 +108,26 @@ class Scene:
|
|||
# 基类step,默认执行行为树tick操作
|
||||
self.time = time.time() - self.start_time
|
||||
|
||||
self.deal_event()
|
||||
self._step()
|
||||
self.robot.step()
|
||||
|
||||
def deal_event(self):
|
||||
if len(self.event_list)>0:
|
||||
next_event = self.event_list[0]
|
||||
t,func = next_event
|
||||
if self.time >= t:
|
||||
print(f'event: {t}, {func.__name__}')
|
||||
self.event_list.pop(0)
|
||||
func()
|
||||
|
||||
def create_chat_event(self,sentence):
|
||||
def customer_say():
|
||||
print(f'顾客说:{sentence}')
|
||||
self.chat_bubble(f'顾客说:{sentence}')
|
||||
self.state['chat_list'].append(f'{sentence}')
|
||||
|
||||
return customer_say
|
||||
|
||||
@property
|
||||
def status(self):
|
||||
|
@ -122,7 +140,6 @@ class Scene:
|
|||
init_world()
|
||||
|
||||
|
||||
|
||||
def walker_control_generator(self, walkerID, autowalk, speed, X, Y, Yaw):
|
||||
if self.use_offset:
|
||||
X, Y = X + loc_offset[0], Y + loc_offset[1]
|
||||
|
|
|
@ -14,6 +14,12 @@ from robowaiter.scene.scene import Scene
|
|||
class SceneGQA(Scene):
|
||||
def __init__(self, robot):
|
||||
super().__init__(robot)
|
||||
# 在这里加入场景中发生的事件, (事件发生的时间,事件函数)
|
||||
self.event_list = [
|
||||
(5, self.create_chat_event("给我一杯咖啡")),
|
||||
(20, self.create_chat_event("我要拿铁")),
|
||||
(40, self.create_chat_event("再来一杯")),
|
||||
]
|
||||
|
||||
def _reset(self):
|
||||
self.add_walker(1085, 2630, 220)
|
||||
|
@ -22,10 +28,3 @@ class SceneGQA(Scene):
|
|||
|
||||
def _run(self):
|
||||
pass
|
||||
|
||||
def _step(self):
|
||||
|
||||
if int(self.time)% 5 == 0:
|
||||
print("顾客说:请问你们这里有哪些咖啡")
|
||||
self.chat_bubble('顾客说:请问你们这里有哪些咖啡')
|
||||
self.state['chat_list'].append('请问你们这里有哪些咖啡')
|
||||
|
|
|
@ -13,20 +13,25 @@
|
|||
from robowaiter.scene.scene import Scene
|
||||
|
||||
class SceneOT(Scene):
|
||||
|
||||
def __init__(self, robot):
|
||||
super().__init__(robot)
|
||||
# 在这里加入场景中发生的事件
|
||||
self.event_list = [
|
||||
(5,self.give_coffee) # (事件发生的时间,事件函数)
|
||||
]
|
||||
|
||||
def _reset(self):
|
||||
self.add_walker(1085, 2630, 220)
|
||||
self.control_walker([self.walker_control_generator(0, False, 100, 755, 1900, 180)])
|
||||
pass
|
||||
# self.add_walker(1085, 2630, 220)
|
||||
# self.control_walker([self.walker_control_generator(0, False, 100, 755, 1900, 180)])
|
||||
|
||||
|
||||
def _run(self):
|
||||
pass
|
||||
|
||||
def _step(self):
|
||||
|
||||
if int(self.time) == 5:
|
||||
print("顾客说:给我一杯咖啡")
|
||||
self.chat_bubble('顾客说:给我一杯咖啡')
|
||||
self.state['chat_list'].append('给我一杯咖啡')
|
||||
def give_coffee(self):
|
||||
self.chat_bubble('顾客说:给我一杯咖啡')
|
||||
self.state['chat_list'].append('给我一杯咖啡')
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import os
|
||||
from robowaiter import Robot, task_map
|
||||
|
||||
TASK_NAME = 'OT'
|
||||
TASK_NAME = 'GQA'
|
||||
|
||||
# create robot
|
||||
project_path = "./robowaiter"
|
||||
|
|
Loading…
Reference in New Issue