main.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // Created by zx on 2019/12/28.
  3. //
  4. #include <iostream>
  5. #include "./laser/Laser.h"
  6. #include "./laser/LivoxLaser.h"
  7. #include "./error_code/error_code.h"
  8. #include "LogFiles.h"
  9. #include <string.h>
  10. #include <fcntl.h>
  11. #include <google/protobuf/io/zero_copy_stream_impl.h>
  12. #include <google/protobuf/text_format.h>
  13. //#include </usr/local/include/google/protobuf/io/zero_copy_stream_impl.h>
  14. using google::protobuf::io::FileInputStream;
  15. using google::protobuf::io::FileOutputStream;
  16. using google::protobuf::io::ZeroCopyInputStream;
  17. using google::protobuf::io::CodedInputStream;
  18. using google::protobuf::io::ZeroCopyOutputStream;
  19. using google::protobuf::io::CodedOutputStream;
  20. using google::protobuf::Message;
  21. #define O_RDONLY 00
  22. //读取protobuf 配置文件
  23. //file:文件
  24. //parameter:要读取的配置
  25. bool read_proto_param(std::string file, ::google::protobuf::Message& parameter)
  26. {
  27. int fd = open(file.c_str(), O_RDONLY);
  28. if (fd == -1) return false;
  29. FileInputStream* input = new FileInputStream(fd);
  30. bool success = google::protobuf::TextFormat::Parse(input, &parameter);
  31. delete input;
  32. close(fd);
  33. return success;
  34. }
  35. int main(int argc,char* argv[])
  36. {
  37. std::cout << "huli 101 main start!" << std::endl;
  38. Error_manager err;
  39. Laser_base *m_laser_vector;
  40. // Laser_proto::Laser_parameter_all laser_parameters;
  41. /* if (!read_proto_param("./setting/laser.prototxt", laser_parameters))
  42. {
  43. err.error_manager_reset(SYSTEM_READ_PARAMETER_ERROR, NORMAL, "read laser parameter failed");
  44. cout << err.to_string() << endl;
  45. return err.get_error_code();
  46. }
  47. */
  48. Laser_proto::laser_parameter laser_param;
  49. laser_param.set_frame_num(1000);
  50. laser_param.set_type("Livox");
  51. laser_param.set_sn("0TFDFG700601881");
  52. int i = 0;
  53. m_laser_vector = LaserRegistory::CreateLaser(laser_param.type(), i,
  54. laser_param);
  55. if (!Start()) {
  56. Uninit();
  57. printf("Livox-SDK init fail!\n");
  58. }
  59. else
  60. {
  61. std::cout << "huli 201 Livox-SDK start" << std::endl;
  62. }
  63. if (m_laser_vector != NULL)
  64. {
  65. err = m_laser_vector->connect_laser();
  66. if ( err != Error_code::SUCCESS)
  67. {
  68. char description[255] = {0};
  69. sprintf(description, "Laser %d connect failed...", i);
  70. err.error_manager_reset(LASER_CONNECT_FAILED, NORMAL, description);
  71. }
  72. else
  73. {
  74. std::cout << "huli 301 connect_laser Error_code::SUCCESS" << std::endl;
  75. }
  76. cout << "huli 311 " << err.to_string() << endl;
  77. pcl::PointCloud<pcl::PointXYZ>::Ptr scan_cloud(new pcl::PointCloud<pcl::PointXYZ>);
  78. std::mutex cloud_lock;
  79. Laser_task *laser_task = new Laser_task();
  80. //
  81. laser_task->task_init(TASK_CREATED, scan_cloud, &cloud_lock);
  82. laser_task->set_task_frame_maxnum(100);
  83. laser_task->set_task_save_path("123");
  84. //发送任务单给雷达
  85. std::this_thread::sleep_for(std::chrono::seconds(5));
  86. std::cout << "huli 401 connect_laser Error_code::SUCCESS" << std::endl;
  87. err = m_laser_vector->execute_task(laser_task);
  88. cout << "huli: 501 :" << err.to_string() << endl;
  89. cout << "huli: 501 :" << err.to_string() << endl;
  90. }
  91. else
  92. {
  93. cout << "huli: 601 :" << err.to_string() << endl;
  94. }
  95. std::this_thread::sleep_for(std::chrono::seconds(5));
  96. cout << "huli: 701 :" << err.to_string() << endl;
  97. m_laser_vector->disconnect_laser();
  98. cout << "huli: 801 :" << err.to_string() << endl;
  99. m_laser_vector->close_save_path();
  100. cout << "huli: 901 :" << err.to_string() << endl;
  101. std::this_thread::sleep_for(std::chrono::seconds(2));
  102. Uninit();
  103. cout << "huli 1234 main end" << endl;
  104. }