|
@@ -77,12 +77,13 @@ void init_glog() {
|
|
|
FLAGS_stop_logging_if_full_disk = true;
|
|
|
}
|
|
|
|
|
|
-typedef struct {
|
|
|
+struct Clamp{
|
|
|
Wanji_716N_lidar_device lidar;
|
|
|
clamp_safety_detect detector;
|
|
|
Safety_status safety_statu;
|
|
|
+ pcl::PointCloud<pcl::PointXYZ>::Ptr last_cloud;
|
|
|
std::mutex mutex;
|
|
|
-} Clamp;
|
|
|
+};
|
|
|
|
|
|
bool run(Wanji_716N_lidar_device *device, clamp_safety_detect *pdetector, Safety_status *safety) {
|
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
|
|
@@ -98,10 +99,20 @@ bool run(Wanji_716N_lidar_device *device, clamp_safety_detect *pdetector, Safety
|
|
|
void thread_func(Clamp *clamp) {
|
|
|
while (true) {
|
|
|
clamp->mutex.lock();
|
|
|
- Safety_status safety_t;
|
|
|
- if (run(&(clamp->lidar), &(clamp->detector), &safety_t)) {
|
|
|
- clamp->safety_statu = safety_t;
|
|
|
+
|
|
|
+ clamp->last_cloud->clear();
|
|
|
+ clamp->lidar.get_last_cloud(clamp->last_cloud, std::chrono::system_clock::now());
|
|
|
+
|
|
|
+ if (clamp->last_cloud->size() < 150) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+
|
|
|
+ clamp->detector.detect(clamp->last_cloud, clamp->safety_statu);
|
|
|
+
|
|
|
+// Safety_status safety_t;
|
|
|
+// if (run(&(clamp->lidar), &(clamp->detector), &safety_t)) {
|
|
|
+// clamp->safety_statu = safety_t;
|
|
|
+// }
|
|
|
clamp->mutex.unlock();
|
|
|
|
|
|
usleep(100 * 1000);
|
|
@@ -166,13 +177,9 @@ int main() {
|
|
|
|
|
|
//调试状态下,绑定识别器输出窗口
|
|
|
#if __VIEW__PCL
|
|
|
- if (parameter.lidars_size()>0)
|
|
|
clamps[0].detector.set_viewer(&g_viewer,v1);
|
|
|
- if (parameter.lidars_size()>1)
|
|
|
clamps[1].detector.set_viewer(&g_viewer,v2);
|
|
|
- if (parameter.lidars_size()>2)
|
|
|
clamps[2].detector.set_viewer(&g_viewer,v3);
|
|
|
- if (parameter.lidars_size()>3)
|
|
|
clamps[3].detector.set_viewer(&g_viewer,v4);
|
|
|
|
|
|
while(1)
|
|
@@ -180,13 +187,9 @@ int main() {
|
|
|
usleep(100*1000);
|
|
|
auto t1=std::chrono::steady_clock::now();
|
|
|
//调试状态下,顺序执行,因为viewer不支持多线程
|
|
|
- if (parameter.lidars_size()>0)
|
|
|
run(&(clamps[0].lidar),&(clamps[0].detector),&(clamps[0].safety_statu));
|
|
|
- if (parameter.lidars_size()>1)
|
|
|
run(&(clamps[1].lidar),&(clamps[1].detector),&(clamps[1].safety_statu));
|
|
|
- if (parameter.lidars_size()>2)
|
|
|
run(&(clamps[2].lidar),&(clamps[2].detector),&(clamps[2].safety_statu));
|
|
|
- if (parameter.lidars_size()>3)
|
|
|
run(&(clamps[3].lidar),&(clamps[3].detector),&(clamps[3].safety_statu));
|
|
|
auto t2=std::chrono::steady_clock::now();
|
|
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1);
|
|
@@ -199,13 +202,13 @@ int main() {
|
|
|
}
|
|
|
#else
|
|
|
// 和plc建立连接,一直等待连接成功
|
|
|
-// auto snap7_client = &Snap7Clamp::get_instance_references();
|
|
|
-// snap7_client->communication_init();
|
|
|
-// Snap7Clamp::Snap7_communication_statu status = snap7_client->get_status();
|
|
|
-// while (status == Snap7Clamp::SNAP7_COMMUNICATION_READY || status == Snap7Clamp::SNAP7_COMMUNICATION_RECEIVE) {
|
|
|
-// sleep(1);
|
|
|
-// status = snap7_client->get_status();
|
|
|
-// }
|
|
|
+ auto snap7_client = &Snap7Clamp::get_instance_references();
|
|
|
+ snap7_client->communication_init();
|
|
|
+ Snap7Clamp::Snap7_communication_statu status = snap7_client->get_status();
|
|
|
+ while (status == Snap7Clamp::SNAP7_COMMUNICATION_READY || status == Snap7Clamp::SNAP7_COMMUNICATION_RECEIVE) {
|
|
|
+ sleep(1);
|
|
|
+ status = snap7_client->get_status();
|
|
|
+ }
|
|
|
|
|
|
// 启动四个线程,分别采集四个雷达的数据。
|
|
|
std::thread threads[CLAMP_SIZE];
|
|
@@ -223,18 +226,17 @@ int main() {
|
|
|
std::unique_lock<std::mutex> t_lock(clamps[i].mutex);
|
|
|
// std::unique_lock<std::mutex> t_lock1(snap7_client->m_data_lock);
|
|
|
if (!clamps[i].safety_statu.is_timeout()) {
|
|
|
- LOG(WARNING) << "id: " << i << ", we: " << clamps[i].safety_statu.wheel_exist << ", cx: " << clamps[i].safety_statu.cx * 1000;
|
|
|
+// LOG(WARNING) << "id: " << i << ", we: " << clamps[i].safety_statu.wheel_exist << ", cx: " << clamps[i].safety_statu.cx * 1000;
|
|
|
// LOG(INFO) << "orid " << i;
|
|
|
// LOG(INFO) << "wheel_exist " << clamps[i].safety_statu.wheel_exist;
|
|
|
// LOG(INFO) << "cx " << clamps[i].safety_statu.cx * 1000;
|
|
|
// LOG(INFO) << "gap " << clamps[i].safety_statu.gap * 1000;
|
|
|
// LOG(INFO) << "clamp_completed " << clamps[i].safety_statu.clamp_completed;
|
|
|
-// snap7_client->plcData.wheels[i].wheel_exist = clamps[i].safety_statu.wheel_exist;
|
|
|
-//// snap7_client->plcData.wheels[i].offset = heart;
|
|
|
-//// snap7_client->plcData.wheels[i].gap = 255 - heart;
|
|
|
-// snap7_client->plcData.wheels[i].offset = clamps[i].safety_statu.cx * 1000;
|
|
|
-// snap7_client->plcData.wheels[i].gap = clamps[i].safety_statu.gap * 1000;
|
|
|
-// snap7_client->plcData.wheels[i].clamp_completed = clamps[i].safety_statu.clamp_completed;
|
|
|
+ snap7_client->plcData.wheels[i].wheel_exist = clamps[i].safety_statu.wheel_exist;
|
|
|
+ snap7_client->plcData.wheels[i].offset = clamps[i].safety_statu.cx * 1000;
|
|
|
+ snap7_client->plcData.wheels[i].gap = clamps[i].safety_statu.gap * 1000;
|
|
|
+ snap7_client->plcData.wheels[i].clamp_completed = clamps[i].safety_statu.clamp_completed;
|
|
|
+ snap7_client->setCloudData(1 << i, clamps[i].last_cloud);
|
|
|
} else {
|
|
|
// snap7_client->plcData.clear();
|
|
|
}
|