Skip to content
Snippets Groups Projects
Commit 2a8d88aa authored by remy245u's avatar remy245u
Browse files

Clean

parent 8a77688e
No related branches found
No related tags found
No related merge requests found
<g id="fanuc1">
<rect id="fanuc1"
x="1000" y="-2000"
style="fill:rosybrown;stroke:black;stroke-width:1px"
width="1600" height="800"
transform="matrix(1 0 0 1 -800 -400)"
/>
<text id="fanuc1"
x="1000" y="-2000"
style="fill:black;font-family:Arial;font-size:350px"
xml:space="preserve"
transform="matrix(1 0 0 1 -600 0)">Fanuc 1
</text>
</g>
\ No newline at end of file
import json
import numpy as np
def compute2Point(P1,P2,offset):
centre = [(P2["x"] - P1["x"])/2 + P1["x"], (P2["y"] - P1["y"])/2 + P1["y"]]
v = [(P2["x"] - P1["x"]), P2["y"] - P1["y"]]
theta = np.arctan2(v[0],v[1])
#print(theta*180/np.pi)
#vecteur = [v[0] * np.cos(theta) - v[1]*np.sin(theta),v[0] * np.cos(theta) + v[1]*np.sin(theta)]
#centre.append(np.arctan2(vecteur[0],vecteur[1])*(180/np.pi))
#centre.append(vecteur)
centre.append((theta*180/np.pi) - offset)
#print("angle = ",centre[2])
return centre
def getDataPos(client,org,tag : str):
dataPos = {}
query = f'''from(bucket: "SAC40")
|> range(start: -1m, stop: now())
|> filter(fn: (r) => r["_measurement"] == "Position")
|> filter(fn: (r) => r["TAG_ID"] == "{tag}")
|> filter(fn: (r) => r["_field"] == "json")
|> aggregateWindow(every: 10m, fn: last, createEmpty: false)
|> yield(name: "last")'''
#print(query)
tables = client.query_api().query(query, org)
for table in tables:
for row in table.records:
dataPos = json.loads(row.values["_value"])
#print(dataPos)
return dataPos
\ No newline at end of file
// def compute2Point(P1,P2,offset):
// centre = [(P2["x"] - P1["x"])/2 + P1["x"], (P2["y"] - P1["y"])/2 + P1["y"]]
// v = [(P2["x"] - P1["x"]), P2["y"] - P1["y"]]
// theta = np.arctan2(v[0],v[1])
// #print(theta*180/np.pi)
// vecteur = [v[0] * np.cos(theta) - v[1]*np.sin(theta),v[0] * np.cos(theta) + v[1]*np.sin(theta)]
// #centre.append(np.arctan2(vecteur[0],vecteur[1])*(180/np.pi))
// #centre.append(vecteur)
// centre.append((theta*180/np.pi) - offset)
// #print("angle = ",centre[2])
// return centre
const config = global.get("config") || [];
function compute2Point(P1, P2, alpha) {
var centre = [(P2.x - P1.x) / 2 + P1.x, (P2.y - P1.y) / 2 + P1.y, 0];
var theta = Math.atan((P2.x - P1.x), P2.y - P1.y);
centre[2] = (theta * 180) / Math.PI;
return centre;
}
function logArrayElements(element, index, array) {
var P1 = flow.get(element.TAG_1);
var P2 = flow.get(element.TAG_2);
var centre = compute2Point(P1, P2, element.alpha);
var res = {};
res.id = element.Ressource;
res.x = centre[0];
res.y = centre[1];
res.a = centre[2];
res.quality = Math.min(P1.quality, P1.quality);
msg.topic = "/AIP/RESSOURCES/" + element.Ressource;
msg.payload = res;
node.send(msg);
node.done();
}
config.forEach(logArrayElements);
\ No newline at end of file
#!/usr/bin/env python
from mqtt_client import MyMQTTClass
from computeDataFunc import *
from multiprocessing import Process
import asyncio,json
import numpy as np
f = open('/home/pi/aip_sac4.0/bindData.json', 'r')
listeLine = f.read().splitlines()
config = []
for i in listeLine:
config.append(json.loads(i))
MQTT_listener = []
ThreadList = []
for ressource in config:
#print(ressource)
i = 0
MQTT_listener.append(MyMQTTClass())
ThreadList.append(Process(target = MQTT_listener[0].run,args=(ressource["Ressource"],ressource["TAG_1"],ressource["TAG_2"],ressource["alpha"])))
i = i + 1
if __name__ == "__main__":
for i in ThreadList:
i.start()
for i in ThreadList:
i.join()
\ No newline at end of file
#!/usr/bin/env python
from computeDataFunc import *
from paho.mqtt import client as mqtt
class MyMQTTClass(mqtt.Client):
def on_connect(self, mqttc, obj, flags, rc):
#print("rc: "+str(rc))
self.subscribe("/AIP/DWM/" + self.ID1, 0)
self.subscribe("/AIP/DWM/" + self.ID2, 1)
self.pos1 = {}
self.pos2 = {}
self.i = 0
# def on_connect_fail(self, mqttc, obj):
# print("Connect failed")
def on_message(self, mqttc, obj, msg):
#print(str(msg.payload))
pos = (json.loads(msg.payload))
if(pos["id"] == self.ID1):
self.pos1 = pos
self.i = self.i + 1
elif(pos["id"] == self.ID2):
self.pos2 = pos
self.i = self.i + 1
# def on_publish(self, mqttc, obj, mid):
# print("mid: "+str(mid))
#def on_subscribe(self, mqttc, obj, mid, granted_qos):
# print("Subscribed: "+str(mid)+" "+str(granted_qos))
# def on_log(self, mqttc, obj, level, string):
# print(string)
def run(self,res:str,ID1:str,ID2:str,alpha:float):
self.connect("127.0.0.1", 1883, 60)
self.ID1 = ID1
self.ID2 = ID2
self.ressource = res
self.alpha = alpha
rc = 0
while rc == 0:
rc = self.loop()
#print(len(self.data))
if(self.pos1 != {} and self.pos2 != {} and self.i > 2):
print(self.pos1)
print(self.pos2)
c = compute2Point(self.pos1,self.pos2,self.alpha)
#print("Angle : ",c[2])
tmp = { "seat" : 0,
"id" : self.ressource,
"x" : c[0],
"y" : c[1],
"a" : c[2],
"quality" : 100}
print(tmp)
self.publish("/AIP/RESSOURCES/" + self.ressource,json.dumps(tmp),0,True)
self.i = 0
return rc
if __name__ == '__main__':
mqttc = MyMQTTClass()
rc = mqttc.run("FANUC1","43A0","2CE5")
#print("rc: "+str(rc))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment