api封装
This commit is contained in:
parent
d9c83ebd8f
commit
59b2ef6116
|
@ -1,2 +1,10 @@
|
||||||
# RoboWaiter
|
# RoboWaiter
|
||||||
大模型具身智能比赛-机器人控制端
|
大模型具身智能比赛-机器人控制端
|
||||||
|
|
||||||
|
### 机器人控制
|
||||||
|
1. 加载场景
|
||||||
|
```python
|
||||||
|
from scene_utils import control
|
||||||
|
control.init_world(scene_num=1, mapID=3)
|
||||||
|
```
|
||||||
|
当前只有一个咖啡馆场景。加载操作只需要执行一遍,当引擎进入相应场景后,可以用`control.reset()`重置场景。
|
|
@ -1,3 +1,4 @@
|
||||||
|
import time
|
||||||
import gym
|
import gym
|
||||||
import grpc
|
import grpc
|
||||||
from proto import GrabSim_pb2
|
from proto import GrabSim_pb2
|
||||||
|
@ -15,6 +16,7 @@ stub = GrabSim_pb2_grpc.GrabSimStub(channel)
|
||||||
|
|
||||||
def init_world(scene_num, mapID):
|
def init_world(scene_num, mapID):
|
||||||
stub.SetWorld(GrabSim_pb2.BatchMap(count=scene_num, mapID=mapID))
|
stub.SetWorld(GrabSim_pb2.BatchMap(count=scene_num, mapID=mapID))
|
||||||
|
time.sleep(3) # wait for the map to load
|
||||||
|
|
||||||
|
|
||||||
class Scene:
|
class Scene:
|
||||||
|
@ -33,7 +35,6 @@ class Scene:
|
||||||
|
|
||||||
def __init__(self, sceneID):
|
def __init__(self, sceneID):
|
||||||
self.sceneID = sceneID
|
self.sceneID = sceneID
|
||||||
self.walkerID_set = set()
|
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -67,28 +68,29 @@ class Scene:
|
||||||
|
|
||||||
def add_walker(self, X, Y, Yaw):
|
def add_walker(self, X, Y, Yaw):
|
||||||
if self.reachable_check(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(
|
stub.AddWalker(
|
||||||
GrabSim_pb2.WalkerList(
|
GrabSim_pb2.WalkerList(
|
||||||
walkers=[
|
walkers=[
|
||||||
GrabSim_pb2.WalkerList.Walker(
|
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,
|
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 = []
|
remove_list = []
|
||||||
for walkerID in args:
|
if isinstance(args[0], list):
|
||||||
if walkerID in self.walkerID_set:
|
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)
|
remove_list.append(walkerID)
|
||||||
self.walkerID_set.remove(walkerID)
|
|
||||||
stub.RemoveWalkers(GrabSim_pb2.RemoveList(IDs=remove_list, scene=self.sceneID))
|
stub.RemoveWalkers(GrabSim_pb2.RemoveList(IDs=remove_list, scene=self.sceneID))
|
||||||
|
|
||||||
def clean_walker(self):
|
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))
|
||||||
|
|
Loading…
Reference in New Issue