| | |
| | | package com.zy.asrs.wcs.core.action; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.zy.asrs.wcs.common.ExecuteSupport; |
| | | import com.zy.asrs.wcs.core.entity.BasShuttle; |
| | | import com.zy.asrs.wcs.core.entity.Loc; |
| | | import com.zy.asrs.wcs.core.entity.Task; |
| | | import com.zy.asrs.wcs.core.model.NavigateNode; |
| | | import com.zy.asrs.wcs.core.model.command.ShuttleAssignCommand; |
| | | import com.zy.asrs.wcs.core.model.command.ShuttleCommand; |
| | | import com.zy.asrs.wcs.core.model.command.ShuttleRedisCommand; |
| | | import com.zy.asrs.wcs.core.model.enums.LocStsType; |
| | | import com.zy.asrs.wcs.core.model.enums.MotionCtgType; |
| | | import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType; |
| | | import com.zy.asrs.wcs.core.model.enums.ShuttleTaskModeType; |
| | | import com.zy.asrs.wcs.core.service.BasShuttleService; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | @Component |
| | | public class ShuttleAction { |
| | |
| | | private LocService locService; |
| | | @Autowired |
| | | private ShuttleDispatcher shuttleDispatcher; |
| | | @Autowired |
| | | private ObjectMapper objectMapper; |
| | | |
| | | public synchronized boolean assignWork(Device device, ShuttleAssignCommand assignCommand) { |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); |
| | |
| | | ShuttleRedisCommand redisCommand = new ShuttleRedisCommand(); |
| | | |
| | | redisCommand.setShuttleNo(assignCommand.getShuttleNo());//四向穿梭车号 |
| | | redisCommand.setWrkNo(assignCommand.getTaskNo());//工作号 |
| | | redisCommand.setTaskNo(assignCommand.getTaskNo());//工作号 |
| | | redisCommand.setCommandStep(0);//命令执行步序 |
| | | redisCommand.setAssignCommand(assignCommand);//命令 |
| | | //任务数据保存到redis |
| | |
| | | || assignCommand.getTaskMode() == ShuttleTaskModeType.MOVE_LOC_NO.id |
| | | || assignCommand.getTaskMode() == ShuttleTaskModeType.SHUTTLE_MOVE_LOC_NO.id) { |
| | | //下发行驶路径 |
| | | boolean result = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getTaskNo()); |
| | | boolean result = shuttleThread.movePath(assignCommand.getNodes(), assignCommand.getDeviceTaskNo()); |
| | | if (!result) { |
| | | return false; |
| | | } |
| | | } |
| | | shuttleProtocol.setTaskNo(assignCommand.getTaskNo()); |
| | | shuttleProtocol.setSyncTaskNo(assignCommand.getTaskNo()); |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | return false; |
| | | } |
| | | |
| | | JSONObject jsonObject = JSON.parseObject(String.valueOf(obj)); |
| | | System.out.println(JSON.parseObject(String.valueOf(obj))); |
| | | ShuttleRedisCommand redisCommand = JSON.parseObject(String.valueOf(obj), ShuttleRedisCommand.class); |
| | | System.out.println(JSON.toJSONString(redisCommand)); |
| | | ShuttleRedisCommand redisCommand = null; |
| | | try { |
| | | redisCommand = objectMapper.readValue(String.valueOf(obj), ShuttleRedisCommand.class); |
| | | } catch (JsonProcessingException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | if (redisCommand == null) { |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | //判断设备是否空闲 |
| | | if (!shuttleThread.isIdle(() -> { |
| | | return shuttleProtocol.getTaskNo().equals(taskNo); |
| | | })) { |
| | | //判断工作号是否相同 |
| | | if (!shuttleProtocol.getTaskNo().equals(taskNo)) { |
| | | return false; |
| | | } |
| | | |
| | |
| | | // 托盘顶升 |
| | | //判断是否顶升到位 |
| | | if (shuttleProtocol.getHasLift()) { |
| | | //判断是否有物 |
| | | if (shuttleProtocol.getHasPallet()) { |
| | | command.setComplete(true); |
| | | } |
| | | command.setComplete(true); |
| | | // //判断是否有物 |
| | | // if (shuttleProtocol.getHasPallet()) { |
| | | // command.setComplete(true); |
| | | // } |
| | | } |
| | | } else if (command.getMode() == ShuttleCommandModeType.PALLET_DOWN.id) { |
| | | // 托盘下降命令 |
| | |
| | | } |
| | | |
| | | // 更新redis数据 |
| | | redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); |
| | | redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand)); |
| | | |
| | | if (!command.getComplete()) { |
| | | return false; |
| | |
| | | |
| | | // 系统任务 |
| | | if (assignCommand.getAuto()) { |
| | | // if (!assignCommand.getCharge()) { |
| | | // //对主线程抛出等待确认状态waiting |
| | | // shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WAITING); |
| | | // }else { |
| | | // shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING); |
| | | // } |
| | | if (!assignCommand.getCharge()) { |
| | | //对主线程抛出等待确认状态waiting |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WAITING); |
| | | }else { |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING); |
| | | } |
| | | News.info("四向穿梭车任务执行下发完成等待执行结束,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); |
| | | |
| | | // 手动任务 |
| | | } else { |
| | | //手动模式不抛出等待状态,直接复位空闲状态 |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.IDLE); |
| | | //任务号清零 |
| | | shuttleProtocol.setTaskNo(0); |
| | | shuttleThread.setSyncTaskNo(0); |
| | | //标记复位 |
| | | shuttleProtocol.setPakMk(true); |
| | | shuttleThread.setPakMk(true); |
| | | News.info("四向穿梭车手动任务执行完成,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); |
| | | } |
| | | |
| | | //删除redis |
| | | redisUtil.del(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo()); |
| | | redisUtil.del(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo()); |
| | | return false;//禁止再下发命令 |
| | | } |
| | | } |
| | |
| | | //取出命令 |
| | | ShuttleCommand command = commands.get(commandStep); |
| | | |
| | | Integer mode = command.getMode(); |
| | | //判断设备是否空闲 |
| | | if (!shuttleThread.isDeviceIdle(new ExecuteSupport() { |
| | | @Override |
| | | public Boolean judgement() { |
| | | if (ShuttleCommandModeType.CHARGE_CLOSE.id.equals(mode)) {//关闭充电motion |
| | | return false;//不需要判断状态 |
| | | } |
| | | return true;//需要判断状态 |
| | | } |
| | | })) { |
| | | return false; |
| | | } |
| | | |
| | | // 下发命令 |
| | | if (!write(command, device)) { |
| | | News.error("四向穿梭车命令下发失败,穿梭车号={},任务数据={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command)); |
| | | return false; |
| | | } |
| | | |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WORKING); |
| | | commandStep++; |
| | | //更新redis数据 |
| | | redisCommand.setCommandStep(commandStep); |
| | | //任务数据保存到redis |
| | | redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); |
| | | redisUtil.set(DeviceRedisConstant.SHUTTLE_WORK_FLAG + redisCommand.getTaskNo(), JSON.toJSONString(redisCommand)); |
| | | return true; |
| | | } |
| | | |
| | |
| | | if (shuttleThread == null) { |
| | | return; |
| | | } |
| | | |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(false); |
| | | if (shuttleProtocol == null) { |
| | | return; |
| | | } |
| | |
| | | } |
| | | |
| | | if (shuttleProtocol.getMoveType() == 0) {//跑轨道 |
| | | ArrayList<String> locs = new ArrayList<>(); |
| | | for (int i = shuttleProtocol.getXCurrent(); i <= shuttleProtocol.getXTarget(); i++) { |
| | | String locNo = Utils.getLocNo(i, shuttleProtocol.getYCurrent(), lev); |
| | | locs.add(locNo); |
| | | } |
| | | |
| | | List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>() |
| | | .in(Loc::getLocNo, locs)); |
| | | if (locList.isEmpty()) { |
| | | //空库位 |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1); |
| | | return; |
| | | } |
| | | |
| | | Loc start = locList.get(0); |
| | | Loc target = locList.get(locList.size() - 1); |
| | | //判断小车是否在起点位置 |
| | | if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//不在起点位置,调度去起点位置 |
| | | shuttleDispatcher.generateMoveTask(device, start.getLocNo()); |
| | | }else { |
| | | //在起点位置,调度去目标位置 |
| | | if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) { |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//小车和目标位置一致,跳过 |
| | | }else { |
| | | shuttleDispatcher.generateMoveTask(device, start.getLocNo()); |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1); |
| | | } |
| | | } |
| | | } else if (shuttleProtocol.getMoveType() == 1) {//跑库位 |
| | | Integer xCurrent = shuttleProtocol.getXCurrent(); |
| | | if (xCurrent > shuttleProtocol.getXTarget()) {//当X值大于X目标值,进行归零且Y方向+1 |
| | | shuttleProtocol.setXCurrent(shuttleProtocol.getXStart()); |
| | |
| | | } else { |
| | | shuttleDispatcher.generateMoveTask(device, target.getLocNo()); |
| | | shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | } |
| | | } else if (shuttleProtocol.getMoveType() == 1) {//跑库位 |
| | | ArrayList<String> locs = new ArrayList<>(); |
| | | for (int i = shuttleProtocol.getXCurrent(); i <= shuttleProtocol.getXTarget(); i++) { |
| | | String locNo = Utils.getLocNo(i, shuttleProtocol.getYCurrent(), lev); |
| | | locs.add(locNo); |
| | | } |
| | | |
| | | List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>() |
| | | .in(Loc::getLocNo, locs)); |
| | | if (locList.isEmpty()) { |
| | | //空库位 |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1); |
| | | return; |
| | | } |
| | | |
| | | Loc start = locList.get(0); |
| | | Loc target = locList.get(locList.size() - 1); |
| | | //判断小车是否在起点位置 |
| | | if (!shuttleProtocol.getCurrentLocNo().equals(start.getLocNo())) {//不在起点位置,调度去起点位置 |
| | | shuttleDispatcher.generateMoveTask(device, start.getLocNo()); |
| | | }else { |
| | | //在起点位置,调度去目标位置 |
| | | if (shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) { |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1);//小车和目标位置一致,跳过 |
| | | }else { |
| | | shuttleDispatcher.generateMoveTask(device, start.getLocNo()); |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYCurrent() + 1); |
| | | } |
| | | } |
| | | } else if (shuttleProtocol.getMoveType() == 2) {//母轨道循环跑 |
| | | Integer xCurrent = shuttleProtocol.getXCurrent(); |
| | |
| | | } |
| | | } |
| | | } |
| | | } else if (shuttleProtocol.getMoveType() == 4) {//取放货 |
| | | Integer xCurrent = shuttleProtocol.getXCurrent(); |
| | | if (xCurrent > shuttleProtocol.getXTarget()) {//当X值大于X目标值 |
| | | shuttleProtocol.setXCurrent(shuttleProtocol.getXStart()); |
| | | shuttleProtocol.setYCurrent(shuttleProtocol.getYStart()); |
| | | return; |
| | | } |
| | | |
| | | //判断x轴货位是否放满 |
| | | boolean flag = true; |
| | | for (Loc loc : locService.list(new LambdaQueryWrapper<Loc>() |
| | | .eq(Loc::getHostId, device.getHostId()) |
| | | .eq(Loc::getRow, xCurrent) |
| | | .ge(Loc::getBay, shuttleProtocol.getYStart()) |
| | | .le(Loc::getBay, shuttleProtocol.getYTarget()))) { |
| | | if (loc.getLocSts() != LocStsType.F.val()) { |
| | | flag = false;//未满 |
| | | break; |
| | | } |
| | | } |
| | | if (flag) { |
| | | shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | return; |
| | | } |
| | | |
| | | //搜索有货库位 |
| | | List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>() |
| | | .eq(Loc::getLocSts, LocStsType.F.val()) |
| | | .eq(Loc::getHostId, device.getHostId()) |
| | | .notIn(Loc::getRow, xCurrent) |
| | | .eq(Loc::getStatus, 1)); |
| | | if (list.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | Loc start = list.get(0); |
| | | |
| | | List<Loc> locList = locService.list(new LambdaQueryWrapper<Loc>() |
| | | .eq(Loc::getHostId, device.getHostId()) |
| | | .eq(Loc::getStatus, 1) |
| | | .eq(Loc::getLocSts, LocStsType.O.val()) |
| | | .eq(Loc::getRow, xCurrent) |
| | | .orderByDesc(Loc::getBay) |
| | | .orderByAsc(Loc::getRow)); |
| | | if (locList.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | Loc target = locList.get(0); |
| | | if (target == null) { |
| | | return; |
| | | } |
| | | |
| | | //调度去目标位置 |
| | | if (!shuttleProtocol.getCurrentLocNo().equals(target.getLocNo())) { |
| | | Task task = shuttleDispatcher.generateManuaTakeMoveTask(device, start.getLocNo(), target.getLocNo()); |
| | | // if(task != null) {//调度成功 |
| | | // shuttleProtocol.setXCurrent(shuttleProtocol.getXCurrent() + 1); |
| | | // } |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | result = shuttleThread.reset(command); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String s = "{\"commandStep\":0,\"liftSecurityMk\":false,\"shuttleNo\":6,\"wrkNo\":30095,\"assignCommand\":{\"sourceLocNo\":\"3-1-1\",\"auto\":true,\"shuttleNo\":6,\"taskMode\":19,\"charge\":false,\"nodes\":[{\"isInflectionPoint\":false,\"f\":0,\"g\":0,\"h\":0,\"x\":3,\"y\":1,\"nodeZ\":1,\"z\":1,\"direction\":\"top\"},{\"isInflectionPoint\":false,\"f\":1,\"g\":0,\"h\":1,\"x\":2,\"y\":1,\"nodeZ\":1,\"z\":1},{\"isInflectionPoint\":false,\"f\":1,\"g\":1,\"h\":0,\"x\":1,\"y\":1,\"nodeZ\":1,\"z\":1}],\"locNo\":\"1-1-1\",\"taskNo\":30095,\"deviceId\":6,\"commands\":[{\"mode\":1,\"targetLocNo\":\"1-1-1\",\"shuttleNo\":78,\"nodes\":[{\"isInflectionPoint\":false,\"moveDistance\":1000,\"f\":0,\"g\":0,\"h\":0,\"x\":3,\"y\":1,\"nodeZ\":1,\"z\":1,\"direction\":\"top\"},{\"isInflectionPoint\":false,\"moveDistance\":1000,\"f\":1,\"g\":0,\"h\":1,\"x\":2,\"y\":1,\"nodeZ\":1,\"z\":1,\"direction\":\"top\"},{\"isInflectionPoint\":false,\"moveDistance\":1000,\"f\":1,\"g\":1,\"h\":0,\"x\":1,\"y\":1,\"nodeZ\":1,\"z\":1,\"direction\":\"top\"}],\"taskNo\":0,\"body\":\"{\\\"messageName\\\":\\\"runOrder\\\",\\\"nodeX\\\":1,\\\"nodeY\\\":1,\\\"msgTime\\\":\\\"2024-04-12 17:39:16\\\",\\\"nodeZ\\\":1,\\\"deviceNo\\\":78,\\\"taskId\\\":5}\",\"complete\":false}]}}"; |
| | | ShuttleRedisCommand shuttleRedisCommand = JSON.parseObject(s, ShuttleRedisCommand.class); |
| | | System.out.println(shuttleRedisCommand); |
| | | } |
| | | |
| | | } |