Invalid lvx file type #179

Closed
opened 2022-06-17 13:18:23 +02:00 by px4Li · 0 comments
px4Li commented 2022-06-17 13:18:23 +02:00 (Migrated from github.com)

Hi,
I got error when I run lvx file in livox viewer. The lvx file is saved by sample/lidar_lvx_file/. Just simply explain my project. I try to code SDK that can use Futaba propo to command AVIA start/stop recording lvx file. When swich on one of switch it can start record, swtich off it then lvx file recording will be stopped and created new name.

Switch on off to recording lvx files:
messageOutput

The data import always stopped at 97% when Import lvx file:
livox_viewer_error

What is correct order to run lvx_file_handler in my code that cat get correct format?

main.cpp:

int main(int argc, const char *argv[])
{

  std::thread zmq_t(zmq_thread);

  /** Set the program options. */
  SetProgramOption(argc, argv);

  printf("Livox SDK initializing.\n");
  /** Initialize Livox-SDK. */
  if (!Init())
  {
    return -1;
  }
  printf("Livox SDK has been initialized.\n");

  LivoxSdkVersion _sdkversion;
  GetLivoxSdkVersion(&_sdkversion);
  printf("Livox SDK version %d.%d.%d .\n", _sdkversion.major, _sdkversion.minor, _sdkversion.patch);

  memset(devices, 0, sizeof(devices));

  /** Set the callback function receiving broadcast message from Livox LiDAR. */
  SetBroadcastCallback(OnDeviceBroadcast);

  /** Set the callback function called when device state change,
   * which means connection/disconnection and changing of LiDAR state.
   */
  SetDeviceStateUpdateCallback(OnDeviceInfoChange);

  /** Start the device discovering routine. */
  if (!Start())
  {
    Uninit();
    return -1;
  }
  printf("Start discovering device.\n");

  WaitForDevicesReady();

  AddDevicesToConnect();

  if (connected_lidar_count == 0)
  {
    printf("No device will be connected.\n");
    Uninit();
    return -1;
  }

  WaitForExtrinsicParameter();

  int i = 0;
  steady_clock::time_point last_time = steady_clock::now();

  bool recording = false;

  for (i = 0; i < lvx_file_save_time * FRAME_RATE; ++i)
  {
    // recording is false and /tmp/record is not existing, initialize lvx file
    if (!recording && std::experimental::filesystem::exists("/tmp/record"))
    {
      recording = true;
      // cur_offset_ needs to be reset by call LvxFileHandle()
      lvx_file_handler = LvxFileHandle();
      // move it to here is for each time switch on recording, the lvx file can be initialized
      printf("Start initialize lvx file.\n");
      if (!lvx_file_handler.InitLvxFile())
      {
        Uninit();
        return -1;
      }
      lvx_file_handler.InitLvxFileHeader();
    }
    // recording is true and /tmp/record is existing, then save frame to lvx file
    else if (recording && std::experimental::filesystem::exists("/tmp/record"))
    {
      std::list<LvxBasePackDetail> point_packet_list_temp;
      {
        std::unique_lock<std::mutex> lock(mtx);
        point_pack_condition.wait_for(lock, milliseconds(kDefaultFrameDurationTime) - (steady_clock::now() - last_time));
        last_time = steady_clock::now();
        point_packet_list_temp.swap(point_packet_list);
      }

      if (point_packet_list_temp.empty())
      {
        printf("Point cloud packet is empty.\n");
        break;
      }

      printf("FINISH SAVE %d FRAME to LVX FILE.\n", i);
      lvx_file_handler.SaveFrameToLvxFile(point_packet_list_temp);
    }
    // recording is true and /tmp/record is not exist, then close lvx file
    else if (recording && !std::experimental::filesystem::exists("/tmp/record"))
    {
      printf("Close LVX FILE. \n");
      recording = false;
      lvx_file_handler.CloseLvxFile();
    }
    else
    {
      usleep(1000);
      // printf("Waiting for commands..................\n");
    }
  }

  for (i = 0; i < kMaxLidarCount; ++i)
  {
    if (devices[i].device_state == kDeviceStateSampling)
    {
      /** Stop the sampling of Livox LiDAR. */
      LidarStopSampling(devices[i].handle, OnStopSampleCallback, nullptr);
    }
  }

  running_ = false;
  zmq_t.join();

  /** Uninitialize Livox-SDK. */
  Uninit();
}
Hi, I got error when I run lvx file in livox viewer. The lvx file is saved by sample/lidar_lvx_file/. Just simply explain my project. I try to code SDK that can use Futaba propo to command AVIA start/stop recording lvx file. When swich on one of switch it can start record, swtich off it then lvx file recording will be stopped and created new name. Switch on off to recording lvx files: ![messageOutput](https://user-images.githubusercontent.com/32841491/174284909-9c2765ad-f5f8-40ac-b5a0-214116b92cae.png) The data import always stopped at 97% when Import lvx file: ![livox_viewer_error](https://user-images.githubusercontent.com/32841491/174286713-4be54e9a-b2a1-4998-a0f3-bb43dfaff8ae.png) What is correct order to run lvx_file_handler in my code that cat get correct format? main.cpp: ``` int main(int argc, const char *argv[]) { std::thread zmq_t(zmq_thread); /** Set the program options. */ SetProgramOption(argc, argv); printf("Livox SDK initializing.\n"); /** Initialize Livox-SDK. */ if (!Init()) { return -1; } printf("Livox SDK has been initialized.\n"); LivoxSdkVersion _sdkversion; GetLivoxSdkVersion(&_sdkversion); printf("Livox SDK version %d.%d.%d .\n", _sdkversion.major, _sdkversion.minor, _sdkversion.patch); memset(devices, 0, sizeof(devices)); /** Set the callback function receiving broadcast message from Livox LiDAR. */ SetBroadcastCallback(OnDeviceBroadcast); /** Set the callback function called when device state change, * which means connection/disconnection and changing of LiDAR state. */ SetDeviceStateUpdateCallback(OnDeviceInfoChange); /** Start the device discovering routine. */ if (!Start()) { Uninit(); return -1; } printf("Start discovering device.\n"); WaitForDevicesReady(); AddDevicesToConnect(); if (connected_lidar_count == 0) { printf("No device will be connected.\n"); Uninit(); return -1; } WaitForExtrinsicParameter(); int i = 0; steady_clock::time_point last_time = steady_clock::now(); bool recording = false; for (i = 0; i < lvx_file_save_time * FRAME_RATE; ++i) { // recording is false and /tmp/record is not existing, initialize lvx file if (!recording && std::experimental::filesystem::exists("/tmp/record")) { recording = true; // cur_offset_ needs to be reset by call LvxFileHandle() lvx_file_handler = LvxFileHandle(); // move it to here is for each time switch on recording, the lvx file can be initialized printf("Start initialize lvx file.\n"); if (!lvx_file_handler.InitLvxFile()) { Uninit(); return -1; } lvx_file_handler.InitLvxFileHeader(); } // recording is true and /tmp/record is existing, then save frame to lvx file else if (recording && std::experimental::filesystem::exists("/tmp/record")) { std::list<LvxBasePackDetail> point_packet_list_temp; { std::unique_lock<std::mutex> lock(mtx); point_pack_condition.wait_for(lock, milliseconds(kDefaultFrameDurationTime) - (steady_clock::now() - last_time)); last_time = steady_clock::now(); point_packet_list_temp.swap(point_packet_list); } if (point_packet_list_temp.empty()) { printf("Point cloud packet is empty.\n"); break; } printf("FINISH SAVE %d FRAME to LVX FILE.\n", i); lvx_file_handler.SaveFrameToLvxFile(point_packet_list_temp); } // recording is true and /tmp/record is not exist, then close lvx file else if (recording && !std::experimental::filesystem::exists("/tmp/record")) { printf("Close LVX FILE. \n"); recording = false; lvx_file_handler.CloseLvxFile(); } else { usleep(1000); // printf("Waiting for commands..................\n"); } } for (i = 0; i < kMaxLidarCount; ++i) { if (devices[i].device_state == kDeviceStateSampling) { /** Stop the sampling of Livox LiDAR. */ LidarStopSampling(devices[i].handle, OnStopSampleCallback, nullptr); } } running_ = false; zmq_t.join(); /** Uninitialize Livox-SDK. */ Uninit(); } ```
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mmr/Livox-SDK#179