main.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //
  2. // Created by zx on 2020/6/18.
  3. //
  4. #include <iostream>
  5. #include "./error_code/error_code.h"
  6. #include "./laser/LogFiles.h"
  7. #include <glog/logging.h>
  8. #include "./laser/laser_manager.h"
  9. #include "./laser/Laser.h"
  10. #include "./laser/LivoxLaser.h"
  11. #include "./locate/locate_manager.h"
  12. #include "./communication/communication_socket_base.h"
  13. #include "./tool/thread_pool.h"
  14. #include "./system/system_communication.h"
  15. #include "./system/system_executor.h"
  16. #define LIVOX_NUMBER 2
  17. void asd(int i)
  18. {
  19. std::cout << " i = " << i << std::endl;
  20. }
  21. int main(int argc,char* argv[])
  22. {
  23. Laser_manager::get_instance_references().laser_manager_init();
  24. std::cout << "Laser_manager = " << Laser_manager::get_instance_references().get_laser_manager_status() << std::endl;
  25. Locate_manager::get_instance_references().Locate_manager_init();
  26. std::cout << "Locate_manager = " << Locate_manager::get_instance_references().get_locate_manager_status() << std::endl;
  27. System_executor::get_instance_references().system_executor_init(4);
  28. std::cout << "System_executor = " << System_executor::get_instance_references().get_system_executor_status() << std::endl;
  29. System_communication::get_instance_references().communication_init();
  30. char ch ;
  31. std::cin >> ch ;
  32. System_communication::get_instance_references().communication_uninit();
  33. System_executor::get_instance_references().system_executor_uninit();
  34. Locate_manager::get_instance_references().Locate_manager_uninit();
  35. Laser_manager::get_instance_references().laser_manager_uninit();
  36. return 0;
  37. Thread_pool pool(4);
  38. std::vector< std::future<int> > results;
  39. // for(int i = 0; i < 8; ++i) {
  40. // results.emplace_back(
  41. // pool.enqueue([i] {
  42. // std::cout << "hello " << i << std::endl;
  43. // std::this_thread::sleep_for(std::chrono::seconds(1));
  44. // std::cout << "world " << i << std::endl;
  45. // return i*i;
  46. // })
  47. // );
  48. // }
  49. pool.enqueue(&asd,8);
  50. for(auto && result: results)
  51. std::cout << result.get() << ' ';
  52. std::cout << std::endl;
  53. return 0;
  54. LOG(INFO) << " --- main start --- " ;
  55. Error_manager t_error;
  56. Error_manager t_result ;
  57. std::cout << "huli 101 main start!" << std::endl;
  58. std::cout << "1111111111111111111111" << std::endl;
  59. Laser_manager::get_instance_pointer()->laser_manager_init();
  60. Locate_manager::get_instance_pointer()->Locate_manager_init();
  61. Point_sift_segmentation* mp_point_sift;
  62. int point_size = 8192;
  63. int cls_num = 3;
  64. double freq = 20.0;
  65. std::string graph = "../model_param/seg_model_404500.ckpt.meta";
  66. std::string cpkt = "../model_param/seg_model_404500.ckpt";
  67. pcl::PointXYZ minp(-10000,-10000,-10000);
  68. pcl::PointXYZ maxp(10000,10000,10000);
  69. while(1)
  70. {
  71. std::cout << "huli 401 connect_laser Error_code::SUCCESS" << std::endl;
  72. std::cout << " press to start" << std::endl;
  73. char ch ;
  74. // = getchar();
  75. std::this_thread::sleep_for(std::chrono::seconds(2));
  76. std::cin >> ch ;
  77. if ( ch == 'b' )
  78. {
  79. std::cout << " end scan ------------" << std::endl;
  80. break;
  81. }
  82. std::cout << " start scan ------------" << std::endl;
  83. int n = 1;
  84. while(n)
  85. {
  86. n--;
  87. std::map<int,pcl::PointCloud<pcl::PointXYZ>::Ptr> point_cloud_map;
  88. std::mutex cloud_lock;
  89. std::vector<int> select_laser_id_vector;
  90. select_laser_id_vector.push_back(0);
  91. time_t nowTime;
  92. nowTime = time(NULL);
  93. struct tm* sysTime = localtime(&nowTime);
  94. char t_save_path[256] = { 0 };
  95. sprintf(t_save_path, "../data/%04d%02d%02d_%02d%02d%02d",
  96. sysTime->tm_year + 1900, sysTime->tm_mon + 1, sysTime->tm_mday, sysTime->tm_hour, sysTime->tm_min, sysTime->tm_sec);
  97. Laser_manager_task * laser_manager_task = new Laser_manager_task;
  98. laser_manager_task->task_init(TASK_CREATED,"",NULL,std::chrono::milliseconds(15000),
  99. true,t_save_path,&cloud_lock,&point_cloud_map,false,
  100. 1000,false,select_laser_id_vector );
  101. t_error = Task_command_manager::get_instance_references().execute_task(laser_manager_task);
  102. // tp_laser_manager->execute_task(laser_manager_task);
  103. if ( t_error != Error_code::SUCCESS )
  104. {
  105. std::cout << "huli Laser_manager:::::" << t_error.to_string() << std::endl;
  106. }
  107. else
  108. {
  109. while ( laser_manager_task->is_task_end() == false)
  110. {
  111. if ( laser_manager_task->is_over_time() )
  112. {
  113. //超时处理。取消任务。
  114. Laser_manager::get_instance_pointer()->cancel_task();
  115. laser_manager_task->set_task_statu(TASK_DEAD);
  116. t_error.error_manager_reset(Error_code::LASER_MANAGER_TASK_OVER_TIME, Error_level::MINOR_ERROR,
  117. " laser_manager_task is_over_time ");
  118. laser_manager_task->set_task_error_manager(t_error);
  119. }
  120. else
  121. {
  122. std::this_thread::yield();
  123. }
  124. }
  125. std::cout << "huli task_error::::" << laser_manager_task->get_task_error_manager().to_string() << std::endl;
  126. }
  127. delete(laser_manager_task);
  128. std::cout << "huli laser result---------------------" << t_error.to_string() << std::endl;
  129. std::cout << "huli zczxczxczx---------------------" << t_error.to_string() << std::endl;
  130. std::cout << "huli zczxczxczx---------------------" << t_error.to_string() << std::endl;
  131. std::cout << "huli zczxczxczx---------------------" << t_error.to_string() << std::endl;
  132. /*
  133. pcl::PointCloud<pcl::PointXYZ>::Ptr scan_cloud ;
  134. scan_cloud = point_cloud_map[0];
  135. //locate
  136. pcl::getMinMax3D(*scan_cloud,minp,maxp);
  137. std::cout << "huli 112" << std::endl;
  138. mp_point_sift = new Point_sift_segmentation(point_size,cls_num,freq,minp,maxp);
  139. std::cout << t_error.to_string() << std::endl;
  140. t_error = mp_point_sift->init(graph,cpkt);
  141. std::cout << t_error.to_string() << std::endl;
  142. std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr> segmentation_clouds;
  143. t_error = mp_point_sift->segmentation(scan_cloud, segmentation_clouds, true, "../data/locate_data");
  144. std::cout << t_error.to_string() << std::endl;
  145. */
  146. Locate_manager_task * locate_manager_task = new Locate_manager_task;
  147. locate_manager_task->task_init(TASK_CREATED,"",NULL,std::chrono::milliseconds(15000),
  148. true,t_save_path,&cloud_lock,&point_cloud_map,true
  149. );
  150. t_error = Task_command_manager::get_instance_references().execute_task(locate_manager_task);
  151. if ( t_error != Error_code::SUCCESS )
  152. {
  153. std::cout << "huli Locate_manager:::::" << t_error.to_string() << std::endl;
  154. }
  155. else
  156. {
  157. while ( locate_manager_task->is_task_end() == false)
  158. {
  159. if ( locate_manager_task->is_over_time() )
  160. {
  161. //超时处理。取消任务。
  162. Locate_manager::get_instance_pointer()->cancel_task();
  163. locate_manager_task->set_task_statu(TASK_DEAD);
  164. t_error.error_manager_reset(Error_code::LOCATE_MANAGER_TASK_OVER_TIME, Error_level::MINOR_ERROR,
  165. " locate_manager_task is_over_time ");
  166. locate_manager_task->set_task_error_manager(t_error);
  167. }
  168. else
  169. {
  170. std::this_thread::yield();
  171. }
  172. }
  173. std::cout << "huli task_error:::::" << locate_manager_task->get_task_error_manager().to_string() << std::endl;
  174. }
  175. delete(locate_manager_task);
  176. std::cout << "huli locate result:::::" << t_error.to_string() << std::endl;
  177. }
  178. cout << "huli: 601 :" << t_error.to_string() << endl;
  179. std::this_thread::sleep_for(std::chrono::seconds(2));
  180. }
  181. Laser_manager::get_instance_pointer()->laser_manager_uninit();
  182. Locate_manager::get_instance_pointer()->Locate_manager_uninit();
  183. cout << "huli 1234 main end" << endl;
  184. std::this_thread::sleep_for(std::chrono::seconds(3));
  185. return 0;
  186. }