Adding plotting and recording of data
This commit is contained in:
parent
3b4d396bb6
commit
2a50334473
2 changed files with 28 additions and 7 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -191,4 +191,7 @@ cython_debug/
|
|||
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
||||
# refer to https://docs.cursor.com/context/ignore-files
|
||||
.cursorignore
|
||||
.cursorindexingignore
|
||||
.cursorindexingignore
|
||||
|
||||
# Project specific
|
||||
sensor_data.bin
|
||||
30
test.py
30
test.py
|
|
@ -1,8 +1,14 @@
|
|||
import serial
|
||||
import time
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from parser_mmw_demo import parser_one_mmw_demo_output_packet
|
||||
|
||||
# Turning interactive mode on for plotting
|
||||
plt.ion()
|
||||
fig = plt.figure()
|
||||
|
||||
# Change the configuration file name
|
||||
configFileName = 'hedgehog.cfg'
|
||||
|
||||
|
|
@ -12,7 +18,7 @@ configFileName = 'hedgehog.cfg'
|
|||
# the configuration file to the radar
|
||||
def serialConfig(configFileName):
|
||||
|
||||
# Raspberry pi
|
||||
# Serial device ports
|
||||
CLIport = serial.Serial('/dev/ttyACM0', 115200)
|
||||
Dataport = serial.Serial('/dev/ttyACM1', 921600)
|
||||
|
||||
|
|
@ -30,17 +36,24 @@ def serialConfig(configFileName):
|
|||
# ------------------------- MAIN -----------------------------------------
|
||||
|
||||
# Configurate the serial port
|
||||
CLIport, Dataport = serialConfig(configFileName)
|
||||
CLIport, Dataport = serialConfig(configFileName) # Enable when reading from sensor
|
||||
# Dataport = open("sensor_data.bin", mode="rb") # Enable when reading from file
|
||||
|
||||
# parser_one_mmw_demo_output_packet extracts only one complete frame at a time
|
||||
# so call this in a loop till end of file
|
||||
|
||||
def parse_frames():
|
||||
|
||||
ax = fig.add_subplot(projection='3d')
|
||||
plt.show()
|
||||
|
||||
sensor_data = bytearray()
|
||||
bytes_parsed = 0
|
||||
while True:
|
||||
read_data = Dataport.read(1024)
|
||||
print(f"Read: {read_data.hex()}")
|
||||
read_data = Dataport.read(256)
|
||||
with open("sensor_data.bin", mode="ab") as fp:
|
||||
fp.write(read_data)
|
||||
|
||||
sensor_data += bytearray(read_data)
|
||||
|
||||
# parser_one_mmw_demo_output_packet function already prints the
|
||||
|
|
@ -62,6 +75,10 @@ def parse_frames():
|
|||
detectedSNR_array, \
|
||||
detectedNoise_array = parser_one_mmw_demo_output_packet(sensor_data[bytes_parsed::1], len(sensor_data) - bytes_parsed)
|
||||
|
||||
ax.clear()
|
||||
ax.scatter(detectedX_array, detectedY_array, detectedZ_array)
|
||||
plt.pause(0.1)
|
||||
|
||||
# Check the parser result
|
||||
print ("Parser result: ", parser_result)
|
||||
if (parser_result == 0):
|
||||
|
|
@ -69,11 +86,12 @@ def parse_frames():
|
|||
print("totalBytesParsed: ", bytes_parsed)
|
||||
else:
|
||||
bytes_parsed += 1
|
||||
|
||||
continue
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
parse_frames()
|
||||
except KeyboardInterrupt:
|
||||
CLIport.write("sensorStop\n".encode())
|
||||
CLIport.write("sensorStop\n".encode()) # Enable when reading from sensor
|
||||
# Dataport.close() # Enable when reading from file
|
||||
exit(0)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue