|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.service.BasShuttleOptService; | 
|---|
|  |  |  | import com.zy.asrs.service.BasShuttleService; | 
|---|
|  |  |  | import com.zy.asrs.service.LocMastService; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.common.model.NavigateNode; | 
|---|
|  |  |  | import com.zy.common.utils.CommonUtils; | 
|---|
|  |  |  | import com.zy.common.utils.NavigatePositionConvert; | 
|---|
|  |  |  | import com.zy.common.utils.NavigateUtils; | 
|---|
|  |  |  | import com.zy.common.utils.RedisUtil; | 
|---|
|  |  |  | import com.zy.common.utils.*; | 
|---|
|  |  |  | import com.zy.core.News; | 
|---|
|  |  |  | import com.zy.core.ThreadHandler; | 
|---|
|  |  |  | import com.zy.core.cache.MessageQueue; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (shuttleProtocol.getErrorCode() != 0 && shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.WORKING) { | 
|---|
|  |  |  | //出现错误 | 
|---|
|  |  |  | reset(shuttleProtocol.getAssignCommand()); | 
|---|
|  |  |  | resetAndTryFix(shuttleProtocol.getTaskNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.FIXING | 
|---|
|  |  |  | 
|---|
|  |  |  | //检测是否有提升机锁定标记,有则检测提升机是否到位,是否能走下一步命令 | 
|---|
|  |  |  | if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE | 
|---|
|  |  |  | && shuttleProtocol.getTaskNo() != 0) { | 
|---|
|  |  |  | Object o = redisUtil.get("wrk_no_" + shuttleProtocol.getTaskNo()); | 
|---|
|  |  |  | Object o = redisUtil.get("shuttle_wrk_no_" + shuttleProtocol.getTaskNo()); | 
|---|
|  |  |  | if (o != null) { | 
|---|
|  |  |  | ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); | 
|---|
|  |  |  | if (redisCommand.getLiftSecurityMk()) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //将四向穿梭车状态保存至数据库 | 
|---|
|  |  |  | BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); | 
|---|
|  |  |  | BasShuttle basShuttle = shuttleService.selectById(shuttleProtocol.getShuttleNo()); | 
|---|
|  |  |  | BasShuttle basShuttle = shuttleService.selectById(slave.getId()); | 
|---|
|  |  |  | if (basShuttle == null) { | 
|---|
|  |  |  | basShuttle = new BasShuttle(); | 
|---|
|  |  |  | //四向穿梭车号 | 
|---|
|  |  |  | 
|---|
|  |  |  | //分配任务 | 
|---|
|  |  |  | private void assignWork(ShuttleAssignCommand assignCommand) { | 
|---|
|  |  |  | if (!assignCommand.getAuto()) { | 
|---|
|  |  |  | List<NavigateNode> allNode = new ArrayList<>(); | 
|---|
|  |  |  | List<ShuttleCommand> commands = new ArrayList<>(); | 
|---|
|  |  |  | ShuttleCommand command = new ShuttleCommand(); | 
|---|
|  |  |  | LocMastService locMastService = SpringUtils.getBean(LocMastService.class); | 
|---|
|  |  |  | NavigateMapData navigateMapData; | 
|---|
|  |  |  | switch (assignCommand.getTaskMode()) { | 
|---|
|  |  |  | case 1://入库 | 
|---|
|  |  |  | case 2://出库 | 
|---|
|  |  |  | 
|---|
|  |  |  | //计算小车起点到中点所需命令 | 
|---|
|  |  |  | LocMast currentLocMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString()); | 
|---|
|  |  |  | List<NavigateNode> firstMastResult = NavigateUtils.calc(currentLocMast.getLocNo(), assignCommand.getSourceLocNo(), ShuttleTaskModeType.PAK_IN.id); | 
|---|
|  |  |  | //所使用的路径进行锁定禁用 | 
|---|
|  |  |  | navigateMapData = new NavigateMapData(Utils.getLev(currentLocMast.getLocNo())); | 
|---|
|  |  |  | navigateMapData.writeNavigateNodeToRedisMap(firstMastResult, true);////所使用的路径进行锁定禁用 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (firstMastResult != null) { | 
|---|
|  |  |  | allNode.addAll(firstMastResult);//将节点进行保存 | 
|---|
|  |  |  | //获取分段路径 | 
|---|
|  |  |  | ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(firstMastResult); | 
|---|
|  |  |  | //将每一段路径分成command指令 | 
|---|
|  |  |  | 
|---|
|  |  |  | NavigateNode endPath = nodes.get(nodes.size() - 1); | 
|---|
|  |  |  | Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleCommand command1 = new ShuttleCommand(); | 
|---|
|  |  |  | command1.setCommandWord((short) 1); | 
|---|
|  |  |  | command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1)); | 
|---|
|  |  |  | command1.setMiddleCodeNum((short) 1); | 
|---|
|  |  |  | command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1)); | 
|---|
|  |  |  | command1.setStartToDistDistance(allDistance); | 
|---|
|  |  |  | command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id); | 
|---|
|  |  |  | command1.setForceMoveDistance(0); | 
|---|
|  |  |  | command1.setIOControl((short) 0); | 
|---|
|  |  |  | command1.setRunSpeed((short) 1000); | 
|---|
|  |  |  | command1.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command1); | 
|---|
|  |  |  | //正常移动命令 | 
|---|
|  |  |  | Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1);//开始二维码 | 
|---|
|  |  |  | Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1);//目标二维码 | 
|---|
|  |  |  | commands.add(getMoveCommand(startCode,distCode,allDistance,ShuttleRunDirection.get(startPath.getDirection()).id)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //托盘顶升 | 
|---|
|  |  |  | ShuttleCommand command2 = new ShuttleCommand(); | 
|---|
|  |  |  | command2.setCommandWord((short) 2); | 
|---|
|  |  |  | command2.setStartCodeNum((short) 0); | 
|---|
|  |  |  | command2.setMiddleCodeNum((short) 0); | 
|---|
|  |  |  | command2.setDistCodeNum((short) 0); | 
|---|
|  |  |  | command2.setStartToDistDistance(0); | 
|---|
|  |  |  | command2.setMiddleToDistDistance(0); | 
|---|
|  |  |  | command2.setRunDirection((short) 0); | 
|---|
|  |  |  | command2.setForceMoveDistance(0); | 
|---|
|  |  |  | command2.setPalletLift((short) 1); | 
|---|
|  |  |  | command2.setRunSpeed((short) 0); | 
|---|
|  |  |  | command2.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command2); | 
|---|
|  |  |  | commands.add(getPalletCommand((short) 1)); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | //没有计算到路径,可能存在小车位置就是起点位置 | 
|---|
|  |  |  | if (currentLocMast.getLocNo().equals(assignCommand.getSourceLocNo())) { | 
|---|
|  |  |  | //小车位置就是起点位置,无需移动,直接顶升 | 
|---|
|  |  |  | //托盘顶升 | 
|---|
|  |  |  | ShuttleCommand command2 = new ShuttleCommand(); | 
|---|
|  |  |  | command2.setCommandWord((short) 2); | 
|---|
|  |  |  | command2.setStartCodeNum((short) 0); | 
|---|
|  |  |  | command2.setMiddleCodeNum((short) 0); | 
|---|
|  |  |  | command2.setDistCodeNum((short) 0); | 
|---|
|  |  |  | command2.setStartToDistDistance(0); | 
|---|
|  |  |  | command2.setMiddleToDistDistance(0); | 
|---|
|  |  |  | command2.setRunDirection((short) 0); | 
|---|
|  |  |  | command2.setForceMoveDistance(0); | 
|---|
|  |  |  | command2.setPalletLift((short) 1); | 
|---|
|  |  |  | command2.setRunSpeed((short) 0); | 
|---|
|  |  |  | command2.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command2); | 
|---|
|  |  |  | commands.add(getPalletCommand((short) 1)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //计算中点到终点路径 | 
|---|
|  |  |  | List<NavigateNode> secMastResult = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id); | 
|---|
|  |  |  | navigateMapData.writeNavigateNodeToRedisMap(firstMastResult, true);////所使用的路径进行锁定禁用 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (secMastResult != null) { | 
|---|
|  |  |  | allNode.addAll(secMastResult);//将节点进行保存 | 
|---|
|  |  |  | //获取分段路径 | 
|---|
|  |  |  | ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(secMastResult); | 
|---|
|  |  |  | //将每一段路径分成command指令 | 
|---|
|  |  |  | 
|---|
|  |  |  | NavigateNode endPath = nodes.get(nodes.size() - 1); | 
|---|
|  |  |  | Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleCommand command1 = new ShuttleCommand(); | 
|---|
|  |  |  | command1.setCommandWord((short) 1); | 
|---|
|  |  |  | command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1)); | 
|---|
|  |  |  | command1.setMiddleCodeNum((short) 1); | 
|---|
|  |  |  | command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1)); | 
|---|
|  |  |  | command1.setStartToDistDistance(allDistance); | 
|---|
|  |  |  | command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id); | 
|---|
|  |  |  | command1.setForceMoveDistance(0); | 
|---|
|  |  |  | command1.setIOControl((short) 0); | 
|---|
|  |  |  | command1.setRunSpeed((short) 1000); | 
|---|
|  |  |  | command1.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command1); | 
|---|
|  |  |  | //正常移动命令 | 
|---|
|  |  |  | Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1);//开始二维码 | 
|---|
|  |  |  | Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1);//目标二维码 | 
|---|
|  |  |  | commands.add(getMoveCommand(startCode, distCode, allDistance, ShuttleRunDirection.get(startPath.getDirection()).id)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //托盘下降 | 
|---|
|  |  |  | ShuttleCommand command2 = new ShuttleCommand(); | 
|---|
|  |  |  | command2.setCommandWord((short) 2); | 
|---|
|  |  |  | command2.setStartCodeNum((short) 0); | 
|---|
|  |  |  | command2.setMiddleCodeNum((short) 0); | 
|---|
|  |  |  | command2.setDistCodeNum((short) 0); | 
|---|
|  |  |  | command2.setStartToDistDistance(0); | 
|---|
|  |  |  | command2.setMiddleToDistDistance(0); | 
|---|
|  |  |  | command2.setRunDirection((short) 0); | 
|---|
|  |  |  | command2.setForceMoveDistance(0); | 
|---|
|  |  |  | command2.setPalletLift((short) 2); | 
|---|
|  |  |  | command2.setRunSpeed((short) 0); | 
|---|
|  |  |  | command2.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command2); | 
|---|
|  |  |  | commands.add(getPalletCommand((short) 2)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 3://托盘顶升 | 
|---|
|  |  |  | case 4://托盘下降 | 
|---|
|  |  |  | command.setCommandWord((short) 2); | 
|---|
|  |  |  | command.setStartCodeNum((short) 0); | 
|---|
|  |  |  | command.setMiddleCodeNum((short) 0); | 
|---|
|  |  |  | command.setDistCodeNum((short) 0); | 
|---|
|  |  |  | command.setStartToDistDistance(0); | 
|---|
|  |  |  | command.setMiddleToDistDistance(0); | 
|---|
|  |  |  | command.setRunDirection((short) 0); | 
|---|
|  |  |  | command.setForceMoveDistance(0); | 
|---|
|  |  |  | command.setPalletLift(assignCommand.getTaskMode() == 3 ? (short)1 : (short)2); | 
|---|
|  |  |  | command.setRunSpeed((short) 0); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | commands.add(getPalletCommand(assignCommand.getTaskMode() == 3 ? (short) 1 : (short) 2)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 5://强制左移 | 
|---|
|  |  |  | commands.add(getForceMoveCommand((short) 2)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 6://强制右移 | 
|---|
|  |  |  | commands.add(getForceMoveCommand((short) 1)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 7://强制上移 | 
|---|
|  |  |  | commands.add(getForceMoveCommand((short) 3)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 8://强制下移 | 
|---|
|  |  |  | command.setCommandWord((short) 3); | 
|---|
|  |  |  | command.setStartCodeNum((short) 0); | 
|---|
|  |  |  | command.setMiddleCodeNum((short) 0); | 
|---|
|  |  |  | command.setDistCodeNum((short) 0); | 
|---|
|  |  |  | command.setStartToDistDistance(600); | 
|---|
|  |  |  | command.setRunDirection((short) (assignCommand.getTaskMode() - 4)); | 
|---|
|  |  |  | command.setForceMoveDistance(600); | 
|---|
|  |  |  | command.setIOControl((short) 0); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | command.setRunSpeed((short) 1000); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | commands.add(getForceMoveCommand((short) 4)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 9://状态复位 | 
|---|
|  |  |  | command.setCommandWord((short) 6); | 
|---|
|  |  |  | command.setStartCodeNum((short) 0); | 
|---|
|  |  |  | command.setMiddleCodeNum((short) 0); | 
|---|
|  |  |  | command.setDistCodeNum((short) 0); | 
|---|
|  |  |  | command.setStartToDistDistance(0); | 
|---|
|  |  |  | command.setMiddleToDistDistance(0); | 
|---|
|  |  |  | command.setRunDirection((short) 0); | 
|---|
|  |  |  | command.setPalletLift((short) 0); | 
|---|
|  |  |  | command.setPalletLift((short) 0); | 
|---|
|  |  |  | command.setForceMoveDistance(0); | 
|---|
|  |  |  | command.setChargeSwitch((short) 0); | 
|---|
|  |  |  | command.setIOControl((short) 0); | 
|---|
|  |  |  | command.setRunSpeed((short) 0); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | ShuttleCommand reset = getResetCommand(); | 
|---|
|  |  |  | commands.add(reset); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 10://向正方向(左)寻库位 | 
|---|
|  |  |  | command.setCommandWord((short) 4); | 
|---|
|  |  |  | command.setRunDirection((short) 1); | 
|---|
|  |  |  | command.setStartToDistDistance(3000); | 
|---|
|  |  |  | command.setRunSpeed((short) 1000); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | commands.add(getFindLocCommand((short) 1)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 11://向负方向(右)寻库位 | 
|---|
|  |  |  | command.setCommandWord((short) 4); | 
|---|
|  |  |  | command.setRunDirection((short) 2); | 
|---|
|  |  |  | command.setStartToDistDistance(3000); | 
|---|
|  |  |  | command.setRunSpeed((short) 1000); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | commands.add(getFindLocCommand((short) 2)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 12://向正方向(前)寻库位 | 
|---|
|  |  |  | command.setCommandWord((short) 4); | 
|---|
|  |  |  | command.setRunDirection((short) 4); | 
|---|
|  |  |  | command.setStartToDistDistance(3000); | 
|---|
|  |  |  | command.setRunSpeed((short) 1000); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | commands.add(getFindLocCommand((short) 4)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 13://向负方向(后)寻库位 | 
|---|
|  |  |  | command.setCommandWord((short) 4); | 
|---|
|  |  |  | command.setRunDirection((short) 3); | 
|---|
|  |  |  | command.setStartToDistDistance(3000); | 
|---|
|  |  |  | command.setRunSpeed((short) 1000); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | commands.add(getFindLocCommand((short) 3)); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 14://移动到目标库位 | 
|---|
|  |  |  | LocMast locMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString()); | 
|---|
|  |  |  | List<NavigateNode> result = NavigateUtils.calc(locMast.getLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id); | 
|---|
|  |  |  | //所使用的路径进行锁定禁用 | 
|---|
|  |  |  | navigateMapData = new NavigateMapData(Utils.getLev(locMast.getLocNo())); | 
|---|
|  |  |  | navigateMapData.writeNavigateNodeToRedisMap(result, true);////所使用的路径进行锁定禁用 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (result != null) { | 
|---|
|  |  |  | allNode.addAll(result);//将节点进行保存 | 
|---|
|  |  |  | //获取分段路径 | 
|---|
|  |  |  | ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(result); | 
|---|
|  |  |  | //将每一段路径分成command指令 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LocMast distLocMast = locMastService.queryByLoc(assignCommand.getLocNo()); | 
|---|
|  |  |  | String qrCodeValue = distLocMast.getQrCodeValue(); | 
|---|
|  |  |  | command.setCommandWord((short) 1); | 
|---|
|  |  |  | command.setStartCodeNum(shuttleProtocol.getCurrentCode()); | 
|---|
|  |  |  | command.setMiddleCodeNum((short) 1); | 
|---|
|  |  |  | command.setDistCodeNum((short) Integer.parseInt(qrCodeValue)); | 
|---|
|  |  |  | command.setStartToDistDistance(allDistance); | 
|---|
|  |  |  | command.setRunSpeed((short) 1000); | 
|---|
|  |  |  | command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id); | 
|---|
|  |  |  | command.setForceMoveDistance(0); | 
|---|
|  |  |  | command.setIOControl((short) 0); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //正常移动命令 | 
|---|
|  |  |  | commands.add(getMoveCommand(shuttleProtocol.getCurrentCode(),(short) Integer.parseInt(qrCodeValue),allDistance,ShuttleRunDirection.get(startPath.getDirection()).id)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 15://充电开关 | 
|---|
|  |  |  | command.setCommandWord((short) 8); | 
|---|
|  |  |  | command.setIOControl((short) 4); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | commands.add(command); | 
|---|
|  |  |  | commands.add(getChargeSwitchCommand()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | } | 
|---|
|  |  |  | assignCommand.setCommands(commands); | 
|---|
|  |  |  | assignCommand.setNodes(allNode);//当前任务所占用的节点list | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleRedisCommand redisCommand = new ShuttleRedisCommand(); | 
|---|
|  |  |  | 
|---|
|  |  |  | shuttleProtocol.setAssignCommand(assignCommand); | 
|---|
|  |  |  | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING); | 
|---|
|  |  |  | //任务数据保存到redis | 
|---|
|  |  |  | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | redisUtil.set("shuttle_wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | //执行下发任务 | 
|---|
|  |  |  | executeWork(assignCommand.getTaskNo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Object o = redisUtil.get("wrk_no_" + wrkNo); | 
|---|
|  |  |  | Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); | 
|---|
|  |  |  | if (o == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | commandStep--; | 
|---|
|  |  |  | redisCommand.setCommandStep(commandStep); | 
|---|
|  |  |  | //任务数据保存到redis | 
|---|
|  |  |  | redisUtil.set("wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | shuttleProtocol.setPakMk(true); | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | 
|---|
|  |  |  | errorCommands.remove(0); | 
|---|
|  |  |  | redisCommand.setErrorCommands(errorCommands); | 
|---|
|  |  |  | //任务数据保存到redis | 
|---|
|  |  |  | redisUtil.set("wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | commandStep++; | 
|---|
|  |  |  | redisCommand.setCommandStep(commandStep); | 
|---|
|  |  |  | //任务数据保存到redis | 
|---|
|  |  |  | redisUtil.set("wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | //已执行完成 | 
|---|
|  |  |  | //保存数据到数据库做流水 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String locNo = shuttleProtocol.getLocNo() == null ? shuttleProtocol.getSourceLocNo() : shuttleProtocol.getLocNo(); | 
|---|
|  |  |  | //解除锁定的库位路径 | 
|---|
|  |  |  | NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(locNo)); | 
|---|
|  |  |  | navigateMapData.writeNavigateNodeToRedisMap(redisCommand.getAssignCommand().getNodes(), false); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除redis | 
|---|
|  |  |  | redisUtil.del("wrk_no_" + redisCommand.getWrkNo()); | 
|---|
|  |  |  | redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!assignCommand.getAuto()) { | 
|---|
|  |  |  | //手动模式不抛出等待状态,直接复位 | 
|---|
|  |  |  | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Object o = redisUtil.get("wrk_no_" + wrkNo); | 
|---|
|  |  |  | Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); | 
|---|
|  |  |  | if (o == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | liftProtocol.setSecurityMk(true);//标记置为true,防止其他任务占用当前提升机 | 
|---|
|  |  |  | redisCommand.setLiftSecurityMk(true);//标记置为true,防止其他任务占用当前提升机 | 
|---|
|  |  |  | //任务数据保存到redis | 
|---|
|  |  |  | redisUtil.set("wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //命令list | 
|---|
|  |  |  | ArrayList<LiftCommand> liftCommands = new ArrayList<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 复位并尝试修复错误 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private boolean reset(ShuttleAssignCommand assignCommand) { | 
|---|
|  |  |  | private boolean resetAndTryFix(Short wrkNo) { | 
|---|
|  |  |  | //读取redis数据 | 
|---|
|  |  |  | if (assignCommand == null) { | 
|---|
|  |  |  | if (wrkNo == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo()); | 
|---|
|  |  |  | Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); | 
|---|
|  |  |  | if (o == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); | 
|---|
|  |  |  | List<ShuttleCommand> commands = assignCommand.getCommands(); | 
|---|
|  |  |  | List<ShuttleCommand> commands = redisCommand.getAssignCommand().getCommands(); | 
|---|
|  |  |  | //当前步序 | 
|---|
|  |  |  | int commandStep = redisCommand.getCommandStep(); | 
|---|
|  |  |  | //path路径数目 | 
|---|
|  |  |  | 
|---|
|  |  |  | ShuttleCommand command = commands.get(commandStep - 1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //复位命令 | 
|---|
|  |  |  | ShuttleCommand resetCommand = new ShuttleCommand(); | 
|---|
|  |  |  | resetCommand.setCommandWord((short) 6); | 
|---|
|  |  |  | resetCommand.setStartCodeNum((short) 0); | 
|---|
|  |  |  | resetCommand.setMiddleCodeNum((short) 0); | 
|---|
|  |  |  | resetCommand.setDistCodeNum((short) 0); | 
|---|
|  |  |  | resetCommand.setStartToDistDistance(0); | 
|---|
|  |  |  | resetCommand.setMiddleToDistDistance(0); | 
|---|
|  |  |  | resetCommand.setRunDirection((short) 0); | 
|---|
|  |  |  | resetCommand.setPalletLift((short) 0); | 
|---|
|  |  |  | resetCommand.setPalletLift((short) 0); | 
|---|
|  |  |  | resetCommand.setForceMoveDistance(0); | 
|---|
|  |  |  | resetCommand.setChargeSwitch((short) 0); | 
|---|
|  |  |  | resetCommand.setIOControl((short) 0); | 
|---|
|  |  |  | resetCommand.setRunSpeed((short) 0); | 
|---|
|  |  |  | resetCommand.setCommandEnd((short) 1); | 
|---|
|  |  |  | ShuttleCommand resetCommand = getResetCommand(); | 
|---|
|  |  |  | list.add(resetCommand); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //车辆空闲,等待写入找库位命令 | 
|---|
|  |  |  | //找库位命令 | 
|---|
|  |  |  | ShuttleCommand searchCommand = new ShuttleCommand(); | 
|---|
|  |  |  | searchCommand.setCommandWord((short) 4); | 
|---|
|  |  |  | short direction = 1; | 
|---|
|  |  |  | switch (command.getRunDirection()) { | 
|---|
|  |  |  | switch (command.getRunDirection()) {//转换运行方向 | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | direction = 2; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | direction = 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | searchCommand.setRunDirection(direction);//运行方向 | 
|---|
|  |  |  | searchCommand.setStartToDistDistance(1200); | 
|---|
|  |  |  | searchCommand.setRunSpeed((short) 1000); | 
|---|
|  |  |  | searchCommand.setCommandEnd((short) 1); | 
|---|
|  |  |  | //找库位命令 | 
|---|
|  |  |  | ShuttleCommand searchCommand = getFindLocCommand(direction, 1200, (short) 1000); | 
|---|
|  |  |  | list.add(searchCommand); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //移动车辆,需要在执行完寻找定位点后再执行 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | redisCommand.setErrorCommands(list); | 
|---|
|  |  |  | //任务数据保存到redis | 
|---|
|  |  |  | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); | 
|---|
|  |  |  | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.FIXING); | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取托盘顶升命令 | 
|---|
|  |  |  | * @param lift 1顶升,2下降 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public ShuttleCommand getPalletCommand(Short lift) { | 
|---|
|  |  |  | ShuttleCommand command = new ShuttleCommand(); | 
|---|
|  |  |  | command.setCommandWord((short) 2); | 
|---|
|  |  |  | command.setStartCodeNum((short) 0); | 
|---|
|  |  |  | command.setMiddleCodeNum((short) 0); | 
|---|
|  |  |  | command.setDistCodeNum((short) 0); | 
|---|
|  |  |  | command.setStartToDistDistance(0); | 
|---|
|  |  |  | command.setMiddleToDistDistance(0); | 
|---|
|  |  |  | command.setRunDirection((short) 0); | 
|---|
|  |  |  | command.setForceMoveDistance(0); | 
|---|
|  |  |  | command.setPalletLift(lift); | 
|---|
|  |  |  | command.setRunSpeed((short) 0); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | return command; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 正常移动命令 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public ShuttleCommand getMoveCommand(Short startCodeNum, Short distCodeNum, Integer startToDistDistance, Short runDirection) { | 
|---|
|  |  |  | ShuttleCommand command = new ShuttleCommand(); | 
|---|
|  |  |  | command.setCommandWord((short) 1); | 
|---|
|  |  |  | command.setStartCodeNum(startCodeNum); | 
|---|
|  |  |  | command.setMiddleCodeNum((short) 1); | 
|---|
|  |  |  | command.setDistCodeNum(distCodeNum); | 
|---|
|  |  |  | command.setStartToDistDistance(startToDistDistance); | 
|---|
|  |  |  | command.setRunDirection(runDirection); | 
|---|
|  |  |  | command.setForceMoveDistance(0); | 
|---|
|  |  |  | command.setIOControl((short) 0); | 
|---|
|  |  |  | command.setRunSpeed((short) 1000); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | return command; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 强制移动命令 | 
|---|
|  |  |  | * @param direction 移动方向 1左移,2右移,3前移,4后移 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public ShuttleCommand getForceMoveCommand(Short direction) { | 
|---|
|  |  |  | ShuttleCommand command = new ShuttleCommand(); | 
|---|
|  |  |  | command.setCommandWord((short) 3); | 
|---|
|  |  |  | command.setStartCodeNum((short) 0); | 
|---|
|  |  |  | command.setMiddleCodeNum((short) 0); | 
|---|
|  |  |  | command.setDistCodeNum((short) 0); | 
|---|
|  |  |  | command.setStartToDistDistance(600); | 
|---|
|  |  |  | command.setRunDirection(direction); | 
|---|
|  |  |  | command.setForceMoveDistance(600); | 
|---|
|  |  |  | command.setIOControl((short) 0); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | command.setRunSpeed((short) 1000); | 
|---|
|  |  |  | return command; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 状态复位命令 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public ShuttleCommand getResetCommand() { | 
|---|
|  |  |  | ShuttleCommand command = new ShuttleCommand(); | 
|---|
|  |  |  | command.setCommandWord((short) 6); | 
|---|
|  |  |  | command.setStartCodeNum((short) 0); | 
|---|
|  |  |  | command.setMiddleCodeNum((short) 0); | 
|---|
|  |  |  | command.setDistCodeNum((short) 0); | 
|---|
|  |  |  | command.setStartToDistDistance(0); | 
|---|
|  |  |  | command.setMiddleToDistDistance(0); | 
|---|
|  |  |  | command.setRunDirection((short) 0); | 
|---|
|  |  |  | command.setPalletLift((short) 0); | 
|---|
|  |  |  | command.setPalletLift((short) 0); | 
|---|
|  |  |  | command.setForceMoveDistance(0); | 
|---|
|  |  |  | command.setChargeSwitch((short) 0); | 
|---|
|  |  |  | command.setIOControl((short) 0); | 
|---|
|  |  |  | command.setRunSpeed((short) 0); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | return command; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取寻库位命令 | 
|---|
|  |  |  | * @param direction 1:向正方向(左)寻库位,2:向负方向(右)寻库位,3:向负方向(后)寻库位,4:向正方向(前)寻库位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public ShuttleCommand getFindLocCommand(Short direction, Integer startToDistance, Short runSpeed) { | 
|---|
|  |  |  | ShuttleCommand command = new ShuttleCommand(); | 
|---|
|  |  |  | command.setCommandWord((short) 4); | 
|---|
|  |  |  | command.setRunDirection(direction); | 
|---|
|  |  |  | command.setStartToDistDistance(startToDistance); | 
|---|
|  |  |  | command.setRunSpeed((short) runSpeed); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | return command; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取寻库位命令,默认移动距离3000,运行速度1000 | 
|---|
|  |  |  | * @param direction 1:向正方向(左)寻库位,2:向负方向(右)寻库位,3:向负方向(后)寻库位,4:向正方向(前)寻库位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public ShuttleCommand getFindLocCommand(Short direction) { | 
|---|
|  |  |  | return getFindLocCommand(direction, 3000, (short) 1000); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取充电开关命令 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public ShuttleCommand getChargeSwitchCommand() { | 
|---|
|  |  |  | ShuttleCommand command = new ShuttleCommand(); | 
|---|
|  |  |  | command.setCommandWord((short) 8); | 
|---|
|  |  |  | command.setIOControl((short) 4); | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | return command; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * charge:1=>开始充电,2=>断开充电 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public ShuttleCommand getChargeSwitchCommand(Short charge) { | 
|---|
|  |  |  | ShuttleCommand command = new ShuttleCommand(); | 
|---|
|  |  |  | command.setCommandWord((short) 5);//充电 | 
|---|
|  |  |  | command.setShuttleNo(shuttleProtocol.getShuttleNo()); | 
|---|
|  |  |  | command.setChargeSwitch(charge);//开始充电 | 
|---|
|  |  |  | command.setCommandEnd((short) 1); | 
|---|
|  |  |  | return command; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /******************************************************************************************/ | 
|---|
|  |  |  | /**************************************** 测试专用 *****************************************/ | 
|---|
|  |  |  | /*****************************************************************************************/ | 
|---|