1
2025-09-29 4747e5dcb4066161b42a7a54cab542949ad5826c
src/main/java/com/zy/core/model/protocol/RgvProtocol.java
@@ -5,6 +5,7 @@
import com.zy.core.enums.RgvStatusType;
import lombok.Data;
import javax.swing.*;
import java.util.HashMap;
import java.util.Map;
@@ -14,7 +15,7 @@
@Data
public class RgvProtocol implements Cloneable{
    private Integer RgvNo;
    private short RgvNo;
    /**
     * 1 = 手动模式
@@ -25,13 +26,29 @@
    public RgvModeType modeType;
    private transient Long loadingStartTime;
    /**
     * RGV当前状态
     * 执行优先级
     * 0:不判断
     * 1:工位1先执行
     * 2:工位2先执行
     */
    public Short wrkTaskPri;
    public Short wrkTaskMove1;
    public Short wrkTaskMove2;
    /**
     * RGV当前状态工位1
     * 0:空闲,无任务
     * 1:作业中
     * 2:报警
     */
    public Short status;
    /**
     * 状态枚举
@@ -41,7 +58,11 @@
    /**
     * 工位1任务号
     */
    public Short taskNo1 = 0;
    public Integer taskNo1 = 0;
    /**
     * 工位1目标站
     */
    public Integer staNo1 = 0;
    /**
     * RGV工位1当前状态
@@ -60,12 +81,18 @@
    /**
     * 工位1有物
     */
    public Short loaded1;
    public Boolean loaded1;
    /**
     * RGV当前位置
     */
    public Short RgvPos;
    public Integer RgvPos;
    /**
     * RGV当前目的位置
     */
    public Integer RgvPosDestination;
    /**
     * 走行在定位
@@ -74,11 +101,56 @@
     */
    public Short walkPos;
    /**
     * 急停触发
     */
    public Boolean err1;
    /**
     *
     */
    public Boolean err2;
    /**
     * 有资料无物
     */
    public Boolean err3;
    /**
     * 命令错误走行联调冲突
     */
    public Boolean err4;
    /**
     * 目标为超过行走极限
     */
    public Boolean err5;
    /**
     *  变频器异常
     */
    public Boolean err6;
    /**
     * 光电异常
     */
    public Boolean err7;
    public Boolean err8;
    public Boolean err9;
    public Boolean err10;
    public Boolean err11;
    public Boolean err12;
    //////////////////////     工位2定义   //////////////////////////////////////////////////
    /**
     * 工位2任务号
     */
    public Short taskNo2 = 0;
    public Integer taskNo2 = 0;
    /**
     * 工位1目标站
     */
    public Integer staNo2 = 0;
    /**
     * RGV工位2当前状态
@@ -97,7 +169,44 @@
    /**
     * 工位2有物
     */
    public Short loaded2;
    public Boolean loaded2;
//    /**
//     * 急停
//     */
//    public Boolean err21;
//
//    /**
//     * 有物无资料
//     */
//    public Boolean err22;
//
//    /**
//     * 有资料无物
//     */
//    public Boolean err23;
//
//    /**
//     * 命令错误走行联调冲突
//     */
//    public Boolean err24;
//
//    /**
//     * 目标为超过行走极限
//     */
//    public Boolean err25;
//
//    /**
//     *  变频器异常
//     */
//    public Boolean err26;
//
//    /**
//     * 光电异常
//     */
//    public Boolean err27;
    ///////////////////////////////////////////////////////////////////////////////////////
    /**
@@ -165,15 +274,24 @@
        this.status1 = RgvStatusType.get(type1).id.shortValue();
    }
//    public void setStatus2(Short status2){
//        this.status2 = status2;
//        this.statusType2 = RgvStatusType.get(status2);
//    }
//
//    public void setStatus2(RgvStatusType type2){
//        this.statusType2 = type2;
//        this.status2 = RgvStatusType.get(type2).id.shortValue();
//    }
    public void setStatus2(Short status2){
        this.status2 = status2;
        this.statusType2 = RgvStatusType.get(status2);
    }
    public void setStatus2(RgvStatusType type2){
        this.statusType2 = type2;
        this.status2 = RgvStatusType.get(type2).id.shortValue();
    }
    public boolean isLoaded1ing() {
        return Boolean.TRUE.equals(this.loaded1);
    }
    public boolean isLoaded2ing() {
        return Boolean.TRUE.equals(this.loaded2);
    }
    /**
     * 最近一次入出库类型
@@ -188,7 +306,7 @@
            basRgv.setRgvErr(alarm.longValue());
        }
        basRgv.setWrkNo1(taskNo1.intValue());
//        basRgv.setWrkNo2(taskNo2.intValue());
        basRgv.setWrkNo2(taskNo2.intValue());
        return basRgv;
    }
@@ -207,17 +325,48 @@
    public Integer getRgvPosI(){
        //需要根据现场改造  根据读到的值获取对应站点位置
        Map<Short,Integer> map = new HashMap<>();
        map.put((short) 1,100);map.put((short) 2,101);
        map.put((short) 3,106);map.put((short) 4,107);
        map.put((short) 5,112);map.put((short) 6,113);
       map.put((short) 7,124); map.put((short) 8,119);
        map.put((short) 9,149);map.put((short) 10,153);
        map.put((short) 11,157);map.put((short) 12,161);
        map.put((short) 1,1004);map.put((short) 2,1007);
        map.put((short) 3,1010);map.put((short) 4,1014);
        map.put((short) 5,1018);map.put((short) 6,1021);
       map.put((short) 7,1024); map.put((short) 8,1028);
        map.put((short) 9,1031);map.put((short) 10,1035);
        map.put((short) 11,2003);map.put((short) 12,2006);
        map.put((short) 13,2009);map.put((short) 14,2012);
        map.put((short) 15,2015);map.put((short) 16,2018);
        map.put((short) 17,2021);map.put((short) 18,2024);
        map.put((short) 19,2027);map.put((short) 20,2030);
        if (RgvPos==null) return 0;
        return map.get(RgvPos);
    }
    public Integer getRgvPosI2() {
        // key: 站点号  value: 基准物理位置
        Map<Integer, Integer> posMap = new HashMap<>();
        posMap.put(1004, 6534);
        posMap.put(1007, 33634);
        posMap.put(1010, 75174);
        posMap.put(1014, 102124);
        posMap.put(1018, 138224);
        posMap.put(1021, 178034);
        posMap.put(1024, 219684);
        posMap.put(1028, 246724);
        posMap.put(1031, 288194);
        posMap.put(1035, 315204);
        int tolerance = 200; // 允许误差范围
        for (Map.Entry<Integer, Integer> entry : posMap.entrySet()) {
            int site = entry.getKey();
            int basePos = entry.getValue();
            if (Math.abs(RgvPos - basePos) <= tolerance) {
                return site;
            }
        }
        return 0; // 没匹配到站点
    }
    @Override
    public RgvProtocol clone() {
        try {