def letsgobaby(anchor, targetfromflask):
    host = 'localhost'
    port = 1883
    con = MQTT_READ.MQTT(broker_address=host, port=port, clientname='Dzungar1')

    anchorlist = []
    targetlist = targetfromflask

    for item in anchor:
        _anchor = Target.Beacon(item['x'], item['y'])
        anchorlist.append(_anchor)

    for target in targetlist:
        target.distanceTab = []
        for i, anchor in enumerate(anchorlist):
            topic = "test/" + str(target.targetID) + "/" + str(i + 1)
            print(f'Topic we read from for {target}', topic)
            v = con.read(topic)

            target.distanceTab.append(float(v.msg))

        l = idxfor3smallest(target.distanceTab)
        print(f'Indexes for trilateration of {target}', l)
        print(f'Target{target} distance tab', target.distanceTab)
        target.Update(l)

        print("Target XY ", target.x, target.y)
        t = 'test/front/' + str(target.targetID)
        print('Topic published to : ', t)
        con.publish(t,
                    str(math.floor(target.x)) + " " +
                    str(math.floor(target.y)) + " " + str(target.targetID),
                    retain=False)

        print("Python calculated position and send it")
Ejemplo n.º 2
0
    def my_create_rectangle(self, x, y):
        rec = self.canvas.create_rectangle(x * self.imscale,
                                           y * self.imscale,
                                           (x + 5) * self.imscale,
                                           (y + 5) * self.imscale,
                                           fill='red',
                                           activefill='black',
                                           tags='rec')
        x = (x * self.imscale + (x + 5) * self.imscale) / 2
        y = (y * self.imscale + (y + 5) * self.imscale) / 2

        anchor = Target.Beacon(x, y)
        Canvas.relationtable.append((rec, anchor))