def main(): logger.critical('CRITICAL message') logger.error('ERROR message') logger.warning('WARNING message') logger.info('INFO message') logger.debug('DEBUG message') module()
def main(): if len(sys.argv) <2: print ("you need to pass the name of a local file that has your desired changes") sys.exit() changeFile = sys.argv[1] try: fil = open(changeFile) except: print ("there were issues with opening your change file") logger = logging.getLogger(__name__) lines = fil.readlines() mod = module.module() while len(lines) > 0: line = lines.pop(0).strip().split(",") # print(line) if line[0] == "": None elif line[0].strip()[0] == "#": None elif len(line) == 3: assert line[0].strip() == "set" process_set(mod,line[1].strip(),line[2].strip()) elif len(line) == 2: if line[1].strip() == "DEFAULT": process_command(mod,line[0].strip(),"This section has been added by the environment configuration tool BenFun") else: process_command(mod,line[0].strip(),line[1].strip()) else: logger.error("mis-formated line in your change file: '%s' " % line)
def zmq_senden_VLACS(adresse, inhalt): #Instanzierung eines zmq socket vlacs = module('VLACS', config) # """ Funktion zum verschicken einer Nachricht mit ZMQ """ anfrage_2 = vlacs.create_message(TO=adresse, CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) # Erstellen einer Message # anfrage_2 da anfrage für anfragen von extern reserviert ist print("Vlacs hat gesendet:" + str(anfrage_2))
def zmq_empfangen_VLACS(): #Instanzierung eines zmq socket vlacs = module('VLACS', config) # """ Auf eine Anwort warten. """ nachricht_2 = vlacs.receive( ) #Warten auf ein Antwort / Kann eventuell darauf verzichtet werden kern_2 = vlacs.extract_core(nachricht_2) #auspacken der message nachricht_2 = kern_2['response'] #Wert der Antwort raus ziehen return nachricht_2
def main(): print("Hello!") ''' config = input("Enter the configuration path: ") log = input("Enter the log path: ") name, status = mod.module(config, log) ''' name, status = mod.module("config.json", "log.txt") if name == 0 or status == 0: quit() print(str(name), str(status))
def main(): restart = module(mod_name='RESTART', config=config) while True: MESSAGE = restart.receive() CORE = restart.extract_core(MESSAGE) if CORE['Anweisung'] == 'NEU': data = dom.parse( "DATABASE/installed_adds.xml") #Get the Data for the New App adds = data.getElementsByTagName("add") add_name = next(iter(CORE["DATA"].keys())) add_identity = CORE["DATA"][add_name][ "identity"] #Lookup the identity for add in adds: if add.getAttribute("id") == add_identity: main = add.getElementsByTagName("main")[ 0].firstChild.data #get the name of the main Module path = "FUNCTIONALITY/" + add_name + "/" + main + ".py" #path to the main script command = "python " + path exec('sub' + add_name + '= subprocess.Popen(command, cwd = getcwd())' ) # Start the mainscript in a Subprocess elif CORE['Anweisung'] == 'LÖSCHE': add_name = CORE['DATA']['module'] try: exec('sub' + add_name + '.kill()') pass except NameError: exec(add_name + '.kill') except Exception as e: print('Exception while killing module socket occurs: ' + str(e)) continue restart.sysout('Prozess beendet', meta=add_name) answer = {'answer': 'gelöscht'}
def formula(num1, num2): res = div.division(pow.power(num1)+sqrt.root(pow.power(pow.power(num2)-mod.module(num1)+5*num1*num2)),sqrt.root(pow.powe(pow.power(num1)-mod.module(num2)+5*num2*num1))-5) return res
def main(args): # initialize logging if args.log != 'OFF': numeric_level = getattr(logging, args.log.upper()) if not isinstance(numeric_level, int): numeric_level = getattr(logging, "INFO") raise ValueError("Invalid log level: %s" % args.log) logging.basicConfig(filename="pyirc_log.log", level=numeric_level, filemode="w", format="%(asctime)s - %(module)s - %(funcName)s - %(lineno)s - %(levelname)s - %(message)s") logger = logging.getLogger(__name__) logger.debug("Starting pyIRC") # get configuration information server_info = config_obj.get_server_info() bot_info = config_obj.get_bot_info() # load modules try: module_obj = module.module(path.abspath('modules')) except ValueError: logger.critical("Bad module path") return -1 if(module_obj.load_module()): mod_dict = module_obj.get_module_dict() # create server socket server_obj = connection.connection(server_info) server_obj.connect_server() # method object created for module security sock_send = server_obj.socket_send # send nick and user commands sock_send(irc_cmd.cmd_nick(bot_info)) sock_send(irc_cmd.cmd_user(bot_info)) # connect to channels for channel_name in server_info['channels']: sock_send(irc_cmd.cmd_join(channel_name)) # main execution loop while True: # incoming message in_msg = server_obj.socket_recv() # parse data msgparser_obj = msgparser.msgparser(in_msg) in_cmd = msgparser_obj.fn_get_cmd() # create threads, call modules for key in iter(mod_dict): logger.debug('KEY: ' + key) if key == 'ALL' or key == in_cmd: for registered_module in mod_dict[key]: logger.debug(registered_module) thread = Thread(target=registered_module.run_module, args=(in_msg, sock_send, bot_info)) thread.start() thread.join() return 0
def main(args): # initialize logging if args.log != 'OFF': numeric_level = getattr(logging, args.log.upper()) if not isinstance(numeric_level, int): numeric_level = getattr(logging, "INFO") raise ValueError("Invalid log level: %s" % args.log) logging.basicConfig( filename="pyirc_log.log", level=numeric_level, filemode="w", format= "%(asctime)s - %(module)s - %(funcName)s - %(lineno)s - %(levelname)s - %(message)s" ) logger = logging.getLogger(__name__) logger.debug("Starting pyIRC") # get configuration information server_info = config_obj.get_server_info() bot_info = config_obj.get_bot_info() # load modules try: module_obj = module.module(path.abspath('modules')) except ValueError: logger.critical("Bad module path") return -1 if (module_obj.load_module()): mod_dict = module_obj.get_module_dict() # create server socket server_obj = connection.connection(server_info) server_obj.connect_server() # method object created for module security sock_send = server_obj.socket_send # send nick and user commands sock_send(irc_cmd.cmd_nick(bot_info)) sock_send(irc_cmd.cmd_user(bot_info)) # connect to channels for channel_name in server_info['channels']: sock_send(irc_cmd.cmd_join(channel_name)) # main execution loop while True: # incoming message in_msg = server_obj.socket_recv() # parse data msgparser_obj = msgparser.msgparser(in_msg) in_cmd = msgparser_obj.fn_get_cmd() # create threads, call modules for key in iter(mod_dict): logger.debug('KEY: ' + key) if key == 'ALL' or key == in_cmd: for registered_module in mod_dict[key]: logger.debug(registered_module) thread = Thread(target=registered_module.run_module, args=(in_msg, sock_send, bot_info)) thread.start() thread.join() return 0
def visit_object(self, node): if len(node.children) > 0: left = node.children[0] type_ = left.children[0].additional_info if type_ == "\"%module\"": self.mident = left.children[1].additional_info.replace("\"","") mod = module.module() mod.name = self.mident self.modules[self.mident] = mod print self.mident print "***********" for vdef in node.children[2].children[1].children: p = "" m = "" f = "" if not vdef.children[0].children[0].additional_info == "\"%rec\"": p, m, f = rewrite_id(vdef.children[0].children[1].additional_info) else: p, m, f = rewrite_id(vdef.children[0].children[1].\ children[0].children[0].children[1].additional_info) mod.qvars[ m+"."+f ] = ForwardReference() func = vdef.visit(self) mod.qvars[ m+"."+f ].become(func) print m+"."+f print "++++++++++++++" return mod elif type_ == "\"%data\"": raise NotImplementedError elif type_ == "\"%newtype\"": raise NotImplementedError elif type_ == "\"qdcon\"" and len(node.children) == 3: raise NotImplementedError elif type_ == "\"%rec\"": func = node.children[0].children[1].visit(self) func.recursive=True return func elif type_ == "\"qvar\"" and len(node.children) == 3: name = node.children[0].children[1].additional_info # Skip result/return type ? t_args = node.children[1].children[1].children[0].children[1].visit(self) #t_args = node.children[1].children[1].visit(self) args = [] while type(t_args) == tuple: args.append(t_args[1]) t_args = t_args[0] print len(args) print repr(args) #args = hh.constr(t_args[0],t_args[1]) exp = node.children[2].children[1].visit(self) #func = hh.make_application( exp, [args] ) func = hh.function( name, [(args, exp)], recursive=False ) return func elif type_ == "\"qvar\"" and len(node.children) == 1: c = node.children[0].children[1].additional_info print c print "ååååååååå" ident = c.replace("\"","") package, mod, func_name = rewrite_id(ident) func = 0 if not (package == "main" or package == ""): func = get_external(package, mod, func_name) else: if mod == "": func = self.modules[self.mident].qvars[func_name] else: mident = package + ":" + mod func = self.modules[mident].qvars[mod+"."+func_name] print "Wakka" print func_name print repr(func) return func elif type_ == "\"qvar\"" and len(node.children) == 2: raise NotImplementedError elif type_ == "\"qtycon\"": c = node.children[0].children[1].additional_info print "-----" print c ident = c.replace("\"","") package, mod, type_name = rewrite_id(ident) type_ = 0 print package print mod print type_name if not package == "main": type_ = get_external(package, mod, type_name) else: mident = package + ":" + mod type_ = self.modules[mident].tdefg[mod+"."+type_name] #print "package name: \"", package_name, "\"" #print "type name: \"", type_name, "\"" return type_ elif type_ == "\"exp\"": raise NotImplementedError elif type_ == "\"aexp\"" and len(node.children) == 2: app = 0 func = node.children[0].children[1].visit(self) args = node.children[1].children[1].visit(self) # type1_ = node.children[0].children[1].children[0].children[0].additional_info type2_ = node.children[1].children[1].children[0].children[0].additional_info if type2_ == "\"aty\"": # Type arguments have no operational effect? return func # elif type1_ == "\"qdcon\"": # return hh.make_constructor( func, [args]) else: return hh.make_application( func, [args] ) elif type_ == "\"aexp\"" and len(node.children) == 1: return node.children[0].children[1].visit(self) elif type_ == "\"aty\"" and len(node.children) == 1: return node.children[0].children[1].visit(self) elif type_ == "\"lambda\"": var = node.children[0].children[1].visit(self) exp = node.children[1].children[1].visit(self) return hh.function( name, [(var, exp)], recursive=False ) elif type_ == "\"%let\"": raise NotImplementedError elif type_ == "\"%case\"": exp = node.children[1].children[1].visit(self) of = node.children[2].children[1].visit(self) alts_ = node.children[3].children[1].children alts = [] print "MMMMMMMMMMMMMMMMMMMMMMM" for alt in alts_: alts.append(alt.visit(self)) print alts print "MMMMMMMMMMMMMMMMMMMMMMM" f = hh.function("case", alts) return hh.make_application(f, exp) elif type_ == "\"%_\"": # Default case expression f = node.children[0].children[1].visit(self) return ([hh.Var("_")], f) elif type_ == "\"%cast\"": raise NotImplementedError elif type_ == "\"%note\"": raise NotImplementedError elif type_ == "\"%external ccal\"": raise NotImplementedError elif type_ == "\"%dynexternal ccal\"": raise NotImplementedError elif type_ == "\"%label\"": raise NotImplementedError elif type_ == "\"lit\"" and len(node.children) == 1: return hh.CString(node.children[0].children[1].additional_info) elif type_ == "\"lit\"" and len(node.children) == 2: pat = node.children[0].children[1].visit(self) body = node.children[1].children[1].visit(self) case = ([pat], body) #print "mmmmmmmmmmmmmmmmmmmmmmmm" #print case #print "mmmmmmmmmmmmmmmmmmmmmmmm" return case elif type_ == "\"bty\"" and node.children[1].children[0].additional_info == "\"aty\"": return (node.children[0].children[1].visit(self), node.children[1].children[1].visit(self)) elif type_ == "\"vbind\"": return node.children[0].children[1].visit(self) elif type_ == "\"var\"": var_name = node.children[0].children[1].additional_info var_name = var_name.replace("\"","") ty = node.children[1].children[1].visit(self) # TODO, use this? var = hh.Var(var_name) self.modules[self.mident].qvars[var_name] = var print var_name print "øøøøøøøøøøøø" return var elif type_ == "\"qdcon\"" and len(node.children) == 4: qdcon = node.children[0].children[1].visit(self) tbinds_ = node.children[1].children[1].children tbinds = [] for tbind in tbinds_: tbinds.append(tbind.visit(self)) vbinds_ = node.children[2].children[1].children vbinds = [] for vbind in vbinds_: vbinds.append(vbind.visit(self)) exp = node.children[3].children[1].visit(self) # TODO ? return (vbinds, exp) #return hh.function("", (vbinds, exp)) elif type_ == "\"qdcon\"" and len(node.children) == 1: package, mod, name = rewrite_id(node.children[0].children[1].additional_info) if not (package == "main" or package == ""): return get_external(package, mod, name) else: return self.modules[self.mident].qvars[name] else: print type_ raise NotImplementedError
def main(): #Instanzierung eines zmq socket vlacs_empfaenger = module('VLACS_EMPFAENGER', config) # while True: """ Funktion zum erhalten einer Nachricht """ #Nachricht von der Schale empfangen nachricht_2 = vlacs_empfaenger.receive() #Warten auf ein Antwort / Kann eventuell darauf verzichtet werden kern_2 = vlacs_empfaenger.extract_core(nachricht_2) #auspacken der message nachricht_2 = kern_2['resource_id'] daten = {"response":"empfangen"} ip_adresse = 'http://192.168.0.100:5000' pfad = "/vlacs/antwort" inhalt = {"request": "POST", "json_data": daten, "ip_address": ip_adresse, "path": pfad } anfrage_2 = vlacs_empfaenger.create_message(TO = nachricht_2 ,CORE = inhalt) #Funktion ist in module.py vlacs_empfaenger.send(anfrage_2) if nachricht_2 == "weiterleiten": print("habe eine nachricht erhalten" + str(nachricht_2)) """ Funktion zum verschicken einer Nachricht mit ZMQ """ #Weiterleitung an den Roboter adresse = 'API_ROBOTARM' inhalt = kern_2['json_data'] inhalt = inhalt['befehl'] anfrage_2 = vlacs_empfaenger.create_message(TO = adresse,CORE = inhalt)#Funktion ist in module.py vlacs_empfaenger.send(anfrage_2) time.sleep(10) #Antwort, dass der Roboter sich bewegt hat daten = {"response":"weitergeleitet"} ip_adresse = 'http://192.168.0.100:5000' pfad = "/vlacs/antwort" inhalt = {"request": "POST", "json_data": daten, "ip_address": ip_adresse, "path": pfad } anfrage_2 = vlacs_empfaenger.create_message(TO = "HTTPOUT" ,CORE = inhalt) #Funktion ist in module.py vlacs_empfaenger.send(anfrage_2) if nachricht_2 == "speichern": #Nachricht 2 inhalt = kern_2['json_data'] inhalt = inhalt['befehl'] #Die hinterlegten Werte aus dem String extrahieren werte = inhalt.split() wert_1 = werte[0] wert_2 = werte[1] wert_3 = werte[2] from vlacs_empfaenger.Kalibrierungsparameter import Parameter #Dictionary ersetteln add_parameter = {'abweichung_x': wert_1, 'abweichung_y': wert_2, 'gesamtabweichung': wert_3 } #An die gewünschte Stelle setzten Parameter["Maschine"] = add_parameter #Die Syntaxerstellen zum Abspeichern / array wird benötigt, da mtx und dist in numpy.arrays gespecihert werden. Beim Laden ohne numpy importiert gibt dies Probleme Parameter = 'Parameter = '+str(Parameter) # Den richtige Pfad finden und abspeichern workdir = os.getcwd() pathToConfFile = os.path.join(workdir, 'FUNCTIONALITY','vlacs_empfaenger','Kalibrierungsparameter.py') file = open(pathToConfFile, "w") file.write(Parameter) file.close() #Nachricht an Vlacs, dass erfolgreich gespeichert wurde. daten = {'response':'gespeichert'} ip_adresse = 'http://192.168.0.100:5000' pfad = "/vlacs/antwort" inhalt = {"request": "POST", "json_data": daten, "ip_address": ip_adresse, "path": pfad } anfrage_2 = vlacs_empfaenger.create_message(TO = "HTTPOUT" ,CORE = inhalt) #Funktion ist in module.py vlacs_empfaenger.send(anfrage_2) except KeyError as e: print('KeyError: '+str(e)+' in the vlacs_empfaenger.')
from module import module from jinja2 import Template, Environment, PackageLoader from v_port import v_port import sys sys.path.append('..') env = Environment(loader=PackageLoader('jay_verilog')) i_a = v_port('input', 'a_i', 'reg', 3) i_b = v_port('input', 'b_i', 'reg', 1) i_c = v_port('input', 'c_i', 'wire', 2, comment='just test comments') o_a = v_port('output', 'a_o', 'reg', 1) o_b = v_port('output', 'b_o', 'wire', 16, comment='just comments') o_c = v_port('output', 'c_o', 'reg', 1) fab_in = [i_a, i_b, i_c] fab_out = [o_a, o_b, o_c] m_fab = module('fab', fab_in + fab_out) temp = env.get_template('module.html') print(temp.render(module=m_fab))
from module import module from mainPackage import mainPackage from mainPackage.subPackage import subPackage module() mainPackage.main_report() subPackage.sub_report()
x = line.split(";") x[-1] = x[-1].rstrip() temp.append(x) for tests in temp: y = test(tests[0],tests[1],tests[2]) listOfTests.append(y) with open("data/modules.txt") as modulesText: temp = [] for line in modulesText: x = [] x = line.split(";") x[-1] = x[-1].rstrip() temp.append(x) for modules in temp: y = module(modules[0],modules[1],modules[2],) listOfModules.append(y) with open("data/lecturers.txt") as lecturersText: temp = [] for line in lecturersText: x = [] x = line.split(";") x[-1] = x[-1].rstrip() temp.append(x) for lecturers in temp: y = lecturer(lecturers[0],lecturers[1],lecturers[2],lecturers[3]) listOfQuestions.append(y) with open("data/students.txt") as studentsText: temp = []
import module m = module.module() m.echoString("The quick brown fox") m.__privatelyEchoString("This shouldn't work")
0, uebergeordneter_pfad) #in die sys.pfad liste einfügen für extern start from configuration import config from module import module """ Anfrage über ZMQ in der Verwaltungsschale zu kommunizieren über die dritte Varaible wird die Anfrage spezialisiert (anfrage) -Nachricht Senden = senden -Nachricht empfange/warten auf eine Anwort = empfangen -Nachrichten senden + empfangen/warten = senden_empfangen """ #Instanzierung eines zmq socket vlacs_empfaenger = module('VLACS_EMPFAENGER', config) # #Hauptfunktion des Prgramms def zmq_senden_VLACS_EMPFAENGER(adresse, inhalt): """ Funktion zum verschicken einer Nachricht mit ZMQ """ anfrage_2 = vlacs_empfaenger.create_message( TO=adresse, CORE=inhalt) #Funktion ist in module.py vlacs_empfaenger.send(anfrage_2) # Erstellen einer Message # anfrage_2 da anfrage für anfragen von extern reserviert ist print("Vlacs hat gesendet:" + str(anfrage_2)) def zmq_empfangen_VLACS_EMPFAENGER():
import module import module1 print("I'm program") module.module() module1.module1()
import torch import torch.nn as nn import math import hyperparameter as hp def _init_weight(network): for layer in network.modules(): if isinstance(layer, nn.Conv2d): n = layer.kernel_size[0] * layer.kernel_size[1] * layer.out_channels layer.weight.data.normal_(0, math.sqrt(2.0 / n)) if layer.bias is not None: layer.bias.data.zero_() elif isinstance(layer, nn.Linear): layer.weight.data.normal_(0, 0.001) layer.bias.data.zero_() Yolo = module() Yolo.apply(_init_weight) test = True if __name__ == '__main__' and test == True: test_net = module() print(test_net) input = torch.randn(1, 3, hp.height, hp.width) test_net.apply(_init_weight) output = test_net(input) print(output) print(output.size)
import module import module1 print ("I'm program") module.module() module1.module1()
adjective="" if len(sys.argv)==2: adjective=sys.argv[1] if len(adjective)>0 and adjective[0] in ['a', 'e', 'i', 'o', 'u']: adjective="an "+adjective elif len(adjective)>0: adjective="a "+adjective else: adjective="a" rgbcam=module("rgb camera", "recieving visual data", "rgb image") motors=module("motors", "operating at optimal rpm", "odometry") battery=module("battery", "fully charged", "voltage") gps=module("GPS", "recieving location data", "location data") imu=module("IMU", "getting quaternions", "quaternions") depthcam=module("depth camera", "recieving depth data", "depth image") parts=[rgbcam, motors, battery, gps, imu, depthcam] print("Hello, I am %s robot"%adjective) print("These are the parts I have installed") for part in parts: part.start() print("starting data collection")
def main(): from configuration import config from module import module """ Anfrage über ZMQ in der Verwaltungsschale zu kommunizieren über die dritte Varaible wird die Anfrage spezialisiert (anfrage) -Nachricht Senden = senden -Nachricht empfange/warten auf eine Anwort = empfangen -Nachrichten senden + empfangen/warten = senden_empfangen """ #Instanzierung eines zmq socket vlacs = module('VLACS', config) # Arbeitszustand = True #Schleife zum überprüfen obeine Anfrage von der Benutzeroberfläche kam und dann die Anweisung ausführen while True: #Nachricht empfangen und die Anweisungen extrahieren MESSAGE = vlacs.receive() CORE = vlacs.extract_core(MESSAGE) befehl = CORE['anweisung'] #Standard Antowrt --> wird überschrieben am Ende jedes Programmes inhalt = {"antwort": "kein Programm ausgeführt"} """ ////////////// Kalibrierung der Kameraparameter zum Kalibrieren der Kamera///////////////////////////// """ if befehl == "kalibrieren": #Funktion zum Kalibrieren antwort = kamera_kalibrieren() #Anwort für die Webseite inhalt = {"antwort": antwort} """ ////////////// Erste Funktion zum Finden einerGlyphe ////////////////////////// """ if befehl == "glyphe_finden": #startet programm Programm zum Erkennen von Glyphen antwort = glyphe_erkennen() #Anwort für die Webseite inhalt = {"antwort": antwort} """ ////////////// Zweite Funktion um den Roboter grade zudrehen ////////////////////////// """ if befehl == "voreinstellung": """ Um Anweisungen an andere Apps zuschicken müssen folgende DAten übergeben werden: ip_adress = Die Ip_Adresse des empfaengers request = GET oder POST Anfrage path = pfad der Verwaltungsschale beim Empfaenger um die zugewiesene App anzusteuern + der dienst der Applikation <module_id>/<resource_id> """ #Roboter starten daten = {'befehl': "20 01 000 000 000 000 000 000 "} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/weiterleiten' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO="HTTPOUT", CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) #Rückmeldung von vlacs_empfaenger abwarten rueckmeldung = vlacs.poll(20000) kern_rueckmeldung = vlacs.extract_core(rueckmeldung) kern = kern_rueckmeldung['json_data'] rueckmeldung_nachricht = kern['response'] if rueckmeldung_nachricht == "response-timeout": inhalt = {"antwort": "keine Verbindung"} antwort = vlacs.create_message(TO=MESSAGE, CORE=inhalt) vlacs.send(antwort) continue #Roboter starten daten = {'befehl': "empfangen"} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/empfangen' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO=rueckmeldung, CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) #Zeit um aufdie Anfrage zu reagieren #Wenn die Antwort von VLACS_EMPFAENGER empfangen wurde dann: if rueckmeldung_nachricht == "weitergeleitet" and Arbeitszustand == True: #startet programmzum Bestimmen des Verdrehungswinkels winkel, befehl = winkel_bestimmen( ) #Der Winkel ist gleich der Winke """ Winkel runden und in einen ganze Zahl wandeln Standarwinkel abziehen in ein dreistelliges Format vor dem Komma anpassen """ neuer_winkel = int(round(winkel, 0)) neuer_winkel = 90 - winkel if neuer_winkel < 0: neuer_winkel = 0 elif neuer_winkel > 180: neuer_winkel = 180 neuer_winkel = str("%0.3u" % (neuer_winkel)) """ Verdrehwinkel ausbessern """ inhalt = {"antwort": "error"} if befehl == "Winkel wird angepasst" and Arbeitszustand == True: #Neue Position mit angepassten Winkel vom Motor G1 in eine Nachricht packen und verschicken anweisung = "18 02 " + str( neuer_winkel) + " 180 000 090 090 000 " daten = {'befehl': anweisung} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/weiterleiten' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO="HTTPOUT", CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) #Abfangen der Rückmeldung von vlacs_empfaenger rueckmeldung = vlacs.poll(20000) kern_rueckmeldung = vlacs.extract_core(rueckmeldung) kern = kern_rueckmeldung['json_data'] rueckmeldung_nachricht = '' rueckmeldung_nachricht = kern['response'] if rueckmeldung_nachricht == "response-timeout": inhalt = {"antwort": "keine Verbindung"} antwort = vlacs.create_message(TO=MESSAGE, CORE=inhalt) vlacs.send(antwort) continue anweisung = "empfangen" daten = {'befehl': anweisung} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/empfangen' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO=rueckmeldung, CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) #Antwort verfassen für die Webseit auf error setzten inhalt = {"antwort": "error"} #Fals die Rückmeldung von vlacs_empfaenger erfolgreich war, soll die Anwort für die Webseit überschrieben werden if rueckmeldung_nachricht == "weitergeleitet" and Arbeitszustand == True: inhalt = {"antwort": "Voreinstellung erfolgreich"} if Arbeitszustand == False: inhalt = {"antwort": "Abgebrochen"} """ ////////////// Dritte Funktion um die Motoren des Roboters zu testen ////////////////////////// """ if befehl == "start2": """ //////////////////////////////////Roboter Fernwartungsanfrage/////////////////////////////////////////////////////// """ if Arbeitszustand == True: #Roboter starten: Fernwartungsanfrage fals nicht schon vorher erledigt daten = {'befehl': "20 01 000 000 000 000 000 000 "} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/weiterleiten' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO="HTTPOUT", CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) #Rückmeldung durch vlacs_empfaenger auffangen rueckmeldung = vlacs.poll(20000) kern_rueckmeldung = vlacs.extract_core(rueckmeldung) kern = kern_rueckmeldung['json_data'] rueckmeldung_nachricht = kern['response'] if rueckmeldung_nachricht == "response-timeout": inhalt = { "antwort": "keine Verbindung zu Vlacs_Empfaenger", "abweichung_x": "0", "abweichung_y": "0", "abweichung_gesamt": "0", "antwort": "keine Verbindung" } antwort = vlacs.create_message(TO=MESSAGE, CORE=inhalt) vlacs.send(antwort) continue daten = {'befehl': "empfangen"} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/empfangen' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO=rueckmeldung, CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) """ //////////////////////////////////Bestimmung des Startpunktes im Bild/////////////////////////////////////////////////////// """ if Arbeitszustand == True: """ Glyphenmittelpunkt1 aus dem Bild und den Berechnungen bestimmen """ gefunden, glyphmittelpunkt_x1, glyphmittelpunkt_y1, hoehe_glyphe = finde_glypmittelpunkt( ) """ //////////////////////////////////Roboter neue Position zuweisen /////////////////////////////////////////////////////// """ if Arbeitszustand == True: #Anweisungen aus der Nachricht auslesen --> Welche Motoren sollen angschaltet werden: 0 = aus / 1 = an anweisungG2 = int(CORE['motorG2']) anweisungG3 = int(CORE['motorG3']) anweisungG4 = int(CORE['motorG4']) #Winkel um den die Motoren bewegt werden sollen winkelG1 = int(neuer_winkel) winkelG2 = int(CORE['winkelG2']) winkelG3 = int(CORE['winkelG3']) winkelG4 = int(CORE['winkelG4']) winkelG2 = anweisungG2 * winkelG2 winkelG3 = anweisungG3 * winkelG3 winkelG4 = anweisungG4 * winkelG4 #Neue winkel in das Format mit 3 stellen ohne Komma bringen G2 = str("%0.3u" % (int(round(180 - winkelG2)))) G3 = str("%0.3u" % (int(round(0 + winkelG3)))) G4 = str("%0.3u" % (int(round(90 + winkelG4)))) if Arbeitszustand == True: #Neue Positionswinkel dem Roboter übergeben anweisung = "18 02 " + str( neuer_winkel ) + " " + G2 + " " + G3 + " " + G4 + " 090 000 " #Grundposition + winkeländerung daten = {'befehl': anweisung} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/weiterleiten' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO="HTTPOUT", CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) #Rückmeldung von vlacs_empfaenger auffangen rueckmeldung = vlacs.poll(20000) kern_rueckmeldung = vlacs.extract_core(rueckmeldung) kern = kern_rueckmeldung['json_data'] rueckmeldung_nachricht = kern['response'] if rueckmeldung_nachricht == "response-timeout": inhalt = { "antwort": "keine Verbindung zu Vlacs_Empfaenger", "abweichung_x": "0", "abweichung_y": "0", "abweichung_gesamt": "0", "antwort": "keine Verbindung" } antwort = vlacs.create_message(TO=MESSAGE, CORE=inhalt) vlacs.send(antwort) continue daten = {'befehl': "empfangen"} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/empfangen' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO=rueckmeldung, CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) """ //////////////////////////////////Endpunkt im Bild bestimmen/////////////////////////////////////////////////////// """ """ Glyphenmittelpunkt2 aus dem Bild und den Berechnungen bestimmen """ if Arbeitszustand == True: #Im Bild den Glyphmittelpunkt bestimmen gefunden, glyphmittelpunkt2_x2, glyphmittelpunkt2_y2, hoehe_glyphe = finde_glypmittelpunkt( ) """ //////////////////////////////////Start und Endpunkt im Berechnungsmodel berechnen/////////////////////////////////////////////////////// """ """ Startpunkt: Vektor bestimmen """ if Arbeitszustand == True: #Standartpositon in Winkeln festhalten #winkelG1_standard = 90 # eventuell schon geändert --> neuer Winkel = winkelG1 winkelG2_standard = 180 winkelG3_standard = 0 winkelG4_standard = 90 #Winkel in neuen winkeln festhalten theta1 = (pi - (pi * winkelG1 / 180)) theta2 = ((winkelG2_standard) / 180) * pi theta3 = (-pi * (172 / 180) + pi * (winkelG3_standard / 180)) theta4 = (-pi * (8 / 180) + pi * (winkelG4_standard / 180)) #Endpunkt vektor bestimmen x2, y2, z2, P02 = kinematik_vor(theta1, theta2, theta3, theta4) """ //////////////////////////////////Berechnung der Abweichung/////////////////////////////////////////////////////// """ if Arbeitszustand == True: #Verschiebung der Bildkoordinaten in pixel verschiebung_bild_x = glyphmittelpunkt2_x2 - glyphmittelpunkt_x1 verschiebung_bild_y = glyphmittelpunkt2_y2 - glyphmittelpunkt_y1 #Umrechnung in mm verschiebung2_bild_x = (verschiebung_bild_x / hoehe_glyphe) * 50 verschiebung2_bild_y = (verschiebung_bild_y / hoehe_glyphe) * 50 """ //////////////////////////////////Abweichung der Motorwinkel/////////////////////////////////////////////////////// """ if Arbeitszustand == True: #Bestimmen des Verktors und der Ausrichtungsverktoren o = [0] x = x2[0] y = x2[1] z = x2[2] x4in0 = array((x, y, z, o)) x = y2[0] y = y2[1] z = y2[2] y4in0 = array((x, y, z, o)) x = z2[0] y = z2[1] z = z2[2] z4in0 = array((x, y, z, o)) #Addieren des visuell bestimmten Verfahrensweges P04 = array((P02[0], P02[1] + verschiebung2_bild_x, P02[2] + verschiebung2_bild_y, o)) #Rückrechnung auf die Motorwinkel theta1, theta2, theta3, theta4 = kinematik_inv( x4in0, y4in0, z4in0, P04) #Winkel in Grad umrechnenen winkelG2_1 = (theta2 / pi) * 180 winkelG3_1 = ((theta3 + pi * (172 / 180)) / pi) * 180 winkelG4_1 = ((theta4 + pi * (8 / 180)) / pi) * 180 #Differenz des vorgegeben Winkels und des ausgerechneten Winkels winkelG2_abweichung = round(winkelG2_1 - (winkelG2 + winkelG2_standard)) winkelG3_abweichung = round(winkelG3_1 - (winkelG3 + winkelG3_standard)) winkelG4_abweichung = round(winkelG4_1 - (winkelG4 + winkelG4_standard)) """ //////////////////////////////////Übergabe Parameter für die Webseit bestimmen/////////////////////////////////////////////////////// """ if Arbeitszustand == True: """ Abweichungen der Winkel, welche übergeben werden. """ abweichung_x_str = str(winkelG2_abweichung) abweichung_y_str = str(winkelG3_abweichung) abweichung_gesamt_str = str(winkelG4_abweichung) #Antowrt verfassen inhalt = { "antwort": "alles klar", "abweichung_x": abweichung_x_str, "abweichung_y": abweichung_y_str, "abweichung_gesamt": abweichung_gesamt_str } if Arbeitszustand == False: #Antowrt verfassen inhalt = { "antwort": "abgebrochen", "abweichung_x": "0", "abweichung_y": "0", "abweichung_gesamt": "0", } """ //////////////////////////////////Programm zum Überprüfen der Verfahrenswege/////////////////////////////////////////////////////// """ if befehl == "start1": """ //////////////////////////////////Roboter Fernwartungsanfrage/////////////////////////////////////////////////////// """ if Arbeitszustand == True: #Roboter starten: Fernwartungsanfrage fals nicht schon vorher erledigt daten = {'befehl': "20 01 000 000 000 000 000 000 "} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/weiterleiten' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO="HTTPOUT", CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) #Rückmeldung durch Vlacs_Empfaenger auffangen rueckmeldung = vlacs.poll(20000) kern_rueckmeldung = vlacs.extract_core(rueckmeldung) kern = kern_rueckmeldung['json_data'] rueckmeldung_nachricht = kern['response'] if rueckmeldung_nachricht == "response-timeout": inhalt = { "antwort": "keine Verbindung zu Vlacs_Empfaenger", "abweichung_x": "0", "abweichung_y": "0", "abweichung_gesamt": "0" } antwort = vlacs.create_message(TO=MESSAGE, CORE=inhalt) vlacs.send(antwort) continue daten = {'befehl': "empfangen"} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/empfangen' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO=rueckmeldung, CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) if Arbeitszustand == True: #Roboter starten: Fernwartungsanfrage fals nicht schon vorher erledigt anweisung = "18 02 " + str( neuer_winkel) + " 180 000 090 090 000 " daten = {'befehl': anweisung} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/weiterleiten' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO="HTTPOUT", CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) #Rückmeldung durch Vlacs_Empfaenger abwarten rueckmeldung = vlacs.poll(20000) kern_rueckmeldung = vlacs.extract_core(rueckmeldung) kern = kern_rueckmeldung['json_data'] rueckmeldung_nachricht = kern['response'] if rueckmeldung_nachricht == "response-timeout": inhalt = { "antwort": "keine Verbindung zu Vlacs_Empfaenger", "abweichung_x": "0", "abweichung_y": "0", "abweichung_gesamt": "0" } antwort = vlacs.create_message(TO=MESSAGE, CORE=inhalt) vlacs.send(antwort) continue daten = {'befehl': "empfangen"} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/empfangen' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO=rueckmeldung, CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) """ //////////////////////////////////Bestimmung des Startpunktes im Bild/////////////////////////////////////////////////////// """ """ Glyphenmittelpunkt1 aus dem Bild und den Berechnungen bestimmen """ if Arbeitszustand == True: gefunden, glyphmittelpunkt_x1, glyphmittelpunkt_y1, hoehe_glyphe = finde_glypmittelpunkt( ) """ //////////////////////////////////Roboter neue Position zuweisen /////////////////////////////////////////////////////// """ if Arbeitszustand == True: ###########################Ausrichtungsvektoren bestimmen ############################ #Standartpositon in Winkeln festhalten #winkelG1_standard = 90 # eventuell schon geändert --> neuer Winkel = winkelG1 winkelG1 = int(neuer_winkel) winkelG2_standard = 180 winkelG3_standard = 0 winkelG4_standard = 90 #Winkel in neuen winkeln festhalten theta1 = (pi - (pi * winkelG1 / 180)) theta2 = ((winkelG2_standard) / 180) * pi theta3 = (-pi * (172 / 180) + pi * (winkelG3_standard / 180)) theta4 = (-pi * (8 / 180) + pi * (winkelG4_standard / 180)) x1, y1, z1, P01 = kinematik_vor(theta1, theta2, theta3, theta4) if Arbeitszustand == True: #Anweisungen wo der Roboter hinbewegt werden soll #mmx = int(CORE['mmx']) mmy = int(CORE['mmy']) mmz = int(CORE['mmz']) #Bestimmen des Verktors und der Ausrichtungsverktoren o = [0] x = x1[0] y = x1[1] z = x1[2] x4in0 = array((x, y, z, o)) x2 = y1[0] y2 = y1[1] z2 = y1[2] y4in0 = array((x2, y2, z2, o)) x3 = z1[0] y3 = z1[1] z3 = z1[2] z4in0 = array((x3, y3, z3, o)) x4 = P01[0] y4 = P01[1] z4 = P01[2] P04 = array((x4, y4 + mmy, z4 + mmz, o)) #Berechnung der Winkel theta1, theta2, theta3, theta4 = kinematik_inv( x4in0, y4in0, z4in0, P04) if Arbeitszustand == True: #Umrechnung in Grad winkelG2 = (theta2 / pi) * 180 winkelG3 = ((theta3 + pi * (172 / 180)) / pi) * 180 winkelG4 = ((theta4 + pi * (8 / 180)) / pi) * 180 #Neue winkel in das Format mit 3 stellen ohne Komma bringen G2 = str("%0.3u" % (int(round(winkelG2)))) G3 = str("%0.3u" % (int(round(winkelG3)))) G4 = str("%0.3u" % (int(round(winkelG4)))) #Neue Positionswinkel dem Roboter übergeben anweisung = "18 02 " + str( neuer_winkel ) + " " + G2 + " " + G3 + " " + G4 + " 090 000 " #Grundposition + winkeländerung daten = {'befehl': anweisung} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/weiterleiten' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO="HTTPOUT", CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) #Rückmeldung von HTTPOUT auffangen rueckmeldung = vlacs.poll(20000) kern_rueckmeldung = vlacs.extract_core(rueckmeldung) kern = kern_rueckmeldung['json_data'] rueckmeldung_nachricht = kern['response'] if rueckmeldung_nachricht == "response-timeout": inhalt = { "antwort": "keine Verbindung zu Vlacs_Empfaenger", "abweichung_x": "0", "abweichung_y": "0", "abweichung_gesamt": "0" } antwort = vlacs.create_message(TO=MESSAGE, CORE=inhalt) vlacs.send(antwort) continue daten = {'befehl': "empfangen"} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/empfangen' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO=rueckmeldung, CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) """ //////////////////////////////////Endpunkt im Bild bestimmen/////////////////////////////////////////////////////// """ #Warten, dass der Roboter die Nachricht empfangne und ausgeführt hat. """ Glyphenmittelpunkt2 aus dem Bild und den Berechnungen bestimmen """ if Arbeitszustand == True: #Im Bild den Glyphmittelpunkt bestimmen gefunden, glyphmittelpunkt2_x2, glyphmittelpunkt2_y2, hoehe_glyphe = finde_glypmittelpunkt( ) """ //////////////////////////////////Berechnung der Abweichung/////////////////////////////////////////////////////// """ if Arbeitszustand == True: #Verktoren der beiden Punkte abziehen um die Verschiebung zu erhalten #Verschiebung der Vektoren 1 und 2 nach der Vorgabe in mm y = x und z = y verschiebung_vektor_x = verschiebung2_vektor_y = int(mmy) verschiebung_vektor_y = verschiebung2_vektor_z = int(mmz) #Verschiebung der Bildkoordinaten in pixel verschiebung_bild_x = abs(glyphmittelpunkt2_x2 - glyphmittelpunkt_x1) verschiebung_bild_y = abs(glyphmittelpunkt2_y2 - glyphmittelpunkt_y1) #Umrechnung in mm verschiebung2_bild_x = (verschiebung_bild_x / hoehe_glyphe) * 50 verschiebung2_bild_y = (verschiebung_bild_y / hoehe_glyphe) * 50 #Abweichung der beiden Vektoren in mm abweichung_x = int(verschiebung2_bild_x - verschiebung_vektor_x) abweichung_y = int(verschiebung2_bild_y - verschiebung_vektor_y) #Gesamtabweichung in x,y in mm x = abweichung_x * abweichung_x y = abweichung_y * abweichung_y abweichung_gesamt = int(sqrt((x + y))) """ //////////////////////////////////Übergabe Parameter für die Webseit bestimmen/////////////////////////////////////////////////////// """ """ x und y Koordinaten der Bildpunkte im Verhaeltnis zur groeße des canvas der Webseite bestimmen zum Zeichnen """ if Arbeitszustand == True: abweichung_x_str = str(round(abweichung_x)) abweichung_y_str = str(round(abweichung_y)) abweichung_gesamt_str = str(round(abweichung_gesamt)) inhalt = { "antwort": "alles klar", "abweichung_x": abweichung_x_str, "abweichung_y": abweichung_y_str, "abweichung_gesamt": abweichung_gesamt_str } if Arbeitszustand == False: inhalt = { "antwort": "abgebrochen", "abweichung_x": "0", "abweichung_y": "0", "abweichung_gesamt": "0", } """ //////////////////////////////////Roboter Fernwartungsanfrage/////////////////////////////////////////////////////// """ if befehl == "speichern": abweichung_x = str(int(CORE['abweichung_x'])) abweichung_y = str(int(CORE['abweichung_y'])) gesamtabweichung = str(int(CORE['gesamtabweichung'])) anweisung = abweichung_x + " " + abweichung_y + " " + gesamtabweichung daten = {'befehl': anweisung} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/speichern' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO="HTTPOUT", CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) #Rückmeldung von HTTPOUT auffangen rueckmeldung = vlacs.poll(20000) kern_rueckmeldung = vlacs.extract_core(rueckmeldung) kern = kern_rueckmeldung['json_data'] rueckmeldung_nachricht = kern['response'] if rueckmeldung_nachricht == "response-timeout": inhalt = {"antwort": "keine Verbindung zu Vlacs_Empfaenger"} antwort = vlacs.create_message(TO=MESSAGE, CORE=inhalt) vlacs.send(antwort) continue daten = {'befehl': "empfangen"} ip_adresse = "http://192.168.0.101:5000" pfad = '/vlacs_empfaenger/empfangen' inhalt = { 'request': "POST", 'json_data': daten, 'ip_address': ip_adresse, 'path': pfad } anfrage_2 = vlacs.create_message( TO=rueckmeldung, CORE=inhalt) #Funktion ist in module.py vlacs.send(anfrage_2) inhalt = {"antwort": "gespeichert"} """ //////////////////////////////////Roboter Fernwartungsanfrage/////////////////////////////////////////////////////// """ if befehl == "stop": Arbeitszustand = False break inhalt = {"antwort": "abgebrochen"} antwort = vlacs.create_message(TO=MESSAGE, CORE=inhalt) vlacs.send(antwort)
####################################################################################################### import sys curdir = os.path.abspath(os.path.dirname(__file__)) topdir = os.path.abspath(os.path.join(curdir, os.pardir)) if topdir not in sys.path: sys.path.insert(0, topdir) from robot_control import robot_control from configuration import config from module import module # use flask module app = Flask(__name__) robotserver = module('REMOTE_MAINTENANCE', config) """ Login homepage """ @app.route('/') @crossdomain(origin='*') def login_robot(): return render_template('Login.html') #### important for robot remote control: get requests are processed here @app.route('/bosch2.html/query', methods=['GET']) @crossdomain(origin='*') def bosch2_query(): with open(os.getcwd()+'/data/data.json') as data_file: json_data = json.load(data_file) a0 = request.args.get('a0_1000', False, type=int)/1000