Beispiel #1
0
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)

        self.recipeModel = recipeModel.Model(self.recipeTable)
        self.instructionModel = instructionModel.Model(self.instructionTable)

        self.windowManager = WindowManager(self.windowsMenu)

        self.recipe_manager = RecipeManager("kitchenModel_1.5.pck")

        self.recipeBrowser = recipeBrowser.MainWindow(self.recipe_manager)
        self.recipeBrowser.show()
        self.windowManager.addWindow(self.recipeBrowser)

        self.costFunctionBrowser = costFunctionBrowser.MainWindow(
            [0, 10, 0, 10], self.recipe_manager.task_planner)
        self.costFunctionBrowser.save_state_tree = True
        self.costFunctionBrowser.allow_null_action = False

        self.windowManager.addWindow(self.costFunctionBrowser)

        self.connect(
            self.recipeTable.selectionModel(),
            SIGNAL("selectionChanged ( QItemSelection, QItemSelection )"),
            self.selectRecipe)

        self.connect(self.sendInstructionButton, SIGNAL("clicked()"),
                     self.sendInstruction)

        self.connect(self.sendRecipeButton, SIGNAL("clicked()"),
                     self.sendRecipe)
Beispiel #2
0
 def testRecipeManager(self):
     manager = RecipeManager("kitchenModel_1.5.pck")
     recipes = Corpus("data/")
     recipe = recipes[0]
     try:
         seq = manager.find_plan(recipe.instruction_text, recipe.start_state)
         for instruction, state_seq, cost in seq:
             for action, state in state_seq:
                 print "action", action.name
     except:
         print "problem on", recipe.name
         raise
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)

        self.recipeModel = recipeModel.Model(self.recipeTable)
        self.instructionModel = instructionModel.Model(self.instructionTable)
        self.inferredInstructionModel = inferredInstructionModel.Model(
            self.inferredTable)

        #self.modeManager = WindowManager(self.modeMenu)

        self.recipe_manager = RecipeManager("kitchenModel_1.5.pck")

        ##        self.recipeBrowser = recipeBrowser.MainWindow(self.recipe_manager)
        ##        self.recipeBrowser.show()
        ##        self.windowManager.addWindow(self.recipeBrowser)

        self.costFunctionBrowser = costFunctionBrowser.MainWindow(
            [0, 10, 0, 10], self.recipe_manager.task_planner)
        self.costFunctionBrowser.save_state_tree = True
        self.costFunctionBrowser.allow_null_action = False

        #self.windowManager.addWindow(self.costFunctionBrowser)

        self.ev = evaluatorGui.Evaluator()
        #TODO: Set title based on mode
        self.setWindowTitle(
            "Recipe Evaluation Browser - Instruction Level Mode")

        self.connect(
            self.recipeTable.selectionModel(),
            SIGNAL("selectionChanged ( QItemSelection, QItemSelection )"),
            self.selectRecipe)

        self.connect(
            self.instructionTable.selectionModel(),
            SIGNAL("selectionChanged ( QItemSelection, QItemSelection )"),
            self.selectInstruction)
Beispiel #4
0
class MainWindow(QMainWindow, recipeCorpusBrowser_ui.Ui_MainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)

        self.recipeModel = recipeModel.Model(self.recipeTable)
        self.instructionModel = instructionModel.Model(self.instructionTable)

        self.windowManager = WindowManager(self.windowsMenu)

        self.recipe_manager = RecipeManager("kitchenModel_1.5.pck")

        self.recipeBrowser = recipeBrowser.MainWindow(self.recipe_manager)
        self.recipeBrowser.show()
        self.windowManager.addWindow(self.recipeBrowser)

        self.costFunctionBrowser = costFunctionBrowser.MainWindow(
            [0, 10, 0, 10], self.recipe_manager.task_planner)
        self.costFunctionBrowser.save_state_tree = True
        self.costFunctionBrowser.allow_null_action = False

        self.windowManager.addWindow(self.costFunctionBrowser)

        self.connect(
            self.recipeTable.selectionModel(),
            SIGNAL("selectionChanged ( QItemSelection, QItemSelection )"),
            self.selectRecipe)

        self.connect(self.sendInstructionButton, SIGNAL("clicked()"),
                     self.sendInstruction)

        self.connect(self.sendRecipeButton, SIGNAL("clicked()"),
                     self.sendRecipe)

    def sendRecipe(self):
        ar = self.recipeModel.selectedEntry()
        self.recipeBrowser.load(ar)

    def sendInstruction(self):
        entry = self.instructionModel.selectedEntry()
        recipe = self.recipeModel.selectedEntry()

        esdc, ggg = self.recipe_manager.make_ggg_for_instruction(entry.text)
        self.costFunctionBrowser.gggs = [ggg]
        self.costFunctionBrowser.esdcs = [esdc]
        start_state = recipe.idx_to_start_state(entry.idx)
        print 'start', start_state
        self.costFunctionBrowser.followCommand(entry.text,
                                               state=start_state,
                                               esdcs=[esdc])

        for plan in self.costFunctionBrowser.plansList[0:10]:
            result = self.recipe_manager.sequence(plan)
            string = planningLanguage.decompile(result)
            print "planning language", string

    def selectRecipe(self):
        ar = self.recipeModel.selectedEntry()
        self.recipeTextEdit.setPlainText(ar.recipe_text)
        self.instructionModel.setRecipe(ar)
        self.instructionTable.selectRow(0)

    def load(self, fname):

        self.recipeTable.selectRow(0)
        self.instructionTable.selectRow(0)

        training_set = pickle_util.load("training.pck")
        print "training", training_set
        recipes = Corpus(fname, training_set)

        self.recipeModel.setData(recipes)
        self.recipeTable.sortByColumn(recipeModel.COL_IS_TRAINING_SET,
                                      Qt.AscendingOrder)
        self.recipeTable.selectRow(0)
Beispiel #5
0
class MainWindow(QMainWindow, recipeBrowser_ui.Ui_MainWindow):
    def __init__(self, recipe_manager):
        QMainWindow.__init__(self)
        self.setupUi(self)

        self.recipe_manager = recipe_manager
        self.instructionModel = instructionModel.Model(self.instructionTable)

        self.windowManager = WindowManager(self.windowsMenu)
        self.recipe_manager = RecipeManager("kitchenModel_1.5.pck")
        self.costFunctionBrowser = costFunctionBrowser.MainWindow(
            [0, 10, 0, 10], self.recipe_manager.task_planner)
        self.costFunctionBrowser.save_state_tree = True
        self.costFunctionBrowser.allow_null_action = False

        self.windowManager.addWindow(self.costFunctionBrowser)

        self.connect(
            self.instructionTable.selectionModel(),
            SIGNAL("selectionChanged ( QItemSelection, QItemSelection )"),
            self.selectInstruction)

        self.connect(self.inferPlanButton, SIGNAL("clicked()"), self.inferPlan)

        self.connect(self.sendToRobotButton, SIGNAL("clicked()"),
                     self.sendToRobot)

        self.connect(self.sendInstructionToCfbButton, SIGNAL("clicked()"),
                     self.sendInstructionToCfb)

        self.start_state = None

    def selectInstruction(self):
        print "select instruction"

    def sendInstructionToCfb(self):
        entry = self.instructionModel.selectedEntry()
        esdc, ggg = self.recipe_manager.make_ggg_for_instruction(entry.text)
        self.costFunctionBrowser.gggs = [ggg]
        self.costFunctionBrowser.esdcs = [esdc]

        self.costFunctionBrowser.followCommand(entry.text,
                                               state=entry.start_state,
                                               esdcs=[esdc])

        for plan in self.costFunctionBrowser.plansList:
            result = self.recipe_manager.sequence(plan)
            string = planningLanguage.decompile(result)
            print "planning language", string

    def sendToRobot(self):

        ingredients_str = "\n".join(i.ros_str()
                                    for i in self.start_state.ingredients)

        plan_string = "\n".join(
            [e.annotation for e in self.instructionModel.entries])
        print "send to robot."
        print "ingredients"
        print ingredients_str
        print "plan"
        print plan_string
        self.sendToRos(ingredients_str + '\n' + plan_string)

    def sendToRos(self, string):
        import roslib
        roslib.load_manifest('bakebot')
        from services.bakebot_recipe_service import BakebotClient
        status = BakebotClient.execute_recipe(string, debug=True)
        print "ros status", status

    def inferPlan(self):
        print "follow command"
        recipe_text = str(self.recipeTextEdit.toPlainText())
        sequence = self.recipe_manager.find_plan(recipe_text, self.start_state)
        entries = []
        for i, (instruction, states, cost) in enumerate(sequence):
            if i == 0:
                start_state = self.start_state
            else:
                start_state = sequence[i - 1][1][-1][1]
            annotation = planningLanguage.decompile(states)

            entry = instructionModel.Entry(i, instruction.text, annotation,
                                           start_state, cost)
            entries.append(entry)
        self.instructionModel.setData(entries)

    def load(self, annotated_recipe):
        self.recipeTextEdit.setPlainText(annotated_recipe.instruction_text)
        self.recipeTitleLabel.setText(annotated_recipe.name)
        self.start_state = annotated_recipe.start_state
        self.annotated_recipe = annotated_recipe