现在behaviour_lib中动作节点的初始化函数增加了参数scene用于调用接口;tasks中给出了要完成的任务demo

This commit is contained in:
Antiman-cmyk 2023-10-17 16:28:36 +08:00
parent 9dbd8f2770
commit 5a1d5f60a4
29 changed files with 309 additions and 62 deletions

110
README.md
View File

@ -7,4 +7,112 @@
from scene_utils import control
control.init_world(scene_num=1, mapID=3)
```
当前只有一个咖啡馆场景。加载操作只需要执行一遍,当引擎进入相应场景后,可以用`control.reset()`重置场景。
当前只有一个咖啡馆场景。加载操作只需要执行一遍,当引擎进入相应场景后,可以用`control.reset()`重置场景。
2. 物品类别
| ID | Item |
|-----|----------------------|
| 0 | Mug |
| 1 | Banana |
| 2 | Toothpaste |
| 3 | Bread |
| 4 | Softdrink |
| 5 | Yogurt |
| 6 | ADMilk |
| 7 | VacuumCup |
| 8 | Bernachon |
| 9 | BottledDrink |
| 10 | PencilVase |
| 11 | Teacup |
| 12 | Caddy |
| 13 | Dictionary |
| 14 | Cake |
| 15 | Date |
| 16 | Stapler |
| 17 | LunchBox |
| 18 | Bracelet |
| 19 | MilkDrink |
| 20 | CocountWater |
| 21 | Walnut |
| 22 | HamSausage |
| 23 | GlueStick |
| 24 | AdhensiveTape |
| 25 | Calculator |
| 26 | Chess |
| 27 | Orange |
| 28 | Glass |
| 29 | Washbowl |
| 30 | Durian |
| 31 | Gum |
| 32 | Towl |
| 33 | OrangeJuice |
| 34 | Cardcase |
| 35 | RubikCube |
| 36 | StickyNotes |
| 37 | NFCJuice |
| 38 | SpringWater |
| 39 | Apple |
| 40 | Coffee |
| 41 | Gauze |
| 42 | Mangosteen |
| 43 | SesameSeedCake |
| 44 | Glove |
| 45 | Mouse |
| 46 | Kettle |
| 47 | Atomize |
| 48 | Chips |
| 49 | SpongeGourd |
| 50 | Garlic |
| 51 | Potato |
| 52 | Tray |
| 53 | Hemomanometer |
| 54 | TennisBall |
| 55 | ToyDog |
| 56 | ToyBear |
| 57 | TeaTray |
| 58 | Sock |
| 59 | Scarf |
| 60 | ToiletPaper |
| 61 | Milk |
| 62 | Soap |
| 63 | Novel |
| 64 | Watermelon |
| 65 | Tomato |
| 66 | CleansingFoam |
| 67 | CocountMilk |
| 68 | SugarlessGum |
| 69 | MedicalAdhensiveTape |
| 70 | SourMilkDrink |
| 71 | PaperCup |
| 72 | Tissue |
| 73 | YogurtDrink |
| 74 | Newspaper |
| 75 | Box |
| 76 | PaperCupStarbucks |
| 77 | CoffeeMachine |
| 78 | GingerLHand |
| 79 | GingerRHand |
| 80 | Straw |
| 81 | Cake |
| 82 | Tray |
| 83 | Bread |
| 84 | Glass |
| 85 | Door |
| 86 | Mug |
| 87 | Machine |
| 88 | Packaged Coffee |
| 89 | Cube Sugar |
| 90 | Apple |
| 91 | Spoon |
| 92 | Drinks |
| 93 | Drink |
| 94 | Take-Away Cup |
| 95 | Saucer |
| 96 | Trash Bin |
| 97 | Knife |
| 251 | Ginger |
| 252 | Floor |
| 253 | Roof |
| 254 | Wall |
注意78及以后无法使用add_object方法生成

View File

@ -5,7 +5,7 @@
// parallel 2:
// act action3(int a, float b)
// act action4()
sequence{
selector{
cond CoffeeCupFound()

View File

@ -1,21 +1,20 @@
import py_trees as ptree
from typing import Any
class CoffeeCupFound(ptree.behaviour.Behaviour):
def __init__(self, name: str):
class CoffeeCupFound(ptree.behaviour.Behaviour):
def __init__(self, name: str, scene):
super().__init__(name)
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...')
print("Start checking IsChatting...")
return ptree.common.Status.SUCCESS
def terminate(self, new_status: ptree.common.Status) -> None:
return super().terminate(new_status)

View File

@ -3,7 +3,7 @@ from typing import Any
class CoffeeCupGrasped(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class CoffeeCupPlaced(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class DestinationAReached(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class FindCoffeeCup(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class Grasp(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class GraspCoffeeCup(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class Istask(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class Move(ptree.behaviour.Behaviour):
def __init__(self, name: str, a, b, c, d):
def __init__(self, name: str, scene, a, b, c, d):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class PlaceCoffeeCup(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class ReachDestinationA(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class SeqTest(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

@ -3,7 +3,7 @@ from typing import Any
class TestTask(ptree.behaviour.Behaviour):
def __init__(self, name: str):
def __init__(self, name: str, scene):
super().__init__(name)
def setup(self, **kwargs: Any) -> None:

View File

View File

@ -12,7 +12,7 @@ else:
from ptmlLexer import ptmlLexer as Lexer
def load(ptml_path: str, behaviour_lib_path: str):
def load(scene, ptml_path: str, behaviour_lib_path: str):
"""_summary_
Args:
@ -40,7 +40,7 @@ def load(ptml_path: str, behaviour_lib_path: str):
tree = parser.root()
walker = ParseTreeWalker()
ptml = ptmlTranslator() # listener mode
ptml = ptmlTranslator(scene, behaviour_lib_path) # listener mode
walker.walk(ptml, tree)
return ptml.bt_root

View File

@ -1,4 +1,4 @@
# Generated from ./ptml.g4 by ANTLR 4.13.0
# Generated from E:/Projects/UE5/HARIX_RDKSim/Plugins/HarixSim/Python/ptml/ptml.g4 by ANTLR 4.13.1
from antlr4 import *
from io import StringIO
import sys
@ -111,7 +111,7 @@ class ptmlLexer(Lexer):
def __init__(self, input=None, output:TextIO = sys.stdout):
super().__init__(input, output)
self.checkVersion("4.13.0")
self.checkVersion("4.13.1")
self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
self._actions = None
self._predicates = None

View File

@ -1,4 +1,4 @@
# Generated from ./ptml.g4 by ANTLR 4.13.0
# Generated from E:/Projects/UE5/HARIX_RDKSim/Plugins/HarixSim/Python/ptml/ptml.g4 by ANTLR 4.13.1
from antlr4 import *
if "." in __name__:
from .ptmlParser import ptmlParser

View File

@ -1,4 +1,4 @@
# Generated from ./ptml.g4 by ANTLR 4.13.0
# Generated from E:/Projects/UE5/HARIX_RDKSim/Plugins/HarixSim/Python/ptml/ptml.g4 by ANTLR 4.13.1
# encoding: utf-8
from antlr4 import *
from io import StringIO
@ -83,7 +83,7 @@ class ptmlParser ( Parser ):
def __init__(self, input:TokenStream, output:TextIO = sys.stdout):
super().__init__(input, output)
self.checkVersion("4.13.0")
self.checkVersion("4.13.1")
self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache)
self._predicates = None

View File

@ -20,10 +20,12 @@ class ptmlTranslator(ptmlListener):
ptmlListener (_type_): _description_
"""
def __init__(self) -> None:
def __init__(self, scene, behaviour_lib_path) -> None:
super().__init__()
self.bt_root = None
self.stack = []
self.scene = scene
self.behaviour_lib_path = behaviour_lib_path
# Enter a parse tree produced by ptmlParser#root.
def enterRoot(self, ctx: ptmlParser.RootContext):
@ -91,24 +93,20 @@ class ptmlTranslator(ptmlListener):
args = "".join(args)
# dynamic import
if "." in __name__: # in package
behaviour_lib_config = "ptml/behaviour_lib"
else:
behaviour_lib_config = "./behaviour_lib"
import sys
sys.path.append(behaviour_lib_config)
sys.path.append(self.behaviour_lib_path)
exec("from {} import {}".format(name, name))
#
tag = "cond_" + short_uuid() if node_type == "cond" else "task_" + short_uuid()
node = None
node = eval("{}('{}', {})".format(name, tag, args))
node = eval(
"{}('{}', scene, {})".format(name, tag, args), {"scene": self.scene, **locals()}
)
# connect
self.stack[-1].add_child(node)
# print(self.stack)
# Exit a parse tree produced by ptmlParser#action_sign.
def exitAction_sign(self, ctx: ptmlParser.Action_signContext):

View File

@ -1,6 +1,7 @@
import os
import py_trees as ptree
from scene_utils import control
from ptmlCompiler import load
@ -10,9 +11,12 @@ if __name__ == '__main__':
ptml_path = os.path.join(project_path, 'CoffeeDelivery.ptml')
behavior_lib_path = os.path.join(project_path, 'behaviour_lib')
scene = control.Scene(sceneID=0)
# load
bt = load(ptml_path, behavior_lib_path)
scene.load_BT(ptml_path, behavior_lib_path)
# ptree.display.render_dot_tree(bt)
# build and tick
bt = ptree.trees.BehaviourTree(bt)
scene.BT = ptree.trees.BehaviourTree(scene.BT)
# todo: tick this bt
print(scene.BT)

View File

@ -18,6 +18,7 @@ channel = grpc.insecure_channel(
stub = GrabSim_pb2_grpc.GrabSimStub(channel)
animation_step = [4, 5, 7, 3, 3]
loc_offset = [-700, -1400]
def init_world(scene_num, mapID):
@ -25,15 +26,6 @@ def init_world(scene_num, mapID):
time.sleep(3) # wait for the map to load
def walker_control_generator(walkerID, autowalk, speed, X, Y, Yaw):
return GrabSim_pb2.WalkerControls.WControl(
id=walkerID,
autowalk=autowalk,
speed=speed,
pose=GrabSim_pb2.Pose(X=X, Y=Y, Yaw=Yaw),
)
def image_extract(camera_data):
image = camera_data.images[0]
return np.frombuffer(image.data, dtype=image.dtype).reshape(
@ -55,10 +47,10 @@ class Scene:
collision: str, info: str
"""
def __init__(self, sceneID):
def __init__(self, sceneID=0):
self.sceneID = sceneID
self.use_offset = True
self.BT = None
self.reset()
@property
def status(self):
@ -67,7 +59,19 @@ class Scene:
def reset(self):
stub.Reset(GrabSim_pb2.ResetParams(scene=self.sceneID))
def walk_to(self, X, Y, Yaw, velocity, dis_limit):
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]
return GrabSim_pb2.WalkerControls.WControl(
id=walkerID,
autowalk=autowalk,
speed=speed,
pose=GrabSim_pb2.Pose(X=X, Y=Y, Yaw=Yaw),
)
def walk_to(self, X, Y, Yaw, velocity=150, dis_limit=100):
if self.use_offset:
X, Y = X + loc_offset[0], Y + loc_offset[1]
stub.Do(
GrabSim_pb2.Action(
scene=self.sceneID,
@ -77,6 +81,8 @@ class Scene:
)
def reachable_check(self, X, Y, Yaw):
if self.use_offset:
X, Y = X + loc_offset[0], Y + loc_offset[1]
navigation_info = stub.Do(
GrabSim_pb2.Action(
scene=self.sceneID,
@ -90,6 +96,8 @@ class Scene:
return True
def add_walker(self, X, Y, Yaw):
if self.use_offset:
X, Y = X + loc_offset[0], Y + loc_offset[1]
if self.reachable_check(X, Y, Yaw):
stub.AddWalker(
GrabSim_pb2.WalkerList(
@ -133,7 +141,9 @@ class Scene:
)
)
def add_object(self, X, Y, Yaw, Z, type):
def add_object(self, type, X, Y, Z, Yaw=0):
if self.use_offset:
X, Y = X + loc_offset[0], Y + loc_offset[1]
stub.AddObjects(
GrabSim_pb2.ObjectList(
objects=[
@ -173,29 +183,38 @@ class Scene:
)
)
def get_camera_color(self):
def get_camera_color(self, image_only=True):
camera_data = stub.Capture(
GrabSim_pb2.CameraList(
cameras=[GrabSim_pb2.CameraName.Head_Color], scene=self.sceneID
)
)
return image_extract(camera_data)
if image_only:
return image_extract(camera_data)
else:
return camera_data
def get_camera_depth(self):
def get_camera_depth(self, image_only=True):
camera_data = stub.Capture(
GrabSim_pb2.CameraList(
cameras=[GrabSim_pb2.CameraName.Head_Depth], scene=self.sceneID
)
)
return image_extract(camera_data)
if image_only:
return image_extract(camera_data)
else:
return camera_data
def get_camera_segment(self):
def get_camera_segment(self, image_only=True):
camera_data = stub.Capture(
GrabSim_pb2.CameraList(
cameras=[GrabSim_pb2.CameraName.Head_Segment], scene=self.sceneID
)
)
return image_extract(camera_data)
if image_only:
return image_extract(camera_data)
else:
return camera_data
def chat_bubble(self, message):
stub.ControlRobot(
@ -220,5 +239,5 @@ class Scene:
def animation_reset(self):
stub.ControlRobot(GrabSim_pb2.ControlInfo(scene=self.sceneID, type=0, action=0))
def load_BT(self, ptml_path):
self.BT = ptmlCompiler.load(ptml_path, "ptml/behaviour_lib")
def load_BT(self, ptml_path, behaviour_lib_path):
self.BT = ptmlCompiler.load(self, ptml_path, behaviour_lib_path)

20
tasks/AEM.py Normal file
View File

@ -0,0 +1,20 @@
"""
环境主动探索和记忆
要求输出探索结果语义地图对环境重点信息记忆生成环境的语义拓扑地图和不少于10个环境物品的识别和位置记忆可以是图片或者文字或者格式化数据
"""
from scene_utils import control
# control.init_world(1, 3)
scene = control.Scene(sceneID=0)
scene.reset()
scene.add_object(0, 570, 1600, 85.5) # type与物品编号对应具体参考README.md
scene.add_object(1, 570, 1630, 85.5)
scene.add_object(2, 570, 1660, 85.5)
scene.add_object(3, 580, 1680, 85.5)
# todo: 探索并获得语义地图
print(scene.status.objects) # 全部的物品信息,包括名称、位置等,与获得的语义地图进行对比

9
tasks/Auto_tasks.py Normal file
View File

@ -0,0 +1,9 @@
"""
在特定环境下机器人发现目标可自主完成任务
1. 打扫地面地面有垃圾机器人主动扫地清理地面垃圾
2. 收拾桌子桌子上的污渍机器人主动擦桌子
3. 摆椅子椅子不正机器人主动摆正椅子
4. 开灯室内光线暗机器人主动打开房屋的灯
"""
# todo: 通过行为树控制自动任务

10
tasks/GQA.py Normal file
View File

@ -0,0 +1,10 @@
"""
具身多轮对话
点餐order的对话咖啡厅服务员可以为客人NPC完成点餐基本对话
场景对话GQA结合场景询问卫生间附近娱乐场所数据来源自主定义
开始条件顾客NPC发出点餐指令
结束条件顾客NPC发出指令表示不再需要服务
"""
# todo: 使用大模型进行对话,获得指令信息,适时结束对话
# order = {...}

19
tasks/Multi_tasks.py Normal file
View File

@ -0,0 +1,19 @@
"""
人提出请求机器人完成任务
1. 做咖啡固定动画接收到做咖啡指令走到咖啡机拿杯子操作咖啡机取杯子送到客人桌子上
2. 倒水
3. 夹点心
具体描述设计一套点单规则如菜单包含咖啡点心等按照规则拟造随机的订单在收到订单后通过大模型让机器人输出合理的备餐计划并尝试在模拟环境中按照这个规划实现任务
"""
from scene_utils import control
# control.init_world(1, 3)
scene = control.Scene(sceneID=0)
scene.reset()
# todo: 接收点单信息,大模型生成任务规划

29
tasks/VLM.py Normal file
View File

@ -0,0 +1,29 @@
"""
视觉语言操作
机器人根据指令人的指令调节空调自主探索环境导航到目标点通过手臂的运动规划能力操作空调比如开关按钮调温按钮显示面板
"""
import time
from scene_utils import control
# control.init_world(1, 3)
scene = control.Scene(sceneID=0)
scene.reset()
# 空调操作
scene.walk_to(950, 1260, 90) # 没法转向?
# todo: 手臂操作
time.sleep(5)
scene.walk_to(947, 1900, 0)
# 物品挪动
# todo: 视觉导航至目标点,操作手臂至可抓位置
"""
scene.grasp(1, your_objectID)
"""
# todo: 视觉导航至目标点,找准释放位置
"""
scene.release(1)
"""

32
tasks/VLN.py Normal file
View File

@ -0,0 +1,32 @@
"""
视觉语言导航
识别顾客NPC靠近打招呼对话领位导航到适合人数的空闲餐桌
开始条件监测到顾客靠近
结束条件完成领位语音请问您想喝点什么并等待下一步指令
"""
from scene_utils import control
# control.init_world(1, 3)
scene = control.Scene(sceneID=0)
# 实现单顾客领位
scene.reset()
scene.add_walker(1085, 2630, 220)
scene.control_walker([scene.walker_control_generator(0, False, 100, 755, 1900, 180)])
# todo: 监测到顾客靠近,打招呼,对话,识别获取空闲餐桌位置
# 可以使用scene.chat_bubble(message)函数实现对话
"""
scene.walk_to(your_free_table_location)
time.sleep(5)
scene.control_walker([scene.walker_control_generator(your_free_table_location)])
"""
reach = True
if reach:
scene.chat_bubble("请问您想喝点什么?")
print(scene.status.walkers)