def __init__(self, q):
        # Setup radar
        self.args = example_utils.ExampleArgumentParser().parse_args()
        example_utils.config_logging(self.args)
        if self.args.socket_addr:
            self.client = JSONClient(self.args.socket_addr)
        else:
            port = self.args.serial_port or example_utils.autodetect_serial_port()
            self.client = RegClient(port)

        self.client.squeeze = False
        self.config = configs.IQServiceConfig()
        self.config.sensor = self.args.sensors
        self.config.range_interval = [0.2, 0.6]  # Intervall för mätningar
        self.config.sweep_rate = 1  # Frekvensen
        self.config.gain = 1  # Gain mellan 0 och 1, vi använder 1
        self.time = 10  # Hur lång mätningen ska vara
        # totalt antal sekvenser som krävs för att få en specifik tid
        self.seq = self.config.sweep_rate * self.time

        self.info = self.client.setup_session(self.config)
        self.num_points = self.info["data_length"]  # Antalet mätpunkter per sekvens
        # print(self.num_points)
        # Matris med nollor som fylls med rardardata
        self.matrix = np.zeros((self.seq, self.num_points), dtype=np.csingle)
        self.matrix_copy = np.zeros((self.seq, self.num_points),
                                    dtype=np.csingle)  # En copy på ovanstående
        self.temp_vector = np.zeros((0, self.num_points), dtype=np.csingle)
        self.matrix_idx = 0  # Index för påfyllning av matris
        super(Radar, self).__init__()
        # En First In First Out (FIFO) kö där mätdata sparas och kan hämtas ut för signalbehandling
        self.q = q
Ejemplo n.º 2
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        raise Exception("Socket is not supported")
    elif args.spi:
        raise Exception("SPI is not supported")
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = RegClient(port)

    client.connect()

    pin = RegClient._XM112_LED_PIN

    client._write_gpio(pin, 1)
    val = client._read_gpio(pin)
    print(val)

    for _ in range(3):
        sleep(0.1)
        client._write_gpio(pin, 0)  # on
        sleep(0.1)
        client._write_gpio(pin, 1)  # off

    client.disconnect()
Ejemplo n.º 3
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    config = configs.IQServiceConfig()
    config.sensor = args.sensors
    config.range_interval = [0.2, 0.6]
    config.sweep_rate = 50

    info = client.start_streaming(config)

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    fc = example_utils.FreqCounter(num_bits=(4 * 8 * info["data_length"]))

    while not interrupt_handler.got_signal:
        info, data = client.get_next()
        fc.tick()

    print("\nDisconnecting...")
    client.disconnect()
Ejemplo n.º 4
0
    def run(self):
        print("#### New thread for %s" % self.name)

        args = self._demo_ctrl.streaming_client_args
        print("args:", args)

        example_utils.config_logging(args)

        if args.socket_addr:
            client = JSONClient(args.socket_addr)
        else:
            port = args.serial_port or example_utils.autodetect_serial_port()
            client = RegClient(port)

        try:
            client.connect()
        except Exception as e:
            print("Got exception:", e)

        session_info = client.setup_session(self.config)
        print("Session info:\n", session_info, "\n")

        client.start_streaming()
        while not self.terminating:
            sweep_info, sweep_data = client.get_next()

            d = self.process_data(sweep_data)
            if d is not None:
                self._demo_ctrl.put_cmd(str(d))
            if self.terminating:
                break
        client.disconnect()
Ejemplo n.º 5
0
    def __init__(self, radar_queue, interrupt_queue):
        # Setup for collecting data from radar
        self.args = example_utils.ExampleArgumentParser().parse_args()
        example_utils.config_logging(self.args)
        if self.args.socket_addr:
            self.client = JSONClient(self.args.socket_addr)
        else:
            port = self.args.serial_port or example_utils.autodetect_serial_port(
            )
            self.client = RegClient(port)

        self.client.squeeze = False
        self.config = configs.IQServiceConfig()
        self.config.sensor = self.args.sensors

        self.config.range_interval = [0.2, 0.6]  # Measurement interval
        self.config.sweep_rate = 1  # Frequency for collecting data
        self.config.gain = 1  # Gain between 0 and 1.
        self.time = 10  # Duration for a set amount of sequences
        self.seq = self.config.sweep_rate * self.time

        self.info = self.client.setup_session(
            self.config)  # Setup acconeer radar session
        self.num_points = self.info[
            "data_length"]  # Amount of data points per sampel

        #### Det här kanske inte ska vara i den här klassen #####
        # Vector for radar values from tracked data
        self.peak_vector = np.zeros((1, self.seq), dtype=np.csingle)
        self.data_idx = 0  # Inedex for peak vector used for filtering

        self.radar_queue = radar_queue
        self.interrupt_queue = interrupt_queue
        self.timeout = time.time() + self.time
        b = 0
Ejemplo n.º 6
0
    def __init__(self):
        # Setup radar data
        self.args = example_utils.ExampleArgumentParser().parse_args()
        example_utils.config_logging(self.args)
        if self.args.socket_addr:
            self.client = JSONClient(self.args.socket_addr)
        else:
            port = self.args.serial_port or example_utils.autodetect_serial_port(
            )
            self.client = RegClient(port)

        self.client.squeeze = False
        self.config = configs.IQServiceConfig()
        self.config.sensor = self.args.sensors
        self.config.range_interval = [0.2, 0.6]
        self.config.sweep_rate = 1
        self.config.gain = 1
        self.time = 5
        self.seq = self.config.sweep_rate * self.time

        self.info = self.client.setup_session(self.config)
        self.num_points = self.info["data_length"]
        self.matrix = np.zeros((self.seq, self.num_points), dtype=np.csingle)
        self.matrix_copy = np.zeros((self.seq, self.num_points),
                                    dtype=np.csingle)
        self.matrix_idx = 0
        super(Radar, self).__init__()
Ejemplo n.º 7
0
def main():
    args = example_utils.ExampleArgumentParser(num_sens=1).parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    sensor_config = get_sensor_config()
    sensor_config.sensor = args.sensors

    processing_config = get_processing_config()

    session_info = client.setup_session(sensor_config)

    pg_updater = PGUpdater(sensor_config, processing_config)
    pg_process = PGProcess(pg_updater)
    pg_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    processor = PhaseTrackingProcessor(sensor_config, processing_config)

    # Record data
    data = []
    counter = 0

    while not interrupt_handler.got_signal:
        info, sweep = client.get_next()
        plot_data = processor.process(sweep)
        data.append(sweep)
        counter += 1

        if plot_data is not None:
            try:
                pg_process.put_data(plot_data)
            except PGProccessDiedException:
                break

    # Save to file
    with open(
            "data" + str(get_sensor_config().sweep_rate) + str(counter) +
            ".pkl", "wb") as outfile:
        pickle.dump(data, outfile, pickle.HIGHEST_PROTOCOL)
    with open(
            "metadata" + str(get_sensor_config().sweep_rate) + str(counter) +
            ".pkl", "wb") as outfile:
        pickle.dump(session_info, outfile, pickle.HIGHEST_PROTOCOL)

    print("Disconnecting...")
    pg_process.close()
    client.disconnect()
Ejemplo n.º 8
0
def main():
    global CAMERA
    global logging
    global client
    global SENSOR_CONFIG
    global SETTINGS
    global SEG

    signal.signal(signal.SIGINT, signal_handler)
    try:
        # create seven segment device
        serial = spi(port=0, device=0, gpio=noop())
        device = max7219(serial, cascaded=1)
        SEG = sevensegment(device)

        SETTINGS.read("settings.ini")

        args = example_utils.ExampleArgumentParser(num_sens=1).parse_args()
        example_utils.config_logging(args)
        logging.info("radarCat starting with args " + str(args))

        if args.socket_addr:
            client = SocketClient(args.socket_addr)
        elif args.spi:
            client = SPIClient()
        else:
            port = args.serial_port or example_utils.autodetect_serial_port()
            client = UARTClient(port)

        # setup Camera date and time
        if os.name != 'nt':
            logging.info("set Camera date and time")
            callback_obj = gp.check_result(gp.use_python_logging())
            # open camera connection
            CAMERA = gp.check_result(gp.gp_camera_new())
            gp.check_result(gp.gp_camera_init(CAMERA))
            # get camera details
            abilities = gp.check_result(gp.gp_camera_get_abilities(CAMERA))
            # get configuration tree
            camConfig = gp.check_result(gp.gp_camera_get_config(CAMERA))

            # find the date/time setting config item and set it
            if set_datetime(camConfig, abilities.model):
                # apply the changed config
                gp.check_result(gp.gp_camera_set_config(CAMERA, camConfig))
            else:
                logging.error("Could not set date & time")

        SENSOR_CONFIG = get_sensor_config()
        SENSOR_CONFIG.sensor = args.sensors
    except:
        print("Unexpected error:", sys.exc_info()[0])

    while True:
        detection()
        time.sleep(3)
def main():
    args = example_utils.ExampleArgumentParser(num_sens=1).parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = JSONClient(args.socket_addr)
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = RegClient(port)

    config = config_setup()
    config.sensor = args.sensors
    info = client.setup_session(config)
    num_points = info["data_length"]
    tracking = Tracking(num_points, config.range_interval)

    fig, (amplitude_ax) = plt.subplots(1)
    fig.set_size_inches(12, 6)
    fig.canvas.set_window_title("filename")

    for ax in [amplitude_ax]:
        ax.set_xlabel("time (s)")
        ax.set_xlim(0, num_points / config.sweep_rate)

    amplitude_ax.set_ylabel("Distance (m)")
    amplitude_ax.set_ylim(config.range_interval[0], config.range_interval[1])

    xs = np.linspace(0, num_points / config.sweep_rate, num=num_points)
    amplitude_line = amplitude_ax.plot(xs, np.zeros_like(xs))[0]

    fig.tight_layout()
    plt.ion()
    plt.show()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    client.start_streaming()
    counter = 0
    while not interrupt_handler.got_signal:
        info, sweep = client.get_next()
        amplitude = np.abs(sweep)
        track = tracking.tracking(sweep, counter)
        peak = track
        counter += 1
        if counter == num_points:
            counter = 0
        # print(peak)
        amplitude_line.set_ydata(peak)
        # amplitude_line.set_ydata(amplitude)
        fig.canvas.flush_events()

    print("Disconnecting...")
    client.disconnect()
Ejemplo n.º 10
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = JSONClient(args.socket_addr)
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = RegClient(port)

    client.squeeze = False

    config = configs.IQServiceConfig()
    config.sensor = args.sensors
    config.range_interval = [1, 8]
    config.sweep_rate = 1
    config.gain = 0.8
    #config.running_average_factor = 0.5
    tid = 5
    sekvenser = config.sweep_rate * tid

    info = client.setup_session(config)
    num_points = info["data_length"]

    fig_updater = ExampleFigureUpdater(config, num_points)
    plot_process = PlotProcess(fig_updater)
    plot_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")
    start = time.time()
    # while not interrupt_handler.got_signal:
    for i in range(0, sekvenser):
        #info, data = client.get_next()
        data = get_data(client)
        plot_data = {
            "amplitude": np.abs(data),
            "phase": np.angle(data),
        }

        try:
            plot_process.put_data(plot_data)
        except PlotProccessDiedException:
            break

    end = time.time()
    # print(i+1)
    print((end - start), "s")
    # print("Disconnecting...")
    plot_process.close()
    client.disconnect()
Ejemplo n.º 11
0
def sensor_read():
    args = example_utils.ExampleArgumentParser(num_sens=1).parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    sensor_config = get_sensor_config()
    sensor_config.sensor = args.sensors

    # Extract metadata
    session_info = client.setup_session(sensor_config)
    range_start = session_info["actual_range_start"]
    range_length = session_info["actual_range_length"]
    #sweep_rate = session_info["frequency"]
    data_length = session_info["data_length"]

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    # Instantiate customProcess
    custom_processor = customProcess(range_length, range_start, AMPL_THRESHOLD, DIST_THRESHOLD, data_length, -1)

    processor = PhaseTrackingProcessor(sensor_config.sweep_rate)
    while not interrupt_handler.got_signal:
        info, sweep = client.get_next()
        plot_data = processor.process(sweep)

        if plot_data is not None:
            try:
                print(np.amax(plot_data["abs"]))
                if custom_processor.process(plot_data):
                    person_counter = custom_processor.person_counter
                    if person_counter == 1:
                        print("1 person in the room")
                        input("Enter")
                    else:
                        print(person_counter, " persons in the room")
                        input("Enter")

            except PGProccessDiedException:
                break

    print("Disconnecting...")
    client.disconnect()
Ejemplo n.º 12
0
    def __init__(self, HR_filter_queue,
                 go):  # Lägg till RR_filter_queue som inputargument
        self.go = go
        # Setup for collecting data from radar
        self.args = example_utils.ExampleArgumentParser().parse_args()
        example_utils.config_logging(self.args)
        if self.args.socket_addr:
            self.client = JSONClient(self.args.socket_addr)
            # Test för att se vilken port som används av radarn
            print("RADAR Port = " + self.args.socket_addr)
        else:
            port = self.args.serial_port or example_utils.autodetect_serial_port(
            )
            self.client = RegClient(port)

        self.client.squeeze = False
        self.config = configs.IQServiceConfig()
        self.config.sensor = self.args.sensors

        self.config.range_interval = [0.2, 0.6]  # Measurement interval
        self.config.sweep_rate = 20  # Frequency for collecting data
        self.config.gain = 1  # Gain between 0 and 1.
        self.time = 1  # Duration for a set amount of sequences
        self.seq = self.config.sweep_rate * self.time  # Amount of sequences during a set time and sweep freq

        self.info = self.client.setup_session(
            self.config)  # Setup acconeer radar session
        self.num_points = self.info[
            "data_length"]  # Amount of data points per sampel
        self.data_getting = 0  # Inedex for printing still getting data once a second

        self.HR_filter_queue = HR_filter_queue
        # self.a = a
        # self.RR_filter_queue = RR_filter_queue
        # Initiation for tracking method
        self.N_avg = 10  # How manny peaks averaged over when calculating peaks_filtered
        self.I_peaks = np.zeros(self.N_avg)
        self.locs = np.zeros(self.N_avg)
        self.I_peaks_filtered = np.zeros(self.N_avg)
        self.tracked_distance = np.zeros(self.N_avg)
        self.tracked_amplitude = np.zeros(self.N_avg)
        self.tracked_phase = np.zeros(self.N_avg)
        self.threshold = 0  # variable for finding peaks above threshold
        self.data_idx = 0  # Index in vector for tracking. Puts new tracked peak into tracking vector
        # converts index to real length
        self.real_dist = np.linspace(self.config.range_interval[0],
                                     self.config.range_interval[1],
                                     num=self.num_points)
        self.counter = 0  # Used only for if statement only for first iteration and not when data_idx goes back to zero

        super(Radar, self).__init__()  # Inherit threading vitals
Ejemplo n.º 13
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    client.squeeze = False

    config = configs.EnvelopeServiceConfig()
    config.sensor = args.sensors
    config.range_interval = [0.3, 0.8]
    config.sweep_rate = 70
    config.gain = 0.6
    # config.experimental_stitching = True
    # config.session_profile = configs.EnvelopeServiceConfig.MAX_SNR
    # config.running_average_factor = 0.5
    # config.compensate_phase = False  # not recommended

    info = client.setup_session(config)
    num_points = info["data_length"]

    pg_updater = PGUpdater(config, num_points)
    pg_process = PGProcess(pg_updater)
    pg_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    while not interrupt_handler.got_signal:
        info, data = client.get_next()

        try:
            pg_process.put_data(data)
            print(data)
            input("Enter")
        except PGProccessDiedException:
            break

    print("Disconnecting...")
    pg_process.close()
    client.disconnect()
Ejemplo n.º 14
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    client.squeeze = False

    config = configs.IQServiceConfig()
    config.sensor = args.sensors
    config.range_interval = [0.2, 0.6]
    config.sweep_rate = 30
    config.gain = 0.6
    # config.running_average_factor = 0.5

    info = client.setup_session(config)
    num_points = info["data_length"]

    fig_updater = ExampleFigureUpdater(config, num_points)
    plot_process = PlotProcess(fig_updater)
    plot_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    while not interrupt_handler.got_signal:
        info, data = client.get_next()

        plot_data = {
            "amplitude": np.abs(data),
            "phase": np.angle(data),
        }

        try:
            plot_process.put_data(plot_data)
        except PlotProccessDiedException:
            break

    print("Disconnecting...")
    plot_process.close()
    client.disconnect()
Ejemplo n.º 15
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    # Normally when using a single sensor, get_next will return
    # (info, data). When using mulitple sensors, get_next will return
    # lists of info and data for each sensor, i.e. ([info], [data]).
    # This is commonly called squeezing. To disable squeezing, making
    # get_next _always_ return lists, set:
    # client.squeeze = False

    config = configs.EnvelopeServiceConfig()
    config.sensor = args.sensors
    config.range_interval = [0.2, 0.3]
    config.sweep_rate = 5

    session_info = client.setup_session(config)
    print("Session info:\n", session_info, "\n")

    # Now would be the time to set up plotting, signal processing, etc.

    client.start_streaming()

    # Normally, hitting Ctrl-C will raise a KeyboardInterrupt which in
    # most cases immediately terminates the script. This often becomes
    # an issue when plotting and also doesn't allow us to disconnect
    # gracefully. Setting up an ExampleInterruptHandler will capture the
    # keyboard interrupt signal so that a KeyboardInterrupt isn't raised
    # and we can take care of the signal ourselves. In case you get
    # impatient, hitting Ctrl-C a couple of more times will raise a
    # KeyboardInterrupt which hopefully terminates the script.
    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session\n")

    while not interrupt_handler.got_signal:
        info, data = client.get_next()
        print(info, "\n", data, "\n")

    print("Disconnecting...")
    client.disconnect()
Ejemplo n.º 16
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    client.squeeze = False

    config = configs.IQServiceConfig()
    config.sensor = args.sensors
    config.range_interval = [0.2, 0.6]
    config.sweep_rate = 30
    config.gain = 0.6
    config.sampling_mode = config.SAMPLING_MODE_A
    # config.running_average_factor = 0.5
    # config.hw_accelerated_average_samples = 7
    # config.stepsize = 1

    info = client.setup_session(config)
    num_points = info["data_length"]

    pg_updater = PGUpdater(config, num_points)
    pg_process = PGProcess(pg_updater)
    pg_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    while not interrupt_handler.got_signal:
        info, data = client.get_next()

        try:
            pg_process.put_data(data)
        except PGProccessDiedException:
            break

    print("Disconnecting...")
    pg_process.close()
    client.disconnect()
Ejemplo n.º 17
0
def main():
    args = example_utils.ExampleArgumentParser(num_sens=1).parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = JSONClient(args.socket_addr)
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = RegClient(port)

    config = config_setup()
    config.sensor = args.sensors

    tid = 10

    sekvenser = tid * config.sweep_rate
    filename = "Reflektor_2.csv"

    info = client.setup_session(config)
    num_points = info["data_length"]
    fig_updater = FigureUpdater2(config, num_points)
    plot_process = PlotProcess(fig_updater)
    plot_process.start()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    client.start_streaming()

    while not interrupt_handler.got_signal:
        info, sweep = client.get_next()
        amplitude = np.abs(sweep)
        plot_data = {
            "amplitude": np.abs(sweep),
            "phase": np.angle(sweep),
            "ymax": amplitude.max(),
            "xmax": config.range_interval[0] + (config.range_interval[1] - config.range_interval[0]) *
            (np.argmax(amplitude)/num_points),
        }
        try:
            plot_process.put_data(plot_data)
        except PlotProccessDiedException:
            break

    print("Disconnecting...")
    plot_process.close()
    client.disconnect()
Ejemplo n.º 18
0
def main():
    args = example_utils.ExampleArgumentParser(num_sens=1).parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    sensor_config = get_sensor_config()
    processing_config = get_processing_config()
    sensor_config.sensor = args.sensors

    session_info = client.setup_session(sensor_config)

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    processor = Processor(sensor_config, processing_config, session_info)

    global speedLimit
    global waitForCompletingSpeedLimitDetection

    while not interrupt_handler.got_signal:
        info, sweep = client.get_next()
        speed = processor.process(sweep)
        # speed = speed * 3.6

        if speed > speedLimit:
            speedLimit = speed
            print("Maximal current Speed: " + str(speedLimit))
            if not waitForCompletingSpeedLimitDetection:
                waitForCompletingSpeedLimitDetection = True
                timer1 = threading.Timer(0.1, captureImageFromCamera)
                timer1.start()
                timer2 = threading.Timer(2.0, sendSpeedCatImage)
                timer2.start()
        print(speed)

    print("Disconnecting...")
    # pg_process.close()
    client.disconnect()
Ejemplo n.º 19
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    client.squeeze = False

    sensor_config = get_sensor_config()
    sensor_config.sensor = args.sensors

    processing_config = get_processing_config()

    session_info = client.setup_session(sensor_config)

    pg_updater = PGUpdater(sensor_config, processing_config, session_info)
    pg_process = PGProcess(pg_updater)
    pg_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    processor = Processor(sensor_config, processing_config, session_info)

    while not interrupt_handler.got_signal:
        info, sweep = client.get_next()
        plot_data = processor.process(sweep)

        if plot_data is not None:
            try:
                pg_process.put_data(plot_data)
            except PGProccessDiedException:
                break

    print("Disconnecting...")
    pg_process.close()
    client.disconnect()
Ejemplo n.º 20
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    client.squeeze = False

    config = configs.SparseServiceConfig()
    config.sensor = args.sensors
    config.range_interval = [0.24, 1.20]
    config.sweep_rate = 60
    config.number_of_subsweeps = 16
    # config.hw_accelerated_average_samples = 60
    # config.stepsize = 1

    client.setup_session(config)

    pg_updater = PGUpdater(config)
    pg_process = PGProcess(pg_updater)
    pg_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    while not interrupt_handler.got_signal:
        info, data = client.get_next()

        try:
            pg_process.put_data(data)
        except PGProccessDiedException:
            break

    print("Disconnecting...")
    pg_process.close()
    client.disconnect()
Ejemplo n.º 21
0
def setup(request):
    conn_type, *args = request.param

    if conn_type == "spi":
        client = RegSPIClient()
        sensor = 1
    elif conn_type == "uart":
        port = args[0] or autodetect_serial_port()
        client = RegClient(port)
        sensor = 1
    elif conn_type == "socket":
        client = JSONClient(args[0])
        sensor = int(args[1])
    else:
        pytest.fail()

    client.connect()
    yield (client, sensor)
    client.disconnect()
Ejemplo n.º 22
0
def check_connection(args):
    print("Checking connection to radar")
    try:
        if args.socket_addr:
            client = SocketClient(args.socket_addr)
        elif args.spi:
            client = SPIClient()
        else:
            port = args.serial_port or example_utils.autodetect_serial_port()
            client = UARTClient(port)

        client.connect()
        client.disconnect()
        return True
    except Exception:
        print()
        traceback.print_exc()
        print()
        return False
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = JSONClient(args.socket_addr)
    elif args.spi:
        client = RegSPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = RegClient(port)

    client.squeeze = False

    config = configs.PowerBinServiceConfig()
    config.sensor = args.sensors
    config.range_interval = [0.1, 0.7]
    config.sweep_rate = 60
    config.gain = 0.6
    # config.bin_count = 8

    client.setup_session(config)

    pg_updater = PGUpdater(config)
    pg_process = PGProcess(pg_updater)
    pg_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    while not interrupt_handler.got_signal:
        info, data = client.get_next()

        try:
            pg_process.put_data(data)
        except PGProccessDiedException:
            break

    print("Disconnecting...")
    pg_process.close()
    client.disconnect()
Ejemplo n.º 24
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    config = configs.EnvelopeServiceConfig()
    config.sensor = args.sensors
    config.range_interval = [0.2, 0.6]
    config.sweep_rate = 10

    client.start_streaming(config)
    client.get_next()
    client.disconnect()
Ejemplo n.º 25
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = SocketClient(args.socket_addr)
    elif args.spi:
        client = SPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = UARTClient(port)

    config = configs.EnvelopeServiceConfig()
    config.sensor = args.sensors

    info = client.connect()
    print("connect info:", info)
    client.start_streaming(config)
    client.get_next()
    client.disconnect()
Ejemplo n.º 26
0
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        print("Using detectors is only supported with the XM112 module")
        sys.exit()
    elif args.spi:
        client = RegSPIClient()
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = RegClient(port)

    config = configs.DistancePeakDetectorConfig()
    config.sensor = args.sensors
    config.range_interval = [0.1, 0.7]
    config.sweep_rate = 60
    config.gain = 0.5

    client.setup_session(config)

    pg_updater = PGUpdater(config)
    pg_process = PGProcess(pg_updater)
    pg_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    while not interrupt_handler.got_signal:
        info, data = client.get_next()

        try:
            pg_process.put_data(data)
        except PGProccessDiedException:
            break

    print("Disconnecting...")
    pg_process.close()
    client.disconnect()
def main():
    args = example_utils.ExampleArgumentParser(num_sens=1).parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = JSONClient(args.socket_addr)
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = RegClient(port)

    config = get_base_config()
    config.sensor = args.sensors

    client.setup_session(config)

    pg_updater = PGUpdater(config)
    pg_process = PGProcess(pg_updater)
    pg_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    processor = ObstacleDetectionProcessor(config)

    while not interrupt_handler.got_signal:
        info, sweep = client.get_next()
        plot_data = processor.process(sweep)

        if plot_data is not None:
            try:
                pg_process.put_data(plot_data)
            except PGProccessDiedException:
                break

    print("Disconnecting...")
    pg_process.close()
    client.disconnect()
def main():
    args = example_utils.ExampleArgumentParser().parse_args()
    example_utils.config_logging(args)
    if args.socket_addr:
        client = JSONClient(args.socket_addr)
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = RegClient(port)
    client.squeeze = False

    # Setup parameters
    filename = "Lins50cmPuls_0328_Test1.csv"
    time = 300
    config = setup_parameters()
    seq = config.sweep_rate * time
    config.sensor = args.sensors
    info = client.setup_session(config)
    num_points = info["data_length"]
    # print(num_points)
    info_file(filename, config, num_points, time, seq)  # Setup info file
    print(num_points)

    matris = np.zeros((seq, num_points), dtype=np.csingle)
    client.start_streaming()
    print("Starting...")

    start = timer.time()
    for i in range(0, seq):
        info, sweep = client.get_next()
        matris[seq - i - 1][:] = sweep[:]
    end = timer.time()
    print(i + 1)
    print((end - start), "s")
    # print("Disconnecting...")
    matris = np.flip(matris, 0)
    np.savetxt(filename, matris, delimiter=";")
    matris = None
    client.disconnect()
Ejemplo n.º 29
0
def main():
    args = example_utils.ExampleArgumentParser(num_sens=1).parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = JSONClient(args.socket_addr)
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = RegClient(port)

    config = get_base_config()
    config.sensor = args.sensors

    info1 = client.setup_session(config)
    num_points = info1["data_length"]

    fig_updater = ExampleFigureUpdater(config)
    plot_process = PlotProcess(fig_updater)
    plot_process.start()

    client.start_streaming()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    processor = PhaseTrackingProcessor(config)
    start = time.time()
    i = 0
    while not interrupt_handler.got_signal:

        info, sweep = client.get_next()
        plot_data = processor.process(sweep)

        try:
            plot_process.put_data(
                plot_data)  # Will ignore the first None from processor
        except PlotProccessDiedException:
            break
        i += 1
    end = time.time()
    print(i + 1)
    print((end - start), "s")
    print("Disconnecting...")
    plot_process.close()
    client.disconnect()
    # k = 1
    # m = num_points
    # n = 50
    # matris_real = np.zeros((n, m), dtype=np.csingle)
    # matris_imag = np.zeros((n, m), dtype=np.csingle)
    # while not interrupt_handler.got_signal:
    #     if k < 100:
    #         k += 1
    #     matris_imag = np.roll(matris_imag, 1, axis=0)
    #     matris_real = np.roll(matris_real, 1, axis=0)
    #     info, sweep = client.get_next()
    #     vector_real_temp = np.real(sweep)
    #     vector_imag_temp = np.imag(sweep)
    #     matris_real[[0], :] = vector_real_temp
    #     matris_imag[[0], :] = vector_imag_temp
    #     vector_real = np.mean(matris_real, axis=0)
    #     vector_imag = np.mean(matris_imag, axis=0)
    #     vector = vector_real + 1j*vector_imag

    #     plot_data = processor.process(vector)
    #     if plot_data is not None:
    #         try:
    #             plot_process.put_data(plot_data)
    #         except PlotProccessDiedException:
    #             break

    # Fungerande test av medelvärdesbildning
    # k=100
    # while not interrupt_handler.got_signal:
    #     info, sweep = client.get_next()
    #     real_tot = np.zeros(num_points)
    #     imag_tot = np.zeros(num_points)
    #     for i in range(1, k):
    #         info, sweep = client.get_next()
    #         real = sweep.real
    #         imag = sweep.imag
    #         imag_tot = list(map(operator.add, imag_tot, imag))
    #         real_tot = np.add(real_tot, real)
    #         imag_tot = [x / k for x in imag_tot]
    #         real = [x / k for x in real_tot]

    #     plot_data = processor.process(sweep)
    #     if plot_data is not None:
    #         try:
    #             plot_process.put_data(plot_data)
    #         except PlotProccessDiedException:
    #             break

    print("Disconnecting...")
    plot_process.close()
    client.disconnect()
def main():
    args = example_utils.ExampleArgumentParser(num_sens=1).parse_args()
    example_utils.config_logging(args)

    if args.socket_addr:
        client = JSONClient(args.socket_addr)
    else:
        port = args.serial_port or example_utils.autodetect_serial_port()
        client = RegClient(port)

    config = configs.EnvelopeServiceConfig()
    config.sensor = args.sensors
    config.range_interval = [0.2, 0.6]
    config.sweep_rate = 60
    config.gain = 0.65

    info = client.setup_session(config)
    num_points = info["data_length"]
    xs = np.linspace(*config.range_interval, num_points)
    num_hist = 2 * config.sweep_rate

    hist_data = np.zeros([num_hist, num_points])
    hist_max = np.zeros(num_hist)
    smooth_max = example_utils.SmoothMax(config.sweep_rate)

    app = QtGui.QApplication([])
    pg.setConfigOption("background", "w")
    pg.setConfigOption("foreground", "k")
    pg.setConfigOptions(antialias=True)
    win = pg.GraphicsLayoutWidget()
    win.closeEvent = lambda _: interrupt_handler.force_signal_interrupt()
    win.setWindowTitle("Acconeer PyQtGraph example")

    env_plot = win.addPlot(title="Envelope")
    env_plot.showGrid(x=True, y=True)
    env_plot.setLabel("bottom", "Depth (m)")
    env_plot.setLabel("left", "Amplitude")
    env_curve = env_plot.plot(pen=pg.mkPen("k", width=2))

    win.nextRow()
    hist_plot = win.addPlot()
    hist_plot.setLabel("bottom", "Time (s)")
    hist_plot.setLabel("left", "Depth (m)")
    hist_image_item = pg.ImageItem()
    hist_image_item.translate(-2, config.range_start)
    hist_image_item.scale(2 / num_hist, config.range_length / num_points)
    hist_plot.addItem(hist_image_item)

    # try to get a colormap from matplotlib
    try:
        hist_image_item.setLookupTable(example_utils.pg_mpl_cmap("viridis"))
    except ImportError:
        pass

    win.show()

    interrupt_handler = example_utils.ExampleInterruptHandler()
    print("Press Ctrl-C to end session")

    client.start_streaming()

    while not interrupt_handler.got_signal:
        info, sweep = client.get_next()

        hist_data = np.roll(hist_data, -1, axis=0)
        hist_data[-1] = sweep
        hist_max = np.roll(hist_max, -1)
        hist_max[-1] = np.max(sweep)
        y_max = smooth_max.update(np.amax(hist_max))
        env_curve.setData(xs, sweep)
        env_plot.setYRange(0, y_max)
        hist_image_item.updateImage(hist_data, levels=(0, y_max))

        app.processEvents()

    print("Disconnecting...")
    app.closeAllWindows()
    client.disconnect()