| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.SpringUtils; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.mapper.*; |
| | |
| | | //不同层,将目标库位分配成提升机库位号 |
| | | |
| | | //小车移动到提升机口,计算路径 |
| | | List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftSiteLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand, shuttleThread); |
| | | List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftSiteLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); |
| | | if (commands == null) { |
| | | continue;//未找到路径 |
| | | } |
| | | |
| | | //获取当前小车所在楼层的站点信息 |
| | | BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo); |
| | |
| | | |
| | | //小车到提升机口指令 |
| | | List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftSiteLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand, shuttleThread); |
| | | if (commands == null) { |
| | | continue;//未找到路径 |
| | | } |
| | | shuttleProtocol.setLocNo(liftSiteLocNo); |
| | | |
| | | //获取当前小车所在楼层的站点信息 |
| | |
| | | } |
| | | } else if (wrkMast.getWrkSts() == 25) { |
| | | List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), liftSiteLocNo, assignCommand, shuttleThread); |
| | | if (commands == null) { |
| | | continue;//未找到路径 |
| | | } |
| | | //此时车在提升机内部,需要多下达一步指令让车移动到提升机口 |
| | | BasDevp basDevp = basDevpService.selectById(109);//获取提升机信息 |
| | | short startCode = Short.parseShort(basDevp.getQrCodeValue());//提升机二维码 |
| | |
| | | //工作档不同楼层的穿梭车 |
| | | diffLev.add(shuttleThread); |
| | | } |
| | | // |
| | | // //更新当前最近的四向穿梭车 |
| | | // if (recentShuttle == null) { |
| | | // recentShuttle = shuttleThread; |
| | | // }else { |
| | | // ShuttleProtocol recentShuttleProtocol = recentShuttle.getShuttleProtocol();//目前最近穿梭车 |
| | | // String recentShuttleLocNo = recentShuttleProtocol.getCurrentLocNo();//二维码对应库位号 |
| | | // String recentShuttleLocNoLay = recentShuttleLocNo.substring(recentShuttleLocNo.length() - 2, recentShuttleLocNo.length());//库位号对应层高 |
| | | // |
| | | // int recentShuttleLocNoLayInt = Integer.parseInt(recentShuttleLocNoLay); |
| | | // int i = Math.abs(lev - recentShuttleLocNoLayInt);//工作档楼层减最近穿梭车楼层,取绝对值 |
| | | // int j = Math.abs(lev - shuttleLocNoLey);//工作档楼层减当前穿梭车楼层,取绝对值 |
| | | // if (i < j) { |
| | | // //更新最近穿梭车 |
| | | // recentShuttle = shuttleThread; |
| | | // } else if (i == j) { |
| | | // //楼层相同情况 |
| | | // //找距离出库点最近的车 |
| | | // |
| | | // if (!(recentShuttleProtocol.isIdle() && shuttleProtocol.isIdle())) { |
| | | // //只要有一辆车不是空闲则不进行调度 |
| | | // map.put("sameLay", false);//不同层 |
| | | // map.put("result", null); |
| | | // return map; |
| | | // } |
| | | // |
| | | // //获取提升机 |
| | | // LiftSlave liftSlave = slaveProperties.getLift().get(0); |
| | | // //提升机库位号 |
| | | // String recentLiftLocNo = liftSlave.getLiftLocNo(recentShuttleLocNoLayInt); |
| | | // String shuttleLiftLocNo = liftSlave.getLiftLocNo(shuttleLocNoLey); |
| | | // |
| | | // //当前最近四向穿梭车到提升机路径 |
| | | // List<NavigateNode> recentShuttlePath = NavigateUtils.calc(recentShuttleLocNo, recentLiftLocNo, ShuttleTaskModeType.PAK_IN.id); |
| | | // //当前楼层四向穿梭车到提升机路径 |
| | | // List<NavigateNode> shuttlePath = NavigateUtils.calc(shuttleLocNo, shuttleLiftLocNo, ShuttleTaskModeType.PAK_IN.id); |
| | | // //判断哪一个路径最短 |
| | | // if (shuttlePath.size() < recentShuttlePath.size()) { |
| | | // //如果当前楼层的车路径更小,则更新最近穿梭车 |
| | | // recentShuttle = shuttleThread; |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | } |
| | | |
| | | if (sameLev.size() > 0) { |
| | |
| | | } |
| | | } |
| | | |
| | | //查询是否有充电任务 |
| | | WrkCharge wrkCharge = wrkChargeMapper.selectByWorkNo(liftProtocol.getTaskNo().intValue()); |
| | | if (wrkCharge != null) { |
| | | switch (wrkCharge.getWrkSts().intValue()) { |
| | | case 54://提升机搬运中 |
| | | wrkCharge.setWrkSts(55L);//提升机搬运完成 |
| | | break; |
| | | default: |
| | | } |
| | | |
| | | if (wrkChargeMapper.updateById(wrkCharge) > 0) { |
| | | //设置提升机为空闲状态 |
| | | liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE); |
| | | //任务号清零 |
| | | liftProtocol.setTaskNo((short) 0); |
| | | //标记复位 |
| | | liftProtocol.setPakMk(true); |
| | | //任务指令清零 |
| | | liftProtocol.setAssignCommand(null); |
| | | News.info("提升机已确认且任务完成状态,复位。提升机号={}", liftProtocol.getLiftNo()); |
| | | } else { |
| | | News.error("提升机已确认且任务完成状态,复位失败,但未找到工作档。提升机号={},工作号={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo()); |
| | | } |
| | | } |
| | | |
| | | //不是入出库调度任务、工作档任务,进行提升机的复位 |
| | | if (liftProtocol.getAssignCommand() != null) { |
| | | //设置提升机为空闲状态 |
| | |
| | | //任务指令清零 |
| | | liftProtocol.setAssignCommand(null); |
| | | News.info("提升机已确认且任务完成状态,复位。提升机号={}", liftProtocol.getLiftNo()); |
| | | // LiftAssignCommand assignCommand = liftProtocol.getAssignCommand(); |
| | | // if (!assignCommand.getAuto()) { |
| | | // //手动命令 |
| | | // |
| | | // } |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | ShuttleChargeType shuttleCharge = null; |
| | | String locNo; |
| | | for (ShuttleChargeType chargeType : ShuttleChargeType.values()) { |
| | | switch (chargeType.id) { |
| | | case 1: |
| | | if (devpThread.charge0 == false) { |
| | | ShuttleChargeType first = ShuttleChargeType.FIRST; |
| | | locNo = first.locNo; |
| | | if (wrkChargeService.selectWorkingOfCharge(first.id) == null) { |
| | | shuttleCharge = first; |
| | | } |
| | | } |
| | | break; |
| | | default: |
| | | if (wrkChargeService.selectWorkingOfCharge(chargeType.id) == null) { |
| | | shuttleCharge = chargeType; |
| | | break; |
| | | } |
| | | } |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkCharge.getShuttleNo()); |
| | | if (shuttleThread == null) { |
| | | return; |
| | |
| | | //当前穿梭车库位号 |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo(); |
| | | //小车当前层高 |
| | | Integer currentLev = currentLocNo == null ? 0 : Integer.parseInt(currentLocNo.substring(currentLocNo.length() - 2, currentLocNo.length())); |
| | | Integer currentLev = currentLocNo == null ? 0 : Utils.getLev(currentLocNo); |
| | | //获取提升机 |
| | | LiftSlave liftSlave = slaveProperties.getLift().get(0); |
| | | //提升机库位号 |
| | | String liftLocNo = liftSlave.getLiftLocNo(currentLev); |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); |
| | | if (liftThread == null) { |
| | | return; |
| | | } |
| | | LiftProtocol liftProtocol = liftThread.getLiftProtocol(); |
| | | if (liftProtocol == null) { |
| | | return; |
| | | } |
| | | //充电库位号 |
| | | String chargeLocNo = wrkCharge.getLocNo(); |
| | | //充电库位层高 |
| | | Integer chargeLocNoLev = Integer.parseInt(chargeLocNo.substring(chargeLocNo.length() - 2, chargeLocNo.length())); |
| | | Integer chargeLocNoLev = Utils.getLev(chargeLocNo); |
| | | |
| | | if (wrkCharge.getWrkSts() == 51 || wrkCharge.getWrkSts() == 55) { |
| | | if (wrkCharge.getWrkSts() == 51) { |
| | | if (currentLev == chargeLocNoLev) { |
| | | //同一层无需经过提升机 |
| | | //直接计算车到充电库位 |
| | |
| | | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); |
| | | |
| | | //获取小车到充电库位路径指令 |
| | | List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, chargeLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand, shuttleThread); |
| | | List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, chargeLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); |
| | | if (commands == null) { |
| | | return;//未找到路径 |
| | | } |
| | | //进行充电中 |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING); |
| | | |
| | |
| | | MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); |
| | | } |
| | | }else { |
| | | //不同层,将目标库位分配成提升机库位号 |
| | | //不同层,调度小车到充电桩目标层 |
| | | |
| | | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); |
| | | |
| | | //小车移动到提升机口,计算路径 |
| | | List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftLocNo, ShuttleTaskModeType.PAK_IN.id, assignCommand, shuttleThread); |
| | | //获取小车当前楼层的站点号 |
| | | String liftSiteLocNo = Utils.levToOutInStaLocNo(currentLev); |
| | | |
| | | //小车移动到提升机口站点,计算路径 |
| | | List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftSiteLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); |
| | | if (commands == null) { |
| | | return;//未找到路径 |
| | | } |
| | | |
| | | //获取当前小车所在楼层的站点信息 |
| | | BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo); |
| | | if (basDevp == null) { |
| | | return;//找不到站点信息 |
| | | } |
| | | Short basDevpQrCode = Short.parseShort(basDevp.getQrCodeValue());//站点二维码 |
| | | |
| | | //增加移动进提升机命令 |
| | | ShuttleCommand moveCommand = shuttleThread.getMoveCommand(basDevpQrCode, liftProtocol.getBarcode(), 1400, ShuttleRunDirection.TOP.id, basDevpQrCode, 1400, 500); |
| | | commands.add(moveCommand); |
| | | |
| | | //分配目标库位 |
| | | shuttleProtocol.setLocNo(liftLocNo); |
| | | |
| | | |
| | | shuttleProtocol.setLocNo(chargeLocNo); |
| | | assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); |
| | | assignCommand.setTaskMode((short) 9);//充电 |
| | | assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue()); |
| | | assignCommand.setCharge(true);//充电任务 |
| | | //目标库位 |
| | | assignCommand.setLocNo(liftLocNo); |
| | | assignCommand.setLocNo(chargeLocNo); |
| | | //源库位 |
| | | assignCommand.setSourceLocNo(currentLocNo); |
| | | assignCommand.setCommands(commands); |
| | |
| | | } |
| | | |
| | | }else if(wrkCharge.getWrkSts() == 53){ |
| | | //小车已经达到提升机口 |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId()); |
| | | if (liftThread == null) { |
| | | return; |
| | | } |
| | | LiftProtocol liftProtocol = liftThread.getLiftProtocol(); |
| | | if (liftProtocol == null) { |
| | | return; |
| | | } |
| | | //小车已经达到提升机内 |
| | | |
| | | //判断提升机是否处于空闲状态 |
| | | if (!liftProtocol.isIdle()) { |
| | | return; |
| | | } |
| | | |
| | | //判断小车是否在提升机内 |
| | | if (shuttleProtocol.getCurrentCode().intValue() != liftProtocol.getBarcode().intValue()) { |
| | | //小车不在提升机内 |
| | | return; |
| | | } |
| | | |
| | | //给提升机分配任务 |
| | | liftProtocol.setLiftLock(true);//锁定提升机 |
| | | liftProtocol.setTaskNo(wrkCharge.getWrkNo().shortValue());//设置任务号 |
| | | liftProtocol.setShuttleNo(wrkCharge.getShuttleNo().shortValue());//设置四向穿梭车号 |
| | | liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//设置提升机状态为工作中 |
| | |
| | | //命令list |
| | | ArrayList<LiftCommand> commands = new ArrayList<>(); |
| | | |
| | | //提升机当前楼层 |
| | | int liftLev = liftProtocol.getLev().intValue(); |
| | | if (liftLev != currentLev) { |
| | | //穿梭车和提升机处于不同楼层 |
| | | //获取目标楼层(穿梭车所在楼层)命令 |
| | | LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), currentLev); |
| | | commands.add(command1);//将命令添加进list |
| | | } |
| | | |
| | | //输送线将四向穿梭车移动进来(正转) |
| | | LiftCommand command2 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 1); |
| | | commands.add(command2);//将命令添加进list |
| | | |
| | | //提升机前往目标楼层 |
| | | //获取充电库位目标楼层命令 |
| | | LiftCommand command3 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), chargeLocNoLev); |
| | | commands.add(command3);//将命令添加进list |
| | | |
| | | //提升机到达指定楼层,输送线将四向穿梭车移出去 |
| | | //输送线将四向穿梭车移动出去(反转) |
| | | LiftCommand command4 = liftThread.getLiftTurnCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), 2); |
| | | commands.add(command4);//将命令添加进list |
| | | LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), chargeLocNoLev >= 2 ? chargeLocNoLev + 1 : chargeLocNoLev); |
| | | commands.add(command1);//将命令添加进list |
| | | |
| | | wrkCharge.setWrkSts(54L);//提升机搬运中 |
| | | //所需命令组合完毕,更新数据库,提交到线程去工作 |
| | |
| | | MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand)); |
| | | } |
| | | |
| | | } else if (wrkCharge.getWrkSts() == 56) { |
| | | }else if(wrkCharge.getWrkSts() == 55){//55.提升机迁移小车完成 |
| | | //直接计算车到充电库位 |
| | | |
| | | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); |
| | | |
| | | Short liftLev = liftProtocol.getLev(); |
| | | if (liftLev == null) { |
| | | return; |
| | | } |
| | | //判断提升机楼层是否到达目标楼层 |
| | | if (liftLev.intValue() != chargeLocNoLev) { |
| | | return;//没有到达目标楼层 |
| | | } |
| | | |
| | | //此时车在提升机内部,下达一步指令让车移动到提升机口 |
| | | Integer staNo = Utils.levToOutInStaNo(liftLev >= 2 ? liftLev + 1 : liftLev);//站点号 |
| | | BasDevp basDevp = basDevpService.selectById(staNo); |
| | | if (basDevp == null) { |
| | | return;//站点不存在 |
| | | } |
| | | |
| | | //获取小车到充电库位路径指令 |
| | | List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, chargeLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); |
| | | if (commands == null) { |
| | | return;//未找到路径 |
| | | } |
| | | |
| | | short startCode = liftProtocol.getBarcode();//提升机内部二维码 |
| | | Short distCode = Short.parseShort(basDevp.getQrCodeValue());//提升机口站点二维码 |
| | | Short runDirection = ShuttleRunDirection.BOTTOM.id;//运行方向 |
| | | //获取命令 |
| | | ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1400, runDirection, startCode, 1400, 500); |
| | | commands.add(0, moveCommand);//将该指令添加到队头 |
| | | |
| | | //进行充电中 |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING); |
| | | |
| | | assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); |
| | | assignCommand.setTaskMode((short) 9);//充电 |
| | | assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue()); |
| | | assignCommand.setCharge(true);//充电任务 |
| | | |
| | | //创建充电指令 |
| | | ShuttleCommand command = shuttleThread.getChargeSwitchCommand((short) 1);//开始充电 |
| | | commands.add(command); |
| | | |
| | | //指令集分配 |
| | | assignCommand.setCommands(commands); |
| | | |
| | | wrkCharge.setWrkSts(56L);//充电中状态 |
| | | if (wrkChargeMapper.updateById(wrkCharge) > 0) { |
| | | //下发任务 |
| | | MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); |
| | | } |
| | | }else if (wrkCharge.getWrkSts() == 56) { |
| | | //充电中 |
| | | //判断小车是否充满电量,满电1000或电压54V以上 |
| | | if (shuttleProtocol.getBatteryPower() >= 1000 || shuttleProtocol.getCurrentVoltage() >= 540) { |
| | | if (shuttleProtocol.getBatteryPower() >= 1000 || shuttleProtocol.getCurrentVoltage() >= 54000) { |
| | | //充满,断开充电 |
| | | List<ShuttleCommand> commands = new ArrayList<>(); |
| | | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); |