Python Forum
Python Beacon positioning and animation with Raspberry pi matplotlib
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
Reply
#2
++ I would be grateful if you could help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,179 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Matplotlib Animation with Threading peterjv26 4 7,011 Oct-08-2021, 05:51 PM
Last Post: peterjv26
  Coding for Python and Raspberry pi beast 3 39,203 Sep-21-2021, 09:56 PM
Last Post: beast
  python 3 raspberry pi 4 dual control motor programming problem yome 0 1,937 Mar-21-2021, 05:17 PM
Last Post: yome
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,160 Mar-11-2021, 10:52 AM
Last Post: buran
  cannot create animation on 2D array using Matplotlib and FuncAnimation Caffeine_Addict 1 2,459 Jan-12-2021, 11:35 AM
Last Post: Caffeine_Addict
  Embedded python fails to compile on Raspberry Pi tryfon 2 3,397 Dec-22-2020, 02:06 PM
Last Post: tryfon
  Uploading files to NAS from Raspberry PI using python zazas321 0 2,424 Sep-07-2020, 09:02 AM
Last Post: zazas321
  Port my python program to Raspberry pi seamlessly Hassibayub 1 1,896 Jun-29-2020, 12:58 PM
Last Post: snippsat
  changing animation speed using buttons in python microwave 1 2,078 Jun-24-2020, 05:21 PM
Last Post: GOTO10

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020