imu and adc work, but not at the same time x.x
This commit is contained in:
@@ -48,12 +48,15 @@ ser.timeout = 5
|
||||
|
||||
ys = []
|
||||
|
||||
imu_readings = {}
|
||||
|
||||
for i in range(1000):
|
||||
ser.write(b'R')
|
||||
data = ser.read(1024)
|
||||
index = 0
|
||||
while (index < 1024):
|
||||
packet_type = (data[index + 1]<<8) + data[index]
|
||||
#print(packet_type)
|
||||
ind = [i for i,t in enumerate(types) if t['type_code'] == packet_type]
|
||||
if len(ind) != 1:
|
||||
break
|
||||
@@ -62,17 +65,34 @@ for i in range(1000):
|
||||
for e in t['elements']:
|
||||
block = d[e['offset']:e['offset'] + e['size']]
|
||||
element_size = int(len(block) / e['n_elements'])
|
||||
if t['type_name'] == b'packet_ekg' and e['name'] == b'readings_cnts[50]':
|
||||
chunked = [int.from_bytes(block[i:i + element_size - 1], byteorder='little', signed = True) for i in range(0, len(block), element_size)]
|
||||
#BB = [block[i:i + element_size] for i in range(0, len(block), element_size)]
|
||||
#if t['type_name'] == b'packet_ekg' and e['name'] == b'readings_cnts[50]':
|
||||
ys += chunked
|
||||
plt.clf()
|
||||
dat = np.array(ys[-1000:])
|
||||
plt.plot(dat, 'k.', linestyle = '--')#signal.filtfilt(b, a, dat))
|
||||
plt.pause(0.01)
|
||||
##print(BB)
|
||||
e['readings'].append(chunked)
|
||||
# if t['type_name'] == b'packet_ekg' and e['name'] == b'readings_cnts[50]':
|
||||
# chunked = [(2.4 / (1<<24)) * int.from_bytes(block[i:i + element_size], byteorder='little', signed = True) for i in range(0, len(block), element_size)]
|
||||
# #BB = [block[i:i + element_size] for i in range(0, len(block), element_size)]
|
||||
# #if t['type_name'] == b'packet_ekg' and e['name'] == b'readings_cnts[50]':
|
||||
# ys += chunked
|
||||
# plt.clf()
|
||||
# dat = np.array(ys[-1000:])
|
||||
# plt.plot(dat, 'k.', linestyle = '--')#signal.filtfilt(b, a, dat))
|
||||
# plt.pause(0.01)
|
||||
# ##print(BB)
|
||||
# e['readings'].append(chunked)
|
||||
if t['type_name'] == b'packet_imu' and e['name'] == b'readings_cnts[4]':
|
||||
imu_reading_type = block[0] >> 3
|
||||
imu_reading_tag_cnt = (block[0] >> 1) & 3 # tag count is sensor time slow
|
||||
reading_xyz = [int.from_bytes(block[2:4], byteorder = 'big', signed = True),
|
||||
int.from_bytes(block[4:6], byteorder = 'big', signed = True),
|
||||
int.from_bytes(block[6:8], byteorder = 'big', signed = True)]
|
||||
if imu_reading_type == 1:
|
||||
#print("{:02x} {:d}".format(imu_reading_type, imu_reading_tag_cnt))
|
||||
print("Gyro: {:f} {:f} {:f}".format(*[250 * e / (1<<16) for e in reading_xyz]))
|
||||
elif imu_reading_type == 2:
|
||||
print("Acc: {:f} {:f} {:f}".format(*[4 * e / (1<<16) for e in reading_xyz]))
|
||||
else:
|
||||
print("ERR")
|
||||
#chunked = [int.from_bytes(block[i:i + element_size], byteorder='little', signed = True) for i in range(0, len(block), element_size)]
|
||||
#print(chunked)
|
||||
#print(t['type_name'])
|
||||
|
||||
index += 2 + t['size']
|
||||
|
||||
#for t in types:
|
||||
|
||||
Reference in New Issue
Block a user