From 2cdb769a5fc08e1efbf724cf92d3b108d634aa26 Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期五, 21 七月 2023 16:54:39 +0800 Subject: [PATCH] 计算中间点到目标点行走距离 --- src/main/java/com/zy/asrs/controller/ShuttleController.java | 160 +++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 118 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/zy/asrs/controller/ShuttleController.java b/src/main/java/com/zy/asrs/controller/ShuttleController.java index 0f428b9..4240bdd 100644 --- a/src/main/java/com/zy/asrs/controller/ShuttleController.java +++ b/src/main/java/com/zy/asrs/controller/ShuttleController.java @@ -1,5 +1,6 @@ package com.zy.asrs.controller; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.annotations.ManagerAuth; import com.core.common.BaseRes; @@ -15,7 +16,9 @@ import com.zy.asrs.service.LocMastService; import com.zy.asrs.service.WrkMastService; import com.zy.asrs.utils.Utils; +import com.zy.common.service.CommonService; import com.zy.common.utils.NavigatePositionConvert; +import com.zy.common.utils.RedisUtil; import com.zy.core.cache.MessageQueue; import com.zy.core.cache.OutputQueue; import com.zy.core.cache.SlaveConnection; @@ -24,6 +27,7 @@ import com.zy.core.model.Task; 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.ShuttleProtocol; import com.zy.core.properties.SlaveProperties; import com.zy.core.thread.ShuttleThread; @@ -32,7 +36,6 @@ import org.springframework.web.bind.annotation.*; import java.util.ArrayList; -import java.util.Date; import java.util.List; /** @@ -51,6 +54,10 @@ private WrkMastService wrkMastService; @Autowired private LocMastService locMastService; + @Autowired + private CommonService commonService; + @Autowired + private RedisUtil redisUtil; @PostMapping("/table/shuttle/state") @ManagerAuth(memo = "鍥涘悜绌挎杞︿俊鎭〃") @@ -115,7 +122,7 @@ vo.setCurrentOrBeforeCode(shuttleProtocol.getCurrentOrBeforeCode());//褰撳墠鎴栬�呬箣鍓嶈鍒扮殑浜岀淮鐮佸�� vo.setCodeOffsetX(shuttleProtocol.getCodeOffsetX());//璇诲埌鐨勪簩缁寸爜X鏂瑰悜鍋忕Щ閲� vo.setCodeOffsetY(shuttleProtocol.getCodeOffsetY());//璇诲埌鐨勪簩缁寸爜Y鏂瑰悜鍋忕Щ閲� - vo.setCurrentVoltage(shuttleProtocol.getCurrentVoltage() * 0.1);//褰撳墠鐨勭數鍘嬪�� + vo.setCurrentVoltage(shuttleProtocol.getCurrentVoltage());//褰撳墠鐨勭數鍘嬪�� vo.setCurrentAnalogValue(shuttleProtocol.getCurrentAnalogValue());//褰撳墠鐨勬ā鎷熼噺鍊� vo.setCurrentLiftServoSpeed(shuttleProtocol.getCurrentLiftServoSpeed());//褰撳墠鐨勫崌闄嶄己鏈嶉�熷害 vo.setCurrentMoveServoSpeed(shuttleProtocol.getCurrentMoveServoSpeed());//褰撳墠鐨勮璧颁己鏈嶉�熷害 @@ -169,7 +176,7 @@ vo.setCurrentLiftServoSpeed(shuttleProtocol.getCurrentLiftServoSpeed());//褰撳墠鐨勫崌闄嶄己鏈嶉�熷害 vo.setPakMk(shuttleProtocol.getPakMk()?"Y" : "N"); // 浣滀笟鏍囪 vo.setLocNo(shuttleProtocol.getLocNo());//鍥涘悜绌挎杞﹀綋鍓嶅簱浣嶅彿 - vo.setLev(Utils.getLev(shuttleProtocol.getLocNo()));//鍥涘悜绌挎杞﹀綋鍓嶅眰楂� + vo.setLev(shuttleProtocol.getLocNo() == null ? 0 : Utils.getLev(shuttleProtocol.getLocNo()));//鍥涘悜绌挎杞﹀綋鍓嶅眰楂� vo.setRunSpeed(basShuttle.getRunSpeed());//鍥涘悜绌挎杞﹁繍琛岄�熷害(璁剧疆) vo.setChargeLine(basShuttle.getChargeLine());//鍏呯數闃堝�� } @@ -240,53 +247,82 @@ return R.ok().add(vo); } - @PostMapping("/detl/update") - @ManagerAuth - public R steUpdate(ShuttleDataVo vo){ - BasShuttle basShuttle = basShuttleService.selectById(vo.getShuttleNo()); - if (basShuttle == null) { + @RequestMapping(value = "/command/query") + public R shuttleCommandQuery(@RequestParam("wrkNo") Integer wrkNo) { + Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + if (o == null) { return R.error(); } - // 鑾峰彇鍥涘悜绌挎杞︿俊鎭� - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, vo.getShuttleNo()); - ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); - if (shuttleProtocol == null) { - throw new CoolException(vo.getShuttleNo() + "鍙峰洓鍚戠┛姊溅涓嶅湪绾匡紝鏃犳硶淇濆瓨"); - } -// if (!Cools.isEmpty(vo.getRow(), vo.getBay(), vo.getLev())) { -// if (!shuttleThread.modifyPosHandle(vo.getRow(), vo.getBay(), vo.getLev())) { -// throw new CoolException("鏈嶅姟鍣ㄩ敊璇�"); -// } -// } - ShuttleCommand shuttleCommand = new ShuttleCommand(); - shuttleCommand.setTaskNo(vo.getWorkNo().shortValue()); - if (MessageQueue.offer(SlaveType.Shuttle, vo.getShuttleNo(), new Task(2, shuttleCommand))) { - } else { - throw new CoolException("鍛戒护涓嬪彂澶辫触"); - } + ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); + return R.ok().add(redisCommand); + } - basShuttle.setPakMk(vo.getPakMk()); - basShuttle.setWrkNo(vo.getWorkNo()); - basShuttle.setUpdateTime(new Date()); - if (!basShuttleService.updateById(basShuttle)) { - throw new CoolException("淇敼澶辫触"); + //鍥為��鍛戒护 + @RequestMapping(value = "/command/rollback") + public R shuttleCommandRollback(@RequestParam("wrkNo") Integer wrkNo + , @RequestParam("commandStep") Integer commandStep) { + Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + if (o == null) { + return R.error(); } + ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); + redisCommand.setCommandStep(commandStep); + redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); return R.ok(); } - @PostMapping("/runSpeed/{shuttleNo}") - @ManagerAuth - public R setRunSpeed(@PathVariable("shuttleNo") String shuttleNo, @RequestParam("runSpeed") Integer runSpeed, @RequestParam("chargeLine") Integer chargeLine) { - - BasShuttle basShuttle = basShuttleService.selectById(shuttleNo); - if (basShuttle == null) { - return R.error("鍥涘悜绌挎杞︿笉瀛樺湪"); - } - basShuttle.setRunSpeed(runSpeed); - basShuttle.setChargeLine(chargeLine); - if (!basShuttleService.updateById(basShuttle)) { + //鍛戒护瀹屾垚鐘舵�佸垏鎹� + @RequestMapping(value = "/command/completeSwitch") + public R shuttleCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo + , @RequestParam("commandStep") Integer commandStep + , @RequestParam("complete") Integer complete) { + Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + if (o == null) { return R.error(); } + ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); + ShuttleAssignCommand assignCommand = redisCommand.getAssignCommand(); + List<ShuttleCommand> commands = assignCommand.getCommands(); + ShuttleCommand command = commands.get(commandStep); + command.setComplete(complete != 0); + redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); + return R.ok(); + } + + //閲嶅惎浠诲姟(鍛戒护) + @RequestMapping(value = "/command/restart") + public R shuttleCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo) { + Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + if (o == null) { + return R.error(); + } + ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); + Short shuttleNo = redisCommand.getShuttleNo(); + ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo.intValue()); + if (shuttleThread == null) { + return R.error(); + } + ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + if (shuttleProtocol == null) { + return R.error(); + } + if (!shuttleProtocol.isIdle()) { + return R.error(); + } + //鍥涘悜绌挎杞﹀浜庣┖闂茬姸鎬侊紝杩涜浠诲姟鐨勬仮澶� + shuttleProtocol.setTaskNo(redisCommand.getWrkNo());//灏嗗洓鍚戠┛姊溅绾跨▼鍒嗛厤浠诲姟鍙� + shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);//宸ヤ綔鐘舵�� + return R.ok(); + } + + //鍒犻櫎浠诲姟(鍛戒护) + @RequestMapping(value = "/command/del") + public R liftCommandDel(@RequestParam("wrkNo") Integer wrkNo) { + Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + if (o == null) { + return R.error(); + } + redisUtil.del("shuttle_wrk_no_" + wrkNo); return R.ok(); } @@ -325,7 +361,7 @@ ShuttleTaskModeType shuttleTaskModeType = ShuttleTaskModeType.get(param.getShuttleTaskMode()); assignCommand.setShuttleNo(shuttleSlave.getId().shortValue()); // 鍥涘悜绌挎杞︾紪鍙� assignCommand.setTaskMode(shuttleTaskModeType.id.shortValue()); - assignCommand.setTaskNo((short) 9999); + assignCommand.setTaskNo((short) commonService.getWorkNo(3));//鑾峰彇浠诲姟鍙� assignCommand.setAuto(false);//鎵嬪姩妯″紡 if (MessageQueue.offer(SlaveType.Shuttle, shuttleSlave.getId(), new Task(3, assignCommand))) { @@ -338,4 +374,44 @@ return R.error(); } + @PostMapping("/detl/update") + @ManagerAuth(memo = "淇敼鏁版嵁") + public R liftUpdate(@RequestParam Integer shuttleNo, + @RequestParam Short workNo, + @RequestParam String pakMk){ + for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) { + ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId()); + if (shuttleThread == null) { + return R.error("plc宸叉帀绾�"); + } + ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + if (shuttleProtocol == null) { + return R.error("plc宸叉帀绾�"); + } + if (workNo != null) { + shuttleProtocol.setTaskNo(workNo); + } + if (pakMk != null) { + shuttleProtocol.setPakMk(pakMk.equals("Y")); + } + } + return R.error("plc宸叉帀绾�"); + } + + @PostMapping("/runSpeed/{shuttleNo}") + @ManagerAuth + public R setRunSpeed(@PathVariable("shuttleNo") String shuttleNo, @RequestParam("runSpeed") Integer runSpeed, @RequestParam("chargeLine") Integer chargeLine) { + + BasShuttle basShuttle = basShuttleService.selectById(shuttleNo); + if (basShuttle == null) { + return R.error("鍥涘悜绌挎杞︿笉瀛樺湪"); + } + basShuttle.setRunSpeed(runSpeed); + basShuttle.setChargeLine(chargeLine); + if (!basShuttleService.updateById(basShuttle)) { + return R.error(); + } + return R.ok(); + } + } -- Gitblit v1.9.1