自动化立体仓库 - WCS系统
1
zhangc
2025-04-10 9fa73c998ffe1ba6d0d79d3c1dbd5a911403c2cc
1
1个文件已添加
6个文件已修改
276 ■■■■ 已修改文件
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java 90 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/MainProcess.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/ServerBootstrap.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/model/LedSlave.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/properties/SlaveProperties.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/NormalLedThread.java 65 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 65 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -91,24 +91,6 @@
    @Autowired
    private LiftAction liftAction;
    //入库站点
    public static final ArrayList<Integer> inSta = new ArrayList<Integer>() {{
        add(1012);
        add(1014);
        add(1022);
        add(1025);
        add(1032);
    }};
    //出库站点
    public static final ArrayList<Integer> outSta = new ArrayList<Integer>() {{
        add(1012);
        add(1014);
        add(1022);
        add(1025);
        add(1032);
    }};
    private boolean isInEnable(DevpThread devpThread, Integer staNo) {
        if (staNo == null) {
@@ -180,7 +162,7 @@
     */
    public synchronized void generateInboundWrk() {
        try {
            DevpSlave devpSlave = slaveProperties.getDevpSlave().get(0);
            DevpSlave devpSlave = slaveProperties.getDevp().get(0);
            // 遍历入库口
            for (DevpSlave.Sta inSta : devpSlave.getInSta()) {
                // 获取入库站信息
@@ -232,7 +214,6 @@
                    }
                    continue;
                }
                // 判断是否满足入库条件
                if (staProtocol.isAutoing() && staProtocol.isLoading()
                        && isInEnable(devpThread, inSta.getStaNo())
@@ -243,7 +224,6 @@
                    if (!Cools.isEmpty(barcode)) {
                        News.info("条码扫描器检测条码信息:{}", barcode);
                    }
                    // 判断重复工作档
                    WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>()
                            .eq("source_sta_no", inSta.getStaNo())
@@ -336,6 +316,74 @@
    /**
     * 出库到出库口
     */
    public synchronized void stnToOutStn() {
        DevpSlave devpSlave = slaveProperties.getDevp().get(0);
        // 遍历堆垛机出库站
        for (DevpSlave.Sta outSta : devpSlave.getOutSta()) {
            // 获取堆垛机出库站信息
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devpSlave.getId());
            StaProtocol staProtocol = devpThread.getStation().get(outSta.getStaNo());
            if (staProtocol == null) {
                continue;
            } else {
                staProtocol = staProtocol.clone();
            }
            if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
                // 查询工作档
//                WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId());
//                if (wrkMast == null) {
//                    continue;
//                }
//                // 判断工作档条件
//                if (wrkMast.getIoType() < 100 || wrkMast.getStaNo() == null || wrkMast.getSourceStaNo() == null) {
//
//                }
                //  判断输送线和小车状态状态等待确认
//                if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
//                        && crnProtocol.statusType == CrnStatusType.WAITING
//                        && crnProtocol.forkPosType == CrnForkPosType.HOME) {
//                    log.info("堆垛机出库完成 - 开始执行");
//
//                    // 命令下发区 --------------------------------------------------------------------------
//
//                    // 下发站点信息
//                    staProtocol.setWorkNo(wrkMast.getWrkNo());
//                    staProtocol.setStaNo(RouteUtils.CrnStaEnd(wrkMast.getStaNo(), wrkMast.getSourceStaNo()));
//                    if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
//                        log.info(staProtocol.getWorkNo() + "," + staProtocol.getStaNo() + "输送线出库命令下发失败");
//                        continue;
//                    } else {
//                        log.info(staProtocol.getWorkNo() + "," + staProtocol.getStaNo() + "输送线出库命令下发成功");
//                    }
//
//                    // 更新工作档状态为14失败
//                    wrkMast.setWrkSts(14L);
//                    wrkMast.setCrnEndTime(new Date());
//                    if (wrkMastMapper.updateById(wrkMast) != 0) {
//                        // 复位堆垛机
//                        log.error("出库任务完成下发堆垛机复位,{}", wrkMast.getWrkNo());
//                        crnThread.setResetFlag(true);
//                    } else {
//                        News.error("" + mark + " - 1" + " - 更新工作档的工作状态为14失败!!! [工作号:{}]", wrkMast.getWrkNo());
//                    }
//
//                } else {
//                    News.errorNoLog("" + mark + " - 6" + " - 堆垛机信息不符合入库条件!!!"
//                            + " 堆垛机状态:" + crnProtocol.modeType + "==自动AUTO:" + CrnModeType.AUTO
//                            + "、堆垛机任务号:" + crnProtocol.getTaskNo() + "==工作档任务号:" + wrkMast.getWrkNo().shortValue()
//                            + "、状态枚举:" + crnProtocol.statusType + "==WAITING:90 //任务完成等待WCS确认):" + CrnStatusType.WAITING
//                            + "、货叉位置:" + crnProtocol.forkPosType + "==HOME:0  // 货叉原位:" + CrnForkPosType.HOME);
//                }
            }
        }
    }
    /**
     * 初始化实时地图
     */
    public synchronized void initRealtimeBasMap() {
src/main/java/com/zy/core/MainProcess.java
@@ -28,7 +28,7 @@
    /**
     * =====>>  开始工作
     */
    public void start(){
    public void start() {
        thread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                try {
@@ -42,10 +42,10 @@
                    }
                    //zhangc
                    //输送线
                    // 入库  ===>> 入库站到堆垛机站,根据条码扫描生成入库工作档
                    mainService.generateInboundWrk(); // 组托
                    // 入库
                    //mainService.generateInboundWrk();
                    // 出库
                    //mainService.stnToOutStn();
                    //初始化实时地图
                    mainService.initRealtimeBasMap();
@@ -84,7 +84,7 @@
    }
    @PreDestroy
    public void shutDown(){
    public void shutDown() {
        if (thread != null) thread.interrupt();
    }
src/main/java/com/zy/core/ServerBootstrap.java
@@ -5,10 +5,7 @@
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.ForkLiftSlave;
import com.zy.core.model.LiftSlave;
import com.zy.core.model.ShuttleSlave;
import com.zy.core.model.*;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.impl.*;
import lombok.extern.slf4j.Slf4j;
@@ -122,7 +119,7 @@
            SlaveConnection.put(SlaveType.Shuttle, shuttleSlave.getId(), thread);
        }
        // 初始化输送线
        for (DevpSlave devpSlave : slaveProperties.getDevpSlave()) {
        for (DevpSlave devpSlave : slaveProperties.getDevp()) {
            News.info("初始化输送线......................................................");
            ThreadHandler thread = null;
            if (devpSlave.getThreadImpl().equals("FyDevpThread")) {
@@ -136,17 +133,17 @@
        }
        // 初始化电视机
        for (DevpSlave devpSlave : slaveProperties.getL()) {
        for (LedSlave ledSlave : slaveProperties.getLed()) {
            News.info("初始化电视机......................................................");
            ThreadHandler thread = null;
            if (devpSlave.getThreadImpl().equals("FyDevpThread")) {
                thread = new FyDevpThread(devpSlave);
            if (ledSlave.getThreadImpl().equals("NormalLedThread")) {
                thread = new NormalLedThread(ledSlave);
            } else {
                throw new CoolException("未知的线程实现");
            }
            new Thread(thread).start();
            SlaveConnection.put(SlaveType.Shuttle, devpSlave.getId(), thread);
            SlaveConnection.put(SlaveType.Shuttle, ledSlave.getId(), thread);
        }
    }
src/main/java/com/zy/core/model/LedSlave.java
New file
@@ -0,0 +1,24 @@
package com.zy.core.model;
import com.zy.core.Slave;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.ArrayList;
import java.util.List;
/**
 * LED配置
 * Created by vincent on 2020/8/6
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class LedSlave extends Slave {
    // 输送线plc编号
    private Integer devpPlcId;
    // 叉车站点数组
    private List<Integer> staArr = new ArrayList<>();
}
src/main/java/com/zy/core/properties/SlaveProperties.java
@@ -1,6 +1,5 @@
package com.zy.core.properties;
import com.zy.core.Slave;
import com.zy.core.model.*;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -23,9 +22,9 @@
    private int groupCount;
    private List<LedS> Led = new ArrayList<>();
    private List<LedSlave> Led = new ArrayList<>();
    private List<DevpSlave> devpSlave = new ArrayList<>();
    private List<DevpSlave> devp = new ArrayList<>();
    private List<ShuttleSlave> shuttle = new ArrayList<>();
src/main/java/com/zy/core/thread/impl/NormalLedThread.java
@@ -1,6 +1,11 @@
package com.zy.core.thread.impl;
import com.zy.common.model.MatDto;
import com.zy.core.Slave;
import com.zy.core.cache.MessageQueue;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.LedSlave;
import com.zy.core.model.Task;
import com.zy.core.model.command.LedCommand;
import com.zy.core.thread.LedThread;
import lombok.extern.slf4j.Slf4j;
@@ -13,7 +18,9 @@
@SuppressWarnings("all")
public class NormalLedThread implements LedThread, Runnable {
    private Slave slave;
    private Set<Integer> workNos = new HashSet<>();
    private boolean ledMk = false;
    private boolean resetStatus = false;    // 复位状态
@@ -23,9 +30,43 @@
    private StringBuffer errorMsg = new StringBuffer();
    public NormalLedThread(LedSlave ledSlave) {
        this.slave = ledSlave;
    }
    @Override
    @SuppressWarnings({"InfiniteLoopStatement", "unchecked"})
    public void run() {
//        connect();
        while (true) {
            try {
                Task task = MessageQueue.poll(SlaveType.Led, slave.getId());
                if (task != null) {
                    switch (task.getStep()) {
                        // 写数据
                        case 1:
                            write((List<LedCommand>) task.getData());
                            break;
                        // 复位
                        case 2:
                            reset();
                            break;
                        case 3:
                            error((String) task.getData());
                            break;
                        case 4:
                            errorReset();
                            break;
                        default:
                            break;
                    }
                }
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public void write(List<LedCommand> list) {
@@ -52,11 +93,13 @@
        errorReset();
    }
    public void reset() {
        commandList = null;
        stringBuffer.delete(0, stringBuffer.length());
        errorMsg.delete(0, errorMsg.length());
    }
    public void error(String msg) {
        errorMsg.delete(0, errorMsg.length());
@@ -68,21 +111,21 @@
    }
    @Override
    public boolean connect() {
        return true;
    }
    @Override
    public void close() {
    }
    @Override
    public void setLedMk(boolean mk) {
        this.ledMk = mk;
    }
    @Override
    public boolean isLedMk() {
        return this.ledMk;
        return false;
    }
    @Override
    public boolean connect() {
        return true;
    }
    @Override
    public void close() {
    }
}
src/main/resources/application.yml
@@ -13,7 +13,7 @@
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/fyxc_shuttle?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: zhangchao
    password: root
  mvc:
    static-path-pattern: /**
  redis:
@@ -72,14 +72,65 @@
    standByBay: 1
    staRow: 2
    staBay: 1
  devpSlave[0]:
    id:
  devp[0]:
    id: 1
    ip: 192.168.10.51
    port: 102
    rack: 0
    slot: 0
    # 入库口1
    inSta[0]:
      staNo:
      backSta:
      staNo: 1012
      backSta: 1011
      led: ${wcs-slave.led[0].id}
    # 入库口2
    inSta[1]:
      staNo:
      backSta:
      staNo: 1014
      backSta: 1013
      led: ${wcs-slave.led[1].id}
    # 入库口3
    inSta[2]:
      staNo: 1022
      backSta: 1021
      led: ${wcs-slave.led[2].id}
    # 入库口4
    inSta[3]:
      staNo: 1025
      backSta: 1024
      led: ${wcs-slave.led[3].id}
    # 出库口1
    outSta[0]:
      staNo: 1012
    outSta[1]:
      staNo: 1014
    outSta[2]:
      staNo: 1022
    outSta[3]:
      staNo: 1025
  # LED1
  led[0]:
    id: 1
    ip: 192.168.10.62
    port: 5005
    devpPlcId: ${wcs-slave.devp[0].id}
  # LED2
  led[1]:
    id: 2
    ip: 192.168.10.63
    port: 5005
    devpPlcId: ${wcs-slave.devp[0].id}
  # LED3
  led[2]:
    id: 3
    ip: 192.168.10.64
    port: 5005
    devpPlcId: ${wcs-slave.devp[0].id}
  # LED4
  led[3]:
    id: 4
    ip: 192.168.10.65
    port: 5005
    devpPlcId: ${wcs-slave.devp[0].id}