| | |
| | | // private RgvProtocol rgvProtocol; |
| | | private TaskProtocolCache taskProtocolCache = new TaskProtocolCache(); |
| | | // # 轨道总长 |
| | | private Long trackEntireLength = 100L; |
| | | private Long trackEntireLength = 215000L; |
| | | //# 轨道基准点 |
| | | private Long trackBenchmark = 100L; |
| | | private Long trackBenchmark = 1L; |
| | | // # 避让距离 |
| | | private Long avoidDistance = 100L; |
| | | private Long avoidDistance = 5000L; |
| | | |
| | | /** |
| | | * 工位1复位信号 |
| | |
| | | |
| | | // 启动漫游线程 |
| | | new Thread(this::taskWalkIssued).start(); |
| | | new Thread(this::taskWalkIssued2).start(); |
| | | |
| | | // 启动任务完成线程 |
| | | // new Thread(this::taskComplete).start(); |
| | | new Thread(this::taskComplete).start(); |
| | | } |
| | | } |
| | | |
| | |
| | | * 完成 |
| | | */ |
| | | private void taskComplete() { |
| | | while (true) { |
| | | try { |
| | | Thread.sleep(100); |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB100.12", (short) 1); |
| | | boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, 0, 1); |
| | | if (status[0]){ |
| | | OperateResult result4 = siemensNet.Write("DB100.12.0", false); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("RGV数据读取线程异常!!!" + e.getMessage()); |
| | | initRgv(); |
| | | // e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 任务下发 |
| | | */ |
| | | private void taskWalkIssued2() { |
| | | while (true) { |
| | | try { |
| | | // 休眠 1 秒 |
| | | Thread.sleep(100); |
| | | if (!deviceDetection()) { |
| | | continue; |
| | | } |
| | | RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId()); |
| | | RgvTaskProtocol rgvTaskProtocol = RgvTaskCache.getRgvStatus(slave.getId()); |
| | | if (rgvProtocol == null || rgvTaskProtocol == null) { |
| | | initRgv(); |
| | | rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId()); |
| | | rgvTaskProtocol = RgvTaskCache.getRgvStatus(slave.getId()); |
| | | } |
| | | if (rgvTaskProtocol.getAvoid() != 0) { |
| | | continue; |
| | | } |
| | | if (!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE)){ |
| | | continue; |
| | | } |
| | | if (rgvProtocol.getLoaded() == -1){ |
| | | continue; |
| | | } |
| | | |
| | | List<TaskProtocol> allTakeTaskProtocol = taskProtocolCache.getAllWalkTaskProtocol(); |
| | | for (TaskProtocol taskProtocol : allTakeTaskProtocol) { |
| | | if (taskProtocol.getIsRunning() == 1) {//准备下发 |
| | | // 双车 |
| | | if (rgvOtherStatusEnable()) { |
| | | //另一台车是否允许此台车执行 |
| | | if (!otherRgvAvoid(taskProtocol.getTargetPosition())) { |
| | | continue; |
| | | } |
| | | } |
| | | if (taskProtocol.getTargetPosition()<=rgvProtocol.getRgvPos()+50 |
| | | && taskProtocol.getTargetPosition()>=rgvProtocol.getRgvPos()-50){ |
| | | taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection()); |
| | | break; |
| | | } else { |
| | | Thread.sleep(100); |
| | | TaskProtocol issued = new TaskProtocol(taskProtocol,true); |
| | | write(issued); |
| | | taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("RGV取货任务下发线程异常!!!" + e.getMessage()); |
| | | // e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | TaskProtocol issued = new TaskProtocol(); |
| | | issued.setTaskNo(32222L); |
| | | issued.setTargetPosition(rgvTaskProtocol.getAvoidingTheDestination()); |
| | | issued.setTaskStatus(1); |
| | | issued.setDirection(true); |
| | | write(issued); |
| | | rgvTaskProtocol.setAvoid(0); |
| | | |
| | |
| | | if (rgvTaskProtocol.getAvoid() != 0) { |
| | | continue; |
| | | } |
| | | if (!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE)){ |
| | | continue; |
| | | } |
| | | if (rgvProtocol.getLoaded() == -1){ |
| | | continue; |
| | | } |
| | | |
| | | List<TaskProtocol> allTakeTaskProtocol = taskProtocolCache.getTakeOrPutTaskProtocol(rgvProtocol.getLoaded()); |
| | | for (TaskProtocol taskProtocol : allTakeTaskProtocol) { |
| | | if (taskProtocol.getIsRunning() == 1) {//准备下发 |
| | | RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId()); |
| | | // RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId()); |
| | | //双车 |
| | | if (rgvOtherStatusEnable()) { |
| | | //另一台车是否允许此台车执行 |
| | |
| | | continue; |
| | | } |
| | | } |
| | | Thread.sleep(100); |
| | | TaskProtocol issued = new TaskProtocol(taskProtocol); |
| | | write(issued); |
| | | taskProtocol.setIsRunning(taskProtocol.getIsRunning() + 1); |
| | | taskProtocolCache.updateTaskProtocol(taskProtocol); |
| | | break; |
| | | if (taskProtocol.getTargetPosition()<=rgvProtocol.getRgvPos()+50 |
| | | && taskProtocol.getTargetPosition()>=rgvProtocol.getRgvPos()-50){ |
| | | Thread.sleep(100); |
| | | TaskProtocol issued = new TaskProtocol(taskProtocol); |
| | | write(issued); |
| | | taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection()); |
| | | break; |
| | | } else { |
| | | Thread.sleep(100); |
| | | TaskProtocol issued = new TaskProtocol(taskProtocol,true); |
| | | write(issued); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | log.error("行走超出范围!!!任务异常 联系管理员!!!"); |
| | | return false; |
| | | } |
| | | long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos()); |
| | | if (avoidAbs<51){ |
| | | return true; |
| | | } |
| | | rgvTaskProtocolOther.setAvoid(1); |
| | | rgvTaskProtocolOther.setAvoidingTheDestination(avoid); |
| | | RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther); |
| | |
| | | log.error("行走超出范围!!!任务异常 联系管理员!!!"); |
| | | return false; |
| | | } |
| | | long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos()); |
| | | if (avoidAbs<51){ |
| | | return true; |
| | | } |
| | | rgvTaskProtocolOther.setAvoid(1); |
| | | rgvTaskProtocolOther.setAvoidingTheDestination(avoid); |
| | | RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther); |
| | |
| | | > avoidDistance) {//无需避让 |
| | | return true; |
| | | } else { |
| | | if (rgvProtocolOther.getRgvPosDestination() >= rgvProtocolOther.getRgvPos()) { |
| | | if (rgvProtocolOther.getRgvPosDestination() >= rgvProtocolOther.getRgvPos()-50) { |
| | | long avoid = rgvProtocolOther.getRgvPos() - rgvProtocolOther.getCarBodyJiaoMing() - avoidDistance - rgvProtocol.getCarBodyKunPeng(); |
| | | if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) { |
| | | log.error("行走超出范围!!!任务异常 联系管理员!!!"); |
| | | return false; |
| | | } |
| | | long avoidAbs = Math.abs(avoid - rgvProtocol.getRgvPos()); |
| | | if (avoidAbs<51){ |
| | | return false; |
| | | } |
| | | rgvTaskProtocol.setAvoid(1); |
| | |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | } else { |
| | | if ((rgvProtocolOther.getRgvPosDestinationOrPos(true) - rgvProtocolOther.getCarBodyJiaoMing()) |
| | | - (targetPosition + rgvProtocol.getCarBodyKunPeng()) |
| | | > avoidDistance) {//无需避让 |
| | | return true; |
| | | } |
| | | } |
| | | } else { |
| | |
| | | if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) { |
| | | log.error("行走超出范围!!!任务异常 联系管理员!!!"); |
| | | return false; |
| | | } |
| | | long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos()); |
| | | if (avoidAbs<51){ |
| | | return true; |
| | | } |
| | | rgvTaskProtocolOther.setAvoid(1); |
| | | rgvTaskProtocolOther.setAvoidingTheDestination(avoid); |
| | |
| | | log.error("行走超出范围!!!任务异常 联系管理员!!!"); |
| | | return false; |
| | | } |
| | | long avoidAbs = Math.abs(avoid - rgvProtocolOther.getRgvPos()); |
| | | if (avoidAbs<51){ |
| | | return true; |
| | | } |
| | | rgvTaskProtocolOther.setAvoid(1); |
| | | rgvTaskProtocolOther.setAvoidingTheDestination(avoid); |
| | | RgvTaskCache.updateRgvStatus(rgvTaskProtocolOther); |
| | |
| | | > avoidDistance) {//无需避让 |
| | | return true; |
| | | } else { |
| | | if (rgvProtocolOther.getRgvPosDestination() <= rgvProtocolOther.getRgvPos()) { |
| | | if (rgvProtocolOther.getRgvPosDestination() <= rgvProtocolOther.getRgvPos() + 50) { |
| | | long avoid = rgvProtocolOther.getRgvPos() + rgvProtocolOther.getCarBodyKunPeng() + avoidDistance + rgvProtocol.getCarBodyJiaoMing(); |
| | | if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) { |
| | | log.error("行走超出范围!!!任务异常 联系管理员!!!"); |
| | | return false; |
| | | } |
| | | long avoidAbs = Math.abs(avoid - rgvProtocol.getRgvPos()); |
| | | if (avoidAbs<51){ |
| | | return false; |
| | | } |
| | | rgvTaskProtocol.setAvoid(1); |
| | |
| | | return false; |
| | | } |
| | | return false; |
| | | } |
| | | } else { |
| | | if ((rgvProtocolOther.getRgvPosDestinationOrPos(false) - rgvProtocolOther.getCarBodyJiaoMing()) |
| | | - (targetPosition + rgvProtocol.getCarBodyKunPeng()) |
| | | > avoidDistance) {//无需避让 |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | |
| | | rgvTaskProtocol = new RgvTaskProtocol(); |
| | | rgvTaskProtocol.setRgvNo(slave.getId()); |
| | | } |
| | | rgvTaskProtocol.setAvoid(-1); |
| | | rgvTaskProtocol.setAvoid(0); |
| | | rgvTaskProtocol.setAvoidingTheDestination(0L); |
| | | |
| | | RgvStatusCache.updateRgvStatus(rgvProtocol); |
| | |
| | | */ |
| | | private void readStatus() { |
| | | try { |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 18); |
| | | OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 19); |
| | | if (result.IsSuccess) { |
| | | // 构建设备状态对象 |
| | | RgvProtocol rgvProtocol = RgvStatusCache.getRgvStatus(slave.getId()); |
| | | if (rgvProtocol == null) { |
| | | rgvProtocol = new RgvProtocol(); |
| | | rgvProtocol.setRgvNo(slave.getId()); |
| | | } |
| | | rgvProtocol.setRgvNo(slave.getId()); |
| | | rgvProtocol.setCarBodyJiaoMing(slave.getCarBodyJiaoMing()); |
| | | rgvProtocol.setCarBodyKunPeng(slave.getCarBodyKunPeng()); |
| | | |
| | | rgvProtocol.setRgvPos((long)siemensNet.getByteTransform().TransInt32(result.Content, 0)); |
| | | rgvProtocol.setRgvPosDestination((long)siemensNet.getByteTransform().TransInt32(result.Content, 4)); |
| | | if (rgvProtocol.getRgvPosDestination()==0L){ |
| | | rgvProtocol.setRgvPosDestination(rgvProtocol.getRgvPos()); |
| | | } |
| | | rgvProtocol.setStatus(siemensNet.getByteTransform().TransInt16(result.Content, 8)); |
| | | rgvProtocol.setTaskNo((long)siemensNet.getByteTransform().TransInt32(result.Content, 10)); |
| | | |
| | |
| | | // rgvProtocol.setxSpeed(siemensNet.getByteTransform().TransInt16(result.Content, 28)); |
| | | // rgvProtocol.setxDistance(siemensNet.getByteTransform().TransInt16(result.Content, 40)); |
| | | // rgvProtocol.setxDuration(siemensNet.getByteTransform().TransInt16(result.Content, 48)); |
| | | |
| | | // OperateResultExOne<byte[]> result11 = siemensNet.Read("DB100.12", (short) 1); |
| | | boolean[] status = siemensNet.getByteTransform().TransBool(result.Content, 18, 1); |
| | | rgvProtocol.setLoaded(status[0]? (short)1:(short)0); |
| | | |
| | | OutputQueue.RGV.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功", DateUtils.convert(new Date()), slave.getId())); |
| | | // // 工位1复位信号 |
| | |
| | | // convertRow(command); |
| | | // taskProtocol.setRgvNo(slave.getId()); |
| | | Long[] array = new Long[11]; |
| | | OperateResult result41 = siemensNet.Write("DB100.12.0", false); |
| | | |
| | | // array[0] = taskProtocol.getAckFinish1(); |
| | | // array[1] = taskProtocol.getTaskNo(); |
| | | // array[2] = taskProtocol.getTaskMode(); |
| | | // array[4] = command.getDestinationStaNo(); |
| | | // array[10] = taskProtocol.getCommand(); |
| | | OperateResult result = siemensNet.Write("DB100.0", taskProtocol.getTaskNo()); |
| | | OperateResult result1 = siemensNet.Write("DB100.1", taskProtocol.isDirection()); // 执行方向(面朝轨道 定位值左小右大) true:左 false:右 |
| | | int taskStatus = taskProtocol.getTaskStatus(); |
| | | |
| | | OperateResult result = siemensNet.Write("DB100.0", taskProtocol.getTargetPosition().intValue()); |
| | | OperateResult result1 = siemensNet.Write("DB100.4", (short) taskStatus); |
| | | OperateResult result2 = siemensNet.Write("DB100.6", taskProtocol.getTaskNo().intValue()); |
| | | OperateResult result3 = siemensNet.Write("DB100.10", taskProtocol.isDirection()? (short) 1 : (short) 2); // 执行方向(面朝轨道 定位值左小右大) true:左 false:右 |
| | | |
| | | OperateResult result4 = siemensNet.Write("DB100.12.0", true); |
| | | // if (taskProtocol.getAckFinish1() == 0) { |
| | | // short commandFinish = 3; //工位1、2任务同时写入 |
| | | // Thread.sleep(100L); |