def new_world(loc_list): p = person() p.id = str(obj2idx('referee', 'PERSONS')) p.locId = str(obj2idx('referee', 'LOCATIONS')) # 2' p.near = NO p.obj1Id = '-1' p.recognized = NO p.memorized = NO p.askedName = NO p.followed = NO p.found = NO # check! if person = referee, location = robot location i = item() i.id = '-1' i.locId = str(obj2idx('sams_table', 'LOCATIONS')) # '-1' i.found = NO i.toBeGrasped = NO i.grasped = NO i.delivered = NO i.pointed = NO r = robot() r.id = '1' r.locId = str(obj2idx('referee', 'LOCATIONS')) r.obj1Id = '-1' r.introduced = NO r.pointedAtLoc = '-1' print r.locId l = [] for loc in loc_list: nl = location() nl.id = loc nl.pointed_at = NO l.append(nl) w = world() w.item = i w.person = p w.robot = r w.location = l print w.robot.locId return w
def new_world(loc_list): #generates a new world p = person() #generates a person, names it referee and ask the translator about its localtion p.id = str(obj2idx('referee', 'PERSONS')) p.locId = str(obj2idx('referee', 'LOCATIONS')) # 2' p.near = NO p.obj1Id = '-1' p.recognized = NO p.memorized = NO p.askedName = NO p.followed = NO p.found = NO # check! if person = referee, location = robot location i = item() #initializes items in the new world i.id = '-1' i.locId = '-1' #str(obj2idx('sams_table', 'LOCATIONS')) # '-1' i.found = NO i.toBeGrasped = NO i.grasped = NO i.delivered = NO i.pointed = NO r = robot() # puts the robot himself in its world map r.id = '1' r.locId = str(obj2idx('referee', 'LOCATIONS')) r.obj1Id = '-1' r.introduced = NO r.pointedAtLoc = '-1' print r.locId l = [] for loc in loc_list: #adds the locations list to this world nl = location() nl.id = loc nl.pointed_at = NO l.append(nl) w = world() #generates a world and fill it with the objects we already created before. w.item = i w.person = p w.robot = r w.location = l return w #return this world
def new_world(loc_list): #generates a new world p = person( ) #generates a person, names it referee and ask the translator about its localtion p.id = str(obj2idx('referee', 'PERSONS')) p.locId = str(obj2idx('referee', 'LOCATIONS')) # 2' p.near = NO p.obj1Id = '-1' p.recognized = NO p.memorized = NO p.askedName = NO p.followed = NO p.found = NO # check! if person = referee, location = robot location i = item() #initializes items in the new world i.id = '-1' i.locId = '-1' #str(obj2idx('sams_table', 'LOCATIONS')) # '-1' i.found = NO i.toBeGrasped = NO i.grasped = NO i.delivered = NO i.pointed = NO r = robot() # puts the robot himself in its world map r.id = '1' r.locId = str(obj2idx('referee', 'LOCATIONS')) r.obj1Id = '-1' r.introduced = NO r.pointedAtLoc = '-1' print r.locId l = [] for loc in loc_list: #adds the locations list to this world nl = location() nl.id = loc nl.pointed_at = NO l.append(nl) w = world( ) #generates a world and fill it with the objects we already created before. w.item = i w.person = p w.robot = r w.location = l return w #return this world
def get_goal(self, GOAL,robot): verb = GOAL.action self.name = verb.replace('_', '-') if verb == 'go_to': self.goal_go_to(GOAL) elif verb == 'introduce': self.goal_introduce(GOAL) elif verb == 'follow': self.goal_follow(GOAL) elif verb == 'find' or verb == 'find_object' or verb == 'find_person': self.goal_find(GOAL) elif verb == 'grasp': self.goal_grasp(GOAL) elif verb == 'bring_to': self.goal_bring_to(GOAL) elif verb == 'bring_from': self.goal_bring_from(GOAL) elif verb == 'learn_person': self.goal_learn_person(GOAL,robot) elif verb == 'exit': GOAL.location = obj2idx('exit', 'LOCATIONS') self.goal_go_to(GOAL) elif verb == 'recognize_person': self.goal_recognize(GOAL) elif verb == 'point_at': self.goal_point_at(GOAL) elif verb == 'guide': self.goal_guide(GOAL) # return self.gen_goal() return self
def check_object_location(obj): if obj != '': result = ask_data(Type='LOCATIONS', objectName=obj) return obj2idx(result, 'LOCATIONS') else: return '-1'
def get_goal(self, GOAL, robot): verb = GOAL.action self.name = verb.replace('_', '-') if verb == 'go_to': self.goal_go_to(GOAL) elif verb == 'introduce': self.goal_introduce(GOAL) elif verb == 'follow': self.goal_follow(GOAL) elif verb == 'find' or verb == 'find_object' or verb == 'find_person': self.goal_find(GOAL) elif verb == 'grasp': self.goal_grasp(GOAL) elif verb == 'bring_to': self.goal_bring_to(GOAL) elif verb == 'bring_from': self.goal_bring_from(GOAL) elif verb == 'learn_person': self.goal_learn_person(GOAL, robot) elif verb == 'exit': GOAL.location = obj2idx('exit', 'LOCATIONS') self.goal_go_to(GOAL) elif verb == 'recognize_person': self.goal_recognize(GOAL) elif verb == 'point_at': self.goal_point_at(GOAL) elif verb == 'guide': self.goal_guide(GOAL) # return self.gen_goal() return self
def print_goal(self): commands = self._goal.orderList iperson = 0 iitem = 0 iloc = 0 perss = [] locc = [] itt = [] for c in commands: if c.person != '': if c.person not in perss: iperson += 1 perss.append(c.person) if c.item != '': if c.item not in itt: iitem += 1 itt.append(c.item) if c.location != '': if c.location not in locc: iloc += 1 locc.append(c.location) command = commands[self._goalDonei] locc = get_list('LOCATIONS') #this is a dummy for tests!!! # command = commands[1] # print command.action # print command.location # print command.item # print command.person # printNewGoal(oaction=command.action, oitem=items[command.item], operson=persons[command.person], olocation=locations[command.location]) # printNewGoal(oaction='go_to', oitem=items[command.item], operson=persons[command.person], olocation=1) # compileInit(locations=iloc, persons=iperson, items=iitem, oaction=command.action, oitem=items[command.item], operson=persons[command.person], olocation=locations[command.location]) # checks that the item is or not a category # print 'blablabal' if command.item in categories: objct = ask_category(command.item) self._world.item.id = obj2idx(objct, 'ITEMS') command.item = objct print idx2obj(self._world.item.id, 'ITEMS') # print command.location # print 'here' if command.location in loc_categories: # print 'ther should be a print here' loca = ask_category_loc(command.location) # print loca # print loca # print self._world.location # print len(self._world.location) # self._world.location.id = obj2idx(loca, 'LOCATIONS') command.location = loca # print loca # checks if the location of objects or persons are known if self._world.person.locId == '-1' : # and command.person == self._world.person.id: ploc = check_object_location(idx2obj(int(self._world.person.id), 'PERSONS')) # if ploc != '-1': # ploc = obj2idx(ploc,'LOCATIONS') self._world.person.locId = ploc # print command.item try: i = obj2idx(command.item, 'ITEMS') self._world.item.id = str(i) except ValueError: print str(self._world.item.id) print command.item i = '' try: p = obj2idx(command.person, 'PERSONS') self._world.person.id = str(p) except ValueError: p = '' try: l = obj2idx(command.location, 'LOCATIONS') # print l # print l except ValueError: l = '' print self._world.robot.locId # print command.location # print idx2obj(l, 'LOCATIONS') # print 'blabla' # print 'here here ' + str(p) if self._world.item.locId == '-1' and self._world.item.id != '-1': # and command.item == self._world.item.id: iloc = check_object_location(idx2obj(int(self._world.item.id), 'ITEMS')) # if iloc != '-1': # iloc = obj2idx(iloc,'LOCATIONS') self._world.item.locId = iloc if command.action == 'bring_from': self._world.item.locId = str(obj2idx(command.location, 'LOCATIONS')) if (command.action == 'memorize' or command.action == 'recognize'): command.person = self._world.person.id # print self._world.item.id # print self._world.item.locId self._last_goal = compileInit(locations=locc, persons=perss, items=itt, oaction=command.action, oitem=i, operson=p, olocation=l, current_world=self._world) # compileInit(locations=locc, persons=perss, items=itt, oaction=command.action, oitem=items[command.item], operson=persons[command.person], olocation=locations[command.location]) # printNewGoal(action, it, pers, loc, self._goalDonei) self._goalDonei += 1
def print_goal(self): commands = self._goal.orderList iperson = 0 iitem = 0 iloc = 0 perss = [] locc = [] itt = [] for c in commands: #extract elements from orderList and put them in the arrays previously initialized if c.person != '': if c.person not in perss: iperson += 1 perss.append(c.person) if c.item != '': if c.item not in itt: iitem += 1 itt.append(c.item) if c.location != '': if c.location not in locc: iloc += 1 locc.append(c.location) command = commands[ self._goalDonei] #Extract command indexed by goalDonei to command locc = get_list('LOCATIONS') #Saves in locc all possible locations #this is a dummy for tests!!! # command = commands[1] # print command.action # print command.location # print command.item # print command.person # printNewGoal(oaction=command.action, oitem=items[command.item], operson=persons[command.person], olocation=locations[command.location]) # printNewGoal(oaction='go_to', oitem=items[command.item], operson=persons[command.person], olocation=1) # compileInit(locations=iloc, persons=iperson, items=iitem, oaction=command.action, oitem=items[command.item], operson=persons[command.person], olocation=locations[command.location]) # checks that the item is or not a category # print 'blablabal' if command.item in categories: #if the item is a category this ask for further information and updates it objct = ask_category(command.item) self._world.item.id = obj2idx(objct, 'ITEMS') command.item = objct if command.location in loc_categories: #if the location is a category this ask for further information and updates it loca = ask_category_loc(command.location) command.location = loca # checks if the location of persons are known if self._world.person.locId == '-1': # and command.person == self._world.person.id: ploc = check_object_location( idx2obj(int(self._world.person.id), 'PERSONS')) # if ploc != '-1': # ploc = obj2idx(ploc,'LOCATIONS') print "LA LOCATION DE LA PERSON ES!!!!!!!!!!!!!!!!: " + str(ploc) self._world.person.locId = ploc try: #adds to world the item id i = obj2idx(command.item, 'ITEMS') self._world.item.id = str(i) except ValueError: print str(self._world.item.id) print command.item i = '' try: #adds to world the person id p = obj2idx(command.person, 'PERSONS') self._world.person.id = str(p) except ValueError: p = '' try: l = obj2idx(command.location, 'LOCATIONS') except ValueError: l = '' print self._world.robot.locId if command.action == 'bring_from': self._world.item.locId = str(obj2idx(command.location, 'LOCATIONS')) if self._world.item.locId == '-1' and self._world.item.id != '-1': # If we know the item but not the location we check it and save it in world iloc = check_object_location( idx2obj(int(self._world.item.id), 'ITEMS')) self._world.item.locId = iloc if (command.action == 'memorize' or command.action == 'recognize'): command.person = self._world.person.id if (idx2obj(int(self._world.person.id), 'PERSONS') == 'person'): #prova per coneguir self._world.person.locId = self._world.robot.locId self._last_goal = compileInit(locations=locc, persons=perss, items=itt, oaction=command.action, oitem=i, operson=p, olocation=l, current_world=self._world) ''' locc: array with all the locations perss: array with all the persons involved in the commands itt: array with all the items involved in the commands comand.action: the action we want to perform i: the index of the object involved in this action p: index of the person involved in this action l: index of the location involved in this action self._world: the world we are working on ''' self._goalDonei += 1
def new_world(self, allFile, locations): l = [] lInits = [] # locations = for loc in locations: locc = obj2idx(loc, 'LOCATIONS') l.append(convert(locc)) #puts locc between <l > and adds it to the array l ll = ' (' + convert(locc) + ' ^id ' + str(locc) + ' ^pointed-at no)' #writes something like the following were 0 is locc # (<l0> ^id 0 ^pointed-at no) lInits.append(ll) #puts the previous phrase in to the array lInits allFile = allFile.replace('LOCATIONS', ' '.join(l)) #replaces LOCATIONS in allFile (witch is like init-template.soar allFile = allFile.replace(' LOCATION', '\n'.join(lInits)) #the same as previous person_text = ' (<pers1> ' #builds the person and its atributes with the correct format to add it to the file first_attr = True ignore_field = True for n in self.person.__dict__.keys(): if str(getattr(self.person, n)) != ignore: if first_attr: person_text += '^' + n + ' ' + str(getattr(self.person, n)) first_attr = False ignore_field = False else: person_text += '\n ^' + n + ' ' + str(getattr(self.person, n)) if ignore_field: person_text = '' else: person_text += ')\n' robot_text = ' (<r> ' first_attr = True ignore_field = True for n in self.robot.__dict__.keys(): if str(getattr(self.robot, n)) != ignore: if first_attr: robot_text += '^' + n + ' ' + str(getattr(self.robot, n)) first_attr = False ignore_field = False else: robot_text += '\n ^' + n + ' ' + str(getattr(self.robot, n)) if ignore_field: robot_text = '' else: robot_text += ')\n' item_text = ' (<obj1> ' first_attr = True ignore_field = True for n in self.item.__dict__.keys(): if str(getattr(self.item, n)) != ignore: if first_attr: item_text += '^' + n + ' ' + str(getattr(self.item, n)) first_attr = False ignore_field = False else: item_text += '\n ^' + n + ' ' + str(getattr(self.item, n)) if ignore_field: item_text = '' else: item_text += ')\n' allFile = allFile.replace(ROBOT, robot_text) allFile = allFile.replace(ITEM, item_text) allFile = allFile.replace(PERSON, person_text) return allFile
def set_current_position(self,location): loc = obj2idx(location, 'LOCATIONS') self.robot.locId = loc
def new_world(self, allFile, locations): l = [] lInits = [] # locations = for loc in locations: locc = obj2idx(loc, 'LOCATIONS') l.append(convert(locc)) ll = ' (' + convert(locc) + ' ^id ' + str(locc) + ' ^pointed-at no)' lInits.append(ll) allFile = allFile.replace('LOCATIONS', ' '.join(l)) allFile = allFile.replace(' LOCATION', '\n'.join(lInits)) person_text = ' (<pers1> ' first_attr = True ignore_field = True for n in self.person.__dict__.keys(): if str(getattr(self.person, n)) != ignore: if first_attr: person_text += '^' + n + ' ' + str(getattr(self.person, n)) first_attr = False ignore_field = False else: person_text += '\n ^' + n + ' ' + str(getattr(self.person, n)) if ignore_field: person_text = '' else: person_text += ')\n' robot_text = ' (<r> ' first_attr = True ignore_field = True for n in self.robot.__dict__.keys(): if str(getattr(self.robot, n)) != ignore: if first_attr: robot_text += '^' + n + ' ' + str(getattr(self.robot, n)) first_attr = False ignore_field = False else: robot_text += '\n ^' + n + ' ' + str(getattr(self.robot, n)) if ignore_field: robot_text = '' else: robot_text += ')\n' item_text = ' (<obj1> ' first_attr = True ignore_field = True for n in self.item.__dict__.keys(): if str(getattr(self.item, n)) != ignore: if first_attr: item_text += '^' + n + ' ' + str(getattr(self.item, n)) first_attr = False ignore_field = False else: item_text += '\n ^' + n + ' ' + str(getattr(self.item, n)) if ignore_field: item_text = '' else: item_text += ')\n' allFile = allFile.replace(ROBOT, robot_text) allFile = allFile.replace(ITEM, item_text) allFile = allFile.replace(PERSON, person_text) return allFile
def print_goal(self): commands = self._goal.orderList iperson = 0 iitem = 0 iloc = 0 perss = [] locc = [] itt = [] for c in commands: #extract elements from orderList and put them in the arrays previously initialized if c.person != '': if c.person not in perss: iperson += 1 perss.append(c.person) if c.item != '': if c.item not in itt: iitem += 1 itt.append(c.item) if c.location != '': if c.location not in locc: iloc += 1 locc.append(c.location) command = commands[self._goalDonei] #Extract command indexed by goalDonei to command locc = get_list('LOCATIONS') #Saves in locc all possible locations #this is a dummy for tests!!! # command = commands[1] # print command.action # print command.location # print command.item # print command.person # printNewGoal(oaction=command.action, oitem=items[command.item], operson=persons[command.person], olocation=locations[command.location]) # printNewGoal(oaction='go_to', oitem=items[command.item], operson=persons[command.person], olocation=1) # compileInit(locations=iloc, persons=iperson, items=iitem, oaction=command.action, oitem=items[command.item], operson=persons[command.person], olocation=locations[command.location]) # checks that the item is or not a category # print 'blablabal' if command.item in categories: #if the item is a category this ask for further information and updates it objct = ask_category(command.item) self._world.item.id = obj2idx(objct, 'ITEMS') command.item = objct if command.location in loc_categories: #if the location is a category this ask for further information and updates it loca = ask_category_loc(command.location) command.location = loca # checks if the location of persons are known if self._world.person.locId == '-1' : # and command.person == self._world.person.id: ploc = check_object_location(idx2obj(int(self._world.person.id), 'PERSONS')) # if ploc != '-1': # ploc = obj2idx(ploc,'LOCATIONS') print "LA LOCATION DE LA PERSON ES!!!!!!!!!!!!!!!!: "+str(ploc) self._world.person.locId = ploc try: #adds to world the item id i = obj2idx(command.item, 'ITEMS') self._world.item.id = str(i) except ValueError: print str(self._world.item.id) print command.item i = '' try: #adds to world the person id p = obj2idx(command.person, 'PERSONS') self._world.person.id = str(p) except ValueError: p = '' try: l = obj2idx(command.location, 'LOCATIONS') except ValueError: l = '' print self._world.robot.locId if command.action == 'bring_from': self._world.item.locId = str(obj2idx(command.location, 'LOCATIONS')) if self._world.item.locId == '-1' and self._world.item.id != '-1': # If we know the item but not the location we check it and save it in world iloc = check_object_location(idx2obj(int(self._world.item.id), 'ITEMS')) self._world.item.locId = iloc if (command.action == 'memorize' or command.action == 'recognize'): command.person = self._world.person.id if (idx2obj(int(self._world.person.id), 'PERSONS') == 'person'): #prova per coneguir self._world.person.locId = self._world.robot.locId self._last_goal = compileInit(locations=locc, persons=perss, items=itt, oaction=command.action, oitem=i, operson=p, olocation=l, current_world=self._world) ''' locc: array with all the locations perss: array with all the persons involved in the commands itt: array with all the items involved in the commands comand.action: the action we want to perform i: the index of the object involved in this action p: index of the person involved in this action l: index of the location involved in this action self._world: the world we are working on ''' self._goalDonei += 1
def new_world(self, allFile, locations): l = [] lInits = [] # locations = for loc in locations: locc = obj2idx(loc, 'LOCATIONS') l.append(convert( locc)) #puts locc between <l > and adds it to the array l ll = ' (' + convert(locc) + ' ^id ' + str( locc ) + ' ^pointed-at no)' #writes something like the following were 0 is locc # (<l0> ^id 0 ^pointed-at no) lInits.append(ll) #puts the previous phrase in to the array lInits allFile = allFile.replace( 'LOCATIONS', ' '.join(l) ) #replaces LOCATIONS in allFile (witch is like init-template.soar allFile = allFile.replace(' LOCATION', '\n'.join(lInits)) #the same as previous person_text = ' (<pers1> ' #builds the person and its atributes with the correct format to add it to the file first_attr = True ignore_field = True for n in self.person.__dict__.keys(): if str(getattr(self.person, n)) != ignore: if first_attr: person_text += '^' + n + ' ' + str(getattr(self.person, n)) first_attr = False ignore_field = False else: person_text += '\n ^' + n + ' ' + str( getattr(self.person, n)) if ignore_field: person_text = '' else: person_text += ')\n' robot_text = ' (<r> ' first_attr = True ignore_field = True for n in self.robot.__dict__.keys(): if str(getattr(self.robot, n)) != ignore: if first_attr: robot_text += '^' + n + ' ' + str(getattr(self.robot, n)) first_attr = False ignore_field = False else: robot_text += '\n ^' + n + ' ' + str( getattr(self.robot, n)) if ignore_field: robot_text = '' else: robot_text += ')\n' item_text = ' (<obj1> ' first_attr = True ignore_field = True for n in self.item.__dict__.keys(): if str(getattr(self.item, n)) != ignore: if first_attr: item_text += '^' + n + ' ' + str(getattr(self.item, n)) first_attr = False ignore_field = False else: item_text += '\n ^' + n + ' ' + str( getattr(self.item, n)) if ignore_field: item_text = '' else: item_text += ')\n' allFile = allFile.replace(ROBOT, robot_text) allFile = allFile.replace(ITEM, item_text) allFile = allFile.replace(PERSON, person_text) return allFile
def set_current_position(self, location): loc = obj2idx(location, 'LOCATIONS') self.robot.locId = loc