Ping 360 get device data

Hi @keshavr,

Receiving Data

The transmitAngle method asks the Ping360 to transmit a ping at the specified angle, using the last used transducer settings (transmit frequency, number of samples, etc), and then waits for and returns the collected data. Your code then calls get_device_data, which doesn’t receive any new data because no new ping has been sent since the last data was collected.

Your code isn’t formatted so I’m not sure if you’re intending to get and print the data from each transmit or if you’re just wanting the last one. Assuming you want to the data for each angle you instead want to do

# import Ping360 class
from brping import Ping360

# Create Ping360 instance
p = Ping360()

... # Connect to, initialize, and set up Ping360 settings

# Loop through a full circle, one gradian at a time
for x in range(400):
    response = p.transmitAngle(x)
    print(response)

Processing Data

If you’re wanting to process the data it might be worth using numpy to turn it into an array that you can do vectorised operations on.

import numpy as np
from brping import Ping360

... # create and initialise Ping360 object

response = p.transmitAngle(x)
data = np.frombuffer(response.data, dtype=np.uint8)
print(data.min(), data.max())
# print all locations that are above threshold
threshold = 200
print(np.where(data >= threshold))

It’s also possible to do processing on the bytearray object directly, but if you’re doing anything much more complicated than a min or max you’ll likely benefit from numpy’s convenience and speed.

On a normal desktop or laptop computer you can install numpy through pip (e.g. pip3 install numpy), but if you’re using the companion computer you’ll need to do

sudo apt install libatlas3-base
sudo pip3 install numpy==1.15.4

which installs the libatlas library, which numpy on Raspberry Pi depends upon, and specifies numpy version 1.15.4, which is the last one supported by Python 3.4 (which is what companion currently uses/has access to). Note that both of those installs take quite a while because they need to compile stuff (unfortunately didn’t think to time it when I installed them earlier - it’s at least less than an hour but not sure if it’s less than half an hour).

1 Like