rslidar_test.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * @Author: yct 18202736439@163.com
  3. * @Date: 2023-01-12 09:17:46
  4. * @LastEditors: yct 18202736439@163.com
  5. * @LastEditTime: 2023-01-12 15:12:49
  6. * @FilePath: /puai_wj_2021/tests/rslidar_test.cpp
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. #include <iostream>
  10. #include <fstream>
  11. #include <glog/logging.h>
  12. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
  13. {
  14. time_t tt;
  15. time( &tt );
  16. tt = tt + 8*3600; // transform the time zone
  17. tm* t= gmtime( &tt );
  18. char buf[255]={0};
  19. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
  20. t->tm_year + 1900,
  21. t->tm_mon + 1,
  22. t->tm_mday,
  23. t->tm_hour,
  24. t->tm_min,
  25. t->tm_sec);
  26. FILE* tp_file=fopen(buf,"w");
  27. fprintf(tp_file,data,strlen(data));
  28. fclose(tp_file);
  29. }
  30. // #include "../rslidar/rslidar_driver.h"
  31. #include "../velodyne_lidar/rs_device_bridge.h"
  32. void bridge_test()
  33. {
  34. velodyne::velodyneLidarParams params;
  35. params.set_ip("");
  36. params.set_port(6699);
  37. params.set_model("HELIOS16P");
  38. params.set_calibrationfile("/home/youchen/extra_space/chutian/measure/puai_wj_2021/setting/VLP16db.yaml");
  39. RS_device_bridge t_device;
  40. auto ec = t_device.init(params);
  41. if(ec != SUCCESS)
  42. {
  43. std::cout<<"init failed. "<< ec.to_string()<<std::endl;
  44. }
  45. usleep(1000 * 1000);
  46. std::mutex p_mutex;
  47. pcl::PointCloud<pcl::PointXYZ>::Ptr p_cloud(new pcl::PointCloud<pcl::PointXYZ>);
  48. for (size_t j = 1; j <= 300; j++)
  49. {
  50. p_cloud->clear();
  51. Error_manager ec = t_device.get_new_cloud_and_wait(&p_mutex, p_cloud, std::chrono::steady_clock::now(), 1000);
  52. if (ec == SUCCESS)
  53. {
  54. if(j % 80 == 0)
  55. {
  56. std::ofstream out((std::string("./device_point") + std::to_string(j) + std::string(".txt")).c_str());
  57. if (out.is_open())
  58. {
  59. for (size_t i = 0; i < p_cloud->size(); i++)
  60. {
  61. char buf[255] = {0};
  62. sprintf(buf, "%.3f %.3f %.3f\n", p_cloud->points[i].x, p_cloud->points[i].y, p_cloud->points[i].z);
  63. out << buf;
  64. }
  65. std::cout << "cloud written" << std::endl;
  66. out.close();
  67. }
  68. else
  69. {
  70. std::cout << "cannot open file to write cloud." << std::endl;
  71. }
  72. }
  73. }
  74. else
  75. {
  76. std::cout << "get cloud failed: "<< ec.to_string() << std::endl;
  77. }
  78. }
  79. t_device.uninit();
  80. }
  81. int main()
  82. {
  83. const char* logPath = "./log/";
  84. google::InitGoogleLogging("LidarMeasurement");
  85. google::SetStderrLogging(google::INFO);
  86. google::SetLogDestination(0, logPath);
  87. google::SetLogFilenameExtension("zxlog");
  88. google::InstallFailureSignalHandler();
  89. google::InstallFailureWriter(&shut_down_logging);
  90. FLAGS_colorlogtostderr = true; // Set log color
  91. FLAGS_logbufsecs = 0; // Set log output speed(s)
  92. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  93. FLAGS_stop_logging_if_full_disk = true;
  94. // device_test();
  95. bridge_test();
  96. return 0;
  97. }