-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_distance.py
29 lines (25 loc) · 1007 Bytes
/
print_distance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import ctypes
from typing import List, Any, Union
class Sonic (object):
def __init__(self):
self.sonic = ctypes.CDLL ("/usr/local/lib/libsonic.so")
self.sonic.measure.restype = ctypes.c_double
self.sonic.initialize()
def getDistance(self, val):
results = []
# FIXME: How many sonic devices have you plugged in? default: 7
for i in range (val):
returnValue = self.sonic.measure (ctypes.c_uint (i))
if returnValue == 0:
i -= 1
else:
results.append (round (returnValue, 2))
return results
#sonic = Sonic ()
#try:
# while True:
# distance = sonic.getDistance()
# # print(distance)
# print("left: ", distance[0], " left45: ", distance[1], " left_front: ", distance[2], " right_front: ", distance[3], " right45: ", distance[4], " right: ", distance[5], " back: ", distance[6])
#except KeyboardInterrupt:
# print ("ende")