2023-10-25 10:34:46 +08:00
|
|
|
import py_trees as ptree
|
2023-11-08 15:28:01 +08:00
|
|
|
from robowaiter.behavior_lib._base.Act import Act
|
2023-11-16 15:29:56 +08:00
|
|
|
from robowaiter.algos.navigator.navigate import Navigator
|
2023-11-09 17:06:34 +08:00
|
|
|
|
2023-11-08 15:28:01 +08:00
|
|
|
class MoveTo(Act):
|
2023-11-13 14:53:00 +08:00
|
|
|
can_be_expanded = True
|
|
|
|
num_args = 1
|
2023-11-17 18:56:58 +08:00
|
|
|
valid_args = Act.all_object | Act.tables_for_placement | Act.tables_for_guiding
|
2023-11-13 22:14:55 +08:00
|
|
|
valid_args.add('Customer')
|
2023-11-13 14:53:00 +08:00
|
|
|
|
|
|
|
def __init__(self, target_place):
|
|
|
|
super().__init__(target_place)
|
|
|
|
self.target_place = target_place
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
2023-11-14 12:09:53 +08:00
|
|
|
def get_info(cls,arg):
|
2023-11-13 22:14:55 +08:00
|
|
|
info = {}
|
2023-11-14 12:09:53 +08:00
|
|
|
info['pre'] = set()
|
2023-11-14 23:16:48 +08:00
|
|
|
if arg in Act.all_object:
|
|
|
|
info['pre'] |= {f'Exist({arg})'}
|
2023-11-13 22:14:55 +08:00
|
|
|
info["add"] = {f'At(Robot,{arg})'}
|
2023-11-14 12:09:53 +08:00
|
|
|
info["del_set"] = {f'At(Robot,{place})' for place in cls.valid_args if place != arg}
|
2023-11-16 23:05:11 +08:00
|
|
|
info['cost']=5
|
2023-11-13 14:53:00 +08:00
|
|
|
return info
|
2023-10-25 10:34:46 +08:00
|
|
|
|
|
|
|
|
2023-10-25 22:12:15 +08:00
|
|
|
def _update(self) -> ptree.common.Status:
|
2023-11-09 17:06:34 +08:00
|
|
|
# self.scene.test_move()
|
|
|
|
|
2023-11-14 12:09:53 +08:00
|
|
|
# navigator = Navigator(scene=self.scene, area_range=[-350, 600, -400, 1450], map=self.scene.state["map"]["2d"])
|
|
|
|
# goal = self.scene.state['map']['obj_pos'][self.args[0]]
|
2023-11-16 15:28:08 +08:00
|
|
|
# navigator.navigate_old(goal, animation=False)
|
2023-11-14 12:09:53 +08:00
|
|
|
|
2023-11-14 23:16:48 +08:00
|
|
|
# 走到固定的地点
|
2023-11-14 12:09:53 +08:00
|
|
|
if self.target_place in Act.place_xyz_dic:
|
|
|
|
goal = Act.place_xyz_dic[self.target_place]
|
2023-11-17 18:56:58 +08:00
|
|
|
self.scene.walk_to(goal[0]+1,goal[1],goal[2])
|
2023-11-16 15:28:08 +08:00
|
|
|
# 走到物品边上
|
|
|
|
else:
|
|
|
|
# 是否用容器装好
|
|
|
|
if self.target_place in Act.container_dic:
|
|
|
|
target_name = Act.container_dic[self.target_place]
|
|
|
|
else:
|
|
|
|
target_name = self.target_place
|
|
|
|
# 根据物体名字找到最近的这类物体对应的位置
|
2023-11-15 14:33:18 +08:00
|
|
|
obj_id = -1
|
|
|
|
min_dis = float('inf')
|
|
|
|
obj_dict = self.scene.status.objects
|
|
|
|
if len(obj_dict)!=0:
|
|
|
|
# 获取obj_id
|
|
|
|
for id,obj in enumerate(obj_dict):
|
2023-11-16 15:28:08 +08:00
|
|
|
if obj.name == target_name:
|
|
|
|
obj_info = obj_dict[id]
|
|
|
|
dis = self.scene.cal_distance_to_robot(obj_info.location.X, obj_info.location.Y, obj_info.location.Z)
|
|
|
|
if dis<min_dis:
|
|
|
|
min_dis = dis
|
|
|
|
obj_id = id
|
|
|
|
# if self.target_place == "CoffeeCup":
|
|
|
|
# # obj_id = 273
|
|
|
|
# obj_id = 275
|
2023-11-15 14:33:18 +08:00
|
|
|
if obj_id == -1:
|
|
|
|
return ptree.common.Status.FAILURE
|
2023-11-15 12:04:49 +08:00
|
|
|
|
2023-11-16 17:57:27 +08:00
|
|
|
# print("self.target_place:",self.target_place,"id:",obj_id,"dis:",min_dis)
|
2023-11-15 14:33:18 +08:00
|
|
|
self.scene.move_to_obj(obj_id=obj_id)
|
2023-11-15 12:04:49 +08:00
|
|
|
|
2023-11-15 14:33:18 +08:00
|
|
|
# 为了演示,写死咖啡位置
|
|
|
|
# if self.target_place=="Coffee":
|
|
|
|
# obj_id = 273
|
2023-11-15 12:04:49 +08:00
|
|
|
# obj_id = -1
|
|
|
|
# obj_dict = self.scene.status.objects
|
|
|
|
# if len(obj_dict)!=0:
|
|
|
|
# # 获取obj_id
|
|
|
|
# for id,obj in enumerate(obj_dict):
|
|
|
|
# if obj.name == self.target_place:
|
|
|
|
# obj_id = id
|
|
|
|
# break
|
|
|
|
# # 为了演示,写死咖啡位置
|
|
|
|
# if self.target_place=="Coffee":
|
|
|
|
# obj_id = 273
|
|
|
|
# if obj_id == -1:
|
|
|
|
# return ptree.common.Status.FAILURE
|
|
|
|
# obj_info = obj_dict[obj_id]
|
|
|
|
# obj_x, obj_y, obj_z = obj_info.location.X, obj_info.location.Y, obj_info.location.Z
|
|
|
|
# self.scene.walk_to(obj_x,obj_y)
|
|
|
|
# print("MoveTo",obj_x, obj_y, obj_z," obj_id:",obj_id," obj_info:",obj_info.name)
|
2023-11-14 08:53:11 +08:00
|
|
|
|
2023-11-14 23:16:48 +08:00
|
|
|
|
2023-11-14 08:53:11 +08:00
|
|
|
# goal = self.scene.state['map']['obj_pos'][self.args[0]]
|
2023-11-14 12:09:53 +08:00
|
|
|
# self.scene.walk_to(goal[0],goal[1]) # X, Y, Yaw=None, velocity=200, dis_limit=0
|
|
|
|
|
2023-11-09 17:06:34 +08:00
|
|
|
|
2023-11-14 12:09:53 +08:00
|
|
|
self.scene.state["condition_set"] |= (self.info["add"])
|
|
|
|
self.scene.state["condition_set"] -= self.info["del_set"]
|
2023-11-09 08:47:57 +08:00
|
|
|
return ptree.common.Status.RUNNING
|