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 3d voxels animation jasiekkm 0 56 Apr-07-2019, 07:44 AM
Last Post: jasiekkm
  Generate matplot animation on a link ambush 0 87 Apr-01-2019, 10:23 AM
Last Post: ambush
  Create Animated Scatter plot in 3d using matplotlib in python barry76 0 91 Mar-29-2019, 12:13 PM
Last Post: barry76
  Enabling I2C on Raspberry Pi DJBuck 1 53 Mar-28-2019, 08:53 PM
Last Post: Larz60+
  Serial communication with raspberry pi 3B and Xbee kj7 0 97 Mar-25-2019, 03:39 AM
Last Post: kj7
  Matplotlib is all messed up! 64humans 1 278 Mar-16-2019, 08:04 PM
Last Post: libervurto
  Gamepad vibration in raspberry pi with Python don't work sleepwalk 0 120 Mar-07-2019, 10:24 PM
Last Post: sleepwalk
  matplotlib annotate datapoints with corresponding dates nuncio 0 103 Feb-08-2019, 11:26 AM
Last Post: nuncio
  Python Matplotlib help!!! kapilan15 1 121 Feb-07-2019, 06:17 PM
Last Post: ichabod801
  Problem installing numpy and matplotlib achondrite 1 213 Jan-16-2019, 11:43 PM
Last Post: snippsat

Forum Jump:


Users browsing this thread: 1 Guest(s)