From 763863395f8c2174cd754ba04d3561d32e29d066 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期日, 07 四月 2024 08:17:50 +0800
Subject: [PATCH] #
---
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java | 645 ++++++++++++++++++++++++++++++----------------------------
1 files changed, 330 insertions(+), 315 deletions(-)
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
index 19a0fed..fc451d3 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ShuttleCommandService.java
@@ -1,134 +1,190 @@
-//package com.zy.asrs.wcs.core.kernel.command;
+package com.zy.asrs.wcs.core.kernel.command;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zy.asrs.framework.common.Cools;
+import com.zy.asrs.framework.exception.CoolException;
+import com.zy.asrs.wcs.core.action.LiftAction;
+import com.zy.asrs.wcs.core.action.ShuttleAction;
+import com.zy.asrs.wcs.core.entity.Loc;
+import com.zy.asrs.wcs.core.model.NavigateNode;
+import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand;
+import com.zy.asrs.wcs.core.model.command.ShuttleCommand;
+import com.zy.asrs.wcs.core.model.enums.*;
+import com.zy.asrs.wcs.core.service.BasShuttleService;
+import com.zy.asrs.wcs.core.service.LocService;
+import com.zy.asrs.wcs.core.service.TaskService;
+import com.zy.asrs.wcs.core.utils.*;
+import com.zy.asrs.wcs.rcs.News;
+import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
+import com.zy.asrs.wcs.core.entity.Motion;
+import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType;
+import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
+import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
+import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
+import com.zy.asrs.wcs.core.service.MotionService;
+import com.zy.asrs.wcs.rcs.thread.LiftThread;
+import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * Created by vincent on 2023/10/23
+ */
+@Slf4j
+@Service
+public class ShuttleCommandService {
+
+ public static final Integer SHUTTLE_ADDITION_COMMAND_SPEED = 500;
+
+ @Autowired
+ private RedisUtil redisUtil;
+ @Autowired
+ private MotionService motionService;
+ @Autowired
+ private TaskService taskService;
+ @Autowired
+ private BasShuttleService basShuttleService;
+ @Autowired
+ private LocService locService;
+ @Autowired
+ private NavigateMapUtils navigateMapUtils;
+ @Autowired
+ private ShuttleAction shuttleAction;
+ @Autowired
+ private LiftAction liftAction;
+
+ // 璁$畻
+ public Boolean accept(Motion motion) {
+ Integer deviceNo = Integer.parseInt(motion.getDevice());
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceNo);
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (null == shuttleProtocol) {
+ return false;
+ }
+ if (!shuttleProtocol.getIdle()) {//璁惧涓嶇┖闂�
+ return false;
+ }
+ if (!shuttleProtocol.getPakMk()) {
+ return false;
+ }
+ if (motionService.count(new LambdaQueryWrapper<Motion>()
+ .eq(Motion::getDeviceCtg, DeviceCtgType.SHUTTLE.val())
+ .eq(Motion::getDevice, motion.getDevice())
+ .eq(Motion::getMotionSts, MotionStsType.EXECUTING.val())) > 0) {
+ return false;
+ }
+
+ ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
+ assignCommand.setShuttleNo(deviceNo);
+ assignCommand.setTaskNo(motion.getWrkNo());
+ assignCommand.setSourceLocNo(motion.getOrigin());
+ assignCommand.setLocNo(motion.getTarget());
+
+ List<ShuttleCommand> shuttleCommands = new ArrayList<>();
+ ShuttleTaskModeType shuttleTaskModeType = null;
+
+ LiftThread liftThread = null;
+ LiftProtocol liftProtocol = null;
+
+ //鍒ゆ柇灏忚溅鐘舵��
+ if (shuttleProtocol.getIdle()
+ && shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.IDLE)
+ && shuttleProtocol.getTaskNo() != 0
+ ) {
+ return false;
+ }
+
+ switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){
+ case SHUTTLE_MOVE:
+ // 濡傛灉宸茬粡鍦ㄥ綋鍓嶆潯鐮佸垯杩囨护
+ if (String.valueOf(shuttleProtocol.getCurrentCode()).equals(locService.getOne(new LambdaQueryWrapper<Loc>()
+ .eq(Loc::getLocNo, motion.getTarget())
+ .eq(Loc::getHostId, motion.getHostId())).getCode())) {
+ return true;
+ }
+ shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
+ shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
+ break;
+ case SHUTTLE_MOVE_LIFT_PALLET://绌挎杞﹂《鍗囧苟绉诲姩
+ shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
+ shuttleTaskModeType = ShuttleTaskModeType.PAK_IN;
+ shuttleCommands.add(0, shuttleThread.getLiftCommand(motion.getWrkNo(), true));
+ break;
+ case SHUTTLE_MOVE_DOWN_PALLET://绌挎杞︾Щ鍔ㄥ苟鎵樼洏涓嬮檷
+ shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
+ shuttleTaskModeType = ShuttleTaskModeType.PAK_IN;
+ shuttleCommands.add(shuttleCommands.size(), shuttleThread.getLiftCommand(motion.getWrkNo(), false));
+ break;
+ case SHUTTLE_MOVE_FROM_LIFT://鍑烘彁鍗囨満
+ // 鍒ゆ柇鎻愬崌鏈虹姸鎬�
+ liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp()));
+ if (liftThread == null) {
+ return false;
+ }
+
+ liftProtocol = liftThread.getStatus();
+ if (liftProtocol == null) {
+ return false;
+ }
+
+ // 鍒ゆ柇鎻愬崌鏈烘槸鍚︾┖闂�
+ if (!liftThread.isIdle()) {
+ return false;
+ }
+
+ if (liftProtocol.getLev() != Utils.getLev(motion.getTarget())) {//鍒ゆ柇鎻愬崌鏈烘槸鍚﹁揪鍒扮洰鏍囧眰
+ return false;
+ }
+
+// //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
+// if (!liftProtocol.getLock()) {
+// //閿佸畾鎻愬崌鏈�
+// LiftCommand lockCommand = liftThread.getLockCommand(motion.getWrkNo(), true);//鑾峰彇鎻愬崌鏈洪攣瀹氬懡浠�
//
-//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-//import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand;
-//import com.zy.asrs.wcs.core.model.command.ShuttleCommand;
-//import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
-//import com.zy.asrs.wcs.core.model.enums.MotionStsType;
-//import com.zy.asrs.wcs.core.service.BasShuttleService;
-//import com.zy.asrs.wcs.core.service.LocService;
-//import com.zy.asrs.wcs.core.service.TaskService;
-//import com.zy.asrs.wcs.core.utils.NavigateMapUtils;
-//import com.zy.asrs.wcs.core.utils.RedisUtil;
-//import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
-//import com.zy.asrs.wcs.rcs.entity.Motion;
-//import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
-//import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
-//import com.zy.asrs.wcs.rcs.service.MotionService;
-//import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
-//import lombok.extern.slf4j.Slf4j;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.stereotype.Service;
+// LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
+// liftAssignCommand.setLiftNo(liftThread.getStatus().getLiftNo());
+// liftAssignCommand.setTaskNo(motion.getWrkNo());
+// ArrayList<LiftCommand> list = new ArrayList<>();
+// list.add(lockCommand);
+// liftAssignCommand.setCommands(list);
//
-//import java.util.ArrayList;
-//import java.util.List;
-//import java.util.Objects;
-//import java.util.Optional;
-//
-///**
-// * Created by vincent on 2023/10/23
-// */
-//@Slf4j
-//@Service
-//public class ShuttleCommandService {
-//
-// public static final Integer SHUTTLE_ADDITION_COMMAND_SPEED = 500;
-//
-// @Autowired
-// private RedisUtil redisUtil;
-// @Autowired
-// private MotionService motionService;
-// @Autowired
-// private TaskService taskService;
-// @Autowired
-// private BasShuttleService basShuttleService;
-// @Autowired
-// private LocService locService;
-// @Autowired
-// private NavigateMapUtils navigateMapUtils;
-//
-// // 璁$畻
-// public Boolean accept(Motion motion) {
-// Integer deviceNo = Integer.parseInt(motion.getDevice());
-// ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceNo);
-// ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
-// if (null == shuttleProtocol) {
-// return false;
-// }
-// if (!shuttleProtocol.getIdle()) {//璁惧涓嶇┖闂�
-// return false;
-// }
-// if (!shuttleProtocol.getPakMk()) {
-// return false;
-// }
-// if (motionService.count(new LambdaQueryWrapper<Motion>()
-// .eq(Motion::getDeviceCtg, DeviceCtgType.SHUTTLE.val())
-// .eq(Motion::getDevice, motion.getDevice())
-// .eq(Motion::getMotionSts, MotionStsType.EXECUTING.val())) > 0) {
-// return false;
-// }
-//
-// ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
-// assignCommand.setShuttleNo(deviceNo.shortValue());
-// assignCommand.setTaskNo(motion.getWrkNo().shortValue());
-// assignCommand.setSourceLocNo(motion.getOrigin());
-// assignCommand.setLocNo(motion.getTarget());
-//
-// List<ShuttleCommand> shuttleCommands = new ArrayList<>();
-// ShuttleTaskModeType shuttleTaskModeType = null;
-//
-// SiemensLiftThread liftThread = null;
-// LiftProtocol liftProtocol = null;
-//
-// //鍒ゆ柇灏忚溅鐘舵��
-// if (shuttleProtocol.getBusyStatusType().equals(ShuttleStatusType.IDLE)
-// && shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.IDLE)
-// && shuttleProtocol.getTaskNo().intValue() != 0
-// ) {
-// return false;
-// }
-//
-// switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){
-// case SHUTTLE_MOVE:
-// // 濡傛灉宸茬粡鍦ㄥ綋鍓嶆潯鐮佸垯杩囨护
-// if (String.valueOf(shuttleProtocol.getCurrentCode()).equals(locMastService.selectById(motion.getTarget()).getQrCodeValue())) {
-// return true;
+// liftAction.assignWork(liftThread.getDevice(), liftAssignCommand);
+// return false;//绛夊緟涓嬩竴娆¤疆璇�
// }
-// shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
-// shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
-// break;
-// case SHUTTLE_MOVE_LIFT_PALLET://绌挎杞﹂《鍗囧苟绉诲姩
-// shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
-// shuttleTaskModeType = ShuttleTaskModeType.PAK_IN;
-// shuttleCommands.add(0, shuttleThread.getPalletCommand((short) 1));
-// break;
-// case SHUTTLE_MOVE_DOWN_PALLET://绌挎杞︾Щ鍔ㄥ苟鎵樼洏涓嬮檷
-// shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.DFX.id, assignCommand, shuttleThread);
-// shuttleTaskModeType = ShuttleTaskModeType.PAK_IN;
-// shuttleCommands.add(shuttleCommands.size(), shuttleThread.getPalletCommand((short) 2));
-// break;
-// case SHUTTLE_MOVE_FROM_LIFT://鍑烘彁鍗囨満
-// // 鍒ゆ柇鎻愬崌鏈虹姸鎬�
-// liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp()));
-// if (liftThread == null) {
-// return false;
-// }
-// liftProtocol = liftThread.getLiftProtocol();
-// // 鍒ゆ柇鎻愬崌鏈烘槸鍚﹁嚜鍔ㄣ�佺┖闂层�佸噯澶囧氨缁�侀摼鏉℃病鏈夎浆鍔ㄣ�佹病鏈夋湭灏辩华鎶ラ敊
-// if (!liftProtocol.getMode()
-// || liftProtocol.getRunning()
-// || !liftProtocol.getReady()
-// || liftProtocol.getForwardRotationFeedback()
-// || liftProtocol.getReverseFeedback()
-// || liftProtocol.getNotReady().intValue() != 0
-// ) {
-// return false;
-// }
-//
-// if (liftProtocol.getLev().intValue() != Utils.getLev(motion.getTarget())) {//鍒ゆ柇鎻愬崌鏈烘槸鍚﹁揪鍒扮洰鏍囧眰
-// return false;
-// }
-//
+
+ //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
+ if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) {
+ return false;
+ }
+
+ shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
+ shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
+ break;
+ case SHUTTLE_MOVE_TO_LIFT://杩涙彁鍗囨満
+ // 鍒ゆ柇鎻愬崌鏈虹姸鎬�
+ liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp()));
+ if (liftThread == null) {
+ return false;
+ }
+ liftProtocol = liftThread.getStatus();
+ if (liftProtocol == null) {
+ return false;
+ }
+ // 鍒ゆ柇鎻愬崌鏈烘槸鍚︾┖闂�
+ if (!liftThread.isIdle()) {
+ return false;
+ }
+
+ if (liftProtocol.getLev() != Utils.getLev(motion.getTarget())) {//鍒ゆ柇鎻愬崌鏈烘槸鍚﹁揪鍒扮洰鏍囧眰
+ return false;
+ }
+
// //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
// if (!liftProtocol.getLiftLock()) {
// //閿佸畾鎻愬崌鏈�
@@ -138,55 +194,15 @@
// liftThread.assignWork(lockCommand);
// return false;//绛夊緟涓嬩竴娆¤疆璇�
// }
-//
-// //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
-// if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) {
-// return false;
-// }
-//
-// shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
-// shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
-// break;
-// case SHUTTLE_MOVE_TO_LIFT://杩涙彁鍗囨満
-// // 鍒ゆ柇鎻愬崌鏈虹姸鎬�
-// liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getTemp()));
-// if (liftThread == null) {
-// return false;
-// }
-// liftProtocol = liftThread.getLiftProtocol();
-// // 鍒ゆ柇鎻愬崌鏈烘槸鍚﹁嚜鍔ㄣ�佺┖闂层�佸噯澶囧氨缁�侀摼鏉℃病鏈夎浆鍔ㄣ�佹病鏈夋湭灏辩华鎶ラ敊
-// if (!liftProtocol.getMode()
-// || liftProtocol.getRunning()
-// || !liftProtocol.getReady()
-// || liftProtocol.getForwardRotationFeedback()
-// || liftProtocol.getReverseFeedback()
-// || liftProtocol.getNotReady().intValue() != 0
-// ) {
-// return false;
-// }
-//
-// if (liftProtocol.getLev().intValue() != Utils.getLev(motion.getTarget())) {//鍒ゆ柇鎻愬崌鏈烘槸鍚﹁揪鍒扮洰鏍囧眰
-// return false;
-// }
-//
-// //鍒ゆ柇鎻愬崌鏈烘槸鍚﹁閿佸畾
-// if (!liftProtocol.getLiftLock()) {
-// //閿佸畾鎻愬崌鏈�
-// LiftCommand lockCommand = liftThread.getLockCommand(true);//鑾峰彇鎻愬崌鏈洪攣瀹氬懡浠�
-// lockCommand.setLiftNo(liftProtocol.getLiftNo());
-// lockCommand.setTaskNo(motion.getWrkNo().shortValue());//鑾峰彇浠诲姟鍙�
-// liftThread.assignWork(lockCommand);
-// return false;//绛夊緟涓嬩竴娆¤疆璇�
-// }
-//
-// //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
-// if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) {
-// return false;
-// }
-//
-// shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
-// shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
-// break;
+
+ //鍒ゆ柇鎻愬崌鏈哄伐浣滃彿鏄惁鍜屽綋鍓嶄换鍔$浉鍚�
+ if (liftProtocol.getTaskNo().intValue() != motion.getWrkNo()) {
+ return false;
+ }
+
+ shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
+ shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
+ break;
// case SHUTTLE_MOVE_FROM_CONVEYOR:
// shuttleCommands = this.shuttleAssignCommand(motion.getOrigin(), motion.getTarget(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
// shuttleTaskModeType = ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO;
@@ -345,76 +361,75 @@
// shuttleCommands.add(shuttleThread.getChargeSwitchCommand((short) 1));
// assignCommand.setCharge(Boolean.TRUE);
// break;
-// default:
-// throw new CoolException(motion.getMotionCtgEl() + "娌℃湁鎸囧畾浠诲姟浣滀笟娴佺▼锛侊紒锛�");
-// }
-//
-// if (Cools.isEmpty(shuttleCommands)) {
-// return false;
-// }
-//
-// assert null != shuttleTaskModeType;
-// assignCommand.setTaskMode(shuttleTaskModeType.id.shortValue());//鍏ュ嚭搴撴ā寮�
-// assignCommand.setCommands(shuttleCommands);
-//
-// if (motion.getOrigin() != null && motion.getTarget() != null) {
-// //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
-// boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), shuttleProtocol.getShuttleNo().intValue(), assignCommand.getNodes(), true);//鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
-// if (!lockResult) {
-// return false;//閿佸畾澶辫触
-// }
-// shuttleThread.assignWork(assignCommand);
-// }else {
-// shuttleThread.assignWork(assignCommand);
-// }
-//
-// return Boolean.TRUE;
-// }
-//
-// public Boolean finish(Motion motion) {
-// Integer deviceNo = Integer.parseInt(motion.getDevice());
-// ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceNo);
-// ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-// if (null == shuttleProtocol) {
-// return false;
-// }
-//
-// if (shuttleProtocol.getTaskNo() != 0 && shuttleProtocol.getTaskNo().intValue() != motion.getWrkNo()) {
-// return false;
-// }
-//
-// //鍏呯數浠诲姟
-// if (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl())).equals(MotionCtgType.SHUTTLE_CHARGE_ON)) {
-// // 澶嶄綅绌挎杞�
-// shuttleProtocol.setTaskNo((short) 0);
-// shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
-// shuttleProtocol.setPakMk(true);
-// return true;
-// }
-//
-// if (!shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.WAITING)
-// && !shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.CHARGING_WAITING)
-// ) {
-// return false;
-// }
-//
-// if (shuttleProtocol.getBusyStatusType().equals(ShuttleStatusType.BUSY)) {
-// return false;
-// }
-//
+ default:
+ throw new CoolException(motion.getMotionCtgEl() + "娌℃湁鎸囧畾浠诲姟浣滀笟娴佺▼锛侊紒锛�");
+ }
+
+ if (Cools.isEmpty(shuttleCommands)) {
+ return false;
+ }
+
+ assert null != shuttleTaskModeType;
+ assignCommand.setTaskMode(shuttleTaskModeType.id);//鍏ュ嚭搴撴ā寮�
+ assignCommand.setCommands(shuttleCommands);
+
+ if (motion.getOrigin() != null && motion.getTarget() != null) {
+ //鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
+ boolean lockResult = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(motion.getTarget()), shuttleProtocol.getShuttleNo(), assignCommand.getNodes(), true);//鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
+ if (!lockResult) {
+ return false;//閿佸畾澶辫触
+ }
+ }
+
+ boolean result = shuttleAction.assignWork(shuttleThread.getDevice(), assignCommand);
+ return result;
+ }
+
+ public Boolean finish(Motion motion) {
+ Integer deviceNo = Integer.parseInt(motion.getDevice());
+ ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceNo);
+ ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
+ if (null == shuttleProtocol) {
+ return false;
+ }
+
+ if (shuttleProtocol.getTaskNo() != 0 && shuttleProtocol.getTaskNo().intValue() != motion.getWrkNo()) {
+ return false;
+ }
+
+ //鍏呯數浠诲姟
+ if (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl())).equals(MotionCtgType.SHUTTLE_CHARGE_ON)) {
+ // 澶嶄綅绌挎杞�
+ shuttleProtocol.setTaskNo(0);
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+ shuttleProtocol.setPakMk(true);
+ return true;
+ }
+
+ if (!shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.WAITING)
+ && !shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.CHARGING_WAITING)
+ ) {
+ return false;
+ }
+
+ //鍒ゆ柇璁惧鏄惁绌洪棽
+ if (!shuttleThread.isIdle()) {
+ return false;
+ }
+
// SiemensLiftThread liftThread = null;
// LiftProtocol liftProtocol = null;
-//
-// switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){
-// case SHUTTLE_MOVE:
-// case SHUTTLE_MOVE_LIFT_PALLET:
-// case SHUTTLE_MOVE_DOWN_PALLET:
-// case SHUTTLE_MOVE_TO_CONVEYOR:
-// case SHUTTLE_MOVE_FROM_CONVEYOR:
-// if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) {
-// return false;
-// }
-// break;
+
+ switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){
+ case SHUTTLE_MOVE:
+ case SHUTTLE_MOVE_LIFT_PALLET:
+ case SHUTTLE_MOVE_DOWN_PALLET:
+ case SHUTTLE_MOVE_TO_CONVEYOR:
+ case SHUTTLE_MOVE_FROM_CONVEYOR:
+ if (!shuttleProtocol.getCurrentLocNo().equals(motion.getTarget())) {
+ return false;
+ }
+ break;
// case SHUTTLE_MOVE_TO_LIFT:
// case SHUTTLE_MOVE_FROM_LIFT:
// case SHUTTLE_TRANSPORT_FROM_LIFT:
@@ -451,73 +466,73 @@
// }
//
// break;
-// default:
-// break;
-// }
-//
-// // 澶嶄綅绌挎杞�
-// shuttleProtocol.setTaskNo((short) 0);
-// shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
-// shuttleProtocol.setPakMk(true);
-//
-// return true;
-// }
-//
-// public synchronized List<ShuttleCommand> shuttleAssignCommand(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
-// //鑾峰彇灏忚溅绉诲姩閫熷害
-// Integer runSpeed = Optional.ofNullable(basShuttleService.selectById(assignCommand.getShuttleNo()).getRunSpeed()).orElse(1000);
-//
-// List<NavigateNode> nodeList = NavigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(startLocNo)));
-// if (nodeList == null) {
-// News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo);
-// return null;
-// }
-// List<NavigateNode> allNode = new ArrayList<>(nodeList);
-//
-// List<ShuttleCommand> commands = new ArrayList<>();
-// //鑾峰彇鍒嗘璺緞
-// ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(nodeList);
-// //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
-// for (ArrayList<NavigateNode> nodes : data) {
-// //寮�濮嬭矾寰�
-// NavigateNode startPath = nodes.get(0);
-//
-// //涓棿璺緞
-// NavigateNode middlePath = null;
-// //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
-// Short middleCodeNum = null;
-// Integer middleToDistDistance = null;//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂�
-// if (nodes.size() > 10) {//涓鐮佷紶鍊掓暟绗笁涓�
-// //涓棿璺緞
-// middlePath = nodes.get(nodes.size() - 3);
-// //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
-// middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ());
-// middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂�
-// } else if (nodes.size() > 5) {//涓鐮佷紶鍊掓暟绗簩涓�
-// //涓棿璺緞
-// middlePath = nodes.get(nodes.size() - 2);
-// //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
-// middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ());
-// middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂�
-// }
-//
-// //鐩爣璺緞
-// NavigateNode endPath = nodes.get(nodes.size() - 1);
-// Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
-// //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
-// Short startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());
-// //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
-// Short distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());
-// //鑾峰彇绉诲姩鍛戒护
-// ShuttleCommand command = shuttleThread.getMoveCommand(startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id, middleCodeNum, middleToDistDistance, runSpeed);
-// command.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑
-// commands.add(command);
-// }
-//
-// assignCommand.setNodes(allNode);//褰撳墠浠诲姟鎵�鍗犵敤鐨勮妭鐐筶ist
-//
-// return commands;
-// }
-//
-//
-//}
+ default:
+ break;
+ }
+
+ // 澶嶄綅绌挎杞�
+ shuttleProtocol.setTaskNo(0);
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+ shuttleProtocol.setPakMk(true);
+
+ return true;
+ }
+
+ public synchronized List<ShuttleCommand> shuttleAssignCommand(String startLocNo, String endLocNo, Integer mapType, ShuttleAssignCommand assignCommand, ShuttleThread shuttleThread) {
+ //鑾峰彇灏忚溅绉诲姩閫熷害
+ Integer runSpeed = Optional.ofNullable(basShuttleService.getById(assignCommand.getShuttleNo()).getRunSpeed()).orElse(1000);
+ Long hostId = shuttleThread.getDevice().getHostId();
+ List<NavigateNode> nodeList = NavigateUtils.calc(startLocNo, endLocNo, mapType, Utils.getShuttlePoints(Integer.parseInt(shuttleThread.getDevice().getDeviceNo()), Utils.getLev(startLocNo)));
+ if (nodeList == null) {
+ News.error("{} dash {} can't find navigate path!", startLocNo, endLocNo);
+ return null;
+ }
+ List<NavigateNode> allNode = new ArrayList<>(nodeList);
+
+ List<ShuttleCommand> commands = new ArrayList<>();
+ //鑾峰彇鍒嗘璺緞
+ ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(nodeList);
+ //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
+ for (ArrayList<NavigateNode> nodes : data) {
+ //寮�濮嬭矾寰�
+ NavigateNode startPath = nodes.get(0);
+
+ //涓棿璺緞
+ NavigateNode middlePath = null;
+ //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
+ String middleCodeNum = null;
+ Integer middleToDistDistance = null;//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂�
+ if (nodes.size() > 10) {//涓鐮佷紶鍊掓暟绗笁涓�
+ //涓棿璺緞
+ middlePath = nodes.get(nodes.size() - 3);
+ //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
+ middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ(), hostId);
+ middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂�
+ } else if (nodes.size() > 5) {//涓鐮佷紶鍊掓暟绗簩涓�
+ //涓棿璺緞
+ middlePath = nodes.get(nodes.size() - 2);
+ //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
+ middleCodeNum = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ(), hostId);
+ middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//璁$畻涓棿鐐瑰埌鐩爣鐐硅璧拌窛绂�
+ }
+
+ //鐩爣璺緞
+ NavigateNode endPath = nodes.get(nodes.size() - 1);
+ Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+ //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
+ String startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ(), hostId);
+ //閫氳繃xy鍧愭爣灏忚溅浜岀淮鐮�
+ String distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ(), hostId);
+ //鑾峰彇绉诲姩鍛戒护
+ ShuttleCommand command = shuttleThread.getMoveCommand(assignCommand.getTaskNo().intValue(), startCodeNum, distCodeNum, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id.intValue(), runSpeed);
+ command.setNodes(nodes);//灏嗚璧拌妭鐐规坊鍔犲埌姣忎竴姝ュ懡浠や腑
+ commands.add(command);
+ }
+
+ assignCommand.setNodes(allNode);//褰撳墠浠诲姟鎵�鍗犵敤鐨勮妭鐐筶ist
+
+ return commands;
+ }
+
+
+}
--
Gitblit v1.9.1