main.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // Created by zx on 2020/6/18.
  3. //
  4. #include <pcl/visualization/pcl_visualizer.h>
  5. #include <iostream>
  6. #include "./error_code/error_code.h"
  7. #include "./wanji_lidar/LogFiles.h"
  8. #include <glog/logging.h>
  9. #include "./communication/communication_socket_base.h"
  10. #include "./tool/thread_pool.h"
  11. #include "./system/system_communication.h"
  12. #include "./system/system_executor.h"
  13. // #include "./wanji_lidar/wanji_lidar_device.h"
  14. #include "./tool/proto_tool.h"
  15. #include "./wanji_lidar/wanji_manager.h"
  16. #include "./velodyne_lidar/velodyne_manager.h"
  17. #define LIVOX_NUMBER 2
  18. // #define POINT_DEBUG
  19. #ifdef POINT_DEBUG
  20. std::shared_ptr<pcl::visualization::PCLVisualizer> gp_visualizer;
  21. #endif
  22. GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
  23. {
  24. time_t tt;
  25. time( &tt );
  26. tt = tt + 8*3600; // transform the time zone
  27. tm* t= gmtime( &tt );
  28. char buf[255]={0};
  29. sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
  30. t->tm_year + 1900,
  31. t->tm_mon + 1,
  32. t->tm_mday,
  33. t->tm_hour,
  34. t->tm_min,
  35. t->tm_sec);
  36. FILE* tp_file=fopen(buf,"w");
  37. fprintf(tp_file,data,strlen(data));
  38. fclose(tp_file);
  39. }
  40. void test_whole_process()
  41. {
  42. System_executor::get_instance_references().execute_for_measure("key_for_test_only", 0, std::chrono::system_clock::now());
  43. }
  44. int main(int argc,char* argv[])
  45. {
  46. std::cout << " measure:: " << " xxxxxxxxxxxxxxxxx " << std::endl;
  47. Error_manager t_error;
  48. Error_manager t_result ;
  49. Error_manager ec;
  50. #ifdef POINT_DEBUG
  51. pcl::PointCloud<pcl::PointXYZ>::Ptr t_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
  52. pcl::visualization::PCLVisualizer viewer("Viewer"); //创建viewer对象
  53. gp_visualizer = std::shared_ptr<pcl::visualization::PCLVisualizer>(&viewer);
  54. gp_visualizer->addCoordinateSystem();
  55. gp_visualizer->setBackgroundColor(0, 0, 0);
  56. gp_visualizer->initCameraParameters();
  57. gp_visualizer->addPointCloud(t_cloud, "region");
  58. #endif
  59. const char* logPath = "./log/";
  60. google::InitGoogleLogging("LidarMeasurement");
  61. google::SetStderrLogging(google::INFO);
  62. google::SetLogDestination(0, logPath);
  63. google::SetLogFilenameExtension("zxlog");
  64. google::InstallFailureSignalHandler();
  65. google::InstallFailureWriter(&shut_down_logging);
  66. FLAGS_colorlogtostderr = true; // Set log color
  67. FLAGS_logbufsecs = 0; // Set log output speed(s)
  68. FLAGS_max_log_size = 1024; // Set max log file size(GB)
  69. FLAGS_stop_logging_if_full_disk = true;
  70. //huli test
  71. // ec = System_communication_mq::get_instance_references().rabbitmq_init();
  72. // if(ec != SUCCESS)
  73. // {
  74. // LOG(ERROR) << "system communication mq init failed: " << ec.to_string();
  75. // return -1;
  76. // }
  77. //
  78. // while (true)
  79. // {}
  80. //
  81. // return 0;
  82. // std::cout << " huli test :::: " << " wanji_manager_init = " << 1 << std::endl;
  83. // 定义服务的终端id
  84. int t_terminal_id = 0;
  85. if ( argc == 2 )
  86. {
  87. std::cout << " huli test :::: " << " argv[1] = " << argv[1] << std::endl;
  88. t_terminal_id = atoi(argv[1]);
  89. }
  90. std::cout << " huli test :::: " << " t_terminal_id = " << t_terminal_id << std::endl;
  91. // Error_manager ec;
  92. // 初始化
  93. if(WJ_VELO == 0 || WJ_VELO == 2)
  94. {
  95. Wanji_manager::get_instance_references().wanji_manager_init(t_terminal_id);
  96. std::cout << "wanji_manager = " << Wanji_manager::get_instance_references().check_status().to_string() << std::endl;
  97. if (ec != SUCCESS)
  98. {
  99. LOG(ERROR) << "wanji_manager init failed: " << ec.to_string();
  100. return -1;
  101. }
  102. }
  103. if(WJ_VELO == 1 || WJ_VELO == 2)
  104. {
  105. ec = Velodyne_manager::get_instance_references().velodyne_manager_init(t_terminal_id);
  106. if (ec != SUCCESS)
  107. {
  108. std::cout << "veodyne_manager = " << ec.to_string() << std::endl;
  109. std::cout << "veodyne_manager = " << Velodyne_manager::get_instance_references().check_status().to_string() << std::endl;
  110. LOG(ERROR) << "velodyne_manager init failed: " << ec.to_string();
  111. return -1;
  112. }
  113. }
  114. ec = System_executor::get_instance_references().system_executor_init(4, t_terminal_id);
  115. std::cout << "System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  116. if(ec != SUCCESS)
  117. {
  118. LOG(ERROR) << "system executor init failed: " << ec.to_string();
  119. return -1;
  120. }
  121. // usleep(1000 * 500);
  122. ec = System_communication::get_instance_references().communication_init();
  123. if(ec != SUCCESS)
  124. {
  125. LOG(ERROR) << "system communication init failed: " << ec.to_string();
  126. return -1;
  127. }
  128. System_communication::get_instance_references().set_encapsulate_cycle_time(110);
  129. ec = System_communication_mq::get_instance_references().rabbitmq_init();
  130. if(ec != SUCCESS)
  131. {
  132. LOG(ERROR) << "system communication mq init failed: " << ec.to_string();
  133. return -1;
  134. }
  135. System_communication_mq::get_instance_references().set_encapsulate_status_cycle_time(100);
  136. // prev_test_pred_task();
  137. // test_whole_process();
  138. // usleep(1000*5000);
  139. char ch='x' ;
  140. pcl::PointCloud<pcl::PointXYZ>::Ptr t_region_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);
  141. while(ch != 'q') {
  142. #ifdef POINT_DEBUG
  143. std::map<int, Ground_region *> t_ground_region_map = Velodyne_manager::get_instance_references().get_ground_region_map();
  144. for (auto iter = t_ground_region_map.begin(); iter != t_ground_region_map.end(); ++iter)
  145. {
  146. if (iter->first == DISP_TERM_ID)
  147. {
  148. t_region_cloud->clear();
  149. // 获取区域点云
  150. iter->second->get_region_cloud(t_region_cloud, Ground_region::Region_cloud_type::filtered);
  151. // gp_visualizer->showCloud(t_region_cloud);
  152. gp_visualizer->updatePointCloud(t_region_cloud, "region");
  153. // LOG(INFO) << "pcl cloud updated." <<t_region_cloud->size();
  154. }
  155. }
  156. gp_visualizer->spinOnce();
  157. usleep(100);
  158. #else
  159. std::cout << "please input q to quit system." << std::endl;
  160. std::cin >> ch;
  161. #endif
  162. }
  163. // 反初始化
  164. System_communication::get_instance_references().communication_uninit();
  165. System_communication_mq::get_instance_references().rabbitmq_uninit();
  166. if(WJ_VELO == 1 || WJ_VELO == 2)
  167. Velodyne_manager::get_instance_references().Velodyne_manager_uninit();
  168. System_executor::get_instance_references().system_executor_uninit();
  169. if(WJ_VELO == 0 || WJ_VELO == 2)
  170. Wanji_manager::get_instance_references().wanji_manager_uninit();
  171. return 0;
  172. }