From 92c572e50893a93a810bbe6adb6d3cdbfc225073 Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期二, 20 五月 2025 14:17:33 +0800
Subject: [PATCH] *
---
src/main/java/com/zy/core/thread/RgvThread.java | 146 +++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 129 insertions(+), 17 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/RgvThread.java b/src/main/java/com/zy/core/thread/RgvThread.java
index 386207f..365d9b9 100644
--- a/src/main/java/com/zy/core/thread/RgvThread.java
+++ b/src/main/java/com/zy/core/thread/RgvThread.java
@@ -14,6 +14,7 @@
import com.zy.asrs.service.BasRgvService;
import com.zy.asrs.utils.RouteUtils;
import com.zy.asrs.utils.TrackRangeUtils;
+import com.zy.core.DevpThread;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.*;
import com.zy.core.enums.RgvModeType;
@@ -25,6 +26,7 @@
import com.zy.core.model.command.RgvCommand;
import com.zy.core.model.protocol.RgvProtocol;
import com.zy.core.model.protocol.RgvTaskProtocol;
+import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.model.protocol.TaskProtocol;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -48,7 +50,7 @@
// private RgvProtocol rgvProtocol;
private TaskProtocolCache taskProtocolCache = new TaskProtocolCache();
// # 杞ㄩ亾鎬婚暱
- private Long trackEntireLength = 215000L;
+ private Long trackEntireLength = 224000L;
//# 杞ㄩ亾鍩哄噯鐐�
private Long trackBenchmark = 1L;
// # 閬胯璺濈
@@ -63,6 +65,9 @@
*/
private boolean resetFlag2 = false;
+ private boolean connectRgv = false;
+ private boolean delRgvTask = false;
+
public RgvThread(RgvSlave slave) {
this.slave = slave;
}
@@ -70,21 +75,48 @@
@Override
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
- boolean connect = this.connect();
- if (connect) {
+ connectRgv = this.connect();
+ while(!connectRgv){
+ try {
+ connectRgv = this.connect();
+ Thread.sleep(100);
+ } catch (Exception e){
- // 鍚姩璇绘暟鎹嚎绋�
- new Thread(this::readStatusRgv).start();
+ }
+ }
- // 鍚姩浠诲姟涓嬪彂绾跨▼
- new Thread(this::taskIssued).start();
+ // 鍚姩璇绘暟鎹嚎绋�
+ new Thread(this::rgvConnect).start();
- // 鍚姩婕父绾跨▼
- new Thread(this::taskWalkIssued).start();
- new Thread(this::taskWalkIssued2).start();
+ new Thread(this::readStatusRgv).start();
- // 鍚姩浠诲姟瀹屾垚绾跨▼
- new Thread(this::taskComplete).start();
+ // 鍚姩浠诲姟涓嬪彂绾跨▼
+ new Thread(this::taskIssued).start();
+
+ // 鍚姩婕父绾跨▼
+ new Thread(this::taskWalkIssued).start();
+ new Thread(this::taskWalkIssued2).start();
+
+ // 鍚姩浠诲姟瀹屾垚绾跨▼
+ new Thread(this::taskComplete).start();
+ }
+
+ private void rgvConnect() {
+ while (true) {
+ try {
+ if(!connectRgv){
+ try {
+ connectRgv = this.connect();
+ Thread.sleep(100);
+ } catch (Exception e){
+
+ }
+ }
+ } catch (Exception e) {
+ log.error("RGV鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛�" + e.getMessage());
+ initRgv();
+// e.printStackTrace();
+ }
}
}
@@ -111,6 +143,11 @@
private void taskComplete() {
while (true) {
try {
+ if (delRgvTask){
+ writeDelRgvTask();
+ delRgvTask = false;
+ continue;
+ }
Thread.sleep(100);
OperateResultExOne<byte[]> result = siemensNet.Read("DB100.12", (short) 1);
boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, 0, 1);
@@ -170,7 +207,6 @@
taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
break;
} else {
- Thread.sleep(100);
TaskProtocol issued = new TaskProtocol(taskProtocol,true);
write(issued);
taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
@@ -255,6 +291,21 @@
for (TaskProtocol taskProtocol : allTakeTaskProtocol) {
if (taskProtocol.getIsRunning() == 1) {//鍑嗗涓嬪彂
// RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId());
+ if (taskProtocol.getTaskStatus()==3){
+ DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, taskProtocol.getTargetPositionStaNoPlcId());
+ StaProtocol staProtocol = devpThread.getStation().get(taskProtocol.getTargetPositionStaNo());
+ if (staProtocol == null ) {
+ continue;
+ }
+ // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
+ if (!staProtocol.isAutoing() || staProtocol.isLoading()
+ || staProtocol.getWorkNo() != 0
+ ){
+ Thread.sleep(500);
+// System.out.println("<鏀捐揣鐩爣绔�>" + taskProtocol.getTargetPositionStaNo() + "<闈炶嚜鍔ㄦ垨鑰呮湁鐗╂垨鑰呭瓨鍦ㄥ伐浣滃彿锛侊紒锛�>");
+// continue;
+ }
+ }
//鍙岃溅
if (rgvOtherStatusEnable()) {
//鍙︿竴鍙拌溅鏄惁鍏佽姝ゅ彴杞︽墽琛�
@@ -264,13 +315,26 @@
}
if (taskProtocol.getTargetPosition()<=rgvProtocol.getRgvPos()+50
&& taskProtocol.getTargetPosition()>=rgvProtocol.getRgvPos()-50){
- Thread.sleep(100);
+ if (taskProtocol.getTaskStatus()==3){
+ DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, taskProtocol.getTargetPositionStaNoPlcId());
+ StaProtocol staProtocol = devpThread.getStation().get(taskProtocol.getTargetPositionStaNo());
+ if (staProtocol == null ) {
+ continue;
+ }
+ // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
+ if (!staProtocol.isAutoing() || staProtocol.isLoading()
+ || staProtocol.getWorkNo() != 0
+ ){
+ Thread.sleep(500);
+// System.out.println("<鏀捐揣鐩爣绔�>" + taskProtocol.getTargetPositionStaNo() + "<闈炶嚜鍔ㄦ垨鑰呮湁鐗╂垨鑰呭瓨鍦ㄥ伐浣滃彿锛侊紒锛�>");
+ continue;
+ }
+ }
TaskProtocol issued = new TaskProtocol(taskProtocol);
write(issued);
taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
break;
} else {
- Thread.sleep(100);
TaskProtocol issued = new TaskProtocol(taskProtocol,true);
write(issued);
break;
@@ -378,7 +442,7 @@
> avoidDistance) {//鏃犻渶閬胯
return true;
} else {
- if (rgvProtocolOther.getRgvPosDestination() >= rgvProtocolOther.getRgvPos()) {
+ if (rgvProtocolOther.getRgvPosDestination() >= rgvProtocolOther.getRgvPos()-50) {
long avoid = rgvProtocolOther.getRgvPos() - rgvProtocolOther.getCarBodyJiaoMing() - avoidDistance - rgvProtocol.getCarBodyKunPeng();
if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) {
log.error("琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛佷换鍔″紓甯� 鑱旂郴绠$悊鍛橈紒锛侊紒");
@@ -450,7 +514,7 @@
> avoidDistance) {//鏃犻渶閬胯
return true;
} else {
- if (rgvProtocolOther.getRgvPosDestination() <= rgvProtocolOther.getRgvPos()) {
+ if (rgvProtocolOther.getRgvPosDestination() <= rgvProtocolOther.getRgvPos() + 50) {
long avoid = rgvProtocolOther.getRgvPos() + rgvProtocolOther.getCarBodyKunPeng() + avoidDistance + rgvProtocol.getCarBodyJiaoMing();
if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) {
log.error("琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛佷换鍔″紓甯� 鑱旂郴绠$悊鍛橈紒锛侊紒");
@@ -618,6 +682,7 @@
} else {
initRgv();
+ connectRgv = false;
// OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆戣鍙朢GV plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
log.error("璇诲彇RGV plc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
}
@@ -695,6 +760,53 @@
}
}
+ private boolean writeDelRgvTask() throws InterruptedException {
+//
+ OperateResult result = siemensNet.Write("DB100.12.0", false);
+ OperateResult result0 = siemensNet.Write("DB100.0", (int) 0);
+ OperateResult result1 = siemensNet.Write("DB100.4", (short) 0);
+ OperateResult result2 = siemensNet.Write("DB100.6", (int) 0);
+ OperateResult result3 = siemensNet.Write("DB100.10", (short) 0); // 鎵ц鏂瑰悜锛堥潰鏈濊建閬� 瀹氫綅鍊煎乏灏忓彸澶э級 true:宸� false:鍙�
+
+ try {
+ // 鏃ュ織璁板綍
+ BasRgvOptService bean = SpringUtils.getBean(BasRgvOptService.class);
+ BasRgvOpt basRgvOpt = new BasRgvOpt(
+ 0,
+ 0,
+ slave.getId(),
+ new Date(),
+ String.valueOf(0),
+ null,
+ null,
+ null,
+ result.IsSuccess ? 1 : 0,
+ null,
+ new Date(),
+ null
+ );
+ bean.insert(basRgvOpt);
+ } catch (Exception ignore) {
+ }
+
+ if (result != null && result.IsSuccess) {
+ Thread.sleep(200);
+ this.readStatus();
+ log.info("RGV 鍛戒护涓嬪彂[id:{}] >>>>> {}", slave.getId(), JSON.toJSON("null"));
+ OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON("null")));
+ return true;
+ } else {
+ OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆戝啓鍏GV plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+ log.error("鍐欏叆RGV plc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ return false;
+ }
+ }
+
+
+ public void setDelRgvTask() {
+ delRgvTask = true;
+ }
+
@Override
public void close() {
siemensNet.ConnectClose();
--
Gitblit v1.9.1