Program gets stuck with higher FPS values

Discussion in 'X4M03' started by JBull, Mar 7, 2019.

  1. JBull

    JBull New Member

    X4M03 / MacOS / ModuleConnector

    A simple C++ program (based on one of the examples) to read and show on screen (or write to a file) raw data works fine with very low frames-per-second (fps) values (1-10), but gets stuck with any higher values (20+). I'm trying to get as many fps, with 70 being good.

    A python program with similar functionality can get 70 fps printed and displayed. I expected cpp to perform better, but it's the opposite.

    Any suggestions what is going on? Also, what is the maximum fps that x4m03 supports?

    Thanks,
    J
     
  2. Charlie Shao

    Charlie Shao Moderator Staff Member

    Hi JBull,

    This app note introduces how to calculate maximum FPS X4 can support.
    Could you share your program file or configuration, I can check them on my setup?
     
  3. JBull

    JBull New Member

    Thanks Charlie. I'll have a look at the note. In the meantime, attached is the code - basically, a stripped down xt_modules_print_record_playback_radar_raw_data_message.cpp.

    Code:
    #include "ModuleConnector.hpp"
    #include "XEP.hpp"
    #include "xtid.h"
    #include <iostream>
    #include <fstream>
    
    using namespace XeThru;
    
    void usage()
    {
        std::cout << "mytest com1\n./mytest /dev/cu.usb1911" << std::endl;
    }
    
    int handle_error(std::string message)
    {
        std::cerr << "ERROR: " << message << std::endl;
        return 1;
    }
    
    volatile sig_atomic_t stop_output;
    void handle_sigint(int num)
    {
        stop_output = 1;
        std::cout << "\nStop recording!" << std::endl;
    }
    
    const uint8_t downconversion = 1;
    const float dac_min = 949;
    const float dac_max = 1100;
    const uint32_t iterations = 16;
    const uint32_t pulses_per_step = 300;
    const float fps = 30;
    
    int print_radar_raw_data_message(ModuleConnector &mc)
    {
        XeThru::DataFloat radar_raw_data;
    
        XEP &xep = mc.get_xep();
    
        xep.x4driver_set_downconversion(downconversion);
        xep.x4driver_set_tx_center_frequency(3);
        xep.x4driver_set_tx_power(1);
        xep.x4driver_set_iterations(iterations);
        xep.x4driver_set_pulses_per_step(pulses_per_step);
        xep.x4driver_set_dac_min(dac_min);
        xep.x4driver_set_dac_max(dac_max);
    
        // start the module and profile
        std::cout << "Set the module FPS and start to output radar raw data." << std::endl;
        if (xep.x4driver_set_fps(fps))
        {
            return handle_error("Set FPS failed");
        }
    
        std::cout << "Printout radar raw message:" << std::endl;
      
        std::eek:fstream datafile;
        datafile.open ("data.log");
    
        int counter = 1;
        while (!stop_output)
        {
            while (xep.peek_message_data_float() > 0)
            {
                xep.read_message_data_float(&radar_raw_data);
                datafile << "Frame: " << counter << "   ";
                for (auto x = std::end(radar_raw_data.data); x != std::begin(radar_raw_data.data);)
                {
                   datafile << *--x << ' ';
                }
                datafile << '\n';
                std::cout << counter << std::endl;
                counter++;
            }
        }
      
        datafile.close();
    
        std::cout << "\n Set the module in STOP state! \n"
                  << std::endl;
    
        std::cout << "Messages output finish!\n"
                  << std::endl;
        return 0;
    }
    
    
    int main(int argc, char **argv)
    {
        const unsigned int log_level = 0;
        if (argc < 2)
        {
            usage();
            return -1;
        }
        else if (argc == 2)
        {
            std::string const addr_str = argv[1];
            stop_output = 0;
            signal(SIGINT, handle_sigint);
            std::cout << "Building Serial/USB port connection ..." << std::endl;
            const std::string device_name = argv[1];
            ModuleConnector mc(device_name, log_level);
            return print_radar_raw_data_message(mc);
        }
    }