#
Junjie
2024-05-15 3700ea78d4c776687ccc0bf555f34fa0e88d7fb7
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/action/ShuttleAction.java
@@ -4,12 +4,15 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zy.asrs.wcs.common.ExecuteSupport;
import com.zy.asrs.wcs.core.entity.Loc;
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.model.NavigateNode;
import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand;
import com.zy.asrs.wcs.core.model.command.ShuttleCommand;
import com.zy.asrs.wcs.core.model.command.ShuttleRedisCommand;
import com.zy.asrs.wcs.core.model.enums.LocStsType;
import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType;
import com.zy.asrs.wcs.core.model.enums.ShuttleTaskModeType;
import com.zy.asrs.wcs.core.service.BasShuttleService;
@@ -31,6 +34,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Component
public class ShuttleAction {
@@ -109,16 +113,6 @@
        if (shuttleProtocol == null) {
            return false;
        }
        //判断设备是否空闲
        if (!shuttleThread.isDeviceIdle()) {
            return false;
        }
//        if (!shuttleThread.isIdle(() -> {
//            return shuttleProtocol.getTaskNo().equals(taskNo);
//        })) {
//            return false;
//        }
        //判断工作号是否相同
        if (!shuttleProtocol.getTaskNo().equals(taskNo)) {
@@ -222,6 +216,20 @@
        //取出命令
        ShuttleCommand command = commands.get(commandStep);
        Integer mode = command.getMode();
        //判断设备是否空闲
        if (!shuttleThread.isDeviceIdle(new ExecuteSupport() {
            @Override
            public Boolean judgement() {
                if (ShuttleCommandModeType.CHARGE_CLOSE.id.equals(mode)) {//关闭充电motion
                    return false;//不需要判断状态
                }
                return true;//需要判断状态
            }
        })) {
            return false;
        }
        // 下发命令
        if (!write(command, device)) {
            News.error("四向穿梭车命令下发失败,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
@@ -243,7 +251,7 @@
        if (shuttleThread == null) {
            return;
        }
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(false);
        if (shuttleProtocol == null) {
            return;
        }
@@ -273,35 +281,6 @@
        }
        if (shuttleProtocol.getMoveType() == 0) {//跑轨道
            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);
                }
            }
        } else if (shuttleProtocol.getMoveType() == 1) {//跑库位
            Integer xCurrent = shuttleProtocol.getXCurrent();
            if (xCurrent > shuttleProtocol.getXTarget()) {//当X值大于X目标值,进行归零且Y方向+1
                shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
@@ -330,6 +309,35 @@
            } 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);
                }
            }
        } else if (shuttleProtocol.getMoveType() == 2) {//母轨道循环跑
            Integer xCurrent = shuttleProtocol.getXCurrent();
@@ -375,6 +383,50 @@
                    }
                }
            }
        } else if (shuttleProtocol.getMoveType() == 4) {//取放货
            Integer xCurrent = shuttleProtocol.getXCurrent();
            if (xCurrent > shuttleProtocol.getXTarget()) {//当X值大于X目标值
                shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
                shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
                return;
            }
            //搜索有货库位
            List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>()
                    .eq(Loc::getLocSts, LocStsType.F.val())
                    .eq(Loc::getHostId, device.getHostId())
                    .eq(Loc::getStatus, 1));
            if (list.isEmpty()) {
                return;
            }
            Loc start = list.get(0);
            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())
                    .eq(Loc::getStatus, 1));
            if (target == null) {
                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
                return;
            }
            if (target.getLocSts() != LocStsType.O.val()) {
                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
                return;
            }
            //调度去目标位置
            if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);//小车和目标位置一致,跳过
            } else {
                Task task = shuttleDispatcher.generateManuaTakeMoveTask(device, start.getLocNo(), target.getLocNo());
                if(task != null) {//调度成功
                    shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
                }
            }
        }
    }