12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #pragma TEST_H_
- #include <time.h>
- #include <iostream>
- #include <fstream>
- #include <byteswap.h>
- #include <pcl/point_cloud.h>
- #include "plc/snap7_communication_base.h"
- #include "lidar/wanji_716N_device.h"
- #include "detect/clamp_safety_detect.h"
- #include "clamp_parameter.pb.h"
- #define plcc
- typedef struct Clamp {
- Wanji_716N_lidar_device lidar;
- clamp_safety_detect detector;
- Safety_status safety_statu;
- std::mutex mutex;
- } Clamp;
- #define DEFAULT_WHEEL_AXIS 406
- #define WARNING_ALG_VALUE 30
- class Test {
- private:
- const std::string filePath = "../record/";
- const std::string fileName = "big_water_measure.txt";
- const std::string lidarPath = "../record/big_water_measure/";
- struct Deviation {
- float alg_x;
- float real_x;
- int id;
- Deviation() {
- alg_x = 0;
- real_x = 0;
- id = 0;
- // now_real_x = 0;
- }
- void info() {
- // printf("point %.3f(%.3f), %.3f (%.3f).\n", old_line_x, old_real_x, now_line_x, now_real_x);
- }
- };
- public:
- Test(Clamp* clamp);
- ~Test() {};
- int initPlc(clamp_safety::clamp_parameter ¶meter) {
- #ifdef plc
- // plc相关
- Snap7_communication_base snap7_client;
- std::string plc_ip = parameter.plc_parameter().ip_address();
- Error_manager code = snap7_client.communication_init(plc_ip);
- if(code != SUCCESS)
- {
- LOG(ERROR) << code;
- return -1;
- }
- #endif
- return 0;
- }
- void setWriteSnap(int ip, int index);
- void setReadSnap(int ip, int index);
- void thread_fun(bool new_thread = false) {
- if (new_thread) {
- m_test_thread = new std::thread(&Test::commnuition, this);
- }
- else {
- commnuition();
- }
- }
- private:
- void exportTxtFile();
- void commnuition();
- void update_clould();
- bool GetAlg(float &x);
- bool snap7_read(float &data);
- bool snap7_read(int16_t &data);
- bool snap7_write(float &data);
- bool snap7_write(int16_t &data);
- float SWAP_float(float x);
- private:
- Clamp *m_clamp;
- std::thread *m_test_thread;
- Snap7_communication_base *m_plc;
- Snap7_buf m_snap_wite;
- Snap7_buf m_snap_read;
- pcl::PointCloud<pcl::PointXYZ>::Ptr m_cloud;
- struct Deviation m_record_data;
- };
|