Example #1
0
def callbackCommandLoadCLIPS(data):
    print 'LOAD FILE'
    filePath = data.data
    if not filePath:
        print 'OPEN FILE, Click on the botton and select a file to be loaded.'
        return

    if filePath[-3:] == 'clp':
        _clipsLock.acquire()
        clips.BatchStar(filePath)
        clipsFunctions.PrintOutput()
        _clipsLock.release()
        print 'File Loaded!'
        return

    path = os.path.dirname(os.path.abspath(filePath))
    f = open(filePath, 'r')
    line = f.readline()
    _clipsLock.acquire()
    while line:
        clips.BatchStar((path + os.sep + line).strip())
        line = f.readline()
    f.close()

    clipsFunctions.PrintOutput()
    _clipsLock.release()

    print 'Files Loaded!'

    clipsFunctions.Reset()
    print 'Facts were reset!'
    setLogLevelTest()
Example #2
0
    def loadFile(self):
        filePath = self.fileVar.get()
        if not filePath:
            tkMessageBox.showinfo(
                'LOAD FILE',
                'Click on the text box to select a file to be loaded.')
            return

        if filePath[-3:] == 'clp':
            _clipsLock.acquire()
            clips.BatchStar(filePath)
            clipsFunctions.PrintOutput()
            _clipsLock.release()
            print 'File Loaded!'
            return

        path = os.path.dirname(os.path.abspath(filePath))
        f = open(filePath, 'r')
        line = f.readline()
        _clipsLock.acquire()
        while line:
            clips.BatchStar((path + os.sep + line).strip())
            line = f.readline()
        f.close()
        clipsFunctions.PrintOutput()
        _clipsLock.release()

        print 'Files Loaded!'
Example #3
0
def Initialize():
    global file_gpsr
    clips.Memory.Conserve = True
    clips.Memory.EnvironmentErrorsEnabled = True

    clips.RegisterPythonFunction(SendCommand)
    #clips.RegisterPythonFunction(SendResponse)
    clips.RegisterPythonFunction(setCmdTimer)
    clips.RegisterPythonFunction(setTimer)
    #clips.RegisterPythonFunction(CreateSharedVar)
    #clips.RegisterPythonFunction(WriteSharedVar)
    #clips.RegisterPythonFunction(SubscribeToSharedVar)

    clips.BuildGlobal('defaultTimeout', defaultTimeout)
    clips.BuildGlobal('defaultAttempts', defaultAttempts)

    filePath = os.path.dirname(os.path.abspath(__file__))
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep + 'BB_interface.clp')
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep +
                    'objects_deftemplates.clp')
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep +
                    'cds_deftemplates.clp')
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep +
                    'scheduled_templates.clp')
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep + 'functions.clp')
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep + 'monitor.clp')
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep +
                    'virbot_blackboard.clp')
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep +
                    'virbot_default_facts.clp')

    file_gpsr = filePath + '/virbot_gpsr/speechTest.dat'
    print file_gpsr
Example #4
0
def init_KDB(req):
    print 'INIT KDB'
    print 'LOAD FILE'
    global file_gpsr
    rospack = rospkg.RosPack()
    #file_gpsr = rospack.get_path('simulator') + '/src/rules_base/oracle.dat'
    if not req.filePath:
        filePath = file_gpsr
    else:
        filepath = rospack.get_path('simulator') 
        #clips.BatchStar(filepath + os.sep + 'CLIPS' + os.sep + 'BB_interface.clp')
        filePath = filepath + req.filePath
        #filePath = req.filePath
    print 'Load file in path' + filePath
    if filePath[-3:] == 'clp':
        _clipsLock.acquire()
        clips.BatchStar(filePath)
        clipsFunctions.PrintOutput()
        _clipsLock.release()
        print 'File Loaded!'
        return

    path = os.path.dirname(os.path.abspath(filePath))
    f = open(filePath, 'r')
    line = f.readline()
    _clipsLock.acquire()
    while line:
        clips.BatchStar((path + os.sep + line).strip())
        line = f.readline()
    f.close()
    clipsFunctions.PrintOutput()
    _clipsLock.release()

    print 'Files Loaded!'

    clipsFunctions.Reset()
    print 'Facts were reset!'
    setLogLevelTest()
    if req.run == True:
        clipsFunctions.Run('')
    return InitKDBResponse()
Example #5
0
def Initialize():
    clips.Memory.Conserve = True
    clips.Memory.EnvironmentErrorsEnabled = True
    
    clips.RegisterPythonFunction(SendCommand)
    clips.RegisterPythonFunction(setCmdTimer)
    clips.RegisterPythonFunction(setTimer)
    
    clips.BuildGlobal('defaultTimeout', defaultTimeout)
    clips.BuildGlobal('defaultAttempts', defaultAttempts)
    
    filePath = os.path.dirname(os.path.abspath(__file__))
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep + 'BB_interface.clp')
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep + 'functions.clp')
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep + 'monitor.clp')
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep + 'virbot_blackboard.clp')
    
    #file_gpsr = filePath + '/virbot_test/oracle.dat'
    rospack = rospkg.RosPack()
    file_gpsr = rospack.get_path('simulator') + '/src/rules_base/oracle.dat'
    print file_gpsr
    BBFunctions.gui.putFileName(file_gpsr)
    # Savage BBFunctions.gui.loadFile()
    BBFunctions.gui.reset()
Example #6
0
def init_KDB(req):
    print 'INIT KDB'
    print 'LOAD FILE'
    global file_gpsr
    if not req.filePath:
        filePath = file_gpsr
    else:
        filePath = req.filePath
    print 'Load file in path' + filePath
    if filePath[-3:] == 'clp':
        _clipsLock.acquire()
        clips.BatchStar(filePath)
        clipsFunctions.PrintOutput()
        _clipsLock.release()
        print 'File Loaded!'
        return

    path = os.path.dirname(os.path.abspath(filePath))
    f = open(filePath, 'r')
    line = f.readline()
    _clipsLock.acquire()
    while line:
        clips.BatchStar((path + os.sep + line).strip())
        line = f.readline()
    f.close()
    clipsFunctions.PrintOutput()
    _clipsLock.release()

    print 'Files Loaded!'

    clipsFunctions.Reset()
    print 'Facts were reset!'
    setLogLevelTest()
    if req.run == True:
        clipsFunctions.Run('')
    return InitKDBResponse()
Example #7
0
def Initialize():
    clips.Memory.Conserve = True
    clips.Memory.EnvironmentErrorsEnabled = True

    clips.RegisterPythonFunction(SendCommand)
    #clips.RegisterPythonFunction(SendResponse)
    clips.RegisterPythonFunction(setCmdTimer)
    clips.RegisterPythonFunction(setTimer)
    #clips.RegisterPythonFunction(CreateSharedVar)
    #clips.RegisterPythonFunction(WriteSharedVar)
    #clips.RegisterPythonFunction(SubscribeToSharedVar)

    clips.BuildGlobal('defaultTimeout', defaultTimeout)
    clips.BuildGlobal('defaultAttempts', defaultAttempts)

    filePath = os.path.dirname(os.path.abspath(__file__))
    clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep + 'BB_interface.clp')

    file_gpsr = filePath + '/open_challenge/challenge.dat'
    print file_gpsr
    BBFunctions.gui.putFileName(file_gpsr)
    BBFunctions.gui.loadFile()
    BBFunctions.gui.reset()
Example #8
0
    def __init__(self):

        _clipsLock.acquire()
        clips.DebugConfig.FactsWatched = True
        clips.DebugConfig.RulesWatched = True
        clips.DebugConfig.FunctionsWatched = False
        clips.DebugConfig.GlobalsWatched = True

        filePath = os.path.dirname(os.path.abspath(__file__))

        clips.BatchStar(filePath + os.sep + 'CLIPS' + os.sep + 'utils.clp')

        _clipsLock.release()

        self.topLevelWindow = tk.Tk()
        self.topLevelWindow.bind_all('<KeyPress-Return>', self.runCLIPS)

        self.watchFactsButton = tk.Button(self.topLevelWindow,
                                          width=20,
                                          text='Watch Facts',
                                          bg='green',
                                          activebackground='green',
                                          command=self.toggleFactsWatched)
        self.watchRulesButton = tk.Button(self.topLevelWindow,
                                          width=20,
                                          text='Watch Rules',
                                          bg='green',
                                          activebackground='green',
                                          command=self.toggleRulesWatched)
        self.watchFunctionsButton = tk.Button(
            self.topLevelWindow,
            width=20,
            text='Watch Functions',
            bg='red',
            activebackground='red',
            command=self.toggleFunctionsWatched)
        self.watchGlobalsButton = tk.Button(self.topLevelWindow,
                                            width=20,
                                            text='Watch Globals',
                                            bg='green',
                                            activebackground='green',
                                            command=self.toggleGlobalsWatched)

        self.watchAllButton = tk.Button(self.topLevelWindow,
                                        text='WATCH ALL',
                                        bg='red',
                                        activebackground='red',
                                        command=self.toggleALLWatched)

        self.logLevelVar = tk.StringVar(value='ERROR')
        self.logLevelLabel = tk.Label(self.topLevelWindow, text="Log level:")
        self.logLevelINFO = tk.Radiobutton(self.topLevelWindow,
                                           text='INFO',
                                           value='INFO',
                                           variable=self.logLevelVar,
                                           command=self.setLogLevel)
        self.logLevelWARNING = tk.Radiobutton(self.topLevelWindow,
                                              text='WARNING',
                                              value='WARNING',
                                              variable=self.logLevelVar,
                                              command=self.setLogLevel)
        self.logLevelERROR = tk.Radiobutton(self.topLevelWindow,
                                            text='ERROR',
                                            value='ERROR',
                                            variable=self.logLevelVar,
                                            command=self.setLogLevel)

        self.cmdFrame = tk.Frame(self.topLevelWindow)

        self.cmdVar = tk.StringVar()
        self.cmdLabel = tk.Label(self.cmdFrame, text='Enter command:')
        self.cmdEntry = tk.Entry(self.cmdFrame,
                                 width=56,
                                 textvariable=self.cmdVar)
        self.cmdButton = tk.Button(self.topLevelWindow,
                                   width=20,
                                   text="SEND COMMAND",
                                   bg='blue',
                                   activebackground='blue',
                                   fg='white',
                                   activeforeground='white',
                                   command=self.sendCommand)

        self.loadFrame = tk.Frame(self.topLevelWindow)

        self.fileVar = tk.StringVar()
        self.fileLabel = tk.Label(self.loadFrame, text='File:')
        self.fileEntry = tk.Entry(self.loadFrame,
                                  width=66,
                                  textvariable=self.fileVar)
        self.fileEntry.bind('<Button-1>', self.getFileName)
        self.loadButton = tk.Button(self.topLevelWindow,
                                    width=20,
                                    text="LOAD FILE",
                                    bg='blue',
                                    activebackground='blue',
                                    fg='white',
                                    activeforeground='white',
                                    command=self.loadFile)

        self.printFactsButton = tk.Button(self.topLevelWindow,
                                          width=20,
                                          text='Print Facts',
                                          bg='white',
                                          activebackground='white',
                                          command=clipsFunctions.PrintFacts)
        self.printRulesButton = tk.Button(self.topLevelWindow,
                                          width=20,
                                          text='Print Rules',
                                          bg='white',
                                          activebackground='white',
                                          command=clipsFunctions.PrintRules)
        self.printAgendaButton = tk.Button(self.topLevelWindow,
                                           width=20,
                                           text='Print Agenda',
                                           bg='white',
                                           activebackground='white',
                                           command=clipsFunctions.PrintAgenda)
        self.resetButton = tk.Button(self.topLevelWindow,
                                     width=20,
                                     text='RESET',
                                     bg='blue',
                                     activebackground='blue',
                                     fg='white',
                                     activeforeground='white',
                                     command=self.reset)

        self.timesFrame = tk.Frame(self.topLevelWindow)

        self.timesTextVar = tk.StringVar(value=0)
        self.runTimesLabel = tk.Label(self.timesFrame,
                                      text='Run # times: (0 to run ALL)')
        self.runTimesEntry = tk.Entry(self.timesFrame,
                                      width=2,
                                      textvariable=self.timesTextVar)
        self.runButton = tk.Button(self.topLevelWindow,
                                   text="RUN",
                                   bg='blue',
                                   activebackground='blue',
                                   fg='white',
                                   activeforeground='white',
                                   command=self.runCLIPS)

        self.watchFunctionsButton.grid({'row': 0, 'column': 0})
        self.watchGlobalsButton.grid({'row': 0, 'column': 1})
        self.watchFactsButton.grid({'row': 0, 'column': 2})
        self.watchRulesButton.grid({'row': 0, 'column': 3})
        self.watchAllButton.grid({
            'row': 1,
            'column': 0,
            'columnspan': 4,
            'sticky': tk.E + tk.W
        })

        self.logLevelLabel.grid({'row': 2, 'column': 0})
        self.logLevelINFO.grid({'row': 2, 'column': 1})
        self.logLevelWARNING.grid({'row': 2, 'column': 2})
        self.logLevelERROR.grid({'row': 2, 'column': 3})

        self.cmdFrame.grid({
            'row': 3,
            'column': 0,
            'columnspan': 3,
            'sticky': tk.E + tk.W
        })
        self.cmdLabel.grid({'row': 0, 'column': 0})
        self.cmdEntry.grid({'row': 0, 'column': 1, 'sticky': tk.E + tk.W})
        self.cmdButton.grid({'row': 3, 'column': 3})

        self.loadFrame.grid({
            'row': 4,
            'column': 0,
            'columnspan': 3,
            'sticky': tk.E + tk.W
        })
        self.fileLabel.grid({'row': 0, 'column': 0})
        self.fileEntry.grid({'row': 0, 'column': 1, 'sticky': tk.E + tk.W})
        self.loadButton.grid({'row': 4, 'column': 3})

        self.printFactsButton.grid({'row': 5, 'column': 0})
        self.printRulesButton.grid({'row': 5, 'column': 1})
        self.printAgendaButton.grid({'row': 5, 'column': 2})
        self.resetButton.grid({'row': 5, 'column': 3})

        self.timesFrame.grid({
            'row': 6,
            'column': 0,
            'columnspan': 3,
            'sticky': tk.E
        })
        self.runTimesLabel.grid({'row': 0, 'column': 0})
        self.runTimesEntry.grid({'row': 0, 'column': 1})
        self.runButton.grid({
            'row': 6,
            'column': 3,
            'sticky': tk.N + tk.S + tk.E + tk.W
        })