| | |
| | | case 1: |
| | | readStatus(); |
| | | break; |
| | | // // 写入数据 |
| | | // case 2: |
| | | // write((ShuttleCommand) task.getData()); |
| | | // break; |
| | | // 写入数据 |
| | | case 2: |
| | | write((ShuttleCommand) task.getData()); |
| | | break; |
| | | //下发任务 |
| | | case 3: |
| | | assignWork((ShuttleAssignCommand) task.getData()); |
| | |
| | | return false; |
| | | } |
| | | |
| | | command.setShuttleNo(slave.getId()); |
| | | command.setShuttleNo(slave.getId().shortValue()); |
| | | // 开始任务 |
| | | short[] array = new short[17]; |
| | | //控制指令字 |
| | | array[0] = command.getCommandWord(); |
| | | //启始二维编号 |
| | | array[1] = command.getStartCodeNum(); |
| | | //中间二维编号 |
| | | array[2] = command.getMiddleCodeNum(); |
| | | //目标二维编号 |
| | | array[3] = command.getDistCodeNum(); |
| | | if (command.getStartCodeNum() != null) { |
| | | //启始二维编号 |
| | | array[1] = command.getStartCodeNum(); |
| | | } |
| | | |
| | | //起点到目标点的距离长度,先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间 |
| | | short[] startToDistDistances = CommonUtils.intToShorts(command.getStartToDistDistance()); |
| | | array[4] = startToDistDistances[0]; |
| | | array[5] = startToDistDistances[1]; |
| | | if (command.getMiddleCodeNum() != null) { |
| | | //中间二维编号 |
| | | array[2] = command.getMiddleCodeNum(); |
| | | } |
| | | |
| | | //中间点到目标点的距离长度,先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间 |
| | | short[] middleToDistDistances = CommonUtils.intToShorts(command.getMiddleToDistDistance()); |
| | | array[6] = middleToDistDistances[0]; |
| | | array[7] = middleToDistDistances[1]; |
| | | if (command.getDistCodeNum() != null) { |
| | | //目标二维编号 |
| | | array[3] = command.getDistCodeNum(); |
| | | } |
| | | |
| | | //小车运行方向 |
| | | array[8] = command.getRunDirection(); |
| | | //托盘顶升 |
| | | array[9] = command.getPalletLift(); |
| | | if (command.getStartToDistDistance() != null) { |
| | | //起点到目标点的距离长度,先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间 |
| | | short[] startToDistDistances = CommonUtils.intToShorts(command.getStartToDistDistance()); |
| | | array[4] = startToDistDistances[0]; |
| | | array[5] = startToDistDistances[1]; |
| | | } |
| | | |
| | | //小车强制移动距离,先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间 |
| | | short[] forceMoveDistances = CommonUtils.intToShorts(command.getForceMoveDistance()); |
| | | array[10] = forceMoveDistances[0]; |
| | | array[11] = forceMoveDistances[1]; |
| | | if (command.getMiddleToDistDistance() != null) { |
| | | //中间点到目标点的距离长度,先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间 |
| | | short[] middleToDistDistances = CommonUtils.intToShorts(command.getMiddleToDistDistance()); |
| | | array[6] = middleToDistDistances[0]; |
| | | array[7] = middleToDistDistances[1]; |
| | | } |
| | | |
| | | //充电开关 |
| | | array[12] = command.getChargeSwitch(); |
| | | //小车IO控制 |
| | | array[13] = command.getIOControl(); |
| | | //小车运行速度 |
| | | array[14] = command.getRunSpeed(); |
| | | //小车雷达备用 |
| | | array[15] = command.getRadarTmp(); |
| | | if (command.getRunDirection() != null) { |
| | | //小车运行方向 |
| | | array[8] = command.getRunDirection(); |
| | | } |
| | | |
| | | if (command.getPalletLift() != null) { |
| | | //托盘顶升 |
| | | array[9] = command.getPalletLift(); |
| | | } |
| | | |
| | | if (command.getForceMoveDistance() != null) { |
| | | //小车强制移动距离,先将int转为byte数组,再将byte数组转成两个short,分别占用4和5空间 |
| | | short[] forceMoveDistances = CommonUtils.intToShorts(command.getForceMoveDistance()); |
| | | array[10] = forceMoveDistances[0]; |
| | | array[11] = forceMoveDistances[1]; |
| | | } |
| | | |
| | | if (command.getChargeSwitch() != null) { |
| | | //充电开关 |
| | | array[12] = command.getChargeSwitch(); |
| | | } |
| | | |
| | | if (command.getIOControl() != null) { |
| | | //小车IO控制 |
| | | array[13] = command.getIOControl(); |
| | | } |
| | | |
| | | if (command.getRunSpeed() != null) { |
| | | //小车运行速度 |
| | | array[14] = command.getRunSpeed(); |
| | | } |
| | | |
| | | if (command.getRadarTmp() != null) { |
| | | //小车雷达备用 |
| | | array[15] = command.getRadarTmp(); |
| | | } |
| | | |
| | | //指令结束位 |
| | | array[16] = command.getCommandEnd(); |
| | | |
| | |
| | | |
| | | //分配任务 |
| | | private void assignWork(ShuttleAssignCommand assignCommand) { |
| | | //计算路径 |
| | | List<NavigateNode> calc = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getDistLocNo(), "in"); |
| | | //获取分段路径 |
| | | ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc); |
| | | //将此map存入redis中 |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | //命令执行步序 |
| | | map.put("commandStep", 0); |
| | | //路径数据 |
| | | map.put("path", data); |
| | | //工作号 |
| | | map.put("wrk_no", assignCommand.getTaskNo()); |
| | | //任务数据保存到redis |
| | | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map)); |
| | | ShuttleCommand command = new ShuttleCommand(); |
| | | switch (assignCommand.getTaskMode()) { |
| | | case 1: |
| | | case 2: |
| | | //计算路径 |
| | | List<NavigateNode> calc = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getDistLocNo(), assignCommand.getTaskMode().intValue()); |
| | | if (calc != null) { |
| | | //获取分段路径 |
| | | ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(calc); |
| | | //将此map存入redis中 |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | //命令执行步序 |
| | | map.put("commandStep", 0); |
| | | //路径数据 |
| | | map.put("path", data); |
| | | //工作号 |
| | | map.put("wrk_no", assignCommand.getTaskNo()); |
| | | //任务数据保存到redis |
| | | redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map)); |
| | | shuttleProtocol.setTaskNo(assignCommand.getTaskNo()); |
| | | |
| | | //执行下发任务 |
| | | executeWork(assignCommand.getTaskNo()); |
| | | //执行下发任务 |
| | | executeWork(assignCommand.getTaskNo()); |
| | | } |
| | | break; |
| | | case 3: |
| | | case 4: |
| | | command.setCommandWord((short) 2); |
| | | command.setPalletLift(assignCommand.getTaskMode() == 3 ? (short)1 : (short)2); |
| | | command.setCommandEnd((short) 1); |
| | | write(command); |
| | | break; |
| | | case 5: |
| | | case 6: |
| | | case 7: |
| | | case 8: |
| | | command.setCommandWord((short) 3); |
| | | command.setForceMoveDistance(1000); |
| | | command.setRunDirection((short) (assignCommand.getTaskMode() - 4)); |
| | | command.setCommandEnd((short) 1); |
| | | write(command); |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | //执行下发的指令 |