From ddb1d3cc65d174d768912ee08f4d08d719c197d0 Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期日, 11 五月 2025 17:54:59 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/RgvThread.java | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 157 insertions(+), 16 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/RgvThread.java b/src/main/java/com/zy/core/thread/RgvThread.java
index 5c1f010..386207f 100644
--- a/src/main/java/com/zy/core/thread/RgvThread.java
+++ b/src/main/java/com/zy/core/thread/RgvThread.java
@@ -48,11 +48,11 @@
// private RgvProtocol rgvProtocol;
private TaskProtocolCache taskProtocolCache = new TaskProtocolCache();
// # 杞ㄩ亾鎬婚暱
- private Long trackEntireLength = 100L;
+ private Long trackEntireLength = 215000L;
//# 杞ㄩ亾鍩哄噯鐐�
- private Long trackBenchmark = 100L;
+ private Long trackBenchmark = 1L;
// # 閬胯璺濈
- private Long avoidDistance = 100L;
+ private Long avoidDistance = 5000L;
/**
* 宸ヤ綅1澶嶄綅淇″彿
@@ -81,9 +81,10 @@
// 鍚姩婕父绾跨▼
new Thread(this::taskWalkIssued).start();
+ new Thread(this::taskWalkIssued2).start();
// 鍚姩浠诲姟瀹屾垚绾跨▼
-// new Thread(this::taskComplete).start();
+ new Thread(this::taskComplete).start();
}
}
@@ -108,7 +109,80 @@
* 瀹屾垚
*/
private void taskComplete() {
+ while (true) {
+ try {
+ Thread.sleep(100);
+ OperateResultExOne<byte[]> result = siemensNet.Read("DB100.12", (short) 1);
+ boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, 0, 1);
+ if (status[0]){
+ OperateResult result4 = siemensNet.Write("DB100.12.0", false);
+ }
+ } catch (Exception e) {
+ log.error("RGV鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛�" + e.getMessage());
+ initRgv();
+// e.printStackTrace();
+ }
+ }
+
+ }
+
+ /**
+ * 浠诲姟涓嬪彂
+ */
+ private void taskWalkIssued2() {
+ while (true) {
+ try {
+ // 浼戠湢 1 绉�
+ Thread.sleep(100);
+ if (!deviceDetection()) {
+ continue;
+ }
+ RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId());
+ RgvTaskProtocol rgvTaskProtocol = RgvTaskCache.getRgvStatus(slave.getId());
+ if (rgvProtocol == null || rgvTaskProtocol == null) {
+ initRgv();
+ rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId());
+ rgvTaskProtocol = RgvTaskCache.getRgvStatus(slave.getId());
+ }
+ if (rgvTaskProtocol.getAvoid() != 0) {
+ continue;
+ }
+ if (!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE)){
+ continue;
+ }
+ if (rgvProtocol.getLoaded() == -1){
+ continue;
+ }
+
+ List<TaskProtocol> allTakeTaskProtocol = taskProtocolCache.getAllWalkTaskProtocol();
+ for (TaskProtocol taskProtocol : allTakeTaskProtocol) {
+ if (taskProtocol.getIsRunning() == 1) {//鍑嗗涓嬪彂
+ // 鍙岃溅
+ if (rgvOtherStatusEnable()) {
+ //鍙︿竴鍙拌溅鏄惁鍏佽姝ゅ彴杞︽墽琛�
+ if (!otherRgvAvoid(taskProtocol.getTargetPosition())) {
+ continue;
+ }
+ }
+ if (taskProtocol.getTargetPosition()<=rgvProtocol.getRgvPos()+50
+ && taskProtocol.getTargetPosition()>=rgvProtocol.getRgvPos()-50){
+ taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
+ break;
+ } else {
+ Thread.sleep(100);
+ TaskProtocol issued = new TaskProtocol(taskProtocol,true);
+ write(issued);
+ taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection());
+ break;
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.error("RGV鍙栬揣浠诲姟涓嬪彂绾跨▼寮傚父锛侊紒锛�" + e.getMessage());
+// e.printStackTrace();
+ }
+ }
}
/**
@@ -134,6 +208,8 @@
TaskProtocol issued = new TaskProtocol();
issued.setTaskNo(32222L);
issued.setTargetPosition(rgvTaskProtocol.getAvoidingTheDestination());
+ issued.setTaskStatus(1);
+ issued.setDirection(true);
write(issued);
rgvTaskProtocol.setAvoid(0);
@@ -168,11 +244,17 @@
if (rgvTaskProtocol.getAvoid() != 0) {
continue;
}
+ if (!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE)){
+ continue;
+ }
+ if (rgvProtocol.getLoaded() == -1){
+ continue;
+ }
List<TaskProtocol> allTakeTaskProtocol = taskProtocolCache.getTakeOrPutTaskProtocol(rgvProtocol.getLoaded());
for (TaskProtocol taskProtocol : allTakeTaskProtocol) {
if (taskProtocol.getIsRunning() == 1) {//鍑嗗涓嬪彂
- RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId());
+// RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId());
//鍙岃溅
if (rgvOtherStatusEnable()) {
//鍙︿竴鍙拌溅鏄惁鍏佽姝ゅ彴杞︽墽琛�
@@ -180,12 +262,19 @@
continue;
}
}
- Thread.sleep(100);
- TaskProtocol issued = new TaskProtocol(taskProtocol);
- write(issued);
- taskProtocol.setIsRunning(taskProtocol.getIsRunning() + 1);
- taskProtocolCache.updateTaskProtocol(taskProtocol);
- break;
+ if (taskProtocol.getTargetPosition()<=rgvProtocol.getRgvPos()+50
+ && taskProtocol.getTargetPosition()>=rgvProtocol.getRgvPos()-50){
+ Thread.sleep(100);
+ 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;
+ }
}
}
} catch (Exception e) {
@@ -254,6 +343,10 @@
log.error("琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛佷换鍔″紓甯� 鑱旂郴绠$悊鍛橈紒锛侊紒");
return false;
}
+ long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos());
+ if (avoidAbs<51){
+ return true;
+ }
rgvTaskProtocolOther.setAvoid(1);
rgvTaskProtocolOther.setAvoidingTheDestination(avoid);
RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther);
@@ -269,6 +362,10 @@
if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) {
log.error("琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛佷换鍔″紓甯� 鑱旂郴绠$悊鍛橈紒锛侊紒");
return false;
+ }
+ long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos());
+ if (avoidAbs<51){
+ return true;
}
rgvTaskProtocolOther.setAvoid(1);
rgvTaskProtocolOther.setAvoidingTheDestination(avoid);
@@ -287,12 +384,22 @@
log.error("琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛佷换鍔″紓甯� 鑱旂郴绠$悊鍛橈紒锛侊紒");
return false;
}
+ long avoidAbs = Math.abs(avoid - rgvProtocol.getRgvPos());
+ if (avoidAbs<51){
+ return false;
+ }
rgvTaskProtocol.setAvoid(1);
rgvTaskProtocol.setAvoidingTheDestination(avoid);
RgvTaskCache.updateRgvStatus(rgvTaskProtocol);
return false;
}
return false;
+ }
+ } else {
+ if ((rgvProtocolOther.getRgvPosDestinationOrPos(true) - rgvProtocolOther.getCarBodyJiaoMing())
+ - (targetPosition + rgvProtocol.getCarBodyKunPeng())
+ > avoidDistance) {//鏃犻渶閬胯
+ return true;
}
}
} else {
@@ -306,6 +413,10 @@
if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) {
log.error("琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛佷换鍔″紓甯� 鑱旂郴绠$悊鍛橈紒锛侊紒");
return false;
+ }
+ long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos());
+ if (avoidAbs<51){
+ return true;
}
rgvTaskProtocolOther.setAvoid(1);
rgvTaskProtocolOther.setAvoidingTheDestination(avoid);
@@ -322,6 +433,10 @@
if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) {
log.error("琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛佷换鍔″紓甯� 鑱旂郴绠$悊鍛橈紒锛侊紒");
return false;
+ }
+ long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos());
+ if (avoidAbs<51){
+ return true;
}
rgvTaskProtocolOther.setAvoid(1);
rgvTaskProtocolOther.setAvoidingTheDestination(avoid);
@@ -341,12 +456,22 @@
log.error("琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛佷换鍔″紓甯� 鑱旂郴绠$悊鍛橈紒锛侊紒");
return false;
}
+ long avoidAbs = Math.abs(avoid - rgvProtocol.getRgvPos());
+ if (avoidAbs<51){
+ return false;
+ }
rgvTaskProtocol.setAvoid(1);
rgvTaskProtocol.setAvoidingTheDestination(avoid);
RgvTaskCache.updateRgvStatus(rgvTaskProtocol);
return false;
}
return false;
+ }
+ } else {
+ if ((rgvProtocolOther.getRgvPosDestinationOrPos(false) - rgvProtocolOther.getCarBodyJiaoMing())
+ - (targetPosition + rgvProtocol.getCarBodyKunPeng())
+ > avoidDistance) {//鏃犻渶閬胯
+ return true;
}
}
}
@@ -390,7 +515,7 @@
rgvTaskProtocol = new RgvTaskProtocol();
rgvTaskProtocol.setRgvNo(slave.getId());
}
- rgvTaskProtocol.setAvoid(-1);
+ rgvTaskProtocol.setAvoid(0);
rgvTaskProtocol.setAvoidingTheDestination(0L);
RgvStatusCache.updateRgvStatus(rgvProtocol);
@@ -425,17 +550,22 @@
*/
private void readStatus() {
try {
- OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 18);
+ OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 19);
if (result.IsSuccess) {
// 鏋勫缓璁惧鐘舵�佸璞�
RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId());
if (rgvProtocol == null) {
rgvProtocol = new RgvProtocol();
- rgvProtocol.setRgvNo(slave.getId());
}
+ rgvProtocol.setRgvNo(slave.getId());
+ rgvProtocol.setCarBodyJiaoMing(slave.getCarBodyJiaoMing());
+ rgvProtocol.setCarBodyKunPeng(slave.getCarBodyKunPeng());
rgvProtocol.setRgvPos((long)siemensNet.getByteTransform().TransInt32(result.Content, 0));
rgvProtocol.setRgvPosDestination((long)siemensNet.getByteTransform().TransInt32(result.Content, 4));
+ if (rgvProtocol.getRgvPosDestination()==0L){
+ rgvProtocol.setRgvPosDestination(rgvProtocol.getRgvPos());
+ }
rgvProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 8));
rgvProtocol.setTaskNo((long)siemensNet.getByteTransform().TransInt32(result.Content, 10));
@@ -445,6 +575,10 @@
// rgvProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 28));
// rgvProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40));
// rgvProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48));
+
+// OperateResultExOne<byte[]> result11 = siemensNet.Read("DB100.12", (short) 1);
+ boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, 18, 1);
+ rgvProtocol.setLoaded(status[0]? (short)1:(short)0);
OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛", DateUtils.convert(new Date()), slave.getId()));
// // 宸ヤ綅1澶嶄綅淇″彿
@@ -506,14 +640,21 @@
// convertRow(command);
// taskProtocol.setRgvNo(slave.getId());
Long[] array = new Long[11];
+ OperateResult result41 = siemensNet.Write("DB100.12.0", false);
+
// array[0] = taskProtocol.getAckFinish1();
// array[1] = taskProtocol.getTaskNo();
// array[2] = taskProtocol.getTaskMode();
// array[4] = command.getDestinationStaNo();
// array[10] = taskProtocol.getCommand();
- OperateResult result = siemensNet.Write("DB100.0", taskProtocol.getTaskNo());
- OperateResult result1 = siemensNet.Write("DB100.1", taskProtocol.isDirection()); // 鎵ц鏂瑰悜锛堥潰鏈濊建閬� 瀹氫綅鍊煎乏灏忓彸澶э級 true:宸� false:鍙�
+ int taskStatus = taskProtocol.getTaskStatus();
+ OperateResult result = siemensNet.Write("DB100.0", taskProtocol.getTargetPosition().intValue());
+ OperateResult result1 = siemensNet.Write("DB100.4", (short) taskStatus);
+ OperateResult result2 = siemensNet.Write("DB100.6", taskProtocol.getTaskNo().intValue());
+ OperateResult result3 = siemensNet.Write("DB100.10", taskProtocol.isDirection()? (short) 1 : (short) 2); // 鎵ц鏂瑰悜锛堥潰鏈濊建閬� 瀹氫綅鍊煎乏灏忓彸澶э級 true:宸� false:鍙�
+
+ OperateResult result4 = siemensNet.Write("DB100.12.0", true);
// if (taskProtocol.getAckFinish1() == 0) {
// short commandFinish = 3; //宸ヤ綅1銆�2浠诲姟鍚屾椂鍐欏叆
// Thread.sleep(100L);
--
Gitblit v1.9.1