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()
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!'
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()
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.')
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()
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)
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()
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()
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)
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()
def callbackCommandSendCLIPS(data): print 'SEND COMMAND' _clipsLock.acquire() clips.SendCommand(data.data, True) clipsFunctions.PrintOutput() _clipsLock.release()
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()
def callbackCommandSendCommand(data): clips.SendCommand(data.command, True) clipsFunctions.PrintOutput()
def timerThread(t, sym): time.sleep(t/1000) clipsFunctions.Assert('(BB_timer {0})'.format(sym)) clipsFunctions.PrintOutput()
def cmdTimerThread(t, cmd, cmdId): time.sleep(t/1000) clipsFunctions.Assert('(BB_timer "{0}" {1})'.format(cmd, cmdId)) clipsFunctions.PrintOutput()
def setLogLevel(self): _clipsLock.acquire() clips.SendCommand('(bind ?*logLevel* ' + self.logLevelVar.get() + ')') clipsFunctions.PrintOutput() _clipsLock.release()
def setLogLevelTest(): _clipsLock.acquire() clips.SendCommand('(bind ?*logLevel* ' + 'getloglevel' + ')') clipsFunctions.PrintOutput() _clipsLock.release()
def sendCommand(self): _clipsLock.acquire() clips.SendCommand(self.cmdVar.get(), True) clipsFunctions.PrintOutput() _clipsLock.release()
def runCLIPS(self, *args): clipsFunctions.Run(self.getRunTimes()) clipsFunctions.PrintOutput()