| | |
| | | switch (step) { |
| | | // 读数据 |
| | | case 1: |
| | | readStatus(); |
| | | read(); |
| | | break; |
| | | // 写入数据 |
| | | case 2: |
| | |
| | | @Override |
| | | public void close() { |
| | | modbusTcpNet.ConnectClose(); |
| | | } |
| | | |
| | | private void read() { |
| | | try { |
| | | readStatus(); |
| | | //四向穿梭车空闲、有任务、标记为true、存在任务指令,需要执行任务的下一条指令 |
| | | if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE |
| | | && shuttleProtocol.getTaskNo() != 0 |
| | | && shuttleProtocol.getPakMk()) { |
| | | //执行下一步指令 |
| | | executeWork(shuttleProtocol.getTaskNo()); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】四向穿梭车plc状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); |
| | | initShuttle(); |
| | | } |
| | | } |
| | | |
| | | private void readStatus() { |
| | |
| | | shuttleProtocol.setPakMk(true); |
| | | } |
| | | |
| | | // if (shuttleProtocol.getErrorCode() != 0 && shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.WORKING) { |
| | | // //出现错误 |
| | | // resetAndTryFix(shuttleProtocol.getTaskNo()); |
| | | // //将四向穿梭车状态保存至数据库 |
| | | // BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); |
| | | // BasShuttle basShuttle = shuttleService.selectById(slave.getId()); |
| | | // if (basShuttle == null) { |
| | | // basShuttle = new BasShuttle(); |
| | | // //四向穿梭车号 |
| | | // basShuttle.setShuttleNo(slave.getId()); |
| | | // shuttleService.insert(basShuttle); |
| | | // } |
| | | // |
| | | // if(shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.FIXING |
| | | // && shuttleProtocol.getTaskNo() != 0 |
| | | // && shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE){ |
| | | // //处于故障修复状态 |
| | | // //执行下一步指令 |
| | | // executeWork(shuttleProtocol.getTaskNo()); |
| | | // //小车忙状态位 |
| | | // basShuttle.setBusyStatus(shuttleProtocol.getBusyStatus().intValue()); |
| | | // //当前二维码 |
| | | // basShuttle.setCurrentCode(shuttleProtocol.getCurrentCode().intValue()); |
| | | // //电池电量百分比 |
| | | // basShuttle.setBatteryPower(shuttleProtocol.getBatteryPower().intValue()); |
| | | // //电池温度 |
| | | // basShuttle.setBatteryTemp(shuttleProtocol.getBatteryTemp().intValue()); |
| | | // //错误编号 |
| | | // basShuttle.setErrorCode(shuttleProtocol.getErrorCode().intValue()); |
| | | // //Plc输出状态IO |
| | | // basShuttle.setPlcOutputStatusIo(shuttleProtocol.getPlcOutputStatusIO().intValue()); |
| | | // //错误信息码 |
| | | // basShuttle.setStatusErrorCode(shuttleProtocol.getStatusErrorCode().intValue()); |
| | | // //PLC输入状态 |
| | | // basShuttle.setPlcInputStatus(shuttleProtocol.getPlcInputStatus().intValue()); |
| | | // //当前或者之前读到的二维码值 |
| | | // basShuttle.setCurrentOrBeforeCode(shuttleProtocol.getCurrentOrBeforeCode().intValue()); |
| | | // //读到的二维码X方向偏移量 |
| | | // basShuttle.setCodeOffsetX(shuttleProtocol.getCodeOffsetX().intValue()); |
| | | // //读到的二维码Y方向偏移量 |
| | | // basShuttle.setCodeOffsetY(shuttleProtocol.getCodeOffsetY().intValue()); |
| | | // //当前的电压值 |
| | | // basShuttle.setCurrentVoltage(shuttleProtocol.getCurrentVoltage().intValue()); |
| | | // //当前的模拟量值 |
| | | // basShuttle.setCurrentAnalogValue(shuttleProtocol.getCurrentAnalogValue().intValue()); |
| | | // //当前的升降伺服速度 |
| | | // basShuttle.setCurrentLiftServoSpeed(shuttleProtocol.getCurrentLiftServoSpeed().intValue()); |
| | | // //当前的行走伺服速度 |
| | | // basShuttle.setCurrentMoveServoSpeed(shuttleProtocol.getCurrentMoveServoSpeed().intValue()); |
| | | // //当前的升降伺服负载率 |
| | | // basShuttle.setCurrentLiftServoLoad(shuttleProtocol.getCurrentLiftServoLoad().intValue()); |
| | | // //当前的行走伺服负载率 |
| | | // basShuttle.setCurrentMoveServoLoad(shuttleProtocol.getCurrentMoveServoLoad().intValue()); |
| | | // //当前小车状态(内部自我维护) |
| | | // basShuttle.setShuttleStatus(shuttleProtocol.getProtocolStatus()); |
| | | // //任务号 |
| | | // basShuttle.setWrkNo(shuttleProtocol.getTaskNo().intValue()); |
| | | // //修改时间 |
| | | // basShuttle.setUpdateTime(new Date()); |
| | | // //作业标记 |
| | | // basShuttle.setPakMk(shuttleProtocol.getPakMk()); |
| | | // if (shuttleService.updateById(basShuttle)) { |
| | | // 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())); |
| | | // } |
| | | |
| | | //四向穿梭车空闲、有任务、标记为true、存在任务指令,需要执行任务的下一条指令 |
| | | if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE |
| | | && shuttleProtocol.getTaskNo() != 0 |
| | | && shuttleProtocol.getPakMk()) { |
| | | //执行下一步指令 |
| | | executeWork(shuttleProtocol.getTaskNo()); |
| | | } |
| | | |
| | | // //检测是否有提升机锁定标记,有则检测提升机是否到位,是否能走下一步命令 |
| | | // if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE |
| | | // && shuttleProtocol.getTaskNo() != 0) { |
| | | // Object o = redisUtil.get("shuttle_wrk_no_" + shuttleProtocol.getTaskNo()); |
| | | // if (o != null) { |
| | | // ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); |
| | | // if (redisCommand.getLiftSecurityMk()) { |
| | | // //执行下一步指令 |
| | | // executeWork(shuttleProtocol.getTaskNo()); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | //将四向穿梭车状态保存至数据库 |
| | | BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); |
| | | BasShuttle basShuttle = shuttleService.selectById(slave.getId()); |
| | | if (basShuttle == null) { |
| | | basShuttle = new BasShuttle(); |
| | | //四向穿梭车号 |
| | | basShuttle.setShuttleNo(slave.getId()); |
| | | shuttleService.insert(basShuttle); |
| | | } |
| | | //小车忙状态位 |
| | | basShuttle.setBusyStatus(shuttleProtocol.getBusyStatus().intValue()); |
| | | //当前二维码 |
| | | basShuttle.setCurrentCode(shuttleProtocol.getCurrentCode().intValue()); |
| | | //电池电量百分比 |
| | | basShuttle.setBatteryPower(shuttleProtocol.getBatteryPower().intValue()); |
| | | //电池温度 |
| | | basShuttle.setBatteryTemp(shuttleProtocol.getBatteryTemp().intValue()); |
| | | //错误编号 |
| | | basShuttle.setErrorCode(shuttleProtocol.getErrorCode().intValue()); |
| | | //Plc输出状态IO |
| | | basShuttle.setPlcOutputStatusIo(shuttleProtocol.getPlcOutputStatusIO().intValue()); |
| | | //错误信息码 |
| | | basShuttle.setStatusErrorCode(shuttleProtocol.getStatusErrorCode().intValue()); |
| | | //PLC输入状态 |
| | | basShuttle.setPlcInputStatus(shuttleProtocol.getPlcInputStatus().intValue()); |
| | | //当前或者之前读到的二维码值 |
| | | basShuttle.setCurrentOrBeforeCode(shuttleProtocol.getCurrentOrBeforeCode().intValue()); |
| | | //读到的二维码X方向偏移量 |
| | | basShuttle.setCodeOffsetX(shuttleProtocol.getCodeOffsetX().intValue()); |
| | | //读到的二维码Y方向偏移量 |
| | | basShuttle.setCodeOffsetY(shuttleProtocol.getCodeOffsetY().intValue()); |
| | | //当前的电压值 |
| | | basShuttle.setCurrentVoltage(shuttleProtocol.getCurrentVoltage().intValue()); |
| | | //当前的模拟量值 |
| | | basShuttle.setCurrentAnalogValue(shuttleProtocol.getCurrentAnalogValue().intValue()); |
| | | //当前的升降伺服速度 |
| | | basShuttle.setCurrentLiftServoSpeed(shuttleProtocol.getCurrentLiftServoSpeed().intValue()); |
| | | //当前的行走伺服速度 |
| | | basShuttle.setCurrentMoveServoSpeed(shuttleProtocol.getCurrentMoveServoSpeed().intValue()); |
| | | //当前的升降伺服负载率 |
| | | basShuttle.setCurrentLiftServoLoad(shuttleProtocol.getCurrentLiftServoLoad().intValue()); |
| | | //当前的行走伺服负载率 |
| | | basShuttle.setCurrentMoveServoLoad(shuttleProtocol.getCurrentMoveServoLoad().intValue()); |
| | | //当前小车状态(内部自我维护) |
| | | basShuttle.setShuttleStatus(shuttleProtocol.getProtocolStatus()); |
| | | //任务号 |
| | | basShuttle.setWrkNo(shuttleProtocol.getTaskNo().intValue()); |
| | | //修改时间 |
| | | basShuttle.setUpdateTime(new Date()); |
| | | //作业标记 |
| | | basShuttle.setPakMk(shuttleProtocol.getPakMk()); |
| | | if (shuttleService.updateById(basShuttle)) { |
| | | 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())); |
| | | } |
| | | |
| | | }else { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】{1}四向穿梭车plc状态信息失败", DateUtils.convert(new Date()), slave.getId())); |
| | |
| | | } |
| | | |
| | | for (int i = 0; i < 5; i++) { |
| | | if (command.getCommandWord().intValue() == 5 || command.getCommandWord().intValue() == 6) { |
| | | break;//充电开关和系统复位不需要重发机制 |
| | | } |
| | | readStatus();//重新读取状态 |
| | | if (shuttleProtocol.getBusyStatusType().equals(ShuttleStatusType.BUSY)) { |
| | | break; |
| | |
| | | News.info("四向穿梭车命令下发[id:{}] >>>>> {},次数:{}", slave.getId(), JSON.toJSON(command), i); |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2},次数:{}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command), i)); |
| | | try { |
| | | Thread.sleep(3000);//命令下发后休眠 |
| | | Thread.sleep(300);//命令下发后休眠 |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | |
| | | //获取小车移动速度 |
| | | BasShuttle basShuttle = shuttleService.selectById(slave.getId()); |
| | | Integer runSpeed = 1000; |
| | | if (basShuttle != null) { |
| | | Integer runSpeed1 = basShuttle.getRunSpeed(); |
| | | if (runSpeed1 != null) { |
| | | runSpeed = runSpeed1; |
| | | } |
| | | } |
| | | // if (basShuttle != null) { |
| | | // Integer runSpeed1 = basShuttle.getRunSpeed(); |
| | | // if (runSpeed1 != null) { |
| | | // runSpeed = runSpeed1; |
| | | // } |
| | | // } |
| | | |
| | | LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); |
| | | LiftProtocol liftProtocol = liftThread.getLiftProtocol(); |
| | |
| | | //目标路径 |
| | | NavigateNode endPath = nodes.get(nodes.size() - 1); |
| | | Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离 |
| | | Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes);//计算中间点到目标点行走距离 |
| | | Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//计算中间点到目标点行走距离 |
| | | |
| | | //正常移动命令 |
| | | Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());//开始二维码 |
| | |
| | | //目标路径 |
| | | NavigateNode endPath = nodes.get(nodes.size() - 1); |
| | | Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离 |
| | | Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes);//计算中间点到目标点行走距离 |
| | | Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//计算中间点到目标点行走距离 |
| | | |
| | | //正常移动命令 |
| | | Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());//开始二维码 |
| | |
| | | //目标路径 |
| | | NavigateNode endPath = nodes.get(nodes.size() - 1); |
| | | Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离 |
| | | Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes);//计算中间点到目标点行走距离 |
| | | Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//计算中间点到目标点行走距离 |
| | | Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());//开始二维码 |
| | | Short middleCode = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ());//中间二维码 |
| | | Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());//目标二维码 |
| | |
| | | //目标路径 |
| | | NavigateNode endPath = nodes.get(nodes.size() - 1); |
| | | Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//计算当前路径行走总距离 |
| | | Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes);//计算中间点到目标点行走距离 |
| | | Integer middleToDistDistance = NavigateUtils.getMiddleToDistDistance(nodes, middlePath);//计算中间点到目标点行走距离 |
| | | Short startCode = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());//开始二维码 |
| | | Short middleCode = NavigatePositionConvert.xyToPosition(middlePath.getX(), middlePath.getY(), middlePath.getZ());//中间二维码 |
| | | Short distCode = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());//目标二维码 |
| | |
| | | } |
| | | } |
| | | |
| | | if (commands.size() == 0) { |
| | | return false; |
| | | } |
| | | |
| | | //当前等待执行的指令 |
| | | ShuttleCommand command = commands.get(commandStep); |
| | | |