radarmimo / Download-Center

A centralized hub for accessing and downloading code samples, scripts, and resources from radarmimo.com. Explore open-source code snippets covering radar signal processing, MIMO systems, and more. Simplify your projects with our regularly updated resources.
32 stars 9 forks source link

"strings are not allowed for 'copy' keyword" on device.get_next_frame() #1

Open dvnicolasdh opened 1 month ago

dvnicolasdh commented 1 month ago

With only a USB connected BGT60LTR11AIP (v3.1): BGT60LTR11AIP with its firmware updated to 2.6.0,

hence with "ENABLE_NEULOG = False",

attempt at running BGT60LTR11AIP.py

encounters an exception on line 162: frame_contents = device.get_next_frame()

with error message "strings are not allowed for 'copy' keyword":

Exception has occurred: ValueError
strings are not allowed for 'copy' keyword. Use True/False/None instead.
  File "C:\dev\Download-Center\Python\VitalSigns\BGT60LTR11AIP.py", line 162, in read_data
    frame_contents = device.get_next_frame()
                     ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: strings are not allowed for 'copy' keyword. Use True/False/None instead.

Tested on Windows 10 (10.0.19045 Build 19045), with Python 3.12.5 and:

ifxradarsdk @ file:///C:/PATH-TO-INFINEON/Infineon/Tools/Radar-Development-Kit/3.5.1.202310261055/assets/software/radar_sdk/python_wheels/ifxradarsdk-3.5.0%2B8c595dbb-py3-none-win_amd64.whl#sha256=f1c56af0b227c8ea1b2787ac9a724499127a9fc6778de5fbb7aae13be64b83c4
numpy==2.1.1
packaging==24.1
pandas==2.2.3
patsy==0.5.6
PyQt5==5.15.11
PyQt5-Qt5==5.15.2
PyQt5_sip==12.15.0
pyqtgraph==0.13.7
pyserial==3.5
python-dateutil==2.9.0.post0
pytz==2024.2
scipy==1.14.1
six==1.16.0
statsmodels==0.14.3
tzdata==2024.1

Note: This BGT60LTR11AIP seems to work fine with "Radar Fusion GUI_3.5.4.202310241225" Note2: The same "Radar-Development-Kit/3.5.1.202310261055" seems to work fine with another device BGT60TR13C and another python code example: "Python Wrapper" from "Infineon/Tools/Radar-Development-Kit/3.5.1.202310261055/quickstart.html" (although needed to add "import numpy as np" at the beginning of this other example).

dvnicolasdh commented 1 month ago

Reduced the code to: BGT60LTR11AIP_stripped.py using device.get_config_defaults() Seem to get the same error message (with some more trace):

Exception in thread Thread-1 (read_data):
Traceback (most recent call last):
  File "C:\Users\dvnicolasdh\.pyenv\pyenv-win\versions\3.12.5\Lib\threading.py", line 1075, in _bootstrap_inner    
    self.run()
  File "C:\Users\dvnicolasdh\.pyenv\pyenv-win\versions\3.12.5\Lib\threading.py", line 1012, in run
    self._target(*self._args, **self._kwargs)
  File "c:\dev\Download-Center\Python\VitalSigns\BGT60LTR11AIP_stripped.py", line 35, in read_data
    frame_contents = device.get_next_frame()
                     ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\Download-Center\venv\Lib\site-packages\ifxradarsdk\ltr11\ltr11.py", line 235, in get_next_frame 
    frame_numpy = frame.contents.to_numpy()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\Download-Center\venv\Lib\site-packages\ifxradarsdk\common\base_types.py", line 163, in to_numpy 
    return np.array(arr_1d[::2] + 1j * arr_1d[1::2], order="C", dtype=np.complex64, copy="True").reshape(shape)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: strings are not allowed for 'copy' keyword. Use True/False/None instead.

where BGT60LTR11AIP_stripped.py:

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Copyright (c) 2024, <Mohammad Alaee>, university of luxembourg
# website: https://radarmimo.com/
# All rights reserved.
# Extract from: https://github.com/radarmimo/Download-Center/blob/main/Python/VitalSigns/BGT60LTR11AIP.py 
import sys
import pprint
import threading
from ifxradarsdk import get_version
from ifxradarsdk.ltr11 import DeviceLtr11
from ifxradarsdk.ltr11.types import Ltr11Config

from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
import time

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prt_index = 0  # 0 = 4000 Hz,  1 = 2000 Hz, 2 = 1000 Hz, 3 = 500 Hz
if prt_index == 0:
    sample_rate = 4000
elif prt_index == 1:
    sample_rate = 2000
elif prt_index == 2:
    sample_rate = 1000
else:
    sample_rate = 500

frame_counter = 0

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def read_data(device):
    global frame_counter
    while True:
        # time.sleep(1)
        frame_contents = device.get_next_frame()
        for frame in frame_contents:
            frame_counter+=1
            if frame_counter % 100 == 0 :
                print(f"{frame_counter=}")

def button_click():
    print("Button clicked!")
    app.quit()

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if __name__ == "__main__":
    app = QApplication([])
    window = QMainWindow()
    window.setWindowTitle("Simple App with Button")
    window.setGeometry(100, 100, 300, 200)
    button = QPushButton("Click Me", window)
    button.setGeometry(100, 50, 100, 30)
    button.clicked.connect(button_click)
    window.show()
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # connect to the device
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    pp = pprint.PrettyPrinter()
    with DeviceLtr11() as device:
        config_defaults = device.get_config_defaults()
        device.set_config(config_defaults)

        print("Radar SDK Version: " + get_version())
        sampling_frequency = device.get_sampling_frequency(prt_index)
        print("sampling_frequency: ", sampling_frequency)

        pp.pprint(device.get_config())

        data_thread = threading.Thread(target=read_data, args=(device,))
        data_thread.start()
        sys.exit(app.exec_())
dvnicolasdh commented 1 month ago

Hence, changing the SDK's line: File "C:\dev\Download-Center\venv\Lib\site-packages\ifxradarsdk\common\base_types.py", line 163, in to_numpy

    return np.array(arr_1d[::2] + 1j * arr_1d[1::2], order="C", dtype=np.complex64, copy="True").reshape(shape)

to

    return np.array(arr_1d[::2] + 1j * arr_1d[1::2], order="C", dtype=np.complex64, copy=True).reshape(shape)

resolves the issue to both:

dvnicolasdh commented 1 month ago

image-2024-09-21-00-31-39-940