Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Python Beacon positioning and animation with Raspberry pi matplotlib
#1
import blescan
import bluetooth._bluetooth as bluez


def calculate_accuracy(txpower, rssi):
    if rssi == 0 or txpower == 0:
        return -1
    else:
        ratio = rssi/txpower
        if ratio < 1:
            return ratio**10
        else:
            return 0.89976 * ratio**7.7095 + 0.111
            return result 

def scan_sock(sock):
    blescan.hci_le_set_scan_parameters(sock)
    blescan.hci_enable_le_scan(sock)
    sample_count = 0

    while True:
        returnedList = blescan.parse_events(sock, 10)
        print "----------"
        for beacon in returnedList:
            print beacon
            beacon = beacon.split(',')
            beaconid = beacon[0]
            txpower = float(beacon[4])
            rssi = float(beacon[5])
            if 0<= calculate_accuracy(txpower, rssi)< 2:
                print beaconid

if __name__ == '__main__':
    dev_id = 0
    try:
        sock = bluez.hci_open_dev(dev_id)
        print "ble thread started"
        scan_scan(sock)
    except:
        print "error accessing bluetooth device..."
#######
fig = plt.figure()
#fig.set_dpi(100)
#fig.set_size_inches(7, 6.5)

ax = plt.axes(xlim=(0, 100), ylim=(0, 100))
patch = plt.Circle((5, -5), 0.75, color='r',fill=False,clip_on=False)
c1 = plt.Circle((5, -5), 0.75, fc='y')
c2 = plt.Circle((5, -5), 0.75, fc='b')
c3 = plt.Circle((5, -5), 0.75, fc='r')
def init():
    patch.center = (50, 50)
    c1.center = (5,5)
    c2.center= (10,10)
    ax.add_patch(c1);
    ax.add_patch(c2);
    ax.add_patch(patch)
    return patch,

def animate(i):
    
    raw_cell = main()
    print raw_cell
    cell = raw_cell[0]
    distance = cell["Distance"]
    print distance
    patch.set_radius(float(distance));
    return patch,
    
    


anim = animation.FuncAnimation(fig, animate, 
                               init_func=init, 
                               interval=5000,
                               blit=True)

plt.show()
I have written code for matplotlib but this code does not show the actual locations. I want him to show me the distance he took at the moment.

I can get the distance. But there is one more problem I want to show on this "matplotlib.pyplot" screen according to the distances. Can I use a particle filter? How do I adapt my Particle Filter to my codes?

I can find the ibeacon distances right now. the only problem I find is that I show distances as animation using particle filter or matplotlib.

https://github.com/AtsushiSakai/PythonRo..._filter.py
Quote
#2
++ I would be grateful if you could help.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Matplotlib : linewidth parameters Zopost 0 82 Aug-16-2019, 07:07 PM
Last Post: Zopost
  A question about python in Raspberry Psycopast 3 62 Aug-14-2019, 06:36 PM
Last Post: buran
  Camera animation to Text file (CINEMA 4D) vbz 0 61 Aug-13-2019, 07:39 AM
Last Post: vbz
  hatching not working properly with matplotlib Staph 3 96 Jul-28-2019, 07:17 AM
Last Post: ThomasL
  HX711&matplotlib problems olego 0 83 Jul-12-2019, 12:22 PM
Last Post: olego
  Raspberry - Python 3.7 - Installation trouble madjo1983 2 180 Jul-07-2019, 02:06 AM
Last Post: DeaD_EyE
  Matplotlib problem ift38375 0 108 Jul-02-2019, 02:55 PM
Last Post: ift38375
  3D animation angel23 1 149 Jul-01-2019, 01:34 AM
Last Post: micseydel
  Matplotlib contour no data coordinates b4rtt 1 207 Jun-18-2019, 09:36 AM
Last Post: b4rtt
  Matplotlib ImportError robertinoc 4 317 Jun-14-2019, 09:11 AM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)