| | |
| | | import com.zy.common.utils.NavigateMapData; |
| | | import com.zy.common.utils.NavigatePositionConvert; |
| | | import com.zy.common.utils.NavigateUtils; |
| | | import com.zy.common.utils.ShuttleDispatchUtils; |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | |
| | | import com.zy.core.model.Task; |
| | | import com.zy.core.model.command.ShuttleAssignCommand; |
| | | import com.zy.core.model.command.ShuttleCommand; |
| | | import com.zy.core.model.protocol.NyShuttleProtocol; |
| | | import com.zy.core.model.protocol.ShuttleProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.NyShuttleThread; |
| | | import com.zy.core.thread.ShuttleThread; |
| | | |
| | | import java.text.DecimalFormat; |
| | |
| | | } |
| | | |
| | | //获取穿梭车所在节点位置 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); |
| | | NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | if (shuttleProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (shuttleProtocol.getLocNo() == null) { |
| | | if (shuttleProtocol.getCurrentLocNo() == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (lev != Utils.getLev(shuttleProtocol.getLocNo())) { |
| | | if (lev != Utils.getLev(shuttleProtocol.getCurrentLocNo())) { |
| | | continue;//楼层不同 |
| | | } |
| | | |
| | | int[] xyPosition = NavigatePositionConvert.positionToXY(shuttleProtocol.getLocNo());//通过库位号获取xy坐标 |
| | | int[] xyPosition = NavigatePositionConvert.positionToXY(shuttleProtocol.getCurrentLocNo());//通过库位号获取xy坐标 |
| | | list.add(xyPosition); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | //检测穿梭车行走路径,是否存在其他小车,如有其他小车则进行调离 |
| | | public static boolean checkShuttlePath(List<NavigateNode> nodes, Integer shuttleId) { |
| | | boolean flag = false; |
| | | int shuttleX = -1; |
| | | int shuttleY = -1; |
| | | int shuttleZ = -1; |
| | | |
| | | LocMastService locMastService = SpringUtils.getBean(LocMastService.class); |
| | | |
| | | if (nodes == null) { |
| | | return false; |
| | | } |
| | | if (nodes.size() == 0) { |
| | | return false; |
| | | } |
| | | NavigateMapData mapData = new NavigateMapData(nodes.get(0).getZ());//获取地图数据 |
| | | int[][] data = mapData.getData(-1, null, Utils.getShuttlePoints(shuttleId, nodes.get(0).getZ())); |
| | | for (NavigateNode node : nodes) { |
| | | int x = node.getX(); |
| | | int y = node.getY(); |
| | | if (data[x][y] == 66) {//判断该路径是否有小车 |
| | | flag = true;//存在小车 |
| | | shuttleX = x; |
| | | shuttleY = y; |
| | | shuttleZ = node.getZ(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (flag) { |
| | | //检测到路径存在其他小车 |
| | | //搜索一条没有小车的空巷道 |
| | | |
| | | //获取小车坐标二维码 |
| | | Short shuttlePosition = NavigatePositionConvert.xyToPosition(shuttleX, shuttleY, shuttleZ); |
| | | LocMast shuttleLocMast = locMastService.queryByQrCode(String.valueOf(shuttlePosition)); |
| | | |
| | | //获取小车线程 |
| | | SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class); |
| | | ShuttleThread currentShuttleThread = null; |
| | | for (ShuttleSlave slave : slaveProperties.getShuttle()) { |
| | | //获取穿梭车所在节点位置 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | if (shuttleProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (shuttleProtocol.getCurrentCode().intValue() == Integer.parseInt(shuttleLocMast.getQrCodeValue())) { |
| | | //小车坐标和线程获取的小车坐标一致 |
| | | currentShuttleThread = shuttleThread; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (currentShuttleThread == null) { |
| | | //没找到小车 |
| | | return false; |
| | | } |
| | | |
| | | ShuttleProtocol shuttleProtocol = currentShuttleThread.getShuttleProtocol(); |
| | | if (!shuttleProtocol.isIdle()) { |
| | | return false;//被调度的小车处于工作状态,禁止触发避让任务 |
| | | } |
| | | |
| | | //搜索一条没有小车的空巷道,并调度小车 |
| | | ShuttleAssignCommand assignCommand = Utils.searchEmptyGroupToMoveShuttle(shuttleZ, shuttleId, currentShuttleThread, null);//shuttleId搜索时需要排除的车辆id,currentShuttleThread是需要被调度的车辆线程 |
| | | |
| | | if (assignCommand == null) { |
| | | return false; |
| | | } |
| | | |
| | | //下发任务 |
| | | MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); |
| | | |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | //搜索一条没有小车的空巷道,并返回移动小车的命令 |
| | | public static ShuttleAssignCommand searchEmptyGroupToMoveShuttle(int z, Integer currentShuttleId, ShuttleThread shuttleThread, String startLocNo) { |
| | | //搜索一条没有小车的空巷道,并调度小车 |
| | | public static boolean searchEmptyGroupToMoveShuttle(int z, Integer currentShuttleId, NyShuttleThread shuttleThread) { |
| | | LocMastService locMastService = SpringUtils.getBean(LocMastService.class); |
| | | MainServiceImpl mainServiceImpl = SpringUtils.getBean(MainServiceImpl.class); |
| | | CommonService commonService = SpringUtils.getBean(CommonService.class); |
| | | ShuttleDispatchUtils shuttleDispatchUtils = SpringUtils.getBean(ShuttleDispatchUtils.class); |
| | | |
| | | if (shuttleThread == null) { |
| | | return null; |
| | | return false; |
| | | } |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | if (shuttleProtocol == null) { |
| | | return null; |
| | | return false; |
| | | } |
| | | |
| | | NavigateMapData mapData = new NavigateMapData(z);//获取地图数据 |
| | |
| | | int distY = -1; |
| | | int distX = -1; |
| | | int distZ = -1; |
| | | for (int y = 3; y <= 25; y++) { |
| | | for (int y = 20; y <= 56; y++) { |
| | | boolean searchFlag = true; |
| | | for (int x = 20; x <= 23; x++) { |
| | | for (int x = 10; x <= 11; x++) { |
| | | if (data[x][y] < 0 || data[x][y] == 66) { |
| | | searchFlag = false;//该巷道有禁用节点或有小车 |
| | | break; |
| | |
| | | if (searchFlag) { |
| | | //搜索出空巷道 |
| | | distY = y; |
| | | distX = 20; |
| | | distX = 11; |
| | | distZ = z; |
| | | break; |
| | | } |
| | |
| | | |
| | | if (distY != -1) { |
| | | |
| | | //获取避让坐标二维码 |
| | | Short distPosition = NavigatePositionConvert.xyToPosition(distX, distY, distZ); |
| | | LocMast distLocMast = locMastService.queryByQrCode(String.valueOf(distPosition)); |
| | | //获取避让库位 |
| | | String distLocNo = NavigatePositionConvert.xyzToLocNo(distX, distY, distZ); |
| | | LocMast distLocMast = locMastService.queryByLoc(distLocNo); |
| | | if (distLocMast == null) { |
| | | return null; |
| | | return false; |
| | | } |
| | | |
| | | if (startLocNo == null) { |
| | | //获取小车坐标二维码 |
| | | LocMast shuttleLocMast = locMastService.queryByQrCode(String.valueOf(shuttleProtocol.getCurrentCode())); |
| | | if (shuttleLocMast == null) { |
| | | return null; |
| | | } |
| | | startLocNo = shuttleLocMast.getLocNo(); |
| | | } |
| | | |
| | | //创建分配命令 |
| | | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); |
| | | assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号 |
| | | assignCommand.setTaskNo((short) commonService.getWorkNo(7));//任务号 |
| | | assignCommand.setTaskMode(ShuttleTaskModeType.AVOID.id.shortValue());//避让任务 |
| | | assignCommand.setSourceLocNo(startLocNo);//源库位 |
| | | |
| | | //分配目标库位 |
| | | shuttleProtocol.setLocNo(distLocMast.getLocNo()); |
| | | //目标库位 |
| | | assignCommand.setLocNo(distLocMast.getLocNo()); |
| | | |
| | | //小车移动到目标位置 |
| | | List<ShuttleCommand> commands = mainServiceImpl.shuttleAssignCommand(startLocNo, distLocMast.getLocNo(), NavigationMapType.NORMAL.id, assignCommand, shuttleThread); |
| | | if (commands == null) { |
| | | return null; |
| | | } |
| | | |
| | | assignCommand.setCommands(commands); |
| | | return assignCommand; |
| | | //调度小车到避让位置 |
| | | return shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(7), distLocNo, shuttleProtocol.getShuttleNo().intValue()); |
| | | } |
| | | return null; |
| | | return false; |
| | | } |
| | | |
| | | } |