diff --git a/README.md b/README.md index fc2fb1f..796cda2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # RoboWaiter 大模型具身智能比赛-机器人控制端 + +### 机器人控制 +1. 加载场景 +```python +from scene_utils import control +control.init_world(scene_num=1, mapID=3) +``` +当前只有一个咖啡馆场景。加载操作只需要执行一遍,当引擎进入相应场景后,可以用`control.reset()`重置场景。 \ No newline at end of file diff --git a/scene_utils/control.py b/scene_utils/control.py index e27f34c..da4b613 100644 --- a/scene_utils/control.py +++ b/scene_utils/control.py @@ -1,3 +1,4 @@ +import time import gym import grpc from proto import GrabSim_pb2 @@ -15,6 +16,7 @@ stub = GrabSim_pb2_grpc.GrabSimStub(channel) def init_world(scene_num, mapID): stub.SetWorld(GrabSim_pb2.BatchMap(count=scene_num, mapID=mapID)) + time.sleep(3) # wait for the map to load class Scene: @@ -33,7 +35,6 @@ class Scene: def __init__(self, sceneID): self.sceneID = sceneID - self.walkerID_set = set() self.reset() @property @@ -67,28 +68,29 @@ class Scene: def add_walker(self, X, Y, Yaw): if self.reachable_check(X, Y, Yaw): - walkerID = 0 if not self.walkerID_set else max(self.walkerID_set) + 1 stub.AddWalker( GrabSim_pb2.WalkerList( walkers=[ GrabSim_pb2.WalkerList.Walker( - id=walkerID, pose=GrabSim_pb2.Pose(X=X, Y=Y, Yaw=Yaw) + id=0, + pose=GrabSim_pb2.Pose( + X=X, Y=Y, Yaw=Yaw + ), # Parameter id is useless ) ], scene=self.sceneID, ) ) - self.walkerID_set.add(walkerID) - return walkerID - else: - return None - def remove_walker(self, *args): + def remove_walker(self, *args): # take single walkerID or a list of walkerIDs remove_list = [] - for walkerID in args: - if walkerID in self.walkerID_set: + if isinstance(args[0], list): + remove_list = args[0] + else: + for walkerID in args: + # walkerID is the index of the walker in status.walkers. + # Since status.walkers is a list, some walkerIDs would change after removing a walker. remove_list.append(walkerID) - self.walkerID_set.remove(walkerID) stub.RemoveWalkers(GrabSim_pb2.RemoveList(IDs=remove_list, scene=self.sceneID)) def clean_walker(self): @@ -126,3 +128,15 @@ class Scene: ) ) + def remove_object(self, *args): # refer to remove_walker + remove_list = [] + if isinstance(args[0], list): + remove_list = args[0] + else: + for objectID in args: + remove_list.append(objectID) + stub.RemoveObjects(GrabSim_pb2.RemoveList(IDs=remove_list, scene=self.sceneID)) + + def clean_object(self): + stub.CleanObjects(GrabSim_pb2.SceneID(value=self.sceneID)) + \ No newline at end of file