-
Notifications
You must be signed in to change notification settings - Fork 7
/
pseudo_code
61 lines (43 loc) · 2.39 KB
/
pseudo_code
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
given: initial state <s_0>, goal state set <G>,
behavior tree set <BT>, tree utility function <u(bt)>,
max_plan_failure <plan_max>, max_execution_failure <exe_max>
def: state <s>, plan <p>
----------------------------------------------------------
START:
feasible_plan_list = []
while difference_in_success_rate(feasible_plan_list) < threshold: # convergence condition
robot_recover()
# initialize in planning
plan_count = 0, exe_count = 0
state = s0
plan = [], result[] = [], last_plan = []
task_success = False
while task_success == False:
update_utility_function(result[]) # actually the success rate function of each subtree based on state transition
# dynamic planning. should always expand, ground and execute until the task is finished or the quit condition is met
if failure_in_condition(plan): # failure in condition: dynamic expanding
if plan_count > plan_max:
break # too many planning tries are forbidden
else
last_plan = plan # record the last plan
plan = expand(last_plan, state) # expand the plan
plan_count += 1 # try the new plan
else if failure_in_action(plan): # failure in action: parameter issue or plan issue
robot_recover_last_action() # (a problem here: how to recover the last action in real experiment?)
new_plan = expand(last_plan) # expand the last plan
if isBetter(new_plan, last_plan): # find a better plan than the last one
exe_count = 0 # reset the execution count
plan = new_plan # and last_plan is still the same
else
if exe_count > exe_max:
break # quit and start again when having tried too many times
else
exe_count += 1 # try one more time
grounded_plan = ground_plan(plan) # ground the plan
task_success, result[] = execute(grounded_p) # execute the plan and get the result
update_utility_function(task_success, result[]) # update the utility function based on the result of the task
if task_success == True:
feasible_plan_list.append([plan, utility(plan)])
plan* = feasible_plan_list.best_plan()
END
---------------------------------------------------------