| | |
| | | import com.zy.asrs.wcs.core.model.enums.ShuttleTaskModeType; |
| | | import com.zy.asrs.wcs.core.service.BasShuttleService; |
| | | import com.zy.asrs.wcs.core.service.LocService; |
| | | import com.zy.asrs.wcs.core.utils.NavigateMapUtils; |
| | | import com.zy.asrs.wcs.core.utils.RedisUtil; |
| | | import com.zy.asrs.wcs.core.utils.ShuttleDispatcher; |
| | | import com.zy.asrs.wcs.core.utils.Utils; |
| | | import com.zy.asrs.wcs.core.utils.*; |
| | | import com.zy.asrs.wcs.rcs.News; |
| | | import com.zy.asrs.wcs.rcs.cache.SlaveConnection; |
| | | import com.zy.asrs.wcs.rcs.constant.DeviceRedisConstant; |
| | |
| | | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; |
| | | import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; |
| | | import com.zy.asrs.wcs.rcs.thread.ShuttleThread; |
| | | import com.zy.asrs.wcs.system.entity.Dict; |
| | | import com.zy.asrs.wcs.system.service.DictService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | private ShuttleDispatcher shuttleDispatcher; |
| | | @Autowired |
| | | private ObjectMapper objectMapper; |
| | | @Autowired |
| | | private DictService dictService; |
| | | @Autowired |
| | | private ConveyorDispatcher conveyorDispatcher; |
| | | |
| | | public synchronized boolean assignWork(Device device, ShuttleAssignCommand assignCommand) { |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); |
| | |
| | | } |
| | | |
| | | int lev = Utils.getLev(shuttleProtocol.getCurrentLocNo());//小车当前楼层 |
| | | if (shuttleProtocol.getYCurrent() > shuttleProtocol.getYTarget()) { |
| | | //跑库结束 |
| | | 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; |
| | | } |
| | | |
| | | if (shuttleProtocol.getMoveType() == 0) {//跑轨道 |
| | | Integer xCurrent = shuttleProtocol.getXCurrent(); |
| | | if (xCurrent > shuttleProtocol.getXTarget()) {//当X值大于X目标值,进行归零且Y方向+1 |
| | | shuttleProtocol.setXCurrent(shuttleProtocol.getXStart()); |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 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(); |
| | | |
| | | Integer yCurrent = shuttleProtocol.getYCurrent(); |
| | | String locNo = Utils.getLocNo(xCurrent, yCurrent, lev); |
| | | Loc target = locService.getOne(new LambdaQueryWrapper<Loc>() |
| | | .eq(Loc::getLocNo, locNo) |
| | | .eq(Loc::getHostId, device.getHostId())); |
| | | if (target == null) { |
| | | shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | return; |
| | | } |
| | | |
| | | // if (!target.getLocSts().equals("O")) { |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | // return; |
| | | // } |
| | | |
| | | //调度去目标位置 |
| | | if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) { |
| | | shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//小车和目标位置一致,跳过 |
| | | } else { |
| | | shuttleDispatcher.generateMoveTask(device, target.getLocNo()); |
| | | shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | } |
| | | } else if (shuttleProtocol.getMoveType() == 1) {//跑库位 |
| | | 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<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>() |
| | | .in(Loc::getLocNo, locs)); |
| | | if (locList.isEmpty()) { |
| | | //空库位 |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 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 { |
| | | //在起点位置,调度去目标位置 |
| | | if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) { |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//小车和目标位置一致,跳过 |
| | | }else { |
| | | shuttleDispatcher.generateMoveTask(device, start.getLocNo()); |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1); |
| | | 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<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>() |
| | | .eq(Loc::getLocSts, LocStsType.O.val()) |
| | | .in(Loc::getLocNo, locs)); |
| | | if (locList.isEmpty()) { |
| | | //空库位 |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 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 { |
| | | //在起点位置,调度去目标位置 |
| | | shuttleDispatcher.generateMoveTask(device, target.getLocNo()); |
| | | 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 { |
| | | //在起点位置,调度去目标位置 |
| | | shuttleDispatcher.generateMoveTask(device, target.getLocNo()); |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //调度去库位 |
| | | 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(); |