From 2a50334473f37d4c3627dbc4b936386d5d882e04 Mon Sep 17 00:00:00 2001 From: HellaJanssen <80407622+HellaJanssen@users.noreply.github.com> Date: Sun, 1 Jun 2025 22:52:55 +0200 Subject: [PATCH] Adding plotting and recording of data --- .gitignore | 5 ++++- test.py | 30 ++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index bda86c7..1e62016 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file +.cursorindexingignore + +# Project specific +sensor_data.bin \ No newline at end of file diff --git a/test.py b/test.py index 4348c92..db13802 100644 --- a/test.py +++ b/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)