#
zjj
2024-06-21 9372f61dcb41eeb2e09871caefce0f764d6ab021
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java
@@ -2,14 +2,12 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.wcs.core.domain.dto.MotionDto;
import com.zy.asrs.wcs.core.entity.ShuttleStandby;
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
import com.zy.asrs.wcs.core.model.enums.WorkZoneType;
import com.zy.asrs.wcs.core.service.ShuttleStandbyService;
import com.zy.asrs.wcs.core.service.TaskService;
import com.zy.asrs.wcs.core.utils.ConveyorDispatcher;
@@ -19,7 +17,6 @@
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.core.entity.Motion;
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.model.enums.LiftProtocolStatusType;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
@@ -32,10 +29,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
 * todo:luxiaotao 1.充电任务,2.库位移转,3.小车迁移
 * 1.充电任务,2.库位移转,3.小车迁移,4.手动任务
 * Created by vincent on 2023/10/11
 */
@Service
@@ -60,12 +56,6 @@
    public List<Motion> generateMotion(Task task) {
        List<Motion> motionList = new ArrayList<>();
//        switch (Objects.requireNonNull(WorkZoneType.query(task.getTaskSts() == TaskStsType.NEW_INBOUND.sts ? task.getOriginSite() : task.getDestSite()))) {
//            case FIRST_ZONE:
//                motionList = this.generateFirstZoneMotion(task);
//                break;
//            default:
//        }
        motionList = this.generateFirstZoneMotion(task);
        return motionList;
    }
@@ -85,21 +75,86 @@
         * 5.穿梭车入库至目标库位
         */
        if (task.getTaskSts() == TaskStsType.NEW_INBOUND.sts) {
//            // lift
//            LiftThread liftThread = liftDispatcher.queryLiftForTransport(task.getOriginSite());
//            LiftProtocol liftProtocol = liftThread.getStatus();
//            if (liftProtocol == null) {
//                return motionList;
//            }
            // locNo
            String destLoc = task.getDestLoc();
            // shuttle
            Device shuttleDevice = deviceService.getOne(new LambdaQueryWrapper<Device>()
                    .eq(Device::getDeviceNo, task.getShuttleNo())
                    .eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())
                    .eq(Device::getHostId, task.getHostId())
                    .eq(Device::getStatus, 1));
            if (shuttleDevice == null) {
                return motionList;
            }
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleDevice.getId().intValue());
            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) {
                return motionList;
            }
            if (!shuttleThread.isIdle()) {
                return motionList;
            }
            String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
            //获取距离目标位置最近的空闲可换层提升机
            LiftThread liftThread = liftDispatcher.searchIdleLift(shuttleLocNo, task.getHostId(), true);
            if (liftThread == null) {
                return motionList;
            }
            Device transferLiftDevice = liftThread.getDevice();
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null || liftProtocol.getLiftNo() == null) {
                return motionList;
            }
            //检测穿梭车是否有任务绑定
            boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice);
            if (shuttleResult) {
                //存在任务,禁止解析
                return motionList;
            }
            //检测提升机是否有任务绑定
            boolean liftResult = Utils.checkLiftHasBinding(Integer.parseInt(transferLiftDevice.getDeviceNo()));
            if (liftResult) {
                //存在任务,禁止解析
                return motionList;
            }
            //获取小车待机库位 ==> 进提升机
            ShuttleStandby shuttleStandbyTo = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
                    .eq(ShuttleStandby::getDeviceId, transferLiftDevice.getId())
                    .eq(ShuttleStandby::getDeviceLev, Utils.getLev(shuttleLocNo))
                    .eq(ShuttleStandby::getStatus, 1));
            //获取小车待机库位 ==> 出提升机
            ShuttleStandby shuttleStandbyFrom = shuttleStandbyService.getOne(new LambdaQueryWrapper<ShuttleStandby>()
                    .eq(ShuttleStandby::getDeviceId, transferLiftDevice.getId())
                    .eq(ShuttleStandby::getDeviceLev, Utils.getLev(destLoc))
                    .eq(ShuttleStandby::getStatus, 1));
            if (shuttleStandbyTo == null || shuttleStandbyFrom == null) {
                return motionList;
            }
            //穿梭车进提升机库位号
            String liftLocNoTo = shuttleStandbyTo.getDeviceLoc();
            //穿梭车出提升机库位号
            String liftLocNoFrom = shuttleStandbyFrom.getDeviceLoc();
            //穿梭车进提升机待机位库位号
            String standbyLocNoTo = shuttleStandbyTo.getDeviceStandbyLoc();
            //穿梭车出提升机待机位库位号
            String standbyLocNoFrom = shuttleStandbyFrom.getDeviceStandbyLoc();
            // shuttle
//            ShuttleThread shuttleThread = shuttleDispatcher.queryShuttleWhichConvenient(task, Integer.parseInt(liftThread.getStatus().getLiftNo()));
//            ShuttleThread shuttleThread = shuttleDispatcher.queryShuttleWhichConvenient(task, 1);
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, 6);
            if (Cools.isEmpty(shuttleThread)) { return motionList; }
            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
//            String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
            String shuttleLocNo = "0100201";
//            // conveyor
//            DevpSlave devpSlave = conveyorDispatcher.queryByInBound(task.getSourceStaNo());
@@ -751,12 +806,13 @@
        String shuttleLocNo = shuttleProtocol.getCurrentLocNo();
        // lift
        Device transferLiftDevice = Utils.getRecentTransferLift(shuttleLocNo, shuttleProtocol.getShuttleNo());
        if (transferLiftDevice == null) {
        //获取距离目标位置最近的空闲可换层提升机
        LiftThread liftThread = liftDispatcher.searchIdleLift(shuttleLocNo, task.getHostId(), true);
        if (liftThread == null) {
            return motionList;
        }
        LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, transferLiftDevice.getId().intValue());
        Device transferLiftDevice = liftThread.getDevice();
        LiftProtocol liftProtocol = liftThread.getStatus();
        if (liftProtocol == null || liftProtocol.getLiftNo() == null) {
            return motionList;
@@ -843,7 +899,15 @@
                    }))
            ));
            // 穿梭车提升机待机位至提升机库位
            // 锁定提升机
            motionList.addAll(kernelService.liftLock(
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(transferLiftDevice.getId().intValue());
                    }))
            ));
            // 穿梭车提升机待机位至提升机
            motionList.addAll(kernelService.shuttleMove(
                    MotionDto.build((dto -> {
                        dto.setShuttleNo(shuttleDevice.getId().intValue());
@@ -857,7 +921,15 @@
                    MotionCtgType.SHUTTLE_MOVE_TO_LIFT
            ));
            // 提升机搬车 至 输送线层
            // 解锁提升机
            motionList.addAll(kernelService.liftUnlock(
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(transferLiftDevice.getId().intValue());
                    }))
            ));
            // 提升机搬车 至 充电层
            motionList.addAll(kernelService.liftMoveShuttle(
                    MotionDto.build((dto -> {
                        dto.setLiftNo(transferLiftDevice.getId().intValue());
@@ -866,6 +938,23 @@
                    MotionDto.build((dto -> {
                        dto.setLiftNo(transferLiftDevice.getId().intValue());
                        dto.setLev(Utils.getLev(chargeLocNo));
                    }))
            ));
            // 锁定提升机
            motionList.addAll(kernelService.liftLock(
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(transferLiftDevice.getId().intValue());
                    }))
            ));
            // 更新小车坐标
            motionList.addAll(kernelService.shuttleUpdateLocation(
                    null
                    , MotionDto.build((dto -> {
                        dto.setShuttleNo(shuttleDevice.getId().intValue());
                        dto.setLocNo(liftLocNoFrom);
                    }))
            ));
@@ -881,6 +970,14 @@
                        dto.setLocNo(standbyLocNoFrom);
                    })),
                    MotionCtgType.SHUTTLE_MOVE_FROM_LIFT
            ));
            // 解锁提升机
            motionList.addAll(kernelService.liftUnlock(
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(transferLiftDevice.getId().intValue());
                    }))
            ));
            // 穿梭车提升机待机位至充电位
@@ -996,24 +1093,26 @@
        // 判断穿梭车是否在目标层
        if (Utils.getLev(shuttleLocNo) == Utils.getLev(locNo)) {
            // 穿梭车走行至目标库位
            motionList.addAll(kernelService.shuttleMove(
                    MotionDto.build((dto -> {
                        dto.setShuttleNo(shuttleDevice.getId().intValue());
                        dto.setLocNo(shuttleLocNo);
                    })),
                    MotionDto.build((dto -> {
                        dto.setShuttleNo(shuttleDevice.getId().intValue());
                        dto.setLocNo(locNo);
                    })),
                    MotionCtgType.SHUTTLE_MOVE
            ));
            if (!shuttleLocNo.equals(locNo)) {//小车不在目标库位
                // 穿梭车走行至目标库位
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(shuttleLocNo);
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(shuttleDevice.getId().intValue());
                            dto.setLocNo(locNo);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                ));
            }
        } else {
            //小车跨层
            //获取距离目标位置最近的空闲提升机
            LiftThread liftThread = liftDispatcher.searchIdleLift(locNo, task.getHostId());
            //获取距离目标位置最近的空闲可换层提升机
            LiftThread liftThread = liftDispatcher.searchIdleLift(locNo, task.getHostId(), true);
            if (liftThread == null) {
                return motionList;
            }
@@ -1055,7 +1154,15 @@
                    }))
            ));
            // 穿梭车待机位至提升机库位
            // 锁定提升机
            motionList.addAll(kernelService.liftLock(
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(liftDevice.getId().intValue());
                    }))
            ));
            // 穿梭车待机位至提升机
            motionList.addAll(kernelService.shuttleMove(
                    MotionDto.build((dto -> {
                        dto.setShuttleNo(shuttleDevice.getId().intValue());
@@ -1069,6 +1176,22 @@
                    MotionCtgType.SHUTTLE_MOVE_TO_LIFT
            ));
            // 向提升机发送小车已到位信号
            motionList.addAll(kernelService.liftShuttleArrival(
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(liftDevice.getId().intValue());
                    }))
            ));
            // 解锁提升机
            motionList.addAll(kernelService.liftUnlock(
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(liftDevice.getId().intValue());
                    }))
            ));
            // 提升机搬车 至 目标位置层
            motionList.addAll(kernelService.liftMoveShuttle(
                    MotionDto.build((dto -> {
@@ -1078,6 +1201,23 @@
                    MotionDto.build((dto -> {
                        dto.setLiftNo(liftDevice.getId().intValue());
                        dto.setLev(Utils.getLev(locNo));
                    }))
            ));
            // 锁定提升机
            motionList.addAll(kernelService.liftLock(
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(liftDevice.getId().intValue());
                    }))
            ));
            // 更新小车坐标
            motionList.addAll(kernelService.shuttleUpdateLocation(
                    null
                    , MotionDto.build((dto -> {
                        dto.setShuttleNo(shuttleDevice.getId().intValue());
                        dto.setLocNo(liftLocNoFrom);
                    }))
            ));
@@ -1093,6 +1233,14 @@
                        dto.setLocNo(standbyLocNoFrom);
                    })),
                    MotionCtgType.SHUTTLE_MOVE_FROM_LIFT
            ));
            // 解锁提升机
            motionList.addAll(kernelService.liftUnlock(
                    null
                    , MotionDto.build((dto -> {
                        dto.setLiftNo(liftDevice.getId().intValue());
                    }))
            ));
            // 穿梭车提升机待机位至目标位置
@@ -1202,18 +1350,20 @@
            // 判断穿梭车是否在目标层
            if (Utils.getLev(shuttleLocNo) == Utils.getLev(targetLoc)) {
                // 穿梭车走行至源库位
                motionList.addAll(kernelService.shuttleMove(
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(device.getId().intValue());
                            dto.setLocNo(shuttleLocNo);
                        })),
                        MotionDto.build((dto -> {
                            dto.setShuttleNo(device.getId().intValue());
                            dto.setLocNo(sourceLoc);
                        })),
                        MotionCtgType.SHUTTLE_MOVE
                ));
                if (!shuttleLocNo.equals(sourceLoc)) {//小车不在目标库位
                    // 穿梭车走行至源库位
                    motionList.addAll(kernelService.shuttleMove(
                            MotionDto.build((dto -> {
                                dto.setShuttleNo(device.getId().intValue());
                                dto.setLocNo(shuttleLocNo);
                            })),
                            MotionDto.build((dto -> {
                                dto.setShuttleNo(device.getId().intValue());
                                dto.setLocNo(sourceLoc);
                            })),
                            MotionCtgType.SHUTTLE_MOVE
                    ));
                }
                //托盘顶升
                motionList.add(Motion.build(motion -> {