main.cpp 6.7 KB

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