修复删除子行为树bug
This commit is contained in:
parent
ced6f521f5
commit
5320acc838
|
@ -1,4 +0,0 @@
|
|||
selector{
|
||||
cond At(Robot, Table)
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ from robowaiter.behavior_lib._base.Behavior import Bahavior
|
|||
|
||||
class Act(Bahavior):
|
||||
print_name_prefix = "act "
|
||||
type = 'Act'
|
||||
|
||||
def __init__(self,*args):
|
||||
super().__init__(*args)
|
||||
|
|
|
@ -1,18 +1,7 @@
|
|||
import py_trees as ptree
|
||||
from typing import Any
|
||||
import enum
|
||||
|
||||
class Status(enum.Enum):
|
||||
"""An enumerator representing the status of a behavior."""
|
||||
|
||||
SUCCESS = ptree.common.Status.SUCCESS
|
||||
"""Behaviour check has passed, or execution of its action has finished with a successful result."""
|
||||
FAILURE = ptree.common.Status.FAILURE
|
||||
"""Behaviour check has failed, or execution of its action finished with a failed result."""
|
||||
RUNNING = ptree.common.Status.RUNNING
|
||||
"""Behaviour is in the middle of executing some action, result still pending."""
|
||||
INVALID = ptree.common.Status.INVALID
|
||||
"""Behaviour is uninitialised and/or in an inactive state, i.e. not currently being ticked."""
|
||||
from py_trees.common import Status
|
||||
|
||||
|
||||
# _base Behavior
|
||||
|
@ -53,7 +42,6 @@ class Bahavior(ptree.behaviour.Behaviour):
|
|||
|
||||
def update(self) -> Status:
|
||||
re = self._update()
|
||||
print(f"{self.__class__.__name__}: {re.value}")
|
||||
return re
|
||||
|
||||
def terminate(self, new_status: Status) -> None:
|
||||
|
|
|
@ -4,6 +4,7 @@ from robowaiter.behavior_lib._base.Behavior import Bahavior, Status
|
|||
|
||||
class Cond(Bahavior):
|
||||
print_name_prefix = "cond "
|
||||
type = 'Cond'
|
||||
|
||||
def __init__(self,*args):
|
||||
super().__init__(*args)
|
||||
|
|
|
@ -3,6 +3,7 @@ from typing import Any
|
|||
|
||||
class Selector(ptree.composites.Selector):
|
||||
print_name = "Selector"
|
||||
type = "Selector"
|
||||
|
||||
def __init__(self,*args,**kwargs):
|
||||
super().__init__(*args,**kwargs)
|
||||
|
|
|
@ -3,6 +3,7 @@ from typing import Any
|
|||
|
||||
class Sequence(ptree.composites.Sequence):
|
||||
print_name = "Sequence"
|
||||
type = "Sequence"
|
||||
|
||||
def __init__(self,*args,**kwargs):
|
||||
super().__init__(*args,**kwargs)
|
||||
|
|
|
@ -1,8 +1,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
|
||||
|
||||
fixed_answers = {
|
||||
"测试VLM:做一杯咖啡":
|
||||
'''
|
||||
|
|
|
@ -10,7 +10,5 @@ class DelSubTree(Act):
|
|||
|
||||
def _update(self) -> ptree.common.Status:
|
||||
sub_task_tree = self.parent
|
||||
print(self.scene.sub_task_seq.children)
|
||||
print(sub_task_tree)
|
||||
self.scene.sub_task_seq.children.remove(sub_task_tree)
|
||||
return Status.RUNNING
|
|
@ -1,3 +1,2 @@
|
|||
|
||||
# from robowaiter.behavior_tree.behavior_tree import BehaviorTree
|
||||
from robowaiter.behavior_tree.utils import load_bt_from_ptml
|
|
@ -1,12 +1,9 @@
|
|||
import os
|
||||
import py_trees as ptree
|
||||
|
||||
# from robowaiter.scene.scene import Scene
|
||||
# from robowaiter.behavior_tree.ptml.ptmlCompiler import load
|
||||
|
||||
import os
|
||||
from robowaiter import Robot, task_map
|
||||
|
||||
from robowaiter.utils.bt.draw import render_dot_tree
|
||||
|
||||
if __name__ == '__main__':
|
||||
TASK_NAME = 'OT'
|
||||
|
@ -21,7 +18,7 @@ if __name__ == '__main__':
|
|||
# create task
|
||||
task = task_map[TASK_NAME](robot)
|
||||
|
||||
ptree.display.render_dot_tree(robot.bt.root,name="test")
|
||||
render_dot_tree(robot.bt.root,name="test")
|
||||
# build and tick
|
||||
# scene.BT = ptree.trees.BehaviourTree(scene.BT)
|
||||
# todo: tick this bt
|
||||
|
|
|
@ -3,27 +3,27 @@ ordering=out;
|
|||
graph [fontname="times-roman"];
|
||||
node [fontname="times-roman"];
|
||||
edge [fontname="times-roman"];
|
||||
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 -> Chatting;
|
||||
DealChat [fillcolor=gray, fontcolor=black, fontsize=9, label=DealChat, shape=ellipse, style=filled];
|
||||
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)*";
|
||||
"34d1cf8a-42d6-49de-a458-0c7d3bffc436" [fillcolor=cyan, fontcolor=black, fontsize=20, height=0.01, label="?", shape=diamond, style=filled, width=0.01];
|
||||
"33446211-2d5c-4e1d-bdb5-5ded443a713c" [fillcolor=cyan, fontcolor=black, fontsize=20, height=0.01, label="?", shape=diamond, style=filled, width=0.01];
|
||||
"34d1cf8a-42d6-49de-a458-0c7d3bffc436" -> "33446211-2d5c-4e1d-bdb5-5ded443a713c";
|
||||
"96622c49-e2f6-4de9-9284-0c5eabbdd741" [fillcolor=yellow, fontcolor=black, fontsize=20, label=HasMap, shape=ellipse, style=filled];
|
||||
"33446211-2d5c-4e1d-bdb5-5ded443a713c" -> "96622c49-e2f6-4de9-9284-0c5eabbdd741";
|
||||
"dc007c72-0338-4616-bac2-bc39c81d2b77" [fillcolor=lawngreen, fontcolor=black, fontsize=20, label=ExploreEnv, shape=box, style=filled];
|
||||
"33446211-2d5c-4e1d-bdb5-5ded443a713c" -> "dc007c72-0338-4616-bac2-bc39c81d2b77";
|
||||
"6fe9e522-557f-473a-a582-2f0d17d1a4f1" [fillcolor=orange, fontcolor=black, fontsize=20, height=0.01, label=">", shape=octagon, style=filled, width=0.01];
|
||||
"34d1cf8a-42d6-49de-a458-0c7d3bffc436" -> "6fe9e522-557f-473a-a582-2f0d17d1a4f1";
|
||||
"cf3e4033-88b1-41bb-a638-26cc06e7a3dd" [fillcolor=yellow, fontcolor=black, fontsize=20, label=Chatting, shape=ellipse, style=filled];
|
||||
"6fe9e522-557f-473a-a582-2f0d17d1a4f1" -> "cf3e4033-88b1-41bb-a638-26cc06e7a3dd";
|
||||
"d2e8364e-dd83-4abb-8234-8466ff0c0483" [fillcolor=lawngreen, fontcolor=black, fontsize=20, label=DealChat, shape=box, style=filled];
|
||||
"6fe9e522-557f-473a-a582-2f0d17d1a4f1" -> "d2e8364e-dd83-4abb-8234-8466ff0c0483";
|
||||
"d78eaf31-cc9d-484d-b564-dbd5912378fa" [fillcolor=orange, fontcolor=black, fontsize=20, height=0.01, label=">", shape=octagon, style=filled, width=0.01];
|
||||
"34d1cf8a-42d6-49de-a458-0c7d3bffc436" -> "d78eaf31-cc9d-484d-b564-dbd5912378fa";
|
||||
"85284b02-fc8e-4418-8d6b-7a154d2004f6" [fillcolor=yellow, fontcolor=black, fontsize=20, label=HasSubTask, shape=ellipse, style=filled];
|
||||
"d78eaf31-cc9d-484d-b564-dbd5912378fa" -> "85284b02-fc8e-4418-8d6b-7a154d2004f6";
|
||||
"eb1bba56-55b1-4a71-8b31-0381812f588a" [fillcolor=orange, fontcolor=black, fontsize=20, height=0.01, label=">", shape=octagon, style=filled, width=0.01];
|
||||
"d78eaf31-cc9d-484d-b564-dbd5912378fa" -> "eb1bba56-55b1-4a71-8b31-0381812f588a";
|
||||
"20b57b46-d59d-4b04-a4ed-eff12e6adc91" [fillcolor=yellow, fontcolor=black, fontsize=20, label="At(Robot,Table)", shape=ellipse, style=filled];
|
||||
"eb1bba56-55b1-4a71-8b31-0381812f588a" -> "20b57b46-d59d-4b04-a4ed-eff12e6adc91";
|
||||
"3d7f6aa9-62b5-4852-ab3e-ac0199cc46a8" [fillcolor=yellow, fontcolor=black, fontsize=20, label="At(Robot,Table)", shape=ellipse, style=filled];
|
||||
"d78eaf31-cc9d-484d-b564-dbd5912378fa" -> "3d7f6aa9-62b5-4852-ab3e-ac0199cc46a8";
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 52 KiB |
|
@ -4,148 +4,148 @@
|
|||
<!-- Generated by graphviz version 9.0.0 (20230911.1827)
|
||||
-->
|
||||
<!-- Title: pastafarianism Pages: 1 -->
|
||||
<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)">
|
||||
<svg width="986pt" height="333pt"
|
||||
viewBox="0.00 0.00 986.41 333.03" 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 329.03)">
|
||||
<title>pastafarianism</title>
|
||||
<polygon fill="white" stroke="none" points="-4,4 -4,-256 579.62,-256 579.62,4 -4,4"/>
|
||||
<!-- Selector -->
|
||||
<polygon fill="white" stroke="none" points="-4,4 -4,-329.03 982.41,-329.03 982.41,4 -4,4"/>
|
||||
<!-- 34d1cf8a-42d6-49de-a458-0c7d3bffc436 -->
|
||||
<g id="node1" class="node">
|
||||
<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>
|
||||
<title>34d1cf8a-42d6-49de-a458-0c7d3bffc436</title>
|
||||
<polygon fill="cyan" stroke="black" points="390.57,-325.03 365.57,-293.78 390.57,-262.53 415.57,-293.78 390.57,-325.03"/>
|
||||
<text text-anchor="middle" x="390.57" y="-286.4" font-family="Times New Roman,serif" font-size="20.00">?</text>
|
||||
</g>
|
||||
<!-- Selector* -->
|
||||
<!-- 33446211-2d5c-4e1d-bdb5-5ded443a713c -->
|
||||
<g id="node2" class="node">
|
||||
<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>
|
||||
<title>33446211-2d5c-4e1d-bdb5-5ded443a713c</title>
|
||||
<polygon fill="cyan" stroke="black" points="193.57,-226.53 168.57,-195.28 193.57,-164.03 218.57,-195.28 193.57,-226.53"/>
|
||||
<text text-anchor="middle" x="193.57" y="-187.9" font-family="Times New Roman,serif" font-size="20.00">?</text>
|
||||
</g>
|
||||
<!-- Selector->Selector* -->
|
||||
<!-- 34d1cf8a-42d6-49de-a458-0c7d3bffc436->33446211-2d5c-4e1d-bdb5-5ded443a713c -->
|
||||
<g id="edge1" class="edge">
|
||||
<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"/>
|
||||
<title>34d1cf8a-42d6-49de-a458-0c7d3bffc436->33446211-2d5c-4e1d-bdb5-5ded443a713c</title>
|
||||
<path fill="none" stroke="black" d="M372.74,-284.05C338.31,-267.18 262.46,-230.02 221.35,-209.89"/>
|
||||
<polygon fill="black" stroke="black" points="223.1,-206.85 212.58,-205.59 220.02,-213.13 223.1,-206.85"/>
|
||||
</g>
|
||||
<!-- Sequence -->
|
||||
<!-- 6fe9e522-557f-473a-a582-2f0d17d1a4f1 -->
|
||||
<g id="node5" class="node">
|
||||
<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>
|
||||
<title>6fe9e522-557f-473a-a582-2f0d17d1a4f1</title>
|
||||
<polygon fill="orange" stroke="black" points="411.43,-185.37 411.43,-205.19 399.21,-219.2 381.93,-219.2 369.72,-205.19 369.72,-185.37 381.93,-171.36 399.21,-171.36 411.43,-185.37"/>
|
||||
<text text-anchor="middle" x="390.57" y="-187.9" font-family="Times New Roman,serif" font-size="20.00">></text>
|
||||
</g>
|
||||
<!-- Selector->Sequence -->
|
||||
<!-- 34d1cf8a-42d6-49de-a458-0c7d3bffc436->6fe9e522-557f-473a-a582-2f0d17d1a4f1 -->
|
||||
<g id="edge4" class="edge">
|
||||
<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"/>
|
||||
<title>34d1cf8a-42d6-49de-a458-0c7d3bffc436->6fe9e522-557f-473a-a582-2f0d17d1a4f1</title>
|
||||
<path fill="none" stroke="black" d="M390.57,-261.98C390.57,-252.07 390.57,-241.02 390.57,-230.86"/>
|
||||
<polygon fill="black" stroke="black" points="394.07,-230.97 390.57,-220.97 387.07,-230.97 394.07,-230.97"/>
|
||||
</g>
|
||||
<!-- Sequence* -->
|
||||
<!-- d78eaf31-cc9d-484d-b564-dbd5912378fa -->
|
||||
<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>
|
||||
<title>d78eaf31-cc9d-484d-b564-dbd5912378fa</title>
|
||||
<polygon fill="orange" stroke="black" points="683.43,-185.37 683.43,-205.19 671.21,-219.2 653.93,-219.2 641.72,-205.19 641.72,-185.37 653.93,-171.36 671.21,-171.36 683.43,-185.37"/>
|
||||
<text text-anchor="middle" x="662.57" y="-187.9" font-family="Times New Roman,serif" font-size="20.00">></text>
|
||||
</g>
|
||||
<!-- Selector->Sequence* -->
|
||||
<!-- 34d1cf8a-42d6-49de-a458-0c7d3bffc436->d78eaf31-cc9d-484d-b564-dbd5912378fa -->
|
||||
<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"/>
|
||||
<title>34d1cf8a-42d6-49de-a458-0c7d3bffc436->d78eaf31-cc9d-484d-b564-dbd5912378fa</title>
|
||||
<path fill="none" stroke="black" d="M409.7,-285.99C455.84,-269.62 573.65,-227.83 630.68,-207.59"/>
|
||||
<polygon fill="black" stroke="black" points="631.56,-211 639.81,-204.35 629.22,-204.4 631.56,-211"/>
|
||||
</g>
|
||||
<!-- HasMap -->
|
||||
<!-- 96622c49-e2f6-4de9-9284-0c5eabbdd741 -->
|
||||
<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>
|
||||
<title>96622c49-e2f6-4de9-9284-0c5eabbdd741</title>
|
||||
<ellipse fill="yellow" stroke="black" cx="59.57" cy="-104.11" rx="59.57" ry="22.1"/>
|
||||
<text text-anchor="middle" x="59.57" y="-96.74" font-family="Times New Roman,serif" font-size="20.00">HasMap</text>
|
||||
</g>
|
||||
<!-- Selector*->HasMap -->
|
||||
<!-- 33446211-2d5c-4e1d-bdb5-5ded443a713c->96622c49-e2f6-4de9-9284-0c5eabbdd741 -->
|
||||
<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"/>
|
||||
<title>33446211-2d5c-4e1d-bdb5-5ded443a713c->96622c49-e2f6-4de9-9284-0c5eabbdd741</title>
|
||||
<path fill="none" stroke="black" d="M177.41,-183.52C157.7,-170.41 123.74,-147.81 97.32,-130.23"/>
|
||||
<polygon fill="black" stroke="black" points="99.5,-127.47 89.23,-124.85 95.62,-133.3 99.5,-127.47"/>
|
||||
</g>
|
||||
<!-- ExploreEnv -->
|
||||
<!-- dc007c72-0338-4616-bac2-bc39c81d2b77 -->
|
||||
<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>
|
||||
<title>dc007c72-0338-4616-bac2-bc39c81d2b77</title>
|
||||
<polygon fill="lawngreen" stroke="black" points="250.32,-122.11 136.82,-122.11 136.82,-86.11 250.32,-86.11 250.32,-122.11"/>
|
||||
<text text-anchor="middle" x="193.57" y="-96.74" font-family="Times New Roman,serif" font-size="20.00">ExploreEnv</text>
|
||||
</g>
|
||||
<!-- Selector*->ExploreEnv -->
|
||||
<!-- 33446211-2d5c-4e1d-bdb5-5ded443a713c->dc007c72-0338-4616-bac2-bc39c81d2b77 -->
|
||||
<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"/>
|
||||
<title>33446211-2d5c-4e1d-bdb5-5ded443a713c->dc007c72-0338-4616-bac2-bc39c81d2b77</title>
|
||||
<path fill="none" stroke="black" d="M193.57,-163.34C193.57,-153.72 193.57,-143.17 193.57,-133.71"/>
|
||||
<polygon fill="black" stroke="black" points="197.07,-134 193.57,-124 190.07,-134 197.07,-134"/>
|
||||
</g>
|
||||
<!-- Chatting -->
|
||||
<!-- cf3e4033-88b1-41bb-a638-26cc06e7a3dd -->
|
||||
<g id="node6" class="node">
|
||||
<title>Chatting</title>
|
||||
<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>
|
||||
<title>cf3e4033-88b1-41bb-a638-26cc06e7a3dd</title>
|
||||
<ellipse fill="yellow" stroke="black" cx="328.57" cy="-104.11" rx="60.63" ry="22.1"/>
|
||||
<text text-anchor="middle" x="328.57" y="-96.74" font-family="Times New Roman,serif" font-size="20.00">Chatting</text>
|
||||
</g>
|
||||
<!-- Sequence->Chatting -->
|
||||
<!-- 6fe9e522-557f-473a-a582-2f0d17d1a4f1->cf3e4033-88b1-41bb-a638-26cc06e7a3dd -->
|
||||
<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"/>
|
||||
<title>6fe9e522-557f-473a-a582-2f0d17d1a4f1->cf3e4033-88b1-41bb-a638-26cc06e7a3dd</title>
|
||||
<path fill="none" stroke="black" d="M377.73,-175.8C369.56,-164.06 358.81,-148.6 349.44,-135.12"/>
|
||||
<polygon fill="black" stroke="black" points="352.37,-133.2 343.78,-126.99 346.62,-137.2 352.37,-133.2"/>
|
||||
</g>
|
||||
<!-- DealChat -->
|
||||
<!-- d2e8364e-dd83-4abb-8234-8466ff0c0483 -->
|
||||
<g id="node7" class="node">
|
||||
<title>DealChat</title>
|
||||
<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>
|
||||
<title>d2e8364e-dd83-4abb-8234-8466ff0c0483</title>
|
||||
<polygon fill="lawngreen" stroke="black" points="500.2,-122.11 406.95,-122.11 406.95,-86.11 500.2,-86.11 500.2,-122.11"/>
|
||||
<text text-anchor="middle" x="453.57" y="-96.74" font-family="Times New Roman,serif" font-size="20.00">DealChat</text>
|
||||
</g>
|
||||
<!-- Sequence->DealChat -->
|
||||
<!-- 6fe9e522-557f-473a-a582-2f0d17d1a4f1->d2e8364e-dd83-4abb-8234-8466ff0c0483 -->
|
||||
<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"/>
|
||||
<title>6fe9e522-557f-473a-a582-2f0d17d1a4f1->d2e8364e-dd83-4abb-8234-8466ff0c0483</title>
|
||||
<path fill="none" stroke="black" d="M403.63,-175.8C412.65,-163.04 424.78,-145.86 434.83,-131.64"/>
|
||||
<polygon fill="black" stroke="black" points="437.61,-133.78 440.52,-123.59 431.89,-129.74 437.61,-133.78"/>
|
||||
</g>
|
||||
<!-- HasSubTask -->
|
||||
<!-- 85284b02-fc8e-4418-8d6b-7a154d2004f6 -->
|
||||
<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>
|
||||
<title>85284b02-fc8e-4418-8d6b-7a154d2004f6</title>
|
||||
<ellipse fill="yellow" stroke="black" cx="601.57" cy="-104.11" rx="82.91" ry="22.1"/>
|
||||
<text text-anchor="middle" x="601.57" y="-96.74" font-family="Times New Roman,serif" font-size="20.00">HasSubTask</text>
|
||||
</g>
|
||||
<!-- Sequence*->HasSubTask -->
|
||||
<!-- d78eaf31-cc9d-484d-b564-dbd5912378fa->85284b02-fc8e-4418-8d6b-7a154d2004f6 -->
|
||||
<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"/>
|
||||
<title>d78eaf31-cc9d-484d-b564-dbd5912378fa->85284b02-fc8e-4418-8d6b-7a154d2004f6</title>
|
||||
<path fill="none" stroke="black" d="M649.93,-175.8C641.96,-164.15 631.47,-148.81 622.3,-135.4"/>
|
||||
<polygon fill="black" stroke="black" points="625.3,-133.59 616.76,-127.31 619.52,-137.54 625.3,-133.59"/>
|
||||
</g>
|
||||
<!-- Sequence** -->
|
||||
<!-- eb1bba56-55b1-4a71-8b31-0381812f588a -->
|
||||
<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>
|
||||
<title>eb1bba56-55b1-4a71-8b31-0381812f588a</title>
|
||||
<polygon fill="orange" stroke="black" points="744.43,-94.2 744.43,-114.02 732.21,-128.03 714.93,-128.03 702.72,-114.02 702.72,-94.2 714.93,-80.19 732.21,-80.19 744.43,-94.2"/>
|
||||
<text text-anchor="middle" x="723.57" y="-96.74" font-family="Times New Roman,serif" font-size="20.00">></text>
|
||||
</g>
|
||||
<!-- Sequence*->Sequence** -->
|
||||
<!-- d78eaf31-cc9d-484d-b564-dbd5912378fa->eb1bba56-55b1-4a71-8b31-0381812f588a -->
|
||||
<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"/>
|
||||
<title>d78eaf31-cc9d-484d-b564-dbd5912378fa->eb1bba56-55b1-4a71-8b31-0381812f588a</title>
|
||||
<path fill="none" stroke="black" d="M675.21,-175.8C683.66,-163.45 694.94,-146.97 704.47,-133.03"/>
|
||||
<polygon fill="black" stroke="black" points="707.13,-135.35 709.89,-125.12 701.35,-131.4 707.13,-135.35"/>
|
||||
</g>
|
||||
<!-- At(Robot,Table)* -->
|
||||
<!-- 3d7f6aa9-62b5-4852-ab3e-ac0199cc46a8 -->
|
||||
<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>
|
||||
<title>3d7f6aa9-62b5-4852-ab3e-ac0199cc46a8</title>
|
||||
<ellipse fill="yellow" stroke="black" cx="870.57" cy="-104.11" rx="107.83" ry="22.1"/>
|
||||
<text text-anchor="middle" x="870.57" y="-96.74" font-family="Times New Roman,serif" font-size="20.00">At(Robot,Table)</text>
|
||||
</g>
|
||||
<!-- Sequence*->At(Robot,Table)* -->
|
||||
<!-- d78eaf31-cc9d-484d-b564-dbd5912378fa->3d7f6aa9-62b5-4852-ab3e-ac0199cc46a8 -->
|
||||
<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"/>
|
||||
<title>d78eaf31-cc9d-484d-b564-dbd5912378fa->3d7f6aa9-62b5-4852-ab3e-ac0199cc46a8</title>
|
||||
<path fill="none" stroke="black" d="M683.66,-185.24C714.19,-172.15 771.78,-147.46 815,-128.93"/>
|
||||
<polygon fill="black" stroke="black" points="816.17,-132.24 823.99,-125.08 813.42,-125.81 816.17,-132.24"/>
|
||||
</g>
|
||||
<!-- At(Robot,Table) -->
|
||||
<!-- 20b57b46-d59d-4b04-a4ed-eff12e6adc91 -->
|
||||
<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>
|
||||
<title>20b57b46-d59d-4b04-a4ed-eff12e6adc91</title>
|
||||
<ellipse fill="yellow" stroke="black" cx="723.57" cy="-22.1" rx="107.83" ry="22.1"/>
|
||||
<text text-anchor="middle" x="723.57" y="-14.72" font-family="Times New Roman,serif" font-size="20.00">At(Robot,Table)</text>
|
||||
</g>
|
||||
<!-- Sequence**->At(Robot,Table) -->
|
||||
<!-- eb1bba56-55b1-4a71-8b31-0381812f588a->20b57b46-d59d-4b04-a4ed-eff12e6adc91 -->
|
||||
<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"/>
|
||||
<title>eb1bba56-55b1-4a71-8b31-0381812f588a->20b57b46-d59d-4b04-a4ed-eff12e6adc91</title>
|
||||
<path fill="none" stroke="black" d="M723.57,-79.97C723.57,-72.46 723.57,-63.99 723.57,-55.92"/>
|
||||
<polygon fill="black" stroke="black" points="727.07,-56.06 723.57,-46.06 720.07,-56.06 727.07,-56.06"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
|
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 11 KiB |
|
@ -37,10 +37,7 @@ def ask_llm(question):
|
|||
|
||||
if __name__ == '__main__':
|
||||
question = '''
|
||||
以下是环境信息,请回答对话和目标状态
|
||||
[环境信息]
|
||||
State: {At(Robot, Table), NotHolding, Available(SpongeGourd)}
|
||||
chat_list: [(Customer, "桌子有点脏,能帮我擦一下吗?")]
|
||||
python中如何通过类名字符串的方式来代替isinstance的作用
|
||||
'''
|
||||
|
||||
print(ask_llm(question))
|
|
@ -1,8 +1,10 @@
|
|||
import io
|
||||
import contextlib
|
||||
|
||||
from robowaiter.behavior_tree.utils import load_bt_from_ptml,find_node_by_name,print_tree_from_root
|
||||
from robowaiter.behavior_tree.obtea.OptimalBTExpansionAlgorithm import Action,OptBTExpAlgorithm,state_transition # 调用最优行为树扩展算法
|
||||
from robowaiter.utils.bt.load import load_bt_from_ptml,find_node_by_name,print_tree_from_root
|
||||
from robowaiter.utils.bt.visitor import StatusVisitor
|
||||
|
||||
from robowaiter.behavior_tree.obtea.OptimalBTExpansionAlgorithm import Action # 调用最优行为树扩展算法
|
||||
from robowaiter.behavior_tree.obtea.opt_bt_exp_main import BTOptExpInterface
|
||||
|
||||
from robowaiter.behavior_lib.act.DelSubTree import DelSubTree
|
||||
|
@ -22,6 +24,7 @@ class Robot(object):
|
|||
self.last_tick_output = ""
|
||||
self.action_list = None
|
||||
|
||||
|
||||
def set_scene(self,scene):
|
||||
self.scene = scene
|
||||
|
||||
|
@ -32,7 +35,10 @@ class Robot(object):
|
|||
sub_task_seq = sub_task_place_holder.parent
|
||||
sub_task_seq.children.pop()
|
||||
self.scene.sub_task_seq = sub_task_seq
|
||||
print(self.scene.sub_task_seq)
|
||||
|
||||
self.bt_visitor = StatusVisitor()
|
||||
self.bt.visitors.append(self.bt_visitor)
|
||||
|
||||
|
||||
def expand_sub_task_tree(self,goal):
|
||||
if self.action_list is None:
|
||||
|
@ -52,12 +58,12 @@ class Robot(object):
|
|||
|
||||
# 加入删除子树的节点
|
||||
seq = Sequence(name="Sequence", memory=False)
|
||||
seq.children.append(sub_task_bt.root)
|
||||
seq.add_child(sub_task_bt.root)
|
||||
del_sub_tree = DelSubTree()
|
||||
del_sub_tree.set_scene(self.scene)
|
||||
seq.children.append(del_sub_tree)
|
||||
seq.add_child(del_sub_tree)
|
||||
|
||||
self.scene.sub_task_seq.children.append(seq)
|
||||
self.scene.sub_task_seq.add_child(seq)
|
||||
print("当前行为树为:")
|
||||
print_tree_from_root(self.bt.root)
|
||||
|
||||
|
@ -75,24 +81,16 @@ class Robot(object):
|
|||
self.next_response_time += self.response_frequency
|
||||
self.step_num += 1
|
||||
|
||||
# 创建一个StringIO对象
|
||||
output = io.StringIO()
|
||||
self.bt.tick()
|
||||
bt_output = self.bt_visitor.output_str
|
||||
|
||||
# 将print输出重定向到StringIO对象
|
||||
with contextlib.redirect_stdout(output):
|
||||
self.bt.tick()
|
||||
|
||||
# 获取StringIO对象中的字符串值
|
||||
contents = output.getvalue()
|
||||
output.close()
|
||||
|
||||
if contents != self.last_tick_output:
|
||||
if bt_output != self.last_tick_output:
|
||||
print(f"==== time:{self.scene.time:f}s ======")
|
||||
|
||||
print(contents)
|
||||
print(bt_output)
|
||||
|
||||
print("\n")
|
||||
self.last_tick_output = contents
|
||||
self.last_tick_output = bt_output
|
||||
|
||||
if __name__ == '__main__':
|
||||
pass
|
|
@ -24,9 +24,10 @@ class SceneVLM(Scene):
|
|||
# self.move_task_area(i)
|
||||
# self.op_task_execute(i)
|
||||
|
||||
if op_type<=10:
|
||||
self.move_task_area(op_type)
|
||||
self.op_task_execute(op_type)
|
||||
|
||||
# if op_type<=10:
|
||||
# self.move_task_area(op_type)
|
||||
# self.op_task_execute(op_type)
|
||||
pass
|
||||
|
||||
def _step(self):
|
||||
pass
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
|
||||
from robowaiter.utils import *
|
||||
from robowaiter.utils import *
|
||||
|
|
@ -0,0 +1,331 @@
|
|||
|
||||
##############################################################################
|
||||
# Imports
|
||||
##############################################################################
|
||||
|
||||
import os
|
||||
import typing
|
||||
import uuid
|
||||
|
||||
import pydot
|
||||
from py_trees import behaviour
|
||||
from py_trees import blackboard
|
||||
from py_trees import common
|
||||
from py_trees import composites
|
||||
from py_trees import decorators
|
||||
from py_trees import utilities
|
||||
|
||||
COMPOSITE_NODE_SIZE = 0.01
|
||||
|
||||
|
||||
def dot_tree(
|
||||
root: behaviour.Behaviour,
|
||||
visibility_level: common.VisibilityLevel = common.VisibilityLevel.DETAIL,
|
||||
collapse_decorators: bool = False,
|
||||
with_blackboard_variables: bool = False,
|
||||
with_qualified_names: bool = False):
|
||||
"""
|
||||
Paint your tree on a pydot graph.
|
||||
|
||||
.. seealso:: :py:func:`render_dot_tree`.
|
||||
|
||||
Args:
|
||||
root (:class:`~py_trees.behaviour.Behaviour`): the root of a tree, or subtree
|
||||
visibility_level (optional): collapse subtrees at or under this level
|
||||
collapse_decorators (optional): only show the decorator (not the child), defaults to False
|
||||
with_blackboard_variables (optional): add nodes for the blackboard variables
|
||||
with_qualified_names (optional): print the class information for each behaviour in each node, defaults to False
|
||||
|
||||
Returns:
|
||||
pydot.Dot: graph
|
||||
|
||||
Examples:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# convert the pydot graph to a string object
|
||||
print("{}".format(py_trees.display.dot_graph(root).to_string()))
|
||||
"""
|
||||
|
||||
def get_node_attributes(node):
|
||||
blackbox_font_colours = {common.BlackBoxLevel.DETAIL: "dodgerblue",
|
||||
common.BlackBoxLevel.COMPONENT: "lawngreen",
|
||||
common.BlackBoxLevel.BIG_PICTURE: "white"
|
||||
}
|
||||
if node.type =="Selector":
|
||||
attributes = ('diamond', 'cyan', 'black') # octagon
|
||||
elif node.type =="Sequence":
|
||||
attributes = ('octagon', 'orange', 'black')
|
||||
elif isinstance(node, composites.Parallel):
|
||||
attributes = ('parallelogram', 'gold', 'black')
|
||||
elif isinstance(node, decorators.Decorator):
|
||||
attributes = ('ellipse', 'ghostwhite', 'black')
|
||||
elif node.type =="Act":
|
||||
attributes = ('box', 'lawngreen', 'black')
|
||||
else:
|
||||
attributes = ('ellipse', 'yellow', 'black')
|
||||
|
||||
try:
|
||||
if node.blackbox_level != common.BlackBoxLevel.NOT_A_BLACKBOX:
|
||||
attributes = (attributes[0], 'gray20', blackbox_font_colours[node.blackbox_level])
|
||||
except AttributeError:
|
||||
# it's a blackboard client, not a behaviour, just pass
|
||||
pass
|
||||
return attributes
|
||||
|
||||
def get_node_label(node_name, behaviour):
|
||||
"""
|
||||
This extracts a more detailed string (when applicable) to append to
|
||||
that which will be used for the node name.
|
||||
"""
|
||||
# Custom handling of composites provided by this library. Not currently
|
||||
# providing a generic mechanism for others to customise visualisations
|
||||
# for their derived composites.
|
||||
# prefix = ""
|
||||
# policy = ""
|
||||
'''
|
||||
if isinstance(behaviour, composites.Composite):
|
||||
try:
|
||||
if behaviour.memory:
|
||||
prefix += console.circled_m
|
||||
except AttributeError:
|
||||
pass
|
||||
try:
|
||||
if behaviour.policy.synchronise:
|
||||
prefix += console.lightning_bolt
|
||||
except AttributeError:
|
||||
pass
|
||||
try:
|
||||
policy = behaviour.policy.__class__.__name__
|
||||
except AttributeError:
|
||||
pass
|
||||
try:
|
||||
indices = [str(behaviour.children.index(child)) for child in behaviour.policy.children]
|
||||
policy += "({})".format(', '.join(sorted(indices)))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
node_label = f"{prefix} {node_name}" if prefix else node_name
|
||||
if policy:
|
||||
node_label += f"\n{str(policy)}"
|
||||
if with_qualified_names:
|
||||
node_label += f"\n({utilities.get_fully_qualified_name(behaviour)})"
|
||||
'''
|
||||
if node_name == "Sequence":
|
||||
node_name = ">"
|
||||
if node_name == "Selector":
|
||||
node_name = "?"
|
||||
return node_name
|
||||
|
||||
fontsize = 20
|
||||
blackboard_colour = "blue" # "dimgray"
|
||||
graph = pydot.Dot(graph_type='digraph', ordering="out")
|
||||
graph.set_name("pastafarianism") # consider making this unique to the tree sometime, e.g. based on the root name
|
||||
# fonts: helvetica, times-bold, arial (times-roman is the default, but this helps some viewers, like kgraphviewer)
|
||||
graph.set_graph_defaults(fontname='times-roman') # splines='curved' is buggy on 16.04, but would be nice to have
|
||||
graph.set_node_defaults(fontname='times-roman')
|
||||
graph.set_edge_defaults(fontname='times-roman')
|
||||
(node_shape, node_colour, node_font_colour) = get_node_attributes(root)
|
||||
root_name = str(root.id)
|
||||
node_root = pydot.Node(
|
||||
name=root_name,
|
||||
label=get_node_label(root.name, root),
|
||||
shape=node_shape,
|
||||
style="filled",
|
||||
fillcolor=node_colour,
|
||||
fontsize=fontsize,
|
||||
fontcolor=node_font_colour,
|
||||
)
|
||||
if isinstance(root, composites.Composite):
|
||||
node_root.set_height(COMPOSITE_NODE_SIZE)
|
||||
node_root.set_width(COMPOSITE_NODE_SIZE)
|
||||
graph.add_node(node_root)
|
||||
behaviour_id_name_map = {root.id: str(root.id)}
|
||||
|
||||
def add_children_and_edges(root, root_node, root_dot_name, visibility_level, collapse_decorators):
|
||||
if isinstance(root, decorators.Decorator) and collapse_decorators:
|
||||
return
|
||||
if visibility_level < root.blackbox_level:
|
||||
node_names = []
|
||||
for c in root.children:
|
||||
(node_shape, node_colour, node_font_colour) = get_node_attributes(c)
|
||||
node_name = str(c.id)
|
||||
# while node_name in behaviour_id_name_map.values():
|
||||
# node_name += ""
|
||||
behaviour_id_name_map[c.id] = node_name
|
||||
# Node attributes can be found on page 5 of
|
||||
# https://graphviz.gitlab.io/_pages/pdf/dot.1.pdf
|
||||
# Attributes that may be useful: tooltip, xlabel
|
||||
node = pydot.Node(
|
||||
name=str(c.id),
|
||||
label=get_node_label(c.name, c),
|
||||
shape=node_shape,
|
||||
style="filled",
|
||||
fillcolor=node_colour,
|
||||
fontsize=fontsize,
|
||||
fontcolor=node_font_colour,
|
||||
)
|
||||
if isinstance(c, composites.Composite):
|
||||
node.set_height(COMPOSITE_NODE_SIZE)
|
||||
node.set_width(COMPOSITE_NODE_SIZE)
|
||||
node_names.append(node_name)
|
||||
graph.add_node(node)
|
||||
edge = pydot.Edge(root_dot_name, node_name)
|
||||
graph.add_edge(edge)
|
||||
if c.children != []:
|
||||
add_children_and_edges(c, node, node_name, visibility_level, collapse_decorators)
|
||||
|
||||
add_children_and_edges(root, node_root, root_name, visibility_level, collapse_decorators)
|
||||
|
||||
def create_blackboard_client_node(blackboard_client_name: str):
|
||||
return pydot.Node(
|
||||
name=blackboard_client_name,
|
||||
label=blackboard_client_name,
|
||||
shape="ellipse",
|
||||
style="filled",
|
||||
color=blackboard_colour,
|
||||
fillcolor="gray",
|
||||
fontsize=fontsize - 2,
|
||||
fontcolor=blackboard_colour,
|
||||
)
|
||||
|
||||
def add_blackboard_nodes(blackboard_id_name_map: typing.Dict[uuid.UUID, str]):
|
||||
data = blackboard.Blackboard.storage
|
||||
metadata = blackboard.Blackboard.metadata
|
||||
clients = blackboard.Blackboard.clients
|
||||
# add client (that are not behaviour) nodes
|
||||
subgraph = pydot.Subgraph(
|
||||
graph_name="Blackboard",
|
||||
id="Blackboard",
|
||||
label="Blackboard",
|
||||
rank="sink",
|
||||
)
|
||||
|
||||
for unique_identifier, client_name in clients.items():
|
||||
if unique_identifier not in blackboard_id_name_map:
|
||||
subgraph.add_node(
|
||||
create_blackboard_client_node(client_name)
|
||||
)
|
||||
# add key nodes
|
||||
for key in blackboard.Blackboard.keys():
|
||||
try:
|
||||
value = utilities.truncate(str(data[key]), 20)
|
||||
label = key + ": " + "{}".format(value)
|
||||
except KeyError:
|
||||
label = key + ": " + "-"
|
||||
blackboard_node = pydot.Node(
|
||||
key,
|
||||
label=label,
|
||||
shape='box',
|
||||
style="filled",
|
||||
color=blackboard_colour,
|
||||
fillcolor='white',
|
||||
fontsize=fontsize - 1,
|
||||
fontcolor=blackboard_colour,
|
||||
width=0, height=0, fixedsize=False, # only big enough to fit text
|
||||
)
|
||||
subgraph.add_node(blackboard_node)
|
||||
for unique_identifier in metadata[key].read:
|
||||
try:
|
||||
edge = pydot.Edge(
|
||||
blackboard_node,
|
||||
blackboard_id_name_map[unique_identifier],
|
||||
color="green",
|
||||
constraint=False,
|
||||
weight=0,
|
||||
)
|
||||
except KeyError:
|
||||
edge = pydot.Edge(
|
||||
blackboard_node,
|
||||
clients[unique_identifier].__getattribute__("name"),
|
||||
color="green",
|
||||
constraint=False,
|
||||
weight=0,
|
||||
)
|
||||
graph.add_edge(edge)
|
||||
for unique_identifier in metadata[key].write:
|
||||
try:
|
||||
edge = pydot.Edge(
|
||||
blackboard_id_name_map[unique_identifier],
|
||||
blackboard_node,
|
||||
color=blackboard_colour,
|
||||
constraint=False,
|
||||
weight=0,
|
||||
)
|
||||
except KeyError:
|
||||
edge = pydot.Edge(
|
||||
clients[unique_identifier].__getattribute__("name"),
|
||||
blackboard_node,
|
||||
color=blackboard_colour,
|
||||
constraint=False,
|
||||
weight=0,
|
||||
)
|
||||
graph.add_edge(edge)
|
||||
graph.add_subgraph(subgraph)
|
||||
|
||||
if with_blackboard_variables:
|
||||
blackboard_id_name_map = {}
|
||||
for b in root.iterate():
|
||||
for bb in b.blackboards:
|
||||
blackboard_id_name_map[bb.id()] = behaviour_id_name_map[b.id]
|
||||
add_blackboard_nodes(blackboard_id_name_map)
|
||||
|
||||
return graph
|
||||
|
||||
|
||||
def render_dot_tree(root: behaviour.Behaviour,
|
||||
visibility_level: common.VisibilityLevel = common.VisibilityLevel.DETAIL,
|
||||
collapse_decorators: bool = False,
|
||||
name: str = None,
|
||||
target_directory: str = os.getcwd(),
|
||||
with_blackboard_variables: bool = False,
|
||||
with_qualified_names: bool = False):
|
||||
"""
|
||||
Render the dot tree to .dot, .svg, .png. files in the current
|
||||
working directory. These will be named with the root behaviour name.
|
||||
|
||||
Args:
|
||||
root: the root of a tree, or subtree
|
||||
visibility_level: collapse subtrees at or under this level
|
||||
collapse_decorators: only show the decorator (not the child)
|
||||
name: name to use for the created files (defaults to the root behaviour name)
|
||||
target_directory: default is to use the current working directory, set this to redirect elsewhere
|
||||
with_blackboard_variables: add nodes for the blackboard variables
|
||||
with_qualified_names: print the class names of each behaviour in the dot node
|
||||
|
||||
Example:
|
||||
|
||||
Render a simple tree to dot/svg/png file:
|
||||
|
||||
.. graphviz:: dot/sequence.dot
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
root = py_trees.composites.Sequence("Sequence")
|
||||
for job in ["Action 1", "Action 2", "Action 3"]:
|
||||
success_after_two = py_trees.behaviours.Count(name=job,
|
||||
fail_until=0,
|
||||
running_until=1,
|
||||
success_until=10)
|
||||
root.add_child(success_after_two)
|
||||
py_trees.display.render_dot_tree(root)
|
||||
|
||||
.. tip::
|
||||
|
||||
A good practice is to provide a command line argument for optional rendering of a program so users
|
||||
can quickly visualise what tree the program will execute.
|
||||
"""
|
||||
graph = dot_tree(
|
||||
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 = 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():
|
||||
filename = filename_wo_extension + '.' + extension
|
||||
pathname = os.path.join(target_directory, filename)
|
||||
print("Writing {}".format(pathname))
|
||||
writer(pathname)
|
||||
filenames[extension] = pathname
|
||||
return filenames
|
|
@ -14,18 +14,6 @@ def load_bt_from_ptml(scene, ptml_path, behavior_lib_path):
|
|||
# print(ptree.display.unicode_tree(root=bt.root, show_status=True))
|
||||
return bt
|
||||
|
||||
def load_bt_from_ptml_str(scene, ptml_path, behavior_lib_path):
|
||||
ptml_bt = ptmlCompiler.load(scene, ptml_path, behavior_lib_path)
|
||||
bt = ptree.trees.BehaviourTree(ptml_bt)
|
||||
|
||||
with open(ptml_path, 'r') as f:
|
||||
ptml = f.read()
|
||||
|
||||
print(f'BT loaded:')
|
||||
print_tree_from_root(bt.root)
|
||||
# print(ptree.display.unicode_tree(root=bt.root, show_status=True))
|
||||
return bt
|
||||
|
||||
|
||||
def print_tree_from_root(node, indent=0):
|
||||
"""
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
from py_trees.visitors import VisitorBase
|
||||
|
||||
|
||||
class StatusVisitor(VisitorBase):
|
||||
"""
|
||||
Logging is done with the behaviour's logger.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super(StatusVisitor, self).__init__(full=False)
|
||||
self.output_str = ""
|
||||
|
||||
def initialise(self) -> None:
|
||||
"""Override if any resetting of variables needs to be performed between ticks (i.e. visitations)."""
|
||||
self.output_str = ""
|
||||
|
||||
|
||||
def run(self, behavior) -> None:
|
||||
"""
|
||||
Log behaviour information on the debug channel.
|
||||
|
||||
Args:
|
||||
behavior: behaviour being visited.
|
||||
"""
|
||||
if behavior.type in ("Sequence","Selector"):
|
||||
return
|
||||
else:
|
||||
self.output_str += f"{behavior.print_name}: {behavior.status.value}\n"
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import os
|
||||
from robowaiter import Robot, task_map
|
||||
|
||||
TASK_NAME = 'VLN'
|
||||
TASK_NAME = 'VLM'
|
||||
|
||||
# create robot
|
||||
project_path = "./robowaiter"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
selector{
|
||||
cond At(Robot,Table)
|
||||
cond At(Coffee,Bar)
|
||||
selector{
|
||||
cond At(Robot,Bar)
|
||||
act MoveTo(Table)
|
||||
cond At(Robot,CoffeeMachine)
|
||||
act MakeCoffee
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue