#
Junjie
2024-05-20 4d8bb57c9eb3fda399fd7b9e9de7ecbf754244f7
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;
@@ -26,12 +29,12 @@
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 org.aspectj.apache.bcel.generic.RET;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Component
public class ShuttleAction {
@@ -110,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)) {
@@ -223,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));
@@ -244,8 +251,7 @@
        if (shuttleThread == null) {
            return;
        }
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(false);
        if (shuttleProtocol == null) {
            return;
        }
@@ -275,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());
@@ -332,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();
@@ -377,6 +383,66 @@
                    }
                }
            }
        } else if (shuttleProtocol.getMoveType() == 4) {//取放货
            Integer xCurrent = shuttleProtocol.getXCurrent();
            if (xCurrent > shuttleProtocol.getXTarget()) {//当X值大于X目标值
                shuttleProtocol.setXCurrent(shuttleProtocol.getXStart());
                shuttleProtocol.setYCurrent(shuttleProtocol.getYStart());
                return;
            }
            //判断x轴货位是否放满
            boolean flag = true;
            for (Loc loc : locService.list(new LambdaQueryWrapper<Loc>()
                    .eq(Loc::getHostId, device.getHostId())
                    .eq(Loc::getRow, xCurrent)
                    .ge(Loc::getBay, shuttleProtocol.getYStart())
                    .le(Loc::getBay, shuttleProtocol.getYTarget()))) {
                if (loc.getLocSts() != LocStsType.F.val()) {
                    flag = false;//未满
                    break;
                }
            }
            if (flag) {
                shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
                return;
            }
            //搜索有货库位
            List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>()
                    .eq(Loc::getLocSts, LocStsType.F.val())
                    .eq(Loc::getHostId, device.getHostId())
                    .notIn(Loc::getRow, xCurrent)
                    .eq(Loc::getStatus, 1));
            if (list.isEmpty()) {
                return;
            }
            Loc start = list.get(0);
            List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>()
                    .eq(Loc::getHostId, device.getHostId())
                    .eq(Loc::getStatus, 1)
                    .eq(Loc::getLocSts, LocStsType.O.val())
                    .eq(Loc::getRow, xCurrent)
                    .orderByDesc(Loc::getBay)
                    .orderByAsc(Loc::getRow));
            if (locList.isEmpty()) {
                return;
            }
            Loc target = locList.get(0);
            if (target == null) {
                return;
            }
            //调度去目标位置
            if (!shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) {
                Task task = shuttleDispatcher.generateManuaTakeMoveTask(device, start.getLocNo(), target.getLocNo());
//                if(task != null) {//调度成功
//                    shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1);
//                }
            }
        }
    }