| | |
| | | import com.core.common.Arith; |
| | | import com.core.common.Cools; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.BasShuttle; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.service.BasShuttleService; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.service.impl.MainServiceImpl; |
| | | import com.zy.common.model.NavigateNode; |
| | |
| | | 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; |
| | |
| | | return locNo; |
| | | } |
| | | |
| | | //楼层转换对应出入库站点库位号 |
| | | public static String levToOutInStaLocNo(Integer lev) { |
| | | String locNo = null; |
| | | if (lev >= 2) { |
| | | lev++; |
| | | } |
| | | switch (lev) { |
| | | case 1: |
| | | locNo = "1800201"; |
| | | break; |
| | | case 3: |
| | | locNo = "1800202"; |
| | | break; |
| | | case 4: |
| | | locNo = "1800203"; |
| | | break; |
| | | case 5: |
| | | locNo = "1800204"; |
| | | break; |
| | | } |
| | | return locNo; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(JSON.toJSONString(getGroupOutsideLoc("0200101"))); |
| | | } |
| | |
| | | |
| | | //获取除白名单外的指定楼层全部穿梭车xy坐标点 |
| | | public static List<int[]> getShuttlePoints(Integer whiteShuttle, Integer lev) { |
| | | BasShuttleService basShuttleService = SpringUtils.getBean(BasShuttleService.class); |
| | | SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class); |
| | | ArrayList<int[]> list = new ArrayList<>(); |
| | | for (ShuttleSlave slave : slaveProperties.getShuttle()) { |
| | |
| | | continue; |
| | | } |
| | | |
| | | if (shuttleProtocol.getCurrentLocNo() == null) { |
| | | continue; |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo(); |
| | | |
| | | if (currentLocNo == null) { |
| | | //小车没有库位号数据,从数据库中取 |
| | | BasShuttle basShuttle = basShuttleService.selectById(slave.getId()); |
| | | if (basShuttle == null || basShuttle.getPoint() == null) { |
| | | continue; |
| | | } |
| | | NyShuttleProtocol.NyShuttlePointClass shuttlePoint = JSON.parseObject(basShuttle.getPoint(), NyShuttleProtocol.NyShuttlePointClass.class); |
| | | currentLocNo = NavigatePositionConvert.nyXyzToLocNo(shuttlePoint.getX(), shuttlePoint.getY(), shuttlePoint.getZ()); |
| | | } |
| | | |
| | | if (lev != Utils.getLev(shuttleProtocol.getCurrentLocNo())) { |
| | | if (lev != Utils.getLev(currentLocNo)) { |
| | | continue;//楼层不同 |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | | |
| | | //检测楼层是否有穿梭车 |
| | | public static boolean checkLevHasShuttle(Integer lev) { |
| | | SlaveProperties slaveProperties = SpringUtils.getBean(SlaveProperties.class); |
| | | for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { |
| | | //获取四向穿梭车线程 |
| | | NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | | NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); |
| | | if (shuttleProtocol == null) { |
| | | continue; |
| | | } |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo(); |
| | | if (currentLocNo == null) { |
| | | continue; |
| | | } |
| | | |
| | | if (lev == Utils.getLev(currentLocNo)) { |
| | | return true;//指定楼层有穿梭车 |
| | | } |
| | | } |
| | | |
| | | return false;//指定楼层没有穿梭车 |
| | | } |
| | | |
| | | } |