Пример #1
0
def callbackCommandResponse(data):
    print "callbackCommandResponse name command:" + data.name
    rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.name)
    clipsFunctions.Assert('(BB_received "{0}" {1} {2} "{3}")'.format(data.name, data.id, data.successful, data.params))
    clipsFunctions.PrintOutput()
    clipsFunctions.Run(BBFunctions.gui.getRunTimes())
    clipsFunctions.PrintOutput()
Пример #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!'
Пример #3
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()
Пример #4
0
def callbackCommandSendAndRunClips(data):
    print 'SEND AND RUN COMMAND'
    _clipsLock.acquire()
    clips.SendCommand(data.data, True)
    clipsFunctions.PrintOutput()
    _clipsLock.release()
    clipsFunctions.Run('')
    clipsFunctions.PrintOutput()
def RunCommand(c):
    clipsFunctions.Assert('(BB_cmd "{0}" {1} "{2}")'.format(
        c.name, c._id, c.params))
    clipsFunctions.PrintOutput()
    clipsFunctions.Run()
    clipsFunctions.PrintOutput()
    time.sleep(1)
    return Response.FromCommandObject(
        c, False, 'CLIPS was busy or not able to handle the command.')
Пример #6
0
def callbackCommandResponse(data):
    print "callbackCommandResponse name command:" + data.name
    rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.name)
    clipsFunctions.Assert('(BB_received "{0}" {1} {2} "{3}")'.format(
        data.name, data.id, data.successful, data.params))
    clipsFunctions.PrintOutput()
    clipsFunctions.Run(
        ''
    )  # aqui se manda el numero de pasos que ejecutara CLIPS con [''] se ejecutan todos los pasos sin detenerse
    clipsFunctions.PrintOutput()
def SharedVarUpdated(sv):

    s = '(BB_sv_updated "' + sv.varName + '" '
    if sv.svType in [
            BB.SharedVarTypes.INT, BB.SharedVarTypes.LONG,
            BB.SharedVarTypes.DOUBLE
    ]:
        s += str(sv.data)
    elif sv.svType in [
            BB.SharedVarTypes.INT_ARRAY, BB.SharedVarTypes.LONG_ARRAY,
            BB.SharedVarTypes.DOUBLE_ARRAY, BB.SharedVarTypes.BYTE_ARRAY
    ]:
        s += str(sv.size) + ' ' + ' '.join([str(x) for x in sv.data])
    elif sv.svType == BB.SharedVarTypes.STRING:
        s += '"' + sv.data + '"'
    elif sv.svType == BB.SharedVarTypes.RECOGNIZED_SPEECH:
        s += str(len(sv.data)) + ' ' + ' '.join(
            ['"' + x + '" ' + str(y) for x, y in sv.data])
    elif sv.svType == BB.SharedVarTypes.VAR:
        s += str(sv.data)
    elif sv.svType == BB.SharedVarTypes.MATRIX:
        s += str(len(sv.data)) + ' ' + str(len(sv.data[0])) + ' '
        for r in sv.data:
            for c in r:
                s += ' ' + str(c)
    else:
        print 'ERROR: Parsing shared var: "{0}" failed'.format(sv.varName)
        return

    s += ')'
    clipsFunctions.Assert(s)
    clipsFunctions.PrintOutput()
Пример #8
0
def str_query_KDB(req):
    print 'QUERY IN KDB ' + req.query
    _clipsLock.acquire()
    clips.SendCommand(req.query, True)
    clipsFunctions.PrintOutput()
    _clipsLock.release()
    clipsFunctions.Run('')
    result = str(clips.StdoutStream.Read())
    print 'RESULT OF QUERY= ' + result
    print ''
    return StrQueryKDBResponse(result)
Пример #9
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()
Пример #10
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()
Пример #11
0
def str_query(req):
    print 'Query in KDB' + req.query
    _clipsLock.acquire()
    clips.SendCommand(req.query, True)
    clipsFunctions.PrintOutput()
    _clipsLock.release()
    clipsFunctions.Run('')
    result = str(clips.StdoutStream.Read())
    if result.count('ROS') == 2:
        print 'ROS response'
        r = result.split('ROS')
        print r
        result = r[1]

    else:
        result = 'None'
        
    print 'Result of Query= ' + result
    print ''
    return StrQueryKDBResponse(result)
Пример #12
0
def ResponseReceived(r):
    clipsFunctions.Assert('(BB_received "{0}" {1} {2} "{3}")'.format(
        r.name, r._id, r.successful, r.params))
    clipsFunctions.PrintOutput()
    clipsFunctions.Run(gui.getRunTimes())
    clipsFunctions.PrintOutput()
Пример #13
0
def callbackCommandSendCLIPS(data):
    print 'SEND COMMAND'
    _clipsLock.acquire()
    clips.SendCommand(data.data, True)
    clipsFunctions.PrintOutput()
    _clipsLock.release()
Пример #14
0
def callbackCommandRunCLIPS(data):
    print "callbackCommandRUNCLIPS "
    clipsFunctions.Run('') # aqui se manda el numero de pasos que ejecutara CLIPS con [''] se ejecutan todos los pasos sin detenerse
    clipsFunctions.PrintOutput()
Пример #15
0
def callbackCommandSendCommand(data):
    clips.SendCommand(data.command, True)
    clipsFunctions.PrintOutput()
Пример #16
0
def timerThread(t, sym):
    time.sleep(t/1000)
    clipsFunctions.Assert('(BB_timer {0})'.format(sym))
    clipsFunctions.PrintOutput()
Пример #17
0
def cmdTimerThread(t, cmd, cmdId):
    time.sleep(t/1000)
    clipsFunctions.Assert('(BB_timer "{0}" {1})'.format(cmd, cmdId))
    clipsFunctions.PrintOutput()
Пример #18
0
 def setLogLevel(self):
     _clipsLock.acquire()
     clips.SendCommand('(bind ?*logLevel* ' + self.logLevelVar.get() + ')')
     clipsFunctions.PrintOutput()
     _clipsLock.release()
Пример #19
0
def setLogLevelTest():
    _clipsLock.acquire()
    clips.SendCommand('(bind ?*logLevel* ' + 'getloglevel' + ')')
    clipsFunctions.PrintOutput()
    _clipsLock.release()
Пример #20
0
 def sendCommand(self):
     _clipsLock.acquire()
     clips.SendCommand(self.cmdVar.get(), True)
     clipsFunctions.PrintOutput()
     _clipsLock.release()
Пример #21
0
 def runCLIPS(self, *args):
     clipsFunctions.Run(self.getRunTimes())
     clipsFunctions.PrintOutput()