本文整理汇总了Python中World.World.makeSlot方法的典型用法代码示例。如果您正苦于以下问题:Python World.makeSlot方法的具体用法?Python World.makeSlot怎么用?Python World.makeSlot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World.World
的用法示例。
在下文中一共展示了World.makeSlot方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HTN
# 需要导入模块: from World import World [as 别名]
# 或者: from World.World import makeSlot [as 别名]
#.........这里部分代码省略.........
i+=1
#group and keep even the slot names
groupedTask=(subtasks[-2]).groupWith(subtasks[-1],name+str(i))
else:
#group and keep even the slot names
groupedTask=(subtasks[-2]).groupWith(subtasks[-1])
#remove the tasks and add grouped task in
subtasks=subtasks[:len(subtasks)-2]
subtasks.append(groupedTask)
#add the new subtasks list in
self.tree[self.currentSubtask].subtasks=subtasks
#reset the input of the top level to be the bottom
self.tree[self.currentSubtask].inputs=[]
self.tree[self.currentSubtask].outputs=[]
for subtask in self.tree[self.currentSubtask].subtasks:
self.tree[self.currentSubtask].inputs.extend(subtask.inputs)
self.tree[self.currentSubtask].outputs.extend(subtask.outputs)
#then lose the slot names to make it a reuseable action
#clean up the grouped task for use in actions
cleanedCopy=self.removeSlotNamesRecursive(groupedTask)
self.actions[groupedTask.name]=cleanedCopy
def getInputsForSlots(self,action,inputs):
#array of Item and containers that go in a slot
final_input=[]
#convert the inputs from a series of strings to a series of Slot classes
#for each input find the appropriate slot and put it into it
for input in inputs:
#if this does not work we cannot figure out where to put this input, so exec fails
if not self.world.makeSlot(input,action.inputs):
rospy.loginfo("Error matching slot "+input)
return False,{'failed_input':input}
#there is a slot add to input
else:
final_input.append(self.world.getObject(input))
return True,final_input
#find the correct action and then check if the inputs match
#if they do, this runs the action and adds it to the current point
#in the tree
#@return if execution was successful, whether the last two subtasks are group-able, error info
def executeTask(self,taskName,inputs):
#check if this is in the set of actions the user can use.
#if it is add it as a subtask of the current highlighted task
if self.actions[taskName]:
#make a copy so that you can fill it in with the correct inputs
action= copy.deepcopy(self.actions[taskName])
match_succeeded,final_input=self.getInputsForSlots(action,inputs)
#if there are matches that can be made
if match_succeeded:
#execute the task
success,reason=action.execute(final_input,self.world)
if not success:
#if compound figure out which action has failed
#it is returned from class Action as an Object as HTN will not contain those details
if not action.type=='primitive':
return False,False,reason
else:
return False,False,{'reason':reason}
#add the task to the current task that is highlighted-
self.tree[self.currentSubtask].addSubtask(action)