-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_planner_exec.py
More file actions
69 lines (50 loc) · 1.98 KB
/
test_planner_exec.py
File metadata and controls
69 lines (50 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import rospy
import actionlib
from MCTS_planner import *
from reward_func_gen import *
from prolex_msgs.msg import BelPullAction, BelPullFeedback, BelPullGoal, BelPullResult
from prolex_msgs.msg import GetObjsAction, GetObjsGoal, GetObjsResult
import pickle as pkl
def found(obj_tp, obj_pull_client):
get_objs_goal = GetObjsGoal()
get_objs_goal.tp = 'new'
obj_pull_client.send_goal(get_objs_goal)
obj_pull_client.wait_for_result()
new_objs = pkl.loads(eval(obj_pull_client.get_result().objs))
if not new_objs:
return False, None
for obj in new_objs:
if obj_tp == new_objs[obj]['obj_tp']:
return True, {obj : new_objs[obj]}
rospy.init_node('test')
# Connect to Belief Pulling server
bel_pull_client = actionlib.SimpleActionClient('/bel_pull_server', BelPullAction)
res = bel_pull_client.wait_for_server()
print("Connected to Belief Pulling Server: ", res)
# Connect to object pulling server
obj_pull_client = actionlib.SimpleActionClient('/get_objs_server', GetObjsAction)
res = obj_pull_client.wait_for_server()
print("Connected to Object Pulling Server: ", res)
success = False
succ_find = False
# Replan until found
while not success or not succ_find:
# Repull Belief each iteration to make sure it's up to date
bel_pull_goal = BelPullGoal()
bel_pull_client.send_goal(bel_pull_goal)
bel_pull_client.wait_for_result()
res = bel_pull_client.get_result()
belief = pkl.loads(eval(bel_pull_client.get_result().bel))
# Regenerate Reward each iteration to make sure it matches new belief
reward_func = generate_reward_func(belief, 'Chair', props=None, func_tp='S_Entropy', exist_thresh=0.6)
# Call planner exec
success = planner_exec(belief, reward_func)
if success == 'Replan':
success = False
elif success == 'Not Found':
print('Not found')
break
print("Done Motion Plan? ", success)
# Check if Found
#succ_find, new_obj = found('Chair', obj_pull_client)
#print(new_obj)