自动化立体仓库 - WCS系统
Junjie
2023-03-27 06bd2d6dbd31315b68e768d6b59139c753f8ff96
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -22,10 +22,7 @@
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.*;
import com.zy.core.model.*;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.command.LedCommand;
import com.zy.core.model.command.ShuttleCommand;
import com.zy.core.model.command.SteCommand;
import com.zy.core.model.command.*;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.model.protocol.StaProtocol;
@@ -631,85 +628,23 @@
                    //分配目标库位
                    shuttleProtocol.setLocNo(wrkSts.getLocNo());
                    //计算路径
                    List<NavigateNode> calc = NavigateUtils.calc(wrkSts.getSourceLocNo(), wrkSts.getLocNo(), "in");
                    //获取分段路径
                    ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc);
                    //将此map存入redis中
                    HashMap<String, Object> map = new HashMap<>();
                    //执行步序
                    map.put("step", 0);
                    //路径数据
                    map.put("path", data);
                    //工作号
                    map.put("wrk_no", wrkSts.getWrkNo());
                    //任务数据保存到redis
                    redisUtil.set("wrk_no_" + wrkSts.getWrkNo().shortValue(), JSON.toJSONString(map));
                    ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
                    //四向穿梭车号
                    assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());
                    //任务号
                    assignCommand.setTaskNo(wrkSts.getWrkNo().shortValue());
                    //入出库模式
                    assignCommand.setTaskMode(0);
                    //源库位
                    assignCommand.setSourceLocNo(wrkSts.getSourceLocNo());
                    //目标库位
                    assignCommand.setDistLocNo(wrkSts.getLocNo());
                    //下发任务
                    MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                }
            } else if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE && shuttleProtocol.getTaskNo() != 0) {
                //四向穿梭车空闲 并且有任务
                Object o = redisUtil.get("wrk_no_" + shuttleProtocol.getTaskNo());
                HashMap map = JSON.parseObject(o.toString(), HashMap.class);
                //当前步序
                int step = Integer.parseInt(map.get("step").toString());
                //当前路径数据
                Object data = map.get("path");
                ArrayList pathList = JSON.parseObject(data.toString(), ArrayList.class);
                //取第一条路径
                Object o1 = pathList.get(step);
                ArrayList path = JSON.parseObject(o1.toString(), ArrayList.class);
                int size = path.size();
                //开始路径
                JSONObject startPath = JSON.parseObject(path.get(0).toString());
                System.out.println(startPath);
                //目标路径
                JSONObject endPath = JSON.parseObject(path.get(size - 1).toString());
                System.out.println(endPath);
                //下发命令
                ShuttleCommand command = new ShuttleCommand();
                command.setCommandWord((short) 1);
                command.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getIntValue("x"), startPath.getIntValue("y")));
                command.setMiddleCodeNum((short) 0);
                command.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getIntValue("x"), endPath.getIntValue("y")));
                command.setStartToDistDistance(1000);
                command.setMiddleToDistDistance(1000);
                command.setRunDirection(ShuttleRunDirection.get(startPath.get("direction").toString()).id);
                command.setPalletLift((short) 1);
                command.setForceMoveDistance(1000);
                command.setChargeSwitch((short) 2);
                command.setIOControl((short) 0);
                command.setRunSpeed((short) 1000);
                command.setRadarTmp((short) 0);
                command.setCommandEnd((short) 1);
                if (!MessageQueue.offer(SlaveType.Shuttle, shuttleProtocol.getShuttleNo().intValue(), new Task(2, command))) {
                    News.error("四向穿梭车命令下发失败,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
                } else {
                    News.info("四向穿梭车命令下发成功,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
                    //判断数据是否执行完成
                    if (step < size) {
                        //更新redis数据
                        //步序增加
                        step++;
                        map.put("step", step);
                        //任务数据保存到redis
                        redisUtil.set("wrk_no_" + map.get("wrk_no").toString(), JSON.toJSONString(map));
                    }else {
                        //已执行完成
                        //保存数据到数据库做流水
                        //删除redis
                        redisUtil.del("wrk_no_" + map.get("wrk_no").toString());
                        //。。。
                        //1、命令下方需要判断小车空闲状态
                        //2、
                    }
                }
            }
        }