test.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma TEST_H_
  2. #include <time.h>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <byteswap.h>
  6. #include <pcl/point_cloud.h>
  7. #include "plc/snap7_communication_base.h"
  8. #include "lidar/wanji_716N_device.h"
  9. #include "detect/clamp_safety_detect.h"
  10. #include "clamp_parameter.pb.h"
  11. #define plcc
  12. typedef struct Clamp {
  13. Wanji_716N_lidar_device lidar;
  14. clamp_safety_detect detector;
  15. Safety_status safety_statu;
  16. std::mutex mutex;
  17. } Clamp;
  18. #define DEFAULT_WHEEL_AXIS 406
  19. #define WARNING_ALG_VALUE 30
  20. class Test {
  21. private:
  22. const std::string filePath = "../record/";
  23. const std::string fileName = "big_water_measure.txt";
  24. const std::string lidarPath = "../record/big_water_measure/";
  25. struct Deviation {
  26. float alg_x;
  27. float real_x;
  28. int id;
  29. Deviation() {
  30. alg_x = 0;
  31. real_x = 0;
  32. id = 0;
  33. // now_real_x = 0;
  34. }
  35. void info() {
  36. // printf("point %.3f(%.3f), %.3f (%.3f).\n", old_line_x, old_real_x, now_line_x, now_real_x);
  37. }
  38. };
  39. public:
  40. Test(Clamp* clamp);
  41. ~Test() {};
  42. int initPlc(clamp_safety::clamp_parameter &parameter) {
  43. #ifdef plc
  44. // plc相关
  45. Snap7_communication_base snap7_client;
  46. std::string plc_ip = parameter.plc_parameter().ip_address();
  47. Error_manager code = snap7_client.communication_init(plc_ip);
  48. if(code != SUCCESS)
  49. {
  50. LOG(ERROR) << code;
  51. return -1;
  52. }
  53. #endif
  54. return 0;
  55. }
  56. void setWriteSnap(int ip, int index);
  57. void setReadSnap(int ip, int index);
  58. void thread_fun(bool new_thread = false) {
  59. if (new_thread) {
  60. m_test_thread = new std::thread(&Test::commnuition, this);
  61. }
  62. else {
  63. commnuition();
  64. }
  65. }
  66. private:
  67. void exportTxtFile();
  68. void commnuition();
  69. void update_clould();
  70. bool GetAlg(float &x);
  71. bool snap7_read(float &data);
  72. bool snap7_read(int16_t &data);
  73. bool snap7_write(float &data);
  74. bool snap7_write(int16_t &data);
  75. float SWAP_float(float x);
  76. private:
  77. Clamp *m_clamp;
  78. std::thread *m_test_thread;
  79. Snap7_communication_base *m_plc;
  80. Snap7_buf m_snap_wite;
  81. Snap7_buf m_snap_read;
  82. pcl::PointCloud<pcl::PointXYZ>::Ptr m_cloud;
  83. struct Deviation m_record_data;
  84. };