#include "../wj_lidar/wj_lidar_encapsulation.h" // #include #include #include #include #include #include #include #include void save_cloud_txt(std::string txt, pcl::PointCloud::Ptr pCloud) { std::ofstream os; os.open(txt, std::ios::out); for (int i = 0; i < pCloud->points.size(); i++) { pcl::PointXYZ point = pCloud->points[i]; char buf[255]; memset(buf, 0, 255); sprintf(buf, "%f %f %f\n", point.x, point.y, point.z); os.write(buf, strlen(buf)); } os.close(); } bool ReadProtoParam(std::string path, wj::wjLidarParams ¶ms) { int fd = open(path.c_str(), O_RDONLY); if (fd == -1) return false; FileInputStream *input = new FileInputStream(fd); bool success = google::protobuf::TextFormat::Parse(input, ¶ms); // std::cout<set_ip_address("192.168.0.2"); // params.mutable_net_config()->set_port(2110); if (lidar != 0) { Error_manager code = lidar->initialize(params); LOG(INFO) << code.to_string(); // usleep(1000 * 1); if (code == SUCCESS) { pcl::PointCloud::Ptr cloud = pcl::PointCloud::Ptr(new pcl::PointCloud); for (int i = 0; i < 10; i++) { LOG(INFO) << "connect status: " << lidar->get_connection_status(); code = lidar->get_cloud(cloud, std::chrono::steady_clock::now(), 3000); if (code == SUCCESS) { char temp[100]; memset(temp, 0, 100); sprintf(temp, "cloud_%d.txt", i); if (cloud->size() > 0) { save_cloud_txt(temp, cloud); LOG(INFO) << "cloud saved to " << std::string(temp); } } else { LOG(WARNING) << code.to_string(); } usleep(1000 * 30); LOG(INFO) << "end of cycle"; } } } delete lidar; } int main(int argc, char *argv[]) { lidar_test(); usleep(1000 * 1000); // lidar_test(); // usleep(1000 * 1000); // lidar_test(); // usleep(1000 * 1000); LOG(INFO) << "end"; getchar(); return 0; }