| | |
| | | } |
| | | } |
| | | |
| | | public synchronized void demoModeRunLoc(Integer shuttleNo) { |
| | | Config demoModeRunLocConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoModeRunLoc")); |
| | | if (demoModeRunLocConfig == null) { |
| | | return; |
| | | } |
| | | |
| | | if (!demoModeRunLocConfig.getValue().equals("Y")) { |
| | | return; |
| | | } |
| | | |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |
| | | if (shuttleThread == null) { |
| | | return; |
| | | } |
| | | |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | return; |
| | | } |
| | | |
| | | if (!shuttleThread.isIdle()) { |
| | | return; |
| | | } |
| | | |
| | | LocMast targetLoc = null; |
| | | EntityWrapper<LocMast> wrapper = new EntityWrapper<>(); |
| | | wrapper.eq("lev1", Utils.getLev(shuttleProtocol.getCurrentLocNo())); |
| | | wrapper.notIn("loc_sts", "X"); |
| | | wrapper.isNull("loc_type"); |
| | | wrapper.last("ORDER BY RAND() LIMIT 1"); |
| | | for (int i = 0; i < 3; i++) { |
| | | LocMast locMast = locMastService.selectOne(wrapper); |
| | | if(locMast == null) { |
| | | continue; |
| | | } |
| | | |
| | | targetLoc = locMast; |
| | | break; |
| | | } |
| | | |
| | | if(targetLoc == null) { |
| | | return; |
| | | } |
| | | |
| | | boolean result = shuttleDispatchUtils.dispatchShuttle(null, targetLoc.getLocNo(), shuttleProtocol.getShuttleNo()); |
| | | if (result) { |
| | | targetLoc.setLocType("Y"); |
| | | locMastService.updateById(targetLoc); |
| | | } |
| | | } |
| | | |
| | | public synchronized boolean clearPath(Integer shuttleNo) { |
| | | return navigateMapUtils.clearPath(shuttleNo); |
| | | } |
| | | |
| | | // //跑库程序 |
| | | // public synchronized void moveLoc(Integer shuttleNo) { |
| | | // ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |
| | | // if (shuttleThread == null) { |
| | | // return; |
| | | // } |
| | | // ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(false); |
| | | // if (shuttleProtocol == null) { |
| | | // return; |
| | | // } |
| | | // |
| | | // //小车开启跑库模式 |
| | | // if (!shuttleProtocol.getMoveLoc()) { |
| | | // return; |
| | | // } |
| | | // |
| | | // //小车空闲 |
| | | // if (!shuttleThread.isIdle()) { |
| | | // return; |
| | | // } |
| | | // |
| | | // int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车当前楼层 |
| | | // |
| | | // if (shuttleProtocol.getMoveType() == 0) {//跑轨道 |
| | | // //根据地图方向决定跑x或y |
| | | // Config config = configService.selectOne(new EntityWrapper<Config>() |
| | | // .eq("code", "direction_map") |
| | | // .eq("status", 1)); |
| | | // if (config == null) { |
| | | // //跑库结束 |
| | | // shuttleProtocol.setMoveLoc(false); |
| | | // shuttleProtocol.setMoveType(0); |
| | | // shuttleProtocol.setXStart(0); |
| | | // shuttleProtocol.setXTarget(0); |
| | | // shuttleProtocol.setXCurrent(0); |
| | | // shuttleProtocol.setYStart(0); |
| | | // shuttleProtocol.setYTarget(0); |
| | | // shuttleProtocol.setYCurrent(0); |
| | | // return; |
| | | // } |
| | | // String direction = config.getValue(); |
| | | // |
| | | // if (direction.equals("y")) {//跑x轴方向,跑完x轴再切换y轴 |
| | | // ArrayList<String> locs = new ArrayList<>(); |
| | | // for (int i = shuttleProtocol.getXCurrent(); i <= shuttleProtocol.getXTarget(); i++) { |
| | | // String locNo = Utils.getLocNo(i, shuttleProtocol.getYCurrent(), lev); |
| | | // locs.add(locNo); |
| | | // } |
| | | // |
| | | // List<LocMast> locList = locMastService.selectList(new EntityWrapper<LocMast>() |
| | | // .eq("loc_sts", LocStsType.O.toString()) |
| | | // .in("loc_no", locs)); |
| | | // if (locList.isEmpty()) { |
| | | // //空库位 |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1); |
| | | // return; |
| | | // } |
| | | // |
| | | // LocMast start = locList.get(0); |
| | | // LocMast target = locList.get(locList.size() - 1); |
| | | // //判断小车是否在起点位置 |
| | | // if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//不在起点位置,调度去起点位置 |
| | | // shuttleDispatcher.generateMoveTask(device, start.getLocNo()); |
| | | // }else { |
| | | // //在起点位置,调度去目标位置 |
| | | // Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo()); |
| | | // if (task != null) { |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//切换y轴 |
| | | // } |
| | | // |
| | | // if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { |
| | | // //y轴也跑完了,结束跑库 |
| | | // shuttleProtocol.setMoveLoc(false); |
| | | // shuttleProtocol.setMoveType(0); |
| | | // shuttleProtocol.setXStart(0); |
| | | // shuttleProtocol.setXTarget(0); |
| | | // shuttleProtocol.setXCurrent(0); |
| | | // shuttleProtocol.setYStart(0); |
| | | // shuttleProtocol.setYTarget(0); |
| | | // shuttleProtocol.setYCurrent(0); |
| | | // return; |
| | | // } |
| | | // } |
| | | // }else {//跑y轴方向,跑完y轴再切换x轴 |
| | | // ArrayList<String> locs = new ArrayList<>(); |
| | | // for (int i = shuttleProtocol.getYCurrent(); i <= shuttleProtocol.getYTarget(); i++) { |
| | | // String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), i, lev); |
| | | // locs.add(locNo); |
| | | // } |
| | | // |
| | | // List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>() |
| | | // .eq(Loc::getLocSts, LocStsType.O.val()) |
| | | // .in(Loc::getLocNo, locs)); |
| | | // if (locList.isEmpty()) { |
| | | // //空库位 |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | // return; |
| | | // } |
| | | // |
| | | // Loc start = locList.get(0); |
| | | // Loc target = locList.get(locList.size() - 1); |
| | | // //判断小车是否在起点位置 |
| | | // if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//不在起点位置,调度去起点位置 |
| | | // shuttleDispatcher.generateMoveTask(device, start.getLocNo()); |
| | | // }else { |
| | | // //在起点位置,调度去目标位置 |
| | | // Task task = shuttleDispatcher.generateMoveTask(device, target.getLocNo()); |
| | | // if (task != null) { |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//切换x轴 |
| | | // } |
| | | // |
| | | // if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) { |
| | | // //y轴也跑完了,结束跑库 |
| | | // shuttleProtocol.setMoveLoc(false); |
| | | // shuttleProtocol.setMoveType(0); |
| | | // shuttleProtocol.setXStart(0); |
| | | // shuttleProtocol.setXTarget(0); |
| | | // shuttleProtocol.setXCurrent(0); |
| | | // shuttleProtocol.setYStart(0); |
| | | // shuttleProtocol.setYTarget(0); |
| | | // shuttleProtocol.setYCurrent(0); |
| | | // return; |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // } else if (shuttleProtocol.getMoveType() == 1) {//跑库位 |
| | | // //根据地图方向决定跑x或y |
| | | // Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>() |
| | | // .eq(Dict::getFlag, "direction_map") |
| | | // .eq(Dict::getStatus, 1)); |
| | | // if (dict == null) { |
| | | // //跑库结束 |
| | | // shuttleProtocol.setMoveLoc(false); |
| | | // shuttleProtocol.setMoveType(0); |
| | | // shuttleProtocol.setXStart(0); |
| | | // shuttleProtocol.setXTarget(0); |
| | | // shuttleProtocol.setXCurrent(0); |
| | | // shuttleProtocol.setYStart(0); |
| | | // shuttleProtocol.setYTarget(0); |
| | | // shuttleProtocol.setYCurrent(0); |
| | | // return; |
| | | // } |
| | | // String direction = dict.getValue(); |
| | | // |
| | | // if (direction.equals("y")) {//跑x轴方向,跑完x轴再切换y轴 |
| | | // Integer xCurrent = shuttleProtocol.getXCurrent(); |
| | | // |
| | | // //获取待跑库位号 |
| | | // String locNo = Utils.getLocNo(xCurrent, shuttleProtocol.getYCurrent(), lev); |
| | | // Loc target = locService.getOne(new LambdaQueryWrapper<Loc>() |
| | | // .eq(Loc::getLocNo, locNo) |
| | | // .eq(Loc::getLocSts, LocStsType.O.val()) |
| | | // .eq(Loc::getHostId, device.getHostId())); |
| | | // if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//库位不存在或小车已在当前位置 |
| | | // shuttleProtocol.setXCurrent(xCurrent + 1); |
| | | // if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) { |
| | | // //x轴跑完,切换y轴 |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXStart()); |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1); |
| | | // |
| | | // if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { |
| | | // //y轴也跑完了,结束跑库 |
| | | // shuttleProtocol.setMoveLoc(false); |
| | | // shuttleProtocol.setMoveType(0); |
| | | // shuttleProtocol.setXStart(0); |
| | | // shuttleProtocol.setXTarget(0); |
| | | // shuttleProtocol.setXCurrent(0); |
| | | // shuttleProtocol.setYStart(0); |
| | | // shuttleProtocol.setYTarget(0); |
| | | // shuttleProtocol.setYCurrent(0); |
| | | // return; |
| | | // } |
| | | // } |
| | | // return; |
| | | // } |
| | | // |
| | | // //调度去库位 |
| | | // Task task = shuttleDispatcher.generateMoveTask(device, locNo); |
| | | // if (task == null) { |
| | | // return;//调度失败 |
| | | // } |
| | | // |
| | | // shuttleProtocol.setXCurrent(xCurrent + 1); |
| | | // if (shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) { |
| | | // //x轴跑完,切换y轴 |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXStart()); |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1); |
| | | // |
| | | // if(shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { |
| | | // //y轴也跑完了,结束跑库 |
| | | // shuttleProtocol.setMoveLoc(false); |
| | | // shuttleProtocol.setMoveType(0); |
| | | // shuttleProtocol.setXStart(0); |
| | | // shuttleProtocol.setXTarget(0); |
| | | // shuttleProtocol.setXCurrent(0); |
| | | // shuttleProtocol.setYStart(0); |
| | | // shuttleProtocol.setYTarget(0); |
| | | // shuttleProtocol.setYCurrent(0); |
| | | // return; |
| | | // } |
| | | // } |
| | | // |
| | | // }else {//跑y轴方向,跑完y轴再切换x轴 |
| | | // Integer yCurrent = shuttleProtocol.getYCurrent(); |
| | | // |
| | | // //获取待跑库位号 |
| | | // String locNo = Utils.getLocNo(shuttleProtocol.getXCurrent(), yCurrent, lev); |
| | | // Loc target = locService.getOne(new LambdaQueryWrapper<Loc>() |
| | | // .eq(Loc::getLocNo, locNo) |
| | | // .eq(Loc::getLocSts, LocStsType.O.val()) |
| | | // .eq(Loc::getHostId, device.getHostId())); |
| | | // if (target == null || shuttleProtocol.getCurrentLocNo().equals(locNo)) {//库位不存在或小车已在当前位置 |
| | | // shuttleProtocol.setYCurrent(yCurrent + 1); |
| | | // if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { |
| | | // //y轴跑完,切换x轴 |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYStart()); |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | // |
| | | // if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) { |
| | | // //x轴也跑完了,结束跑库 |
| | | // shuttleProtocol.setMoveLoc(false); |
| | | // shuttleProtocol.setMoveType(0); |
| | | // shuttleProtocol.setXStart(0); |
| | | // shuttleProtocol.setXTarget(0); |
| | | // shuttleProtocol.setXCurrent(0); |
| | | // shuttleProtocol.setYStart(0); |
| | | // shuttleProtocol.setYTarget(0); |
| | | // shuttleProtocol.setYCurrent(0); |
| | | // return; |
| | | // } |
| | | // } |
| | | // return; |
| | | // } |
| | | // |
| | | // //调度去库位 |
| | | // Task task = shuttleDispatcher.generateMoveTask(device, locNo); |
| | | // if (task == null) { |
| | | // return;//调度失败 |
| | | // } |
| | | // |
| | | // shuttleProtocol.setYCurrent(yCurrent + 1); |
| | | // if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { |
| | | // //y轴跑完,切换x轴 |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYStart()); |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | // |
| | | // if(shuttleProtocol.getXCurrent() > shuttleProtocol.getXTarget()) { |
| | | // //x轴也跑完了,结束跑库 |
| | | // shuttleProtocol.setMoveLoc(false); |
| | | // shuttleProtocol.setMoveType(0); |
| | | // shuttleProtocol.setXStart(0); |
| | | // shuttleProtocol.setXTarget(0); |
| | | // shuttleProtocol.setXCurrent(0); |
| | | // shuttleProtocol.setYStart(0); |
| | | // shuttleProtocol.setYTarget(0); |
| | | // shuttleProtocol.setYCurrent(0); |
| | | // return; |
| | | // } |
| | | // } |
| | | // |
| | | // } |
| | | // } else if (shuttleProtocol.getMoveType() == 2) {//母轨道循环跑 |
| | | // Integer xCurrent = shuttleProtocol.getXCurrent(); |
| | | // Integer yCurrent = shuttleProtocol.getYCurrent(); |
| | | // |
| | | // String locNo = Utils.getLocNo(xCurrent, yCurrent, lev); |
| | | // //调度去目标位置 |
| | | // if (shuttleProtocol.getCurrentLocNo().equals(locNo)) { |
| | | // if (yCurrent.equals(shuttleProtocol.getYStart())) { |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYTarget());//小车和目标位置一致,切换库位 |
| | | // } else { |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());//小车和目标位置一致,切换库位 |
| | | // } |
| | | // } else { |
| | | // Task result = shuttleDispatcher.generateMoveTask(device, locNo); |
| | | // if (result != null) {//调度成功 |
| | | // if (yCurrent.equals(shuttleProtocol.getYStart())) { |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYTarget());//切换库位 |
| | | // } else { |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());//切换库位 |
| | | // } |
| | | // } |
| | | // } |
| | | // } else if (shuttleProtocol.getMoveType() == 3) {//子轨道循环跑 |
| | | // Integer xCurrent = shuttleProtocol.getXCurrent(); |
| | | // Integer yCurrent = shuttleProtocol.getYCurrent(); |
| | | // |
| | | // String locNo = Utils.getLocNo(xCurrent, yCurrent, lev); |
| | | // //调度去目标位置 |
| | | // if (shuttleProtocol.getCurrentLocNo().equals(locNo)) { |
| | | // if (xCurrent.equals(shuttleProtocol.getXStart())) { |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//小车和目标位置一致,切换库位 |
| | | // } else { |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//小车和目标位置一致,切换库位 |
| | | // } |
| | | // } else { |
| | | // Task result = shuttleDispatcher.generateMoveTask(device, locNo); |
| | | // if (result != null) {//调度成功 |
| | | // if (xCurrent.equals(shuttleProtocol.getXStart())) { |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXTarget());//切换库位 |
| | | // } else { |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());//切换库位 |
| | | // } |
| | | // } |
| | | // } |
| | | // } else if (shuttleProtocol.getMoveType() == 4) {//取放货 |
| | | // Integer xCurrent = shuttleProtocol.getXCurrent(); |
| | | // if (xCurrent > shuttleProtocol.getXTarget()) {//当X值大于X目标值 |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXStart()); |
| | | // shuttleProtocol.setYCurrent(shuttleProtocol.getYStart()); |
| | | // return; |
| | | // } |
| | | // |
| | | // //判断x轴货位是否放满 |
| | | // boolean flag = true; |
| | | // for (Loc loc : locService.list(new LambdaQueryWrapper<Loc>() |
| | | // .eq(Loc::getHostId, device.getHostId()) |
| | | // .eq(Loc::getRow, xCurrent) |
| | | // .ge(Loc::getBay, shuttleProtocol.getYStart()) |
| | | // .le(Loc::getBay, shuttleProtocol.getYTarget()))) { |
| | | // if (loc.getLocSts() != LocStsType.F.val()) { |
| | | // flag = false;//未满 |
| | | // break; |
| | | // } |
| | | // } |
| | | // if (flag) { |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | // return; |
| | | // } |
| | | // |
| | | // //搜索有货库位 |
| | | // List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>() |
| | | // .eq(Loc::getLocSts, LocStsType.F.val()) |
| | | // .eq(Loc::getHostId, device.getHostId()) |
| | | // .notIn(Loc::getRow, xCurrent) |
| | | // .eq(Loc::getStatus, 1)); |
| | | // if (list.isEmpty()) { |
| | | // return; |
| | | // } |
| | | // |
| | | // Loc start = list.get(0); |
| | | // |
| | | // List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>() |
| | | // .eq(Loc::getHostId, device.getHostId()) |
| | | // .eq(Loc::getStatus, 1) |
| | | // .eq(Loc::getLocSts, LocStsType.O.val()) |
| | | // .eq(Loc::getRow, xCurrent) |
| | | // .orderByDesc(Loc::getBay) |
| | | // .orderByAsc(Loc::getRow)); |
| | | // if (locList.isEmpty()) { |
| | | // return; |
| | | // } |
| | | // |
| | | // Loc target = locList.get(0); |
| | | // if (target == null) { |
| | | // return; |
| | | // } |
| | | // |
| | | // //调度去目标位置 |
| | | // if (!shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) { |
| | | // Task task = shuttleDispatcher.generateManuaTakeMoveTask(device, start.getLocNo(), target.getLocNo()); |
| | | //// if(task != null) {//调度成功 |
| | | //// shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | //// } |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | private CommandResponse write(ShuttleCommand command, Integer shuttleNo) { |
| | | CommandResponse response = new CommandResponse(false); |