自动化立体仓库 - WCS系统
Junjie
2023-06-10 19df3213d5d4a7b85d2d4ceffef7460a59c1f062
src/main/java/com/zy/common/utils/NavigateUtils.java
@@ -1,6 +1,7 @@
package com.zy.common.utils;
import com.alibaba.fastjson.JSONObject;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.MapNode;
import com.zy.common.model.NavigateNode;
import com.zy.core.enums.ShuttleTaskModeType;
@@ -16,13 +17,16 @@
        int[] startArr = NavigatePositionConvert.positionToXY(startPoint);//开始节点
        int[] endArr = NavigatePositionConvert.positionToXY(endPoint);//结束节点
        //获取当前节点计算的层高,并赋值到每一个节点中
        int lev = Utils.getLev(startPoint);
        //初始化开始节点
        NavigateNode start = new NavigateNode(startArr[0], startArr[1]);
        //开始节点无父节点
        start.setFather(null);
        NavigateNode end = new NavigateNode(endArr[0], endArr[1]);
        NavigateSolution solution = new NavigateSolution(mapType);
        NavigateSolution solution = new NavigateSolution(mapType, lev);
        NavigateNode res_node = solution.astarSearch(start, end);
        if (res_node == null) {
            System.out.println("未找到路径");
@@ -35,6 +39,7 @@
            while (res_node != null) {
                res_node.setDirection(null);
                res_node.setIsInflectionPoint(false);
                res_node.setZ(lev);//设置层高
                //寻找拐点
                HashMap<String, Object> result = searchInflectionPoint(res_node, fatherNode, res_node.getFather());//分别传入当前节点、父节点、下一节点
@@ -129,7 +134,9 @@
        ArrayList<ArrayList<NavigateNode>> list = new ArrayList<>();
        ArrayList<NavigateNode> data = new ArrayList<>();
        String direction = mapList.get(0).getDirection();//行走方向
        for (NavigateNode mapNode : mapList) {
        for (int i = 0; i < mapList.size(); i++) {
            NavigateNode mapNode = mapList.get(i);
            boolean isInflectionPoint = mapNode.getIsInflectionPoint();
            data.add(mapNode);
            if (isInflectionPoint) {
@@ -138,6 +145,7 @@
                list.add(data);//添加某一段数据
                direction = mapNode.getDirection();//更新行走方向
                data = new ArrayList<>();
                data.add(mapNode);//将拐点的终点,更新成下一段命令的起点坐标
            }else {
                //直行线路
                mapNode.setDirection(direction);//设置行走方向
@@ -155,11 +163,20 @@
    //获取从x点到下一点的行走距离
    public static Integer getXToNextDistance(NavigateNode xNode) {
        NavigateMapData mapData = new NavigateMapData();
        ArrayList<ArrayList<JSONObject>> lists = mapData.getJsonData(1);
        List<List<MapNode>> lists = mapData.getJsonData(1);
        if (lists != null) {
            JSONObject jsonObject = lists.get(xNode.getX()).get(xNode.getY());
            if (jsonObject != null) {
                return Integer.parseInt(jsonObject.getOrDefault(xNode.getDirection(), 0).toString());
            MapNode mapNode = lists.get(xNode.getX()).get(xNode.getY());
            if (mapNode != null) {
                switch (xNode.getDirection()) {
                    case "top":
                        return mapNode.getTop();
                    case "bottom":
                        return mapNode.getBottom();
                    case "left":
                        return mapNode.getLeft();
                    case "right":
                        return mapNode.getRight();
                }
            }
            return 0;
        }
@@ -169,7 +186,7 @@
    /**
     * 获取当前路径总行走距离
     */
    public static Integer getCurrentPathAllDistance(ArrayList<NavigateNode> path) {
    public static Integer getCurrentPathAllDistance(List<NavigateNode> path) {
        if (path.size() == 1) {
            //路径只有一条数据,则直接返回行走距离
            return path.get(0).getMoveDistance();
@@ -183,6 +200,15 @@
        return allDistance;
    }
    /**
     * 获取中间点到目标点行走距离
     */
    public static Integer getMiddleToDistDistance(List<NavigateNode> path) {
        //中间路径
        NavigateNode middlePath = path.get(path.size() - 2);
        return middlePath.getMoveDistance();
    }
    public static void main(String[] args) {
        //计算路径
        List<NavigateNode> calc = calc("1000901", "1800201", ShuttleTaskModeType.PAK_OUT.id);