| | |
| | | |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.common.model.NyShuttleOperaResult; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.*; |
| | | import com.zy.core.News; |
| | |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import javax.swing.*; |
| | | import java.io.IOException; |
| | | import java.net.Socket; |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | private void readStatus() { |
| | | try { |
| | | if (null == shuttleProtocol) { |
| | | shuttleProtocol = new NyShuttleProtocol(); |
| | | shuttleProtocol.setShuttleNo(slave.getId().shortValue()); |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); |
| | | } |
| | | |
| | | //----------读取四向穿梭车状态----------- |
| | | NyShuttleHttpCommand readStatusCommand = NyHttpUtils.getReadStatusCommand(slave.getId()); |
| | | JSONObject jsonObject = NyHttpUtils.requestCommand(socket, readStatusCommand); |
| | |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | // log.info(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), slave.getId())); |
| | | } |
| | | // log.warn(JSON.toJSONString(shuttleProtocol));//输出小车状态 |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | socket.setSoTimeout(60000); |
| | | socket.setKeepAlive(true); |
| | | this.socket = socket; |
| | | if (null == shuttleProtocol) { |
| | | shuttleProtocol = new NyShuttleProtocol(); |
| | | shuttleProtocol.setShuttleNo(slave.getId().shortValue()); |
| | | } |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); |
| | | log.info(MessageFormat.format("【{0}】四向穿梭车Socket链接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | } catch (IOException e) { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】四向穿梭车Socket链接失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | |
| | | shuttleProtocol.setAssignCommand(assignCommand); |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING); |
| | | //任务数据保存到redis |
| | | redisUtil.set("shuttle_wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); |
| | | redisUtil.set(RedisKeyType.SHUTTLE.key + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); |
| | | //执行下发任务 |
| | | executeWork(assignCommand.getTaskNo()); |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | NavigateMapUtils navigateMapUtils = SpringUtils.getBean(NavigateMapUtils.class); |
| | | WrkMastMapper wrkMastMapper = SpringUtils.getBean(WrkMastMapper.class); |
| | | WrkMast wrkMast = wrkMastMapper.selectByWorkNo(wrkNo.intValue()); |
| | | |
| | | Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); |
| | | Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); |
| | | if (o == null) { |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(shuttleProtocol.getCurrentLocNo())); |
| | | checkIOSta(commands, commandStep);//检测小车是否进出提升机输送站 |
| | | |
| | | boolean isLock = false;//是否解锁路径 |
| | | //取出命令 |
| | |
| | | //上一条指令的目标位置和当前小车位置相同,则认定上一条任务完成 |
| | | lastCommand.setComplete(true); |
| | | //解锁锁定路径,上一条路径 |
| | | List<NavigateNode> nodes = lastCommand.getNodes(); |
| | | List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(lastCommand.getNodes()), NavigateNode.class);//进行深度copy |
| | | // //解锁当前路径 |
| | | // if (command != null && command.getNodes() != null) { |
| | | // nodes.addAll(command.getNodes()); |
| | | // } |
| | | if (nodes != null) { |
| | | navigateMapData.writeNavigateNodeToRedisMap(nodes, false);//解锁路径 |
| | | NavigateNode targetNode = assignCommand.getNodes().get(assignCommand.getNodes().size() - 1);//最终节点 |
| | | NavigateNode node = nodes.get(nodes.size() - 1); |
| | | if (!(targetNode.getX() == node.getX() && targetNode.getY() == node.getY())) { |
| | | nodes.remove(nodes.size() - 1);//剔除尾节点 |
| | | } |
| | | boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(shuttleProtocol.getCurrentLocNo()), nodes, false);//解锁路径 |
| | | if (!result) { |
| | | return false;//解锁失败 |
| | | } |
| | | isLock = true;//解锁过路径 |
| | | } |
| | | } |
| | |
| | | lastCommand.setComplete(true);//其他命令默认认为完成 |
| | | } |
| | | //任务数据保存到redis |
| | | redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); |
| | | redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); |
| | | |
| | | if (!lastCommand.getComplete()) { |
| | | //上一条任务未完成,禁止下发命令 |
| | |
| | | NyShuttleHttpCommand endCommand = commands.get(commands.size() - 1); |
| | | if (endCommand.getComplete()) { |
| | | //删除redis |
| | | redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo()); |
| | | redisUtil.del(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo()); |
| | | |
| | | if (!assignCommand.getCharge()) { |
| | | //对主线程抛出等待确认状态waiting |
| | |
| | | return false; |
| | | } |
| | | |
| | | if (command.getRequest().getBody().get("requestType").equals("move")) { |
| | | ArrayList<int[]> whiteList = new ArrayList<>();//设置节点的白名单 |
| | | if (wrkMast != null && ((wrkMast.getIoType() > 100 && wrkMast.getIoType() < 200) || wrkMast.getIoType() == 11)) { |
| | | //出库任务,不检测首节点 |
| | | int[] startArr = NavigatePositionConvert.positionToXY(wrkMast.getSourceLocNo());//开始节点 |
| | | whiteList.add(startArr); |
| | | } |
| | | |
| | | //解锁过路径,只检测下一段路径是否可走(当前路径已经被锁定无需再检测) |
| | | if (isLock) { |
| | | //只检测下一段路径是否可走(当前路径已经被锁定无需再检测) |
| | | //检测路径是否可行走 |
| | | if (!checkPath(nextNodes == null ? command.getNodes() : nextNodes, null, whiteList)) { |
| | | return false; |
| | | } |
| | | }else { |
| | | //检测当前路径和下一段路径 |
| | | //检测路径是否可行走 |
| | | if (!checkPath(command.getNodes(), nextNodes, whiteList)) { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | //锁定路径,锁定当前路径和下一步路径 |
| | | List<NavigateNode> nodes = command.getNodes(); |
| | | if (nextNodes != null) { |
| | | nodes.addAll(nextNodes); |
| | | } |
| | | if (nodes != null) { |
| | | navigateMapData.writeNavigateNodeToRedisMap(nodes, true);//所使用的路径进行锁定禁用 |
| | | } |
| | | } |
| | | // if (command.getRequest().getBody().get("requestType").equals("move")) { |
| | | // ArrayList<int[]> whiteList = new ArrayList<>();//设置节点的白名单 |
| | | // if (wrkMast != null && ((wrkMast.getIoType() > 100 && wrkMast.getIoType() < 200) || wrkMast.getIoType() == 11)) { |
| | | // //出库任务,不检测首节点 |
| | | // int[] startArr = NavigatePositionConvert.positionToXY(wrkMast.getSourceLocNo());//开始节点 |
| | | // whiteList.add(startArr); |
| | | // } |
| | | // |
| | | // //解锁过路径,只检测下一段路径是否可走(当前路径已经被锁定无需再检测) |
| | | // if (isLock) { |
| | | // //只检测下一段路径是否可走(当前路径已经被锁定无需再检测) |
| | | // //检测路径是否可行走 |
| | | // if (!checkPath(nextNodes == null ? command.getNodes() : nextNodes, null, whiteList)) { |
| | | // return false; |
| | | // } |
| | | // }else { |
| | | // //检测当前路径和下一段路径 |
| | | // //检测路径是否可行走 |
| | | // if (!checkPath(command.getNodes(), nextNodes, whiteList)) { |
| | | // return false; |
| | | // } |
| | | // } |
| | | // |
| | | // //锁定路径,锁定当前路径和下一步路径 |
| | | // List<NavigateNode> nodes = command.getNodes(); |
| | | // if (nextNodes != null) { |
| | | // nodes.addAll(nextNodes); |
| | | // } |
| | | // if (nodes != null) { |
| | | // boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(shuttleProtocol.getCurrentLocNo()), nodes, true);//所使用的路径进行锁定禁用 |
| | | // if (!result) { |
| | | // return false;//路径锁定失败 |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | //可执行命令 |
| | | if (!write(command, assignCommand)) { |
| | |
| | | //更新redis数据 |
| | | redisCommand.setCommandStep(commandStep); |
| | | //任务数据保存到redis |
| | | redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); |
| | | redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); |
| | | |
| | | return true; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); |
| | | Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); |
| | | if (o == null) { |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); |
| | | Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); |
| | | if (o == null) { |
| | | return false; |
| | | } |
| | |
| | | // assignCommand.setCommands(commands); |
| | | // redisCommand.setAssignCommand(assignCommand); |
| | | // //任务数据保存到redis |
| | | // redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); |
| | | // redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); |
| | | // return false;//当前不可行走,等待下一次执行走新路径 |
| | | // } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | //检测小车是否进出提升机输送站 |
| | | public void checkIOSta(List<NyShuttleHttpCommand> commands, int commandStep) { |
| | | if (commandStep != 0) { |
| | | NyShuttleHttpCommand lastCommand = commands.get(commandStep - 1);//上一步命令 |
| | | if (lastCommand.getRequest().getBody().get("requestType").equals("move")) { |
| | | //检测起点是否为提升机输送站点 |
| | | NyShuttleProtocol.NyShuttlePointClass start = JSON.parseObject(lastCommand.getRequest().getBody().get("start").toString(), NyShuttleProtocol.NyShuttlePointClass.class); |
| | | int[] startPoint = NavigatePositionConvert.NyXyzToWCSXyz(start.getX(), start.getY(), start.getZ()); |
| | | if (startPoint[0] == 13 && (startPoint[1] == 22 || startPoint[1] == 38 || startPoint[1] == 57)) { |
| | | //输送站点位置 |
| | | |
| | | int liftNo; |
| | | if (startPoint[1] == 22) { |
| | | liftNo = 1; |
| | | } else if (startPoint[1] == 38) { |
| | | liftNo = 2; |
| | | } else { |
| | | liftNo = 3; |
| | | } |
| | | |
| | | HashMap<String, Object> data = new HashMap<>(); |
| | | data.put("lev", startPoint[2]); |
| | | data.put("status", false);//出输送站 |
| | | |
| | | //下发任务 |
| | | MessageQueue.offer(SlaveType.Lift, liftNo, new Task(4, data)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (commands.size() == commandStep) { |
| | | return; |
| | | } |
| | | NyShuttleHttpCommand command = commands.get(commandStep);//当前命令 |
| | | if (command.getRequest().getBody().get("requestType").equals("move")) { |
| | | NyShuttleProtocol.NyShuttlePointClass target = JSON.parseObject(command.getRequest().getBody().get("target").toString(), NyShuttleProtocol.NyShuttlePointClass.class); |
| | | int[] targetPoint = NavigatePositionConvert.NyXyzToWCSXyz(target.getX(), target.getY(), target.getZ()); |
| | | //检测目标位置是否为提升机输送站点 |
| | | if (targetPoint[0] == 13 && (targetPoint[1] == 22 || targetPoint[1] == 38 || targetPoint[1] == 57)) { |
| | | //输送站点位置 |
| | | |
| | | int liftNo; |
| | | if (targetPoint[1] == 22) { |
| | | liftNo = 1; |
| | | } else if (targetPoint[1] == 38) { |
| | | liftNo = 2; |
| | | } else { |
| | | liftNo = 3; |
| | | } |
| | | |
| | | HashMap<String, Object> data = new HashMap<>(); |
| | | data.put("lev", targetPoint[2]); |
| | | data.put("status", true);//进输送站 |
| | | |
| | | //下发任务 |
| | | MessageQueue.offer(SlaveType.Lift, liftNo, new Task(4, data)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |