| | |
| | | return false; |
| | | } |
| | | |
| | | News.info("[RCS Debug] Execute check command {},{}", shuttleNo, taskNo); |
| | | //检测命令 |
| | | int checked = checkCommand(redisCommand, shuttleNo); |
| | | if (checked == 0) { |
| | | ShuttleCheckCommandResultType checked = checkCommand(redisCommand, shuttleNo); |
| | | News.info("[RCS Debug] Execute check command complete {},{}", shuttleNo, taskNo); |
| | | if (checked.equals(ShuttleCheckCommandResultType.FAIL)) { |
| | | return false; |
| | | } |
| | | |
| | |
| | | |
| | | //取出命令 |
| | | ShuttleCommand command = null; |
| | | if (checked == 1) { |
| | | if (checked.equals(ShuttleCheckCommandResultType.SUCCESS)) { |
| | | //非连续指令,需要检测上一条指令是否完成 |
| | | if (commandStep > 0) { |
| | | ShuttleCommand lastCommand = commands.get(commandStep - 1); |
| | |
| | | } |
| | | |
| | | command = commands.get(commandStep); |
| | | } else if (checked == 2) { |
| | | } else if (checked.equals(ShuttleCheckCommandResultType.SUCCESS_GO)) { |
| | | //连续指令直接取数据 |
| | | command = commands.get(commandStep); |
| | | } |
| | |
| | | } |
| | | |
| | | List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(command.getNodes()), NavigateNode.class); |
| | | //申请管制 |
| | | applyTrafficControl(commands, nodes, shuttleNo, taskNo); |
| | | |
| | | Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_LOCK_APPLY.key + shuttleNo); |
| | | if (object == null) { |
| | | //申请管制 |
| | | News.info("[RCS Debug] Execute apply control {},{}", shuttleNo, taskNo); |
| | | redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_LOCK_APPLY.key + shuttleNo, "lock", 10); |
| | | applyTrafficControl(commands, nodes, shuttleNo, taskNo); |
| | | News.info("[RCS Debug] Execute apply control complete {},{}", shuttleNo, taskNo); |
| | | } |
| | | |
| | | News.info("[RCS Debug] Execute query control {},{}", shuttleNo, taskNo); |
| | | //查询管制 |
| | | boolean apply = queryTrafficControl(shuttleNo, taskNo); |
| | | News.info("[RCS Debug] Execute query control complete {},{}", shuttleNo, taskNo); |
| | | if(!apply){ |
| | | return false;//申请失败 |
| | | } |
| | | // //检测路径是否冲突 |
| | | // int conflict = searchShuttlePathConflict(nodes, shuttleNo); |
| | | // if(conflict == 2){ |
| | | // return false;//检测后有冲突 |
| | | // } |
| | | |
| | | if (checked == 2) { |
| | | if (checked.equals(ShuttleCheckCommandResultType.SUCCESS_GO)) { |
| | | nodes.remove(0); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | News.info("[RCS Debug] Execute send command {},{}", shuttleNo, taskNo); |
| | | // 下发命令 |
| | | CommandResponse response = write(command, shuttleNo); |
| | | News.info("[RCS Debug] Execute send command complete {},{}", shuttleNo, taskNo); |
| | | |
| | | //保存命令日志 |
| | | BasShuttleOpt basShuttleOpt = new BasShuttleOpt(); |
| | |
| | | * 检测命令 |
| | | * 0:未通过 1:通过 2:通过且可提前下发指令 |
| | | */ |
| | | private int checkCommand(ShuttleRedisCommand redisCommand, Integer shuttleNo) { |
| | | private ShuttleCheckCommandResultType checkCommand(ShuttleRedisCommand redisCommand, Integer shuttleNo) { |
| | | TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1); |
| | | if(trafficControlThread == null){ |
| | | return 0; |
| | | return ShuttleCheckCommandResultType.FAIL; |
| | | } |
| | | |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |
| | | if (shuttleThread == null) { |
| | | return 0; |
| | | return ShuttleCheckCommandResultType.FAIL; |
| | | } |
| | | |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | return 0; |
| | | return ShuttleCheckCommandResultType.FAIL; |
| | | } |
| | | |
| | | int commandStep = redisCommand.getCommandStep(); |
| | | if (commandStep == 0) { |
| | | return 1;//第一条命令无需检测 |
| | | return ShuttleCheckCommandResultType.SUCCESS;//第一条命令无需检测 |
| | | } |
| | | |
| | | ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand(); |
| | | List<ShuttleCommand> commands = assignCommand.getCommands(); |
| | | if (commands.isEmpty()) { |
| | | return 0; |
| | | return ShuttleCheckCommandResultType.FAIL; |
| | | } |
| | | |
| | | boolean supportContinuously = false; |
| | | int checkIdx = commandStep - 2; |
| | | if (checkIdx < 0) { |
| | | supportContinuously = true; |
| | | checkIdx = commandStep - 1; |
| | | } |
| | | |
| | | ShuttleCommand last2Command = commands.get(checkIdx); |
| | | if(last2Command.getComplete()){ |
| | | supportContinuously = true; |
| | |
| | | //小车移动连续下发指令 |
| | | if (assignCommand.getShuttleMoveCommandsContinuously()) { |
| | | if (!supportContinuously) { |
| | | return 0; |
| | | return ShuttleCheckCommandResultType.FAIL; |
| | | } |
| | | |
| | | //移动指令 |
| | | if(lastCommand.getMode() != ShuttleCommandModeType.MOVE.id) { |
| | | return 0; |
| | | return ShuttleCheckCommandResultType.FAIL; |
| | | } |
| | | |
| | | List<NavigateNode> nodes = lastCommand.getNodes(); |
| | | NavigateNode startNode = nodes.get(0); |
| | | if (!startNode.getLinePartAllowGo()) {//直线段部分,允许直接行走 |
| | | return 0; |
| | | return ShuttleCheckCommandResultType.FAIL; |
| | | } |
| | | |
| | | //直线段数据标识 |
| | |
| | | //取指令 |
| | | ShuttleCommand currentCommand = commands.get(commandStep); |
| | | if(currentCommand.getMode() != ShuttleCommandModeType.MOVE.id) { |
| | | return 0; |
| | | return ShuttleCheckCommandResultType.FAIL; |
| | | } |
| | | |
| | | List<NavigateNode> currentNodes = currentCommand.getNodes(); |
| | | NavigateNode currentStartNode = currentNodes.get(0); |
| | | if(!currentStartNode.getLinePartAllowGo()) {//直线段部分,允许直接行走 |
| | | return 0; |
| | | return ShuttleCheckCommandResultType.FAIL; |
| | | } |
| | | |
| | | if(currentStartNode.getLinePartFlag().equals(linePartFlag)) { |
| | | //数据标识一致 |
| | | return 2;//允许小车移动连续下发指令 |
| | | return ShuttleCheckCommandResultType.SUCCESS_GO;//允许小车移动连续下发指令 |
| | | } |
| | | } |
| | | } |
| | | |
| | | return 0; |
| | | return ShuttleCheckCommandResultType.FAIL; |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // 系统任务 |
| | | if (assignCommand.getAuto()) { |
| | | if (!assignCommand.getCharge()) { |
| | | //对主线程抛出等待确认状态waiting |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING); |
| | | } else { |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING); |
| | | if (assignCommand.getTaskMode() == ShuttleTaskModeType.UPDATE_LOCATION.id) {//更新坐标无需等待确认 |
| | | //直接复位空闲状态 |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE); |
| | | //任务号清零 |
| | | shuttleThread.setSyncTaskNo(0); |
| | | //标记复位 |
| | | shuttleThread.setPakMk(true); |
| | | News.info("四向穿梭车更新坐标任务执行完成,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand)); |
| | | }else { |
| | | if (!assignCommand.getCharge()) { |
| | | //对主线程抛出等待确认状态waiting |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING); |
| | | } else { |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING); |
| | | } |
| | | News.info("四向穿梭车任务执行下发完成等待执行结束,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand)); |
| | | } |
| | | News.info("四向穿梭车任务执行下发完成等待执行结束,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(endCommand)); |
| | | |
| | | // 手动任务 |
| | | } else { |
| | | } else {// 手动任务 |
| | | //手动模式不抛出等待状态,直接复位空闲状态 |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE); |
| | | //任务号清零 |
| | |
| | | } |
| | | |
| | | //申请取消管制 |
| | | trafficControlThread.cancelTrafficControl(shuttleNo, shuttleProtocol.getTaskNo()); |
| | | cancelTrafficControl(shuttleNo, shuttleProtocol.getTaskNo()); |
| | | |
| | | //删除redis |
| | | redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo()); |
| | | return 0;//禁止再下发命令 |
| | | return ShuttleCheckCommandResultType.FAIL;//禁止再下发命令 |
| | | } |
| | | |
| | | return 1; |
| | | return ShuttleCheckCommandResultType.SUCCESS; |
| | | } |
| | | |
| | | //检测更新命令完成 |
| | |
| | | return false; |
| | | } |
| | | //上报交管 |
| | | News.info("[RCS Debug] Execute check command report traffic {},{}", shuttleNo, shuttleProtocol.getTaskNo()); |
| | | trafficControlThread.trafficReport(command.getNodesDeepCopy(), shuttleNo, shuttleProtocol.getTaskNo()); |
| | | News.info("[RCS Debug] Execute check command report traffic complete {},{}", shuttleNo, shuttleProtocol.getTaskNo()); |
| | | |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo(); |
| | | if (currentLocNo == null) { |
| | |
| | | |
| | | //查询是否申请管制成功 |
| | | public boolean queryTrafficControl(Integer shuttleNo, Integer taskNo) { |
| | | TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1); |
| | | if (trafficControlThread == null) { |
| | | Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo); |
| | | if (object == null) { |
| | | return false; |
| | | } |
| | | |
| | | TrafficControlDataModel trafficControlDataModel = trafficControlThread.queryTrafficControl(shuttleNo, taskNo); |
| | | if (trafficControlDataModel == null) { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | // /** |
| | | // * 搜索小车路径是否存在冲突 |
| | | // * 0:未检测 1:检测无冲突 2:检测有冲突 |
| | | // */ |
| | | // public int searchShuttlePathConflict(List<NavigateNode> nodeList, Integer shuttleNo) { |
| | | // ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); |
| | | // if (shuttleThread == null) { |
| | | // return 0; |
| | | // } |
| | | // |
| | | // ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | // if (shuttleProtocol == null) { |
| | | // return 0; |
| | | // } |
| | | // |
| | | // int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo()); |
| | | // |
| | | // TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1); |
| | | // if (trafficControlThread == null) { |
| | | // return 2; |
| | | // } |
| | | // HashMap<String, List<Integer>> nodeMap = trafficControlThread.getNodesMapByLev(lev); |
| | | // if (nodeMap == null || nodeMap.isEmpty()) { |
| | | // return 2; |
| | | // } |
| | | // |
| | | // List<String> conflictLocList = new ArrayList<>(); |
| | | // for (NavigateNode node : nodeList) { |
| | | // String locNo = Utils.getLocNo(node.getX(), node.getY(), lev); |
| | | // if(!nodeMap.containsKey(locNo)) { |
| | | // return 2; |
| | | // } |
| | | // |
| | | // List<Integer> shuttleNos = nodeMap.get(locNo); |
| | | // if (shuttleNos.size() > 1) { |
| | | // //路径存在多车,冲突 |
| | | // conflictLocList.add(locNo); |
| | | // } |
| | | // } |
| | | // |
| | | // if (conflictLocList.isEmpty()) { |
| | | // //无冲突,解除交通管制 |
| | | // shuttleThread.setTrafficControl(false, null); |
| | | // return 1;//检测后无冲突 |
| | | // } |
| | | // |
| | | // //路径存在冲突,检测可执行车辆是否为当前小车 |
| | | // //上报小车状态-交通管制中 |
| | | // shuttleThread.setTrafficControl(true, nodeList); |
| | | // |
| | | // HashMap<String, Integer> deviceMap = trafficControlThread.getDeviceMap(); |
| | | // if(deviceMap == null) { |
| | | // return 2; |
| | | // } |
| | | // |
| | | // boolean detected = false; |
| | | //// for (Map.Entry<String, Integer> entry : deviceMap.entrySet()) { |
| | | //// List<String> mainList = JSON.parseArray(entry.getKey(), String.class); |
| | | //// Integer device = entry.getValue(); |
| | | //// if(result) { |
| | | //// //判断管制车辆是否匹配 |
| | | //// if(shuttleNo.equals(device)) { |
| | | //// detected = true; |
| | | //// break; |
| | | //// } |
| | | //// } |
| | | //// } |
| | | // |
| | | // for (Map.Entry<String, Integer> entry : deviceMap.entrySet()) { |
| | | // String key = entry.getKey(); |
| | | // Integer value = entry.getValue(); |
| | | // if(shuttleNo.equals(value)) { |
| | | // //判断管制车辆是否匹配 |
| | | // detected = true; |
| | | // break; |
| | | // } |
| | | // } |
| | | // |
| | | // if (detected) { |
| | | // return 1;//检测后无冲突,交通管制已允许此小车运行 |
| | | // } |
| | | // |
| | | // return 2;//检测后有冲突 |
| | | // } |
| | | public boolean cancelTrafficControl(Integer shuttleNo, Integer taskNo) { |
| | | TrafficControlDataModel model = new TrafficControlDataModel(); |
| | | model.setShuttleNo(shuttleNo); |
| | | model.setTaskNo(taskNo); |
| | | redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_CANCEL_LIST.key + shuttleNo + "_" + taskNo, model); |
| | | return true; |
| | | } |
| | | |
| | | //演示模式 |
| | | public synchronized void demo(Integer shuttleNo) { |
| | |
| | | return; |
| | | } |
| | | |
| | | if (shuttleThread.isRequireCharge()) { |
| | | if (!shuttleThread.isRequireCharge().equals(ShuttleRequireChargeType.NONE)) { |
| | | return; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | // //跑库程序 |
| | | // 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); |
| | | //// } |
| | | // } |
| | | // } |
| | | // } |
| | | public synchronized void demoModeRunLoc(Integer shuttleNo) { |
| | | Config demoModeRunLocConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoModeRunLoc")); |
| | | if (demoModeRunLocConfig == null) { |
| | | return; |
| | | } |
| | | |
| | | private synchronized CommandResponse write(ShuttleCommand command, Integer shuttleNo) { |
| | | 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); |
| | | } |
| | | |
| | | private CommandResponse write(ShuttleCommand command, Integer shuttleNo) { |
| | | CommandResponse response = new CommandResponse(false); |
| | | if (null == command) { |
| | | News.error("四向穿梭车写入命令为空"); |