自动化立体仓库 - WCS系统
*
lsh
23 小时以前 98f1c4c9ffbbb3347ad752821505bc3c70ea4efc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package com.zy.asrs.utils;
 
import com.zy.asrs.entity.BasDevpPosition;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.entity.WrkMast;
import com.zy.core.enums.RouteCollectCountType;
import com.zy.core.model.RgvSlave;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
import static java.util.stream.Collectors.toList;
 
/**
 * Created by Monkey D. Luffy on 2023/7/18
 */
public class RouteUtils {
    //排序  执行方向(面朝轨道 定位值左小右大)  0:左 小   1:右 大
    public static List<Integer>[] gradeRange(List<Integer> staNoList, List<BasDevpPosition> basDevpPositionList, boolean itSmall) {
        List<Integer>[] avoidRangeArray = new ArrayList[2];
 
        Integer[] rangeList = new Integer[staNoList.size()];
        List<Integer> rangeList1 = new ArrayList<>();
        List<Integer> rangeList2 = new ArrayList<>();
 
        int i = 0;
        for (BasDevpPosition basDevpPosition : basDevpPositionList) {
            for (Integer staNo : staNoList) {
                if (basDevpPosition.getDevNo().equals(staNo)) {
                    rangeList[i] = staNo;
                    i = i + 1;
                    break;
                }
            }
        }
        boolean sign = true;
        for (int j = 0; j < rangeList.length; j++) {
            if (itSmall) {
                if (sign) {
                    rangeList1.add(rangeList[j]);
                } else {
                    rangeList2.add(rangeList[j]);
                }
                if (sign && j >= rangeList.length / 2) {
                    sign = false;
                }
            } else {
                if (sign && j >= rangeList.length / 2) {
                    sign = false;
                }
                if (sign) {
                    rangeList1.add(rangeList[j]);
                } else {
                    rangeList2.add(rangeList[j]);
                }
            }
        }
 
        avoidRangeArray[0] = rangeList1;
        avoidRangeArray[1] = rangeList2;
        return avoidRangeArray;
    }
 
 
    //获取在范围的站点
    public static List<Integer> belongToRange(List<Integer> staNoList, Long[] avoid, List<BasDevpPosition> basDevpPositions) {
        List<Integer> siteList = new ArrayList<>();
 
        for (BasDevpPosition basDevpPosition : basDevpPositions) {
            if (new TrackRangeUtils().avoidRange(basDevpPosition.getPlcPosition(), avoid)) {
                for (Integer staNo : staNoList) {
                    if (basDevpPosition.getDevNo().equals(staNo)) {
                        siteList.add(staNo);
                        break;
                    }
                }
            }
        }
 
        return siteList;
    }
 
    //提取站点集合
    public static List<Integer> BasDevpPositionExtractSites(List<BasDevpPosition> basDevpPositions) {
        List<Integer> siteList = new ArrayList<>();
        for (BasDevpPosition basDevpPosition : basDevpPositions) {
            if (!siteList.contains(basDevpPosition.getDevNo())) {
                siteList.add(basDevpPosition.getDevNo());
            }
        }
        return siteList;
    }
 
    //提取站点集合//就近排序
    public static List<Integer> SortNearby(List<Integer> staNoList, Long rgvNowPos, List<BasDevpPosition> basDevpPositionList) {
        List<Integer> siteList = new ArrayList<>();
 
        List<BasDevpPosition> basDevpPositions = devpNoSort(basDevpPositionList, rgvNowPos);
        for (BasDevpPosition basDevpPosition : basDevpPositions) {
            for (Integer staNo : staNoList) {
                if (basDevpPosition.getDevNo().equals(staNo)) {
                    siteList.add(staNo);
                    break;
                }
            }
        }
 
 
        return siteList;
    }
 
    //站点过滤
    public static List<BasDevpPosition> devpNoSort(List<BasDevpPosition> devpPositionList, Long rgvNowPos) {
 
        List<BasDevpPosition> basDevpPositions = new ArrayList<>();
        List<BasDevpPosition> basDevpPositionSort = new ArrayList<>();
        ArrayList<Long> arrayList = new ArrayList<>();
        for (BasDevpPosition basDevpPosition : devpPositionList) {
            long position = Math.abs(basDevpPosition.getPlcPosition() - rgvNowPos);
            BasDevpPosition devpPosition = new BasDevpPosition(basDevpPosition, position);
            basDevpPositions.add(devpPosition);
            arrayList.add(position);
        }
        Collections.sort(arrayList); // 升序排序
        for (Long position : arrayList) {
            for (BasDevpPosition basDevpPosition : basDevpPositions) {
                if (basDevpPosition.getPlcPosition().equals(position)) {
                    basDevpPositionSort.add(basDevpPosition);
                    break;
                }
            }
        }
        return basDevpPositionSort;
    }
 
    //检测是否在范围
    public static boolean CheckIfItIsWithinTheRange(List<Integer> staNoList, Long staNoNowPos, List<BasDevpPosition> basDevpPositionList, boolean itSmall) {
        List<Integer> siteList = new ArrayList<>();
 
 
        Integer[] rangeList = new Integer[staNoList.size()];
        int i = 0;
        for (BasDevpPosition basDevpPosition : basDevpPositionList) {
            for (Integer staNo : staNoList) {
                if (basDevpPosition.getDevNo().equals(staNo)) {
                    rangeList[i] = staNo;
                    i = i + 1;
                    break;
                }
            }
        }
 
        if (itSmall) {
            return staNoNowPos <= rangeList[rangeList.length - 1];
        }
        return staNoNowPos >= rangeList[0];
    }
 
    public static long absoluteDifference(Long a, Long b) {
        if (a == null || b == null) {
            a = 0L;
            b = 0L;
//            throw new IllegalArgumentException("");
            System.out.println("a or b is null");
        }
        return Math.abs(a - b);
    }
 
}