From 0d04e9440d19f30a8220f498ebdde5a8bfcc48a8 Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期二, 10 十月 2023 13:50:03 +0800 Subject: [PATCH] #机械臂任务下发 --- src/main/java/com/zy/asrs/controller/ShuttleController.java | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 154 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/zy/asrs/controller/ShuttleController.java b/src/main/java/com/zy/asrs/controller/ShuttleController.java index 1614b21..ce01db0 100644 --- a/src/main/java/com/zy/asrs/controller/ShuttleController.java +++ b/src/main/java/com/zy/asrs/controller/ShuttleController.java @@ -1,6 +1,7 @@ package com.zy.asrs.controller; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.annotations.ManagerAuth; import com.core.common.BaseRes; @@ -15,16 +16,21 @@ import com.zy.asrs.service.LocMastService; import com.zy.asrs.service.WrkMastService; import com.zy.asrs.utils.Utils; +import com.zy.common.model.NyShuttleOperaResult; +import com.zy.common.model.enums.NavigationMapType; import com.zy.common.service.CommonService; +import com.zy.common.utils.NyHttpUtils; +import com.zy.common.utils.NyShuttleOperaUtils; import com.zy.common.utils.RedisUtil; +import com.zy.common.utils.ShuttleDispatchUtils; import com.zy.core.cache.MessageQueue; import com.zy.core.cache.OutputQueue; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.*; import com.zy.core.model.ShuttleSlave; import com.zy.core.model.Task; +import com.zy.core.model.command.NyShuttleHttpCommand; import com.zy.core.model.command.ShuttleAssignCommand; -import com.zy.core.model.command.ShuttleCommand; import com.zy.core.model.command.ShuttleRedisCommand; import com.zy.core.model.protocol.NyShuttleProtocol; import com.zy.core.model.protocol.ShuttleProtocol; @@ -58,11 +64,13 @@ private CommonService commonService; @Autowired private RedisUtil redisUtil; + @Autowired + private ShuttleDispatchUtils shuttleDispatchUtils; @PostMapping("/table/shuttle/state") @ManagerAuth(memo = "鍥涘悜绌挎杞︿俊鎭〃") public R shuttleStateTable(){ - ArrayList<NyShuttleProtocol> list = new ArrayList<>(); + ArrayList<JSONObject> list = new ArrayList<>(); List<BasShuttle> shuttles = basShuttleService.selectList(new EntityWrapper<BasShuttle>().orderBy("shuttle_no")); for (BasShuttle basShuttle : shuttles) { // 鑾峰彇鍥涘悜绌挎杞︿俊鎭� @@ -71,10 +79,25 @@ continue; } NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + JSONObject shuttleData = JSON.parseObject(JSON.toJSONString(shuttleProtocol)); if (shuttleProtocol == null || shuttleProtocol.getShuttleNo()==null) { + if (shuttleData != null) { + list.add(shuttleData); + } continue; } - list.add(shuttleProtocol); + + shuttleData.put("moveAdvancePath", null);//绌挎杞﹂璁¤矾寰� + if (shuttleProtocol.getTaskNo() != 0) { + //瀛樺湪浠诲姟锛岃幏鍙栨寚浠� + Object object = redisUtil.get("shuttle_wrk_no_" + shuttleProtocol.getTaskNo()); + if (object != null) { + ShuttleRedisCommand redisCommand = JSON.parseObject(object.toString(), ShuttleRedisCommand.class); + shuttleData.put("moveAdvancePath", redisCommand.getAssignCommand().getNodes());//绌挎杞﹂璁¤矾寰� + } + } + + list.add(shuttleData); } return R.ok().add(list); } @@ -184,8 +207,8 @@ } ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand(); - List<ShuttleCommand> commands = assignCommand.getCommands(); - ShuttleCommand command = commands.get(commandStep); + List<NyShuttleHttpCommand> commands = assignCommand.getCommands(); + NyShuttleHttpCommand command = commands.get(commandStep); command.setComplete(complete != 0); redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); return R.ok(); @@ -266,6 +289,90 @@ assignCommand.setTaskNo((short) commonService.getWorkNo(3));//鑾峰彇浠诲姟鍙� assignCommand.setAuto(false);//鎵嬪姩妯″紡 + if (shuttleTaskModeType == ShuttleTaskModeType.TRANSPORT) { + //鎼繍璐х墿浠诲姟 + NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), shuttleProtocol.getCurrentLocNo(), param.getSourceLocNo(), param.getDistLocNo()); + if (result == null) { + throw new CoolException("璺緞璁$畻澶辫触"); + } + + assignCommand.setCommands(result.getCommands()); + assignCommand.setNodes(result.getNodes()); + } else if (shuttleTaskModeType == ShuttleTaskModeType.MOVE_LOC_NO) { + //绉诲姩鍒扮洰鏍囧簱浣� + Integer mapType = NavigationMapType.NORMAL.id; + if (shuttleProtocol.getLiftPosition() == 2) { + mapType = NavigationMapType.DFX.id; + } + NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), shuttleProtocol.getCurrentLocNo(), param.getDistLocNo(), mapType); + if (result == null) { + throw new CoolException("璺緞璁$畻澶辫触"); + } + + assignCommand.setCommands(result.getCommands()); + assignCommand.setNodes(result.getNodes()); + } else if (shuttleTaskModeType == ShuttleTaskModeType.PALLET_LIFT) { + //鎵樼洏椤跺崌 + NyShuttleHttpCommand command = NyHttpUtils.getPalletLiftCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), true); + ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); + commands.add(command); + assignCommand.setCommands(commands); + } else if (shuttleTaskModeType == ShuttleTaskModeType.PALLET_DOWN) { + //鎵樼洏涓嬮檷 + NyShuttleHttpCommand command = NyHttpUtils.getPalletLiftCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), false); + ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); + commands.add(command); + assignCommand.setCommands(commands); + } else if (shuttleTaskModeType == ShuttleTaskModeType.CHARGE) { + //鍏呯數寮�鍏� + boolean charge = false; + if (shuttleProtocol.getChargState() == 1) { + //宸插厖鐢碉紝鍏抽棴鍏呯數 + charge = false; + }else { + //寮�鍚厖鐢� + charge = true; + } + NyShuttleHttpCommand command = NyHttpUtils.getChargeCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), charge); + ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); + commands.add(command); + assignCommand.setCommands(commands); + } else if (shuttleTaskModeType == ShuttleTaskModeType.RESET) { + //澶嶄綅 + shuttleProtocol.setTaskNo(0);//宸ヤ綔鍙锋竻绌� + shuttleProtocol.setToken(0);//浠ょ墝娓呯┖ + shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);//浠诲姟鐘舵��-绌洪棽 + shuttleProtocol.setPakMk(false);//浣滀笟鏍囪澶嶄綅 + + shuttleProtocol.setMoveLoc(false); + shuttleProtocol.setMoveType(0); + shuttleProtocol.setXStart(0); + shuttleProtocol.setXTarget(0); + shuttleProtocol.setXCurrent(0); + shuttleProtocol.setYStart(0); + shuttleProtocol.setYTarget(0); + shuttleProtocol.setYCurrent(0); + return R.ok(); + } else if (shuttleTaskModeType == ShuttleTaskModeType.SHUTTLE_CONTROL) { + //灏忚溅绠″埗 + NyShuttleHttpCommand suspendCommand = NyHttpUtils.getSuspendCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), true); + ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); + commands.add(suspendCommand); + assignCommand.setCommands(commands); + } else if (shuttleTaskModeType == ShuttleTaskModeType.SHUTTLE_CANCEL_CONTROL) { + //灏忚溅鍙栨秷绠″埗 + NyShuttleHttpCommand suspendCommand = NyHttpUtils.getSuspendCommand(shuttleSlave.getId(), assignCommand.getTaskNo().intValue(), false); + ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); + commands.add(suspendCommand); + assignCommand.setCommands(commands); + } else if (shuttleTaskModeType == ShuttleTaskModeType.MOVE_LOC_NO_WRK_MAST) { + //绉诲姩鍒扮洰鏍囧簱浣�(鐢熸垚绉诲姩浠诲姟) + shuttleDispatchUtils.dispatchShuttle(commonService.getWorkNo(3), param.getDistLocNo(), param.getShuttleNo()); + return R.ok(); + } else { + throw new CoolException("鏈煡鍛戒护"); + } + if (MessageQueue.offer(SlaveType.Shuttle, shuttleSlave.getId(), new Task(3, assignCommand))) { return R.ok(); } else { @@ -279,8 +386,9 @@ @PostMapping("/detl/update") @ManagerAuth(memo = "淇敼鏁版嵁") public R shuttleUpdate(@RequestParam Integer shuttleNo, - @RequestParam Integer workNo, - @RequestParam String pakMk){ + @RequestParam Integer workNo, + @RequestParam String pakMk, + @RequestParam Integer token) { NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); if (shuttleThread == null) { return R.error("plc宸叉帀绾�"); @@ -294,6 +402,9 @@ } if (pakMk != null) { shuttleProtocol.setPakMk(pakMk.equals("Y")); + } + if (token != null) { + shuttleProtocol.setToken(token); } return R.ok(); } @@ -313,4 +424,40 @@ return R.ok(); } + /** + * 璺戝簱绋嬪簭 + */ + @PostMapping("/moveLoc") + @ManagerAuth + public R moveLoc(@RequestParam Integer shuttleNo, + @RequestParam Integer moveType, + @RequestParam Integer xStart, + @RequestParam Integer xTarget, + @RequestParam Integer yStart, + @RequestParam Integer yTarget) { + NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); + if (shuttleThread == null) { + return R.error(); + } + + NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + if (shuttleProtocol == null) { + return R.error(); + } + + if (!shuttleProtocol.isIdle()) { + return R.error("灏忚溅蹇欑涓�"); + } + + shuttleProtocol.setMoveLoc(true);//寮�鍚窇搴� + shuttleProtocol.setMoveType(moveType); + shuttleProtocol.setXStart(xStart); + shuttleProtocol.setXTarget(xTarget); + shuttleProtocol.setXCurrent(xStart); + shuttleProtocol.setYStart(yStart); + shuttleProtocol.setYTarget(yTarget); + shuttleProtocol.setYCurrent(yStart); + return R.ok(); + } + } -- Gitblit v1.9.1