| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.domain.enums.NotifyMsgType; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.service.*; |
| | |
| | | private DeviceConfigService deviceConfigService; |
| | | @Autowired |
| | | private LiftDispatchUtils liftDispatchUtils; |
| | | @Autowired |
| | | private BasShuttleService basShuttleService; |
| | | |
| | | /** |
| | | * 初始化实时地图 |
| | |
| | | } |
| | | |
| | | //将数据库地图数据存入redis |
| | | redisUtil.set(RedisKeyType.MAP.key + lev, JSON.toJSONString(basMap)); |
| | | redisUtil.set(RedisKeyType.MAP.key + lev, lists); |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | //检测障碍物车 |
| | | boolean checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getLocNo(), new ArrayList<Integer>() {{ |
| | | int checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getLocNo(), new ArrayList<Integer>() {{ |
| | | add(shuttleProtocol.getShuttleNo()); |
| | | }}, new ArrayList<>()); |
| | | if (checkObstacle) { |
| | | if (checkObstacle > 0) { |
| | | News.info("{}任务,避障范围有小车,等待障碍小车调离中", wrkMast.getWrkNo()); |
| | | return false; |
| | | } |
| | |
| | | //判断小车是否到达货物库位 |
| | | if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) { |
| | | //检测障碍物车 |
| | | boolean checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getSourceLocNo(), new ArrayList<Integer>() {{ |
| | | int checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getSourceLocNo(), new ArrayList<Integer>() {{ |
| | | add(shuttleProtocol.getShuttleNo()); |
| | | }}, new ArrayList<>()); |
| | | if (checkObstacle) { |
| | | if (checkObstacle > 0) { |
| | | News.info("{}任务,避障范围有小车,等待障碍小车调离中", wrkMast.getWrkNo()); |
| | | return false; |
| | | } |
| | |
| | | } |
| | | |
| | | //检测障碍物车 |
| | | boolean checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getLocNo(), new ArrayList<Integer>() {{ |
| | | int checkObstacle = shuttleOperaUtils.checkObstacle(wrkMast.getLocNo(), new ArrayList<Integer>() {{ |
| | | add(shuttleProtocol.getShuttleNo()); |
| | | }}, new ArrayList<>()); |
| | | if (checkObstacle) { |
| | | if (checkObstacle > 0) { |
| | | News.info("{}任务,避障范围有小车,等待障碍小车调离中", wrkMast.getWrkNo()); |
| | | return false; |
| | | } |
| | |
| | | } |
| | | |
| | | //判断当前小车是否满足需要充电要求 |
| | | if (!shuttleThread.isRequireCharge()) { |
| | | continue; |
| | | if (shuttleThread.isRequireCharge().equals(ShuttleRequireChargeType.NONE)) { |
| | | continue;//无需充电 |
| | | } |
| | | |
| | | boolean forceCharge = true; |
| | | if (shuttleThread.isRequireCharge().equals(ShuttleRequireChargeType.SUGGEST_CHARGE)) { |
| | | BasShuttle basShuttle = basShuttleService.selectOne(new EntityWrapper<BasShuttle>().eq("shuttle_no", device.getDeviceNo())); |
| | | if (basShuttle != null) { |
| | | Integer suggestChargeLine = basShuttle.getSuggestChargeLine(); |
| | | boolean chargeSuggestResult = Integer.parseInt(shuttleProtocol.getBatteryPower()) < suggestChargeLine; |
| | | if (chargeSuggestResult) { |
| | | //检测系统是否有任务 |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().in("io_type", 1, 101, 201)); |
| | | if (wrkMasts.isEmpty()) { |
| | | forceCharge = false; |
| | | }else { |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | WrkMast wrkMast1 = wrkMastService.selectShuttleWorking(shuttleProtocol.getShuttleNo()); |
| | |
| | | wrkMast.setIoPri((double) 999); |
| | | wrkMast.setLocNo(chargeLocNo); |
| | | wrkMast.setShuttleNo(device.getDeviceNo()); |
| | | wrkMast.setMemo("charge"); |
| | | wrkMast.setMemo(forceCharge ? "forceCharge" : "suggestCharge"); |
| | | wrkMast.setAppeTime(new Date()); |
| | | if (!wrkMastService.insert(wrkMast)) { |
| | | News.error("保存{}号四向穿梭车充电任务失败!!!", device.getDeviceNo()); |
| | |
| | | List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleChargeCommand(assignCommand, shuttleThread, true); |
| | | assignCommand.setCommands(commands);//运行命令 |
| | | |
| | | wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_WORKING.sts); |
| | | wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_START_CHARGING.sts); |
| | | wrkMast.setModiTime(new Date()); |
| | | if (!wrkMastService.updateById(wrkMast)) { |
| | | return false; |
| | |
| | | |
| | | //小车停止充电 |
| | | private synchronized boolean executeShuttleChargeStepStopCharge(WrkMast wrkMast) { |
| | | if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_WORKING.sts) { |
| | | if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_CHARGING.sts) { |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); |
| | | if (shuttleThread == null) { |
| | | return false; |
| | |
| | | return false; |
| | | } |
| | | |
| | | if (!shuttleThread.isChargingCompleted()) { |
| | | boolean stopCharge = false; |
| | | if (wrkMast.getMemo().equals("suggestChargeTaskStop")) { |
| | | stopCharge = true; |
| | | }else { |
| | | if (shuttleThread.isChargingCompleted()) { |
| | | stopCharge = true; |
| | | } |
| | | } |
| | | |
| | | if (!stopCharge) { |
| | | return false; |
| | | } |
| | | |
| | |
| | | |
| | | //小车离开充电桩 |
| | | private synchronized boolean executeShuttleChargeStepLeaveCharge(WrkMast wrkMast) { |
| | | if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_COMPLETE.sts) { |
| | | if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_CHARGING_COMPLETE.sts) { |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); |
| | | if (shuttleThread == null) { |
| | | return false; |
| | |
| | | } |
| | | |
| | | //检测障碍物车 |
| | | boolean checkObstacle = shuttleOperaUtils.checkObstacle(basShuttleCharge.getWaitLocNo(), new ArrayList<Integer>() {{ |
| | | int checkObstacle = shuttleOperaUtils.checkObstacle(basShuttleCharge.getWaitLocNo(), new ArrayList<Integer>() {{ |
| | | add(shuttleProtocol.getShuttleNo()); |
| | | }}, new ArrayList<>()); |
| | | if (checkObstacle) { |
| | | if (checkObstacle > 0) { |
| | | News.info("{}任务,避障范围有小车,等待障碍小车调离中", wrkMast.getWrkNo()); |
| | | return false; |
| | | } |
| | |
| | | } |
| | | |
| | | //搜索最近且无故障提升机 |
| | | LiftStaProtocol recentLiftStation = liftDispatchUtils.getRecentLiftStation(shuttleProtocol.getShuttleNo(), Utils.getLev(wrkMast.getLocNo())); |
| | | LiftStaProtocol recentLiftStation = liftDispatchUtils.getRecentLiftStation(shuttleProtocol.getShuttleNo(), Utils.getLev(shuttleProtocol.getCurrentLocNo())); |
| | | if(recentLiftStation == null) { |
| | | News.info("{}号小车,{}目标库位,没有可用空闲输送站点", shuttleProtocol.getShuttleNo(), wrkMast.getLocNo()); |
| | | return false; |
| | |
| | | if(targetLiftSta == null) { |
| | | return false; |
| | | } |
| | | |
| | | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); |
| | | assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号 |
| | | assignCommand.setTaskMode(ShuttleTaskModeType.MOVE_LOC_NO.id);//小车移库任务 |
| | | assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号 |
| | | assignCommand.setAuto(true);//自动模式 |
| | | |
| | | //计算近点位置 |
| | | String endLocation = navigateUtils.calcEndLocation(shuttleProtocol.getCurrentLocNo(), recentLiftStation.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL), null, null, 1); |
| | |
| | | wrkMastService.updateById(wrkMast); |
| | | return true; |
| | | } |
| | | |
| | | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); |
| | | assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号 |
| | | assignCommand.setTaskMode(ShuttleTaskModeType.MOVE_LOC_NO.id);//小车移库任务 |
| | | assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号 |
| | | assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位 |
| | | assignCommand.setLocNo(endLocation); |
| | | assignCommand.setAuto(true);//自动模式 |
| | | |
| | | //获取小车到近点行走命令 |
| | | List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), endLocation, NavigationMapType.getMapTypes(NavigationMapType.NORMAL, NavigationMapType.SHUTTLE), assignCommand, shuttleThread); |
| | |
| | | return false; |
| | | } |
| | | |
| | | Object object = redisUtil.get(RedisKeyType.LIFT_MOVE_TO_SHUTTLE_LIMIT.key + wrkMast.getWrkNo()); |
| | | int targetLev = Utils.getLev(shuttleProtocol.getCurrentLocNo()); |
| | | if (liftProtocol.getLev() != targetLev) { |
| | | if (object == null || liftProtocol.getLev() != targetLev) { |
| | | //获取提升机命令 |
| | | LiftCommand liftCommand = liftThread.getMoveCommand(wrkMast.getWrkNo(), liftProtocol.getLev(), targetLev); |
| | | ArrayList<LiftCommand> commands = new ArrayList<>(); |
| | |
| | | //下发任务 |
| | | liftAction.assignWork(wrkMast.getLiftNo(), assignCommand); |
| | | News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}号提升机在{}层,提升机不在小车层,调度移动中", wrkMast.getWrkNo(), liftProtocol.getLev(), wrkMast.getLiftNo()); |
| | | redisUtil.set(RedisKeyType.LIFT_MOVE_TO_SHUTTLE_LIMIT.key + wrkMast.getWrkNo(), "lift_moving", 60 * 3); |
| | | return false; |
| | | } |
| | | |
| | | String liftLocNo = liftThread.getCurrentLocNo(); |
| | | |
| | | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); |
| | | assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号 |
| | | assignCommand.setTaskMode(ShuttleTaskModeType.MOVE_LOC_NO.id);//小车移库任务 |
| | | assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号 |
| | | assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位 |
| | | assignCommand.setLocNo(liftLocNo); |
| | | assignCommand.setAuto(true);//自动模式 |
| | | |
| | | //获取小车到提升机行走命令 |
| | | List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftThread.getCurrentLocNo(), NavigationMapType.getNormalWithDevice(), assignCommand, shuttleThread, "inLift"); |
| | | List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), liftLocNo, NavigationMapType.getMapTypes(NavigationMapType.NORMAL), assignCommand, shuttleThread, "inLift"); |
| | | if (commands == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo()); |
| | | return false;//路径解锁失败 |
| | |
| | | return false; |
| | | } |
| | | |
| | | if (Utils.getLev(shuttleProtocol.getCurrentLocNo()) != Utils.getLev(wrkMast.getLocNo())) { |
| | | Object object = redisUtil.get(RedisKeyType.SHUTTLE_UPDATE_LOCATION.key + shuttleProtocol.getShuttleNo()); |
| | | if(object != null) { |
| | | return false; |
| | | } |
| | | |
| | | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); |
| | | assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号 |
| | | assignCommand.setTaskMode(ShuttleTaskModeType.UPDATE_LOCATION.id);//更新坐标 |
| | | assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号 |
| | | assignCommand.setAuto(true);//自动模式 |
| | | assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位 |
| | | assignCommand.setLocNo(wrkMast.getLocNo());//目标库位 |
| | | |
| | | //更新小车坐标 |
| | | ShuttleCommand command = shuttleThread.getUpdateLocationCommand(wrkMast.getWrkNo(), wrkMast.getLocNo()); |
| | | ArrayList<ShuttleCommand> commands = new ArrayList<>(); |
| | | commands.add(command); |
| | | |
| | | assignCommand.setCommands(commands); |
| | | //下发任务 |
| | | shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand); |
| | | redisUtil.set(RedisKeyType.SHUTTLE_UPDATE_LOCATION.key + shuttleProtocol.getShuttleNo(), "update", 10); |
| | | return false; |
| | | } |
| | | |
| | | //小车出提升机近点距离 |
| | | int shuttleOutLiftLocationDistance = 2; |
| | | Config shuttleOutLiftLocationDistanceConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "shuttleOutLiftLocationDistance")); |
| | | if (shuttleOutLiftLocationDistanceConfig != null) { |
| | | shuttleOutLiftLocationDistance = Integer.parseInt(shuttleOutLiftLocationDistanceConfig.getValue()); |
| | | } |
| | | |
| | | String targetLocNo = navigateUtils.calcFirstLocation(shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.getMapTypes(NavigationMapType.NORMAL), null, null, shuttleOutLiftLocationDistance); |
| | | if (targetLocNo == null) {//出提升机近点计算失败 |
| | | News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,出提升机近点计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo()); |
| | | return false; |
| | | } |
| | | |
| | | ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); |
| | | assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); // 四向穿梭车编号 |
| | | assignCommand.setTaskMode(ShuttleTaskModeType.UPDATE_LOCATION.id);//更新坐标 |
| | | assignCommand.setTaskMode(ShuttleTaskModeType.MOVE_LOC_NO.id);//小车移库任务 |
| | | assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号 |
| | | assignCommand.setAuto(true);//自动模式 |
| | | assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位 |
| | | assignCommand.setLocNo(wrkMast.getLocNo());//目标库位 |
| | | assignCommand.setLocNo(targetLocNo);//目标库位 |
| | | |
| | | //更新小车坐标 |
| | | ShuttleCommand command = shuttleThread.getUpdateLocationCommand(wrkMast.getWrkNo(), wrkMast.getLocNo()); |
| | | ArrayList<ShuttleCommand> commands = new ArrayList<>(); |
| | | commands.add(command); |
| | | |
| | | //获取小车到近点命令 |
| | | List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), targetLocNo, NavigationMapType.getMapTypes(NavigationMapType.NORMAL), assignCommand, shuttleThread); |
| | | if (commands == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}小车,路径计算失败", wrkMast.getWrkNo(), shuttleProtocol.getShuttleNo()); |
| | | return false;//路径计算失败 |
| | | } |
| | | assignCommand.setCommands(commands); |
| | | |
| | | wrkMast.setWrkSts(WrkStsType.MOVE_OUT_LIFT.sts);//小车迁出提升机中 |
| | | wrkMast.setSystemMsg("");//清空消息 |
| | | wrkMast.setModiTime(now); |
| | | |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | //下发任务 |
| | | shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand); |