Parcourir la source

20210925, 剥离地面雷达

huli il y a 3 ans
Parent
commit
8c45292a3e

+ 16 - 16
dispatch/dispatch_communication.h

@@ -419,10 +419,10 @@ public:
 #define GROUND_LIDAR_RESPONSE_FROM_MANAGER_TO_PLC_DBNUMBER_1		9014
 	struct Ground_lidar_response_from_manager_to_plc_for_key
 	{
-		unsigned char			m_heartbeat = 0;							//心跳位, 0-255循环
-		unsigned char			m_communication_mode = 0;					//通信模式	0 = 未知, 1=自动循环模式,2=手动刷新模式
-		unsigned char			m_refresh_command = 0;						//刷新指令 0-255任意数字,与上一次不同即可
-		unsigned char			m_data_validity = 0;						//数据有效性, 0 = 未知, 1 = 有效, 2 = 无效
+		unsigned char			m_response_heartbeat = 0;							//心跳位, 0-255循环
+		unsigned char			m_response_communication_mode = 0;					//通信模式	0 = 未知, 1=自动循环模式,2=手动刷新模式
+		unsigned char			m_response_refresh_command = 0;						//刷新指令 0-255任意数字,与上一次不同即可
+		unsigned char			m_response_data_validity = 0;						//数据有效性, 0 = 未知, 1 = 有效, 2 = 无效
 
 	};
 
@@ -446,10 +446,10 @@ public:
 #define GROUND_LIDAR_REQUEST_FROM_PLC_TO_MANAGER_DBNUMBER_1		9015
 	struct Ground_lidar_request_from_plc_to_manager
 	{
-		unsigned char			m_heartbeat = 0;							//心跳位, 0-255循环
-		unsigned char			m_communication_mode = 0;					//通信模式	0 = 未知, 1=自动循环模式,2=手动刷新模式
-		unsigned char			m_refresh_command = 0;						//刷新指令 0-255任意数字,与上一次不同即可
-		unsigned char			m_data_validity = 0;						//数据有效性, 0 = 未知, 1 = 有效, 2 = 无效
+		unsigned char			m_request_heartbeat = 0;							//心跳位, 0-255循环
+		unsigned char			m_request_communication_mode = 0;					//通信模式	0 = 未知, 1=自动循环模式,2=手动刷新模式
+		unsigned char			m_request_refresh_command = 0;						//刷新指令 0-255任意数字,与上一次不同即可
+		unsigned char			m_request_data_validity = 0;						//数据有效性, 0 = 未知, 1 = 有效, 2 = 无效
 	};
 
 
@@ -457,10 +457,10 @@ public:
 #define ANTICOLLISION_LIDAR_RESPONSE_FROM_MANAGER_TO_PLC_DBNUMBER_0		9006
 	struct Anticollision_lidar_response_from_manager_to_plc_for_key
 	{
-		unsigned char			m_heartbeat = 0;							//心跳位, 0-255循环
-		unsigned char			m_communication_mode = 0;					//通信模式	0 = 未知, 1=自动循环模式,2=手动刷新模式
-		unsigned char			m_refresh_command = 0;						//刷新指令 0-255任意数字,与上一次不同即可
-		unsigned char			m_data_validity = 0;						//数据有效性, 0 = 未知, 1 = 有效, 2 = 无效
+		unsigned char			m_response_heartbeat = 0;							//心跳位, 0-255循环
+		unsigned char			m_response_communication_mode = 0;					//通信模式	0 = 未知, 1=自动循环模式,2=手动刷新模式
+		unsigned char			m_response_refresh_command = 0;						//刷新指令 0-255任意数字,与上一次不同即可
+		unsigned char			m_response_data_validity = 0;						//数据有效性, 0 = 未知, 1 = 有效, 2 = 无效
 
 	};
 
@@ -476,10 +476,10 @@ public:
 #define ANTICOLLISION_LIDAR_REQUEST_FROM_PLC_TO_MANAGER_DBNUMBER_0		9007
 	struct Anticollision_lidar_request_from_plc_to_manager
 	{
-		unsigned char			m_heartbeat = 0;							//心跳位, 0-255循环
-		unsigned char			m_communication_mode = 0;					//通信模式	0 = 未知, 1=自动循环模式,2=手动刷新模式
-		unsigned char			m_refresh_command = 0;						//刷新指令 0-255任意数字,与上一次不同即可
-		unsigned char			m_data_validity = 0;						//数据有效性, 0 = 未知, 1 = 有效, 2 = 无效
+		unsigned char			m_request_heartbeat = 0;							//心跳位, 0-255循环
+		unsigned char			m_request_communication_mode = 0;					//通信模式	0 = 未知, 1=自动循环模式,2=手动刷新模式
+		unsigned char			m_request_refresh_command = 0;						//刷新指令 0-255任意数字,与上一次不同即可
+		unsigned char			m_request_data_validity = 0;						//数据有效性, 0 = 未知, 1 = 有效, 2 = 无效
 	};
 
 #pragma pack(pop)		//取消对齐

+ 99 - 0
dispatch/dispatch_ground_lidar.cpp

@@ -0,0 +1,99 @@
+//
+// Created by huli on 2021/9/25.
+//
+
+#include "dispatch_ground_lidar.h"
+
+Dispatch_ground_lidar::Dispatch_ground_lidar()
+{
+	m_dispatch_ground_lidar_status = DISPATCH_GROUND_LIDAR_UNKNOW;
+	m_plc_id = 0;
+	m_ground_lidar_id = 0;
+}
+
+Dispatch_ground_lidar::~Dispatch_ground_lidar()
+{
+	dispatch_plc_uninit();
+}
+
+
+//调度地面雷达 初始化
+Error_manager Dispatch_ground_lidar::dispatch_plc_init(int plc_id, int ground_lidar_id)
+{
+	m_plc_id =	plc_id;
+	m_ground_lidar_id = ground_lidar_id;
+
+	return Error_code::SUCCESS;
+}
+//调度地面雷达 反初始化
+Error_manager Dispatch_ground_lidar::dispatch_plc_uninit()
+{
+	return Error_code::SUCCESS;
+}
+//调度地面雷达 执行状态消息
+Error_manager Dispatch_ground_lidar::execute_for_ground_status_msg(message::Ground_status_msg &ground_status_msg)
+{
+	//将nnxx的protobuf 转化为 snap7的DB块,  把店面雷达数据转发给plc
+	int t_inlet_id = ground_status_msg.terminal_id() %2;
+	std::unique_lock<std::mutex> t_lock(Dispatch_communication::get_instance_references().m_data_lock);
+	Dispatch_communication::Ground_lidar_response_from_manager_to_plc_for_data * p_response_data = & Dispatch_communication::get_instance_references().m_ground_lidar_response_from_manager_to_plc_for_data[t_inlet_id];
+	Dispatch_communication::Ground_lidar_response_from_manager_to_plc_for_key * p_response_key = & Dispatch_communication::get_instance_references().m_ground_lidar_response_from_manager_to_plc_for_key[t_inlet_id];
+	Dispatch_communication::Ground_lidar_request_from_plc_to_manager * p_request = & Dispatch_communication::get_instance_references().m_ground_lidar_request_from_plc_to_manager[t_inlet_id];
+
+	if ( p_request->m_request_communication_mode == 0 )
+	{
+		p_response_key->m_response_heartbeat++;
+		p_response_key->m_response_communication_mode = p_request->m_request_communication_mode;
+		p_response_key->m_response_refresh_command = p_request->m_request_refresh_command;
+
+		p_response_data->m_response_car_center_x = ground_status_msg.locate_information_realtime().locate_x();
+		p_response_data->m_response_car_center_y = ground_status_msg.locate_information_realtime().locate_y();
+		p_response_data->m_response_car_angle = ground_status_msg.locate_information_realtime().locate_angle();
+		p_response_data->m_response_car_front_theta = ground_status_msg.locate_information_realtime().locate_front_theta();
+		p_response_data->m_response_car_length = ground_status_msg.locate_information_realtime().locate_length();
+		p_response_data->m_response_car_width = ground_status_msg.locate_information_realtime().locate_width();
+		p_response_data->m_response_car_height = ground_status_msg.locate_information_realtime().locate_height();
+		p_response_data->m_response_car_wheel_base = ground_status_msg.locate_information_realtime().locate_wheel_base();
+		p_response_data->m_response_car_wheel_width = ground_status_msg.locate_information_realtime().locate_wheel_width();
+		p_response_data->m_response_locate_correct = ground_status_msg.locate_information_realtime().locate_correct();
+	}
+	else if ( p_response_key->m_response_refresh_command == p_request->m_request_refresh_command )
+	{
+		p_response_key->m_response_heartbeat++;
+		p_response_key->m_response_communication_mode = p_request->m_request_communication_mode;
+		p_response_key->m_response_refresh_command = p_request->m_request_refresh_command;
+	}
+	else
+	{
+		p_response_key->m_response_heartbeat++;
+		p_response_key->m_response_communication_mode = p_request->m_request_communication_mode;
+		p_response_key->m_response_refresh_command = p_request->m_request_refresh_command;
+
+		p_response_data->m_response_car_center_x = ground_status_msg.locate_information_realtime().locate_x();
+		p_response_data->m_response_car_center_y = ground_status_msg.locate_information_realtime().locate_y();
+		p_response_data->m_response_car_angle = ground_status_msg.locate_information_realtime().locate_angle();
+		p_response_data->m_response_car_front_theta = ground_status_msg.locate_information_realtime().locate_front_theta();
+		p_response_data->m_response_car_length = ground_status_msg.locate_information_realtime().locate_length();
+		p_response_data->m_response_car_width = ground_status_msg.locate_information_realtime().locate_width();
+		p_response_data->m_response_car_height = ground_status_msg.locate_information_realtime().locate_height();
+		p_response_data->m_response_car_wheel_base = ground_status_msg.locate_information_realtime().locate_wheel_base();
+		p_response_data->m_response_car_wheel_width = ground_status_msg.locate_information_realtime().locate_wheel_width();
+		p_response_data->m_response_locate_correct = ground_status_msg.locate_information_realtime().locate_correct();
+	}
+
+}
+
+Dispatch_ground_lidar::Dispatch_ground_lidar_status Dispatch_ground_lidar::get_dispatch_ground_lidar_status()
+{
+	return m_dispatch_ground_lidar_status;
+}
+
+
+
+
+
+
+
+
+
+

+ 63 - 0
dispatch/dispatch_ground_lidar.h

@@ -0,0 +1,63 @@
+//
+// Created by huli on 2021/9/25.
+//
+
+#ifndef NNXX_TESTS_DISPATCH_GROUND_LIDAR_H
+#define NNXX_TESTS_DISPATCH_GROUND_LIDAR_H
+
+#include "../error_code/error_code.h"
+#include <glog/logging.h>
+#include <thread>
+#include <mutex>
+#include "../tool/thread_condition.h"
+#include "../tool/common_data.h"
+#include "../tool/time_tool.h"
+#include "../task/task_base.h"
+#include "../message/dispatch_message.pb.h"
+#include "../message/measure_message.pb.h"
+#include "../dispatch/dispatch_communication.h"
+
+//调度地面雷达
+class Dispatch_ground_lidar
+{
+public:
+	//调度plc状态
+	enum Dispatch_ground_lidar_status
+	{
+		DISPATCH_GROUND_LIDAR_UNKNOW               	= 0,    //未知
+		DISPATCH_GROUND_LIDAR_READY               	= 1,    //准备,待机
+
+
+		DISPATCH_GROUND_LIDAR_FAULT					= 10,	//故障
+		DISPATCH_GROUND_LIDAR_DISCONNECT			= 11, 	//断连
+
+	};
+public:
+	Dispatch_ground_lidar();
+	Dispatch_ground_lidar(const Dispatch_ground_lidar& other)= default;
+	Dispatch_ground_lidar& operator =(const Dispatch_ground_lidar& other)= default;
+	~Dispatch_ground_lidar();
+public://API functions
+	//调度地面雷达 初始化
+	Error_manager dispatch_plc_init(int plc_id, int ground_lidar_id);
+	//调度地面雷达 反初始化
+	Error_manager dispatch_plc_uninit();
+	//调度地面雷达 执行状态消息
+	Error_manager execute_for_ground_status_msg(message::Ground_status_msg &ground_status_msg);
+public://get or set member variable
+	Dispatch_ground_lidar_status get_dispatch_ground_lidar_status();
+protected://member functions
+
+protected://member variable
+	std::atomic<Dispatch_ground_lidar_status>				m_dispatch_ground_lidar_status;//调度地面雷达的状态
+
+
+	int 										m_plc_id;				//设备id, 索引, 就是楚天车库的单元号.
+	int 										m_ground_lidar_id;		//地面雷达的id
+	std::mutex									m_lock;	//锁
+private:
+
+};
+
+
+#endif //NNXX_TESTS_DISPATCH_GROUND_LIDAR_H

+ 7 - 46
dispatch/dispatch_manager.cpp

@@ -57,6 +57,8 @@ Error_manager Dispatch_manager::dispatch_manager_init_from_protobuf(Dispatch_pro
 	Error_manager t_error;
 
 	m_dispatch_plc.dispatch_plc_init(m_dispatch_manager_id);
+	m_dispatch_ground_lidar[0].dispatch_plc_init(m_dispatch_manager_id, 0);
+	m_dispatch_ground_lidar[1].dispatch_plc_init(m_dispatch_manager_id, 1);
 
 	m_dispatch_motion_direction_next = Common_data::Dispatch_motion_direction::DISPATCH_MOTION_DIRECTION_PICKUP;
 
@@ -86,6 +88,10 @@ Error_manager Dispatch_manager::dispatch_manager_uninit()
 	m_dispatch_manager_status = E_DISPATCH_MANAGER_UNKNOW;
 	m_dispatch_manager_id = -1;
 
+	m_dispatch_plc.dispatch_plc_uninit();
+	m_dispatch_ground_lidar[0].dispatch_plc_uninit();
+	m_dispatch_ground_lidar[1].dispatch_plc_uninit();
+
 
 	return Error_code::SUCCESS;
 }
@@ -315,53 +321,8 @@ Error_manager Dispatch_manager::release_dispatch_process(std::string command_key
 //调度模块 ///地面雷达的状态消息(地面雷达->null)
 Error_manager Dispatch_manager::execute_for_ground_status_msg(message::Ground_status_msg ground_status_msg)
 {
-	//将nnxx的protobuf 转化为 snap7的DB块,  把店面雷达数据转发给plc
 	int t_inlet_id = ground_status_msg.terminal_id() %2;
-	std::unique_lock<std::mutex> t_lock(Dispatch_communication::get_instance_references().m_data_lock);
-	Dispatch_communication::Ground_lidar_response_from_manager_to_plc_for_data * p_response_data = & Dispatch_communication::get_instance_references().m_ground_lidar_response_from_manager_to_plc_for_data[t_inlet_id];
-	Dispatch_communication::Ground_lidar_response_from_manager_to_plc_for_key * p_response_key = & Dispatch_communication::get_instance_references().m_ground_lidar_response_from_manager_to_plc_for_key[t_inlet_id];
-	Dispatch_communication::Ground_lidar_request_from_plc_to_manager * p_request = & Dispatch_communication::get_instance_references().m_ground_lidar_request_from_plc_to_manager[t_inlet_id];
-
-	if ( p_request->m_communication_mode == 0 )
-	{
-		p_response_key->m_heartbeat++;
-		p_response_key->m_communication_mode = p_request->m_communication_mode;
-		p_response_key->m_refresh_command = p_request->m_refresh_command;
-
-		p_response_data->m_response_car_center_x = ground_status_msg.locate_information_realtime().locate_x();
-		p_response_data->m_response_car_center_y = ground_status_msg.locate_information_realtime().locate_y();
-		p_response_data->m_response_car_angle = ground_status_msg.locate_information_realtime().locate_angle();
-		p_response_data->m_response_car_front_theta = ground_status_msg.locate_information_realtime().locate_front_theta();
-		p_response_data->m_response_car_length = ground_status_msg.locate_information_realtime().locate_length();
-		p_response_data->m_response_car_width = ground_status_msg.locate_information_realtime().locate_width();
-		p_response_data->m_response_car_height = ground_status_msg.locate_information_realtime().locate_height();
-		p_response_data->m_response_car_wheel_base = ground_status_msg.locate_information_realtime().locate_wheel_base();
-		p_response_data->m_response_car_wheel_width = ground_status_msg.locate_information_realtime().locate_wheel_width();
-		p_response_data->m_response_locate_correct = ground_status_msg.locate_information_realtime().locate_correct();
-	}
-	else if ( p_response_key->m_refresh_command == p_request->m_refresh_command )
-	{
-		p_response_key->m_heartbeat++;
-		p_response_key->m_communication_mode = p_request->m_communication_mode;
-		p_response_key->m_refresh_command = p_request->m_refresh_command;
-	}
-	else
-	{
-		p_response_key->m_heartbeat++;
-		p_response_key->m_communication_mode = p_request->m_communication_mode;
-		p_response_key->m_refresh_command = p_request->m_refresh_command;
-
-		p_response_data->m_response_car_center_x = ground_status_msg.locate_information_realtime().locate_x();
-		p_response_data->m_response_car_center_y = ground_status_msg.locate_information_realtime().locate_y();
-		p_response_data->m_response_car_angle = ground_status_msg.locate_information_realtime().locate_angle();
-		p_response_data->m_response_car_front_theta = ground_status_msg.locate_information_realtime().locate_front_theta();
-		p_response_data->m_response_car_length = ground_status_msg.locate_information_realtime().locate_length();
-		p_response_data->m_response_car_width = ground_status_msg.locate_information_realtime().locate_width();
-		p_response_data->m_response_car_height = ground_status_msg.locate_information_realtime().locate_height();
-		p_response_data->m_response_car_wheel_base = ground_status_msg.locate_information_realtime().locate_wheel_base();
-		p_response_data->m_response_car_wheel_width = ground_status_msg.locate_information_realtime().locate_wheel_width();
-		p_response_data->m_response_locate_correct = ground_status_msg.locate_information_realtime().locate_correct();
-	}
+	return	m_dispatch_ground_lidar[t_inlet_id].execute_for_ground_status_msg(ground_status_msg);
 
 	return Error_code::SUCCESS;
 }

+ 3 - 0
dispatch/dispatch_manager.h

@@ -25,6 +25,7 @@
 #include "../message/dispatch_message.pb.h"
 #include "../dispatch/dispatch_parameter.pb.h"
 #include "../dispatch/dispatch_plc.h"
+#include "../dispatch/dispatch_ground_lidar.h"
 #include "../message/measure_message.pb.h"
 
 
@@ -153,6 +154,8 @@ public://member variable
 
 	//调度plc
 	Dispatch_plc								m_dispatch_plc;						//调度plc
+	Dispatch_ground_lidar						m_dispatch_ground_lidar[2];			//调度地面雷达
+
 
 	//请求指令的list, 按照创建顺序排序, 先来后到, 停车和停车不能插队, 但是停车和取车可以插队.
 	std::list<message::Dispatch_request_msg>				m_dispatch_request_store_list;					//存车请求指令的list, 内存由线程池管理

+ 2 - 2
system/system_executor.cpp

@@ -94,8 +94,8 @@ Error_manager System_executor::check_msg(Communication_message* p_msg)
 				//针对消息类型, 对消息进行二次解析
 				if (t_ground_status_msg.ParseFromString(p_msg->get_message_buf()))
 				{
-					int t_terminal_id = t_ground_status_msg.terminal_id();
-					if ( (t_terminal_id/2) == Dispatch_manager::get_instance_references().get_dispatch_manager_id() )
+					if ( t_ground_status_msg.terminal_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id()*2 ||
+					t_ground_status_msg.terminal_id() == Dispatch_manager::get_instance_references().get_dispatch_manager_id()*2+1)
 					{
 						return Error_code::SUCCESS;
 					}