From b18d5b80fccc2579c4685a4f462d4bab7694ccf4 Mon Sep 17 00:00:00 2001 From: liuxy Date: Fri, 30 Jan 2026 13:00:35 +0800 Subject: [PATCH] =?UTF-8?q?rev=EF=BC=9A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/device_driver/DriverTypeEnum.java | 2 + .../agv/ndcone/AgvNdcOneDeviceDriver.java | 90 ++- .../pallet_dispenser/ItemProtocol.java | 41 +- .../PalletDispenseDeviceDriver.java | 72 ++- .../PalletDispenserDefination.java | 5 +- .../basedriver/robot_arm/ItemProtocol.java | 77 +++ .../robot_arm/RobotArmDefination.java} | 30 +- .../robot_arm/RobotArmDeviceDriver.java | 232 ++++++++ .../StretchWrapperDeviceDriver.java | 47 +- .../BoxStorageManipulatorDeviceDriver.java | 538 ------------------ .../InteractionJsonDTO.java | 31 - .../box_storage_manipulator/ItemProtocol.java | 186 ------ .../return_good_manipulator/ItemProtocol.java | 161 ------ .../ReturnGoodManipulatorDefination.java | 56 -- .../ReturnGoodManipulatorDeviceDriver.java | 478 ---------------- .../InteractionJsonDTO.java | 27 - .../trapped_manipulator/ItemProtocol.java | 179 ------ .../TrappedManipulatorDefination.java | 56 -- ...pedManipulatorManipulatorDeviceDriver.java | 493 ---------------- .../nl/acs/ext/wms/data/one/BaseRequest.java | 1 - .../acs/ext/wms/service/AcsToWmsService.java | 9 +- .../wms/service/impl/AcsToWmsServiceImpl.java | 44 +- .../src/views/acs/device/config.vue | 3 +- .../src/views/acs/device/driver/robot_arm.vue | 364 ++++++++++++ 24 files changed, 921 insertions(+), 2301 deletions(-) create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/ItemProtocol.java rename acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/{one_manipulator/box_storage_manipulator/BoxStorageManipulatorDefination.java => basedriver/robot_arm/RobotArmDefination.java} (56%) create mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/RobotArmDeviceDriver.java delete mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java delete mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java delete mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/ItemProtocol.java delete mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ItemProtocol.java delete mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDefination.java delete mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java delete mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java delete mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/ItemProtocol.java delete mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java delete mode 100644 acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java create mode 100644 acs/nladmin-ui/src/views/acs/device/driver/robot_arm.vue diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 375fbe1..61916ee 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -32,6 +32,8 @@ public enum DriverTypeEnum { STRETCH(22, "stretch_wrapper", "缠绕机", "stretch"), + ROBOT(23, "robot_arm", "机械手", "robot"), + STANDARD_STACKER(11, "standard_stacker", "标准版-单工位堆垛机", "stacker"), SIEMENS_CONVEYOR_LABELING(12, "siemens_conveyor_labeling", "西门子-输送机驱动-贴标", "conveyor"), diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java index 227e644..5b5c537 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java @@ -2,22 +2,16 @@ package org.nl.acs.device_driver.basedriver.agv.ndcone; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.http.HttpResponse; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import jodd.util.StringUtil; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.nl.acs.AcsConfig; import org.nl.acs.agv.server.NDCAgvService; import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun; import org.nl.acs.device.domain.Device; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.RequestMethodEnum; -import org.nl.acs.device_driver.basedriver.agv.utils.AgvActionEnum; import org.nl.acs.device_driver.basedriver.pallet_dispenser.PalletDispenseDeviceDriver; +import org.nl.acs.device_driver.basedriver.robot_arm.RobotArmDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; import org.nl.acs.device_driver.basedriver.stretch_wrapper.ItemProtocol; import org.nl.acs.device_driver.basedriver.stretch_wrapper.StretchWrapperDeviceDriver; @@ -39,13 +33,11 @@ import org.nl.acs.task.service.impl.TaskServiceImpl; import org.nl.config.SpringContextHolder; import org.nl.config.thread.ThreadPoolExecutorUtil; import org.nl.system.service.lucene.LuceneExecuteLogService; -import org.nl.system.service.lucene.dto.LuceneLogDto; import org.nl.system.service.param.ISysParamService; import org.nl.system.service.param.impl.SysParamServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; /** @@ -233,20 +225,30 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic } } + // 到达机械手 + if (device.getDeviceDriver() instanceof RobotArmDeviceDriver) { + RobotArmDeviceDriver deviceDriver = (RobotArmDeviceDriver) device.getDeviceDriver(); + // 下发正在取货 + deviceDriver.writing(org.nl.acs.device_driver.basedriver.robot_arm.ItemProtocol.to_out, "1"); + log.info("到达{}取货点开始取货", device_code); + inst.setExecute_status("1"); + instructionService.update(inst); + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + flag = true; + } + // 到达拆盘机 if (device.getDeviceDriver() instanceof PalletDispenseDeviceDriver) { PalletDispenseDeviceDriver deviceDriver = (PalletDispenseDeviceDriver) device.getDeviceDriver(); - // 下发请求取货 - deviceDriver.writing(org.nl.acs.device_driver.basedriver.pallet_dispenser.ItemProtocol.to_out,"1"); - // 判断是否允许取货 - if (deviceDriver.getAction() == 1) { - log.info("到达{}取货点开始取货", device_code); - inst.setExecute_status("1"); - instructionService.update(inst); - data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); - flag = true; - } + // 下发正在取货 + deviceDriver.writing(org.nl.acs.device_driver.basedriver.pallet_dispenser.ItemProtocol.to_out, "1"); + log.info("到达{}取货点开始取货", device_code); + inst.setExecute_status("1"); + instructionService.update(inst); + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + flag = true; } + } else if (phase == 0x04) { data = getData(data, index, inst, task); //取货完毕 @@ -311,11 +313,15 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic flag = true; } - // 到达拆盘机取货完成 - if (device.getDeviceDriver() instanceof PalletDispenseDeviceDriver) { - PalletDispenseDeviceDriver deviceDriver = (PalletDispenseDeviceDriver) device.getDeviceDriver(); - deviceDriver.writing(org.nl.acs.device_driver.basedriver.pallet_dispenser.ItemProtocol.to_out_finish, "1"); + // 到达机械手取货完成 + if (device.getDeviceDriver() instanceof RobotArmDeviceDriver) { + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + log.info("agv进入" + device_code + "取货完成"); + flag = true; + } + // 到达拆盘机手取货完成 + if (device.getDeviceDriver() instanceof PalletDispenseDeviceDriver) { data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); log.info("agv进入" + device_code + "取货完成"); flag = true; @@ -392,6 +398,30 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic flag = true; } } + + // 机械手 + if (device.getDeviceDriver() instanceof RobotArmDeviceDriver) { + RobotArmDeviceDriver deviceDriver = (RobotArmDeviceDriver) device.getDeviceDriver(); + // 下发请求放货 + deviceDriver.writing(org.nl.acs.device_driver.basedriver.robot_arm.ItemProtocol.to_in, "1"); + log.info("到达{}放货点开始放货", device_code); + inst.setExecute_status("1"); + instructionService.update(inst); + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + flag = true; + } + + // 拆盘机 + if (device.getDeviceDriver() instanceof PalletDispenseDeviceDriver) { + PalletDispenseDeviceDriver deviceDriver = (PalletDispenseDeviceDriver) device.getDeviceDriver(); + // 下发请求放货 + deviceDriver.writing(org.nl.acs.device_driver.basedriver.pallet_dispenser.ItemProtocol.to_in, "1"); + log.info("到达{}放货点开始放货", device_code); + inst.setExecute_status("1"); + instructionService.update(inst); + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + flag = true; + } //放货完毕 //(需要WCS反馈) } else if (phase == 0x09) { @@ -458,6 +488,20 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic log.info("{}放货完成", device_code); flag = true; } + + // 到达机械手放货完成 + if (device.getDeviceDriver() instanceof RobotArmDeviceDriver) { + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + log.info("{}放货完成", device_code); + flag = true; + } + + // 到达拆盘机放货完成 + if (device.getDeviceDriver() instanceof PalletDispenseDeviceDriver) { + data = ndcAgvService.sendAgvOneModeInst(phase, index, 0); + log.info("{}放货完成", device_code); + flag = true; + } } //到达位置点 //(需要WCS反馈) diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/ItemProtocol.java index 910aa0e..efe28ab 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/ItemProtocol.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/ItemProtocol.java @@ -8,15 +8,17 @@ import java.util.List; @Slf4j public class ItemProtocol { - // 入口允许取放货 - public static String action = "action"; - // 故障信号 - public static String error = "error"; + // 心跳 + public static String heartbeat = "heartbeat"; + // 托盘就绪 + public static String emp_ready = "emp_ready"; + // 申请托盘任务 + public static String emp_apply = "emp_apply"; - // 下发请求取货 + // AGV取栈板中 public static String to_out = "to_out"; - // 下发取货完成 - public static String to_out_finish = "to_out_finish"; + // AGV放栈板中 + public static String to_in = "to_in"; private PalletDispenseDeviceDriver driver; @@ -24,20 +26,24 @@ public class ItemProtocol { this.driver = driver; } - public int getAction() { - return this.getOpcIntegerValue(action); + public int getHeartbeat() { + return this.getOpcIntegerValue(heartbeat); } - public int getError() { - return this.getOpcIntegerValue(error); + public int getEmpReady() { + return this.getOpcIntegerValue(emp_ready); + } + + public int getEmpApply() { + return this.getOpcIntegerValue(emp_apply); } public int getToOut() { return this.getOpcIntegerValue(to_out); } - public int getToOutFinish() { - return this.getOpcIntegerValue(to_out_finish); + public int getToIn() { + return this.getOpcIntegerValue(to_in); } public int getOpcIntegerValue(String protocol) { @@ -53,15 +59,16 @@ public class ItemProtocol { public static List getReadableItemDtos() { ArrayList list = new ArrayList(); - list.add(new ItemDto(action, "是否允许取货", "V6200.0")); - list.add(new ItemDto(error, "报警信号", "V6200.1")); + list.add(new ItemDto(heartbeat, "心跳", "V6200.0")); + list.add(new ItemDto(emp_ready, "栈板就绪", "V6200.1")); + list.add(new ItemDto(emp_apply, "缺栈板请求", "V6200.1")); return list; } public static List getWriteableItemDtos() { ArrayList list = new ArrayList(); - list.add(new ItemDto(to_out, "下发请求取货", "V6300.0")); - list.add(new ItemDto(to_out_finish, "下发取货完成", "V6300.1")); + list.add(new ItemDto(to_out, "取栈板中", "V6300.0")); + list.add(new ItemDto(to_in, "放栈板中", "V6300.1")); return list; } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/PalletDispenseDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/PalletDispenseDeviceDriver.java index c280588..1a2f49f 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/PalletDispenseDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/PalletDispenseDeviceDriver.java @@ -2,6 +2,7 @@ package org.nl.acs.device_driver.basedriver.pallet_dispenser; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -14,6 +15,7 @@ import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.domain.Task; import org.nl.acs.task.service.TaskService; import org.nl.acs.utils.ReadUtil; import org.nl.config.SpringContextHolder; @@ -21,10 +23,7 @@ import org.nl.system.service.lucene.LuceneExecuteLogService; import org.nl.system.service.lucene.dto.LuceneLogDto; import org.openscada.opc.lib.da.Server; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.*; /** * 拆盘机驱动 @@ -57,16 +56,17 @@ public class PalletDispenseDeviceDriver extends AbstractOpcDeviceDriver implemen //有货标记 protected boolean has_goods_tag = false; String devicecode; - int action = 0; - int error = 0; + int heartbeat = 0; + int emp_ready = 0; + int emp_apply = 0; Boolean iserror = false; int move = 0; int task = 0; - int last_action = 0; - int last_error = 0; - int last_task_out = 0; - int last_move = 0; + int last_heartbeat = 0; + int last_emp_ready = 0; + int last_emp_apply = 0; + int last_task = 0; boolean hasVehicle = false; @@ -89,7 +89,7 @@ public class PalletDispenseDeviceDriver extends AbstractOpcDeviceDriver implemen private Date instruction_require_time = new Date(); private Date instruction_finished_time = new Date(); - private int instruction_require_time_out; + private int instruction_require_time_out = 5000; boolean requireSucess = false; private int instruction_finished_time_out; @@ -107,35 +107,47 @@ public class PalletDispenseDeviceDriver extends AbstractOpcDeviceDriver implemen @Override public void execute() { devicecode = this.getDevice().getDevice_code(); - action = this.itemProtocol.getAction(); - error = this.itemProtocol.getError(); + heartbeat = this.itemProtocol.getHeartbeat(); + emp_ready = this.itemProtocol.getEmpReady(); + emp_apply = this.itemProtocol.getEmpApply(); - last_action = action; - last_error = error; + last_heartbeat = heartbeat; + last_emp_ready = emp_ready; + last_emp_apply = emp_apply; + + if (last_heartbeat == 1) { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + } else { + this.instruction_require_time = date; + this.executeTask(); + } + } } /** * 执行业务逻辑 */ public void executeTask() { + // 判断是否有这个任务 + List list = taskserver.list( + new QueryWrapper().lambda() + .eq(Task::getNext_device_code, devicecode) + .eq(Task::getIs_delete, "0") + .in(Task::getTask_status, "0", "1") + ); + if (ObjectUtil.isEmpty(list)) { + // 申请拆盘机叫料任务 + JSONObject param = new JSONObject(); + param.put("device_code", devicecode); + param.put("type", "3"); + acsToWmsService.applyTask(param); + } } public synchronized String getStatus() { - JSONObject jo = new JSONObject(); - - if (action == 1) { - jo.put("name", this.getDevice().getDevice_code()); - jo.put("status", "OPEN"); - - } else if (action == 2) { - jo.put("name", this.getDevice().getDevice_code()); - jo.put("status", "CLOSE"); - - } else { - jo.put("name", this.getDevice().getDevice_code()); - jo.put("status", "ERROR"); - } - return jo.toString(); + return null; } /** diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/PalletDispenserDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/PalletDispenserDefination.java index 107d028..e752ec6 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/PalletDispenserDefination.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/pallet_dispenser/PalletDispenserDefination.java @@ -56,8 +56,9 @@ public class PalletDispenserDefination implements OpcDeviceDriverDefination { public static List getReadableItemDtos2() { List list = new ArrayList(); - list.add(new ItemDto(ItemProtocol.action, "是否允许取货", "V6200.0")); - list.add(new ItemDto(ItemProtocol.error, "报警信号", "V6200.1")); + list.add(new ItemDto(ItemProtocol.heartbeat, "心跳", "V6200.0")); + list.add(new ItemDto(ItemProtocol.emp_ready, "栈板就绪", "V6200.1")); + list.add(new ItemDto(ItemProtocol.emp_apply, "缺栈板请求", "V6200.2")); return list; } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/ItemProtocol.java new file mode 100644 index 0000000..c2cee6a --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/ItemProtocol.java @@ -0,0 +1,77 @@ +package org.nl.acs.device_driver.basedriver.robot_arm; + +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +public class ItemProtocol { + // 心跳 + public static String heartbeat = "heartbeat"; + // 空栈板请求 + public static String emp_task = "emp_apply"; + // 码垛拉走请求 + public static String pallet_apply = "pallet_apply"; + + // AGV取栈板中 + public static String to_out = "to_out"; + // AGV放栈板中 + public static String to_in = "to_in"; + + private RobotArmDeviceDriver driver; + + public ItemProtocol(RobotArmDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(heartbeat); + } + + public int getEmp() { + return this.getOpcIntegerValue(emp_task); + } + + public int getPallet() { + return this.getOpcIntegerValue(pallet_apply); + } + + public int getToOut() { + return this.getOpcIntegerValue(to_out); + } + + public int getToIn() { + return this.getOpcIntegerValue(to_in); + } + + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { +// log.error("读取错误!"); + } else { + return value; + } + return 0; + + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(heartbeat, "心跳", "V6000.0")); + list.add(new ItemDto(emp_task, "空栈板请求", "V6000.1")); + list.add(new ItemDto(pallet_apply, "码垛拉走请求", "V6000.3")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(to_out, "取栈板中", "V6100.0")); + list.add(new ItemDto(to_in, "放栈板中", "V6100.1")); + return list; + } + +} + diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/RobotArmDefination.java similarity index 56% rename from acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDefination.java rename to acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/RobotArmDefination.java index 44b8be5..d61efc4 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDefination.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/RobotArmDefination.java @@ -1,4 +1,4 @@ -package org.nl.acs.device_driver.one_manipulator.box_storage_manipulator; +package org.nl.acs.device_driver.basedriver.robot_arm; import org.nl.acs.device.device_driver.standard_inspect.ItemDto; import org.nl.acs.device.domain.Device; @@ -7,34 +7,39 @@ import org.nl.acs.device_driver.DeviceDriver; import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +/** + * 机械手驱动定义 + */ @Service -public class BoxStorageManipulatorDefination implements OpcDeviceDriverDefination { +public class RobotArmDefination implements OpcDeviceDriverDefination { @Override public String getDriverCode() { - return "box_storage_manipulator"; + return "robot_arm"; } @Override public String getDriverName() { - return "木箱入库行架"; + return "码垛机械手"; } @Override public String getDriverDescription() { - return "木箱入库行架"; + return "码垛机械手"; } @Override public DeviceDriver getDriverInstance(Device device) { - return (new BoxStorageManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); + return (new RobotArmDeviceDriver()).setDevice(device).setDriverDefination(this); + } @Override public Class getDeviceDriverType() { - return BoxStorageManipulatorDeviceDriver.class; + return RobotArmDeviceDriver.class; } @Override @@ -46,11 +51,20 @@ public class BoxStorageManipulatorDefination implements OpcDeviceDriverDefinatio @Override public List getReadableItemDtos() { - return ItemProtocol.getReadableItemDtos(); + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.heartbeat, "心跳", "V6000.0")); + list.add(new ItemDto(ItemProtocol.emp_task, "空栈板请求", "V6000.1")); + list.add(new ItemDto(ItemProtocol.pallet_apply, "码垛拉走请求", "V6000.3")); + return list; } @Override public List getWriteableItemDtos() { return ItemProtocol.getWriteableItemDtos(); } + } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/RobotArmDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/RobotArmDeviceDriver.java new file mode 100644 index 0000000..e649008 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/robot_arm/RobotArmDeviceDriver.java @@ -0,0 +1,232 @@ +package org.nl.acs.device_driver.basedriver.robot_arm; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.domain.Device; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.domain.Task; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.utils.ReadUtil; +import org.nl.config.SpringContextHolder; +import org.nl.system.service.lucene.LuceneExecuteLogService; +import org.nl.system.service.lucene.dto.LuceneLogDto; +import org.openscada.opc.lib.da.Server; + +import java.util.*; + +/** + * 机械手驱动 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class RobotArmDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver { + + protected ItemProtocol itemProtocol = new ItemProtocol(this); + + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + + LuceneExecuteLogService lucene = SpringContextHolder.getBean("luceneExecuteLogServiceImpl"); + + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + AcsToWmsService acsToWmsService = SpringContextHolder.getBean("acsToWmsServiceImpl"); + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + String devicecode; + int heartbeat = 0; + int emp_task = 0; + int pallet_apply = 0; + int to_out = 0; + int to_in = 0; + Boolean iserror = false; + + int move = 0; + int task = 0; + int last_error = 0; + + int last_heartbeat = 0; + int last_emp_task = 0; + int last_pallet_apply = 0; + int last_to_out = 0; + int last_to_in = 0; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + protected boolean hasGoods = false; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out = 5000; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + + String message = ""; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + devicecode = this.getDevice().getDevice_code(); + heartbeat = this.itemProtocol.getHeartbeat(); + emp_task = this.itemProtocol.getEmp(); + pallet_apply = this.itemProtocol.getPallet(); + + last_heartbeat = heartbeat; + last_emp_task = emp_task; + last_pallet_apply = pallet_apply; + + if (last_heartbeat == 1) { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + } else { + this.instruction_require_time = date; + this.executeTask(); + } + } + } + + /** + * 执行业务逻辑 + */ + public void executeTask() { + JSONObject param = new JSONObject(); + // 申请叫料任务 + if (last_emp_task == 1) { + List list = taskserver.list( + new QueryWrapper().lambda() + .eq(Task::getNext_device_code, devicecode) + .eq(Task::getIs_delete, "0") + .in(Task::getTask_status, "0", "1") + ); + if (ObjectUtil.isEmpty(list)) { + // 调用上位接口 + param.put("device_code", devicecode); + param.put("type", "2"); + param.put("type_dtl", "2"); + acsToWmsService.applyTask(param); + } + } + // 申请下料任务 + if (pallet_apply == 1) { + List list = taskserver.list( + new QueryWrapper().lambda() + .eq(Task::getStart_device_code, devicecode) + .eq(Task::getIs_delete, "0") + .in(Task::getTask_status, "0", "1") + ); + if (ObjectUtil.isEmpty(list)) { + // 调用上位接口 + param.put("device_code", devicecode); + param.put("type", "2"); + param.put("type_dtl", "1"); + acsToWmsService.applyTask(param); + } + } + } + + public synchronized String getStatus() { + return null; + } + + /** + * 多个信号一起下发电气 + * + * @param map + */ + public void writing(Map map) { + LuceneExecuteLogService lucene = SpringContextHolder.getBean(LuceneExecuteLogService.class); + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + Map itemMap = new LinkedHashMap<>(); + map.forEach((key, value) -> { + if (ObjectUtil.isNotEmpty(value)) { + itemMap.put(getToParam() + key, value); + } + }); + if (ObjectUtil.isNotEmpty(itemMap)) { + try { + this.checkcontrol(itemMap); + } catch (Exception e) { + e.printStackTrace(); + try { + this.checkcontrol(itemMap); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); + lucene.deviceExecuteLog(new LuceneLogDto(this.getDeviceCode(), "下发多个电气信号:" + itemMap)); + } + } + + /** + * 抽取统一下发电气信号前缀 + * + * @return + */ + public String getToParam() { + return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; + } + + public void writing(String param, String value) { + + String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + param; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (value instanceof String) { + itemMap.put(to_param, value); + } else { + itemMap.put(to_param, value); + } + ReadUtil.write(itemMap, server); + server.disconnect(); + log.info("下发PLC信号:{},{}", this.devicecode, "to_command:" + value); + lucene.deviceExecuteLog(new LuceneLogDto(this.devicecode, message + param + " 写入 " + value)); + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/stretch_wrapper/StretchWrapperDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/stretch_wrapper/StretchWrapperDeviceDriver.java index e30a92f..2e4ee04 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/stretch_wrapper/StretchWrapperDeviceDriver.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/basedriver/stretch_wrapper/StretchWrapperDeviceDriver.java @@ -2,6 +2,7 @@ package org.nl.acs.device_driver.basedriver.stretch_wrapper; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -14,6 +15,7 @@ import org.nl.acs.ext.wms.service.AcsToWmsService; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.task.domain.Task; import org.nl.acs.task.service.TaskService; import org.nl.acs.utils.ReadUtil; import org.nl.config.SpringContextHolder; @@ -21,10 +23,7 @@ import org.nl.system.service.lucene.LuceneExecuteLogService; import org.nl.system.service.lucene.dto.LuceneLogDto; import org.openscada.opc.lib.da.Server; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.*; /** * 缠绕机驱动 @@ -92,7 +91,7 @@ public class StretchWrapperDeviceDriver extends AbstractOpcDeviceDriver implemen private Date instruction_require_time = new Date(); private Date instruction_finished_time = new Date(); - private int instruction_require_time_out; + private int instruction_require_time_out = 5000; boolean requireSucess = false; private int instruction_finished_time_out; @@ -106,7 +105,6 @@ public class StretchWrapperDeviceDriver extends AbstractOpcDeviceDriver implemen return this.device; } - @Override public void execute() { devicecode = this.getDevice().getDevice_code(); @@ -119,19 +117,52 @@ public class StretchWrapperDeviceDriver extends AbstractOpcDeviceDriver implemen last_error = error; last_task_in = task_in; last_task_out = task_out; + Date date = new Date(); + + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + } else { + this.instruction_require_time = date; + this.executeTask(); + } } /** * 执行业务逻辑 */ public void executeTask() { + JSONObject param = new JSONObject(); // 申请叫料任务 if (last_task_in == 1) { - // 调用上位接口 + List list = taskserver.list( + new QueryWrapper().lambda() + .eq(Task::getNext_device_code, devicecode) + .eq(Task::getIs_delete, "0") + .in(Task::getTask_status, "0", "1") + ); + if (ObjectUtil.isEmpty(list)) { + // 调用上位接口 + param.put("device_code", devicecode); + param.put("type", "1"); + param.put("type_dtl", "2"); + acsToWmsService.applyTask(param); + } } // 申请下料任务 if (last_task_out == 1) { - // 调用上位接口 + List list = taskserver.list( + new QueryWrapper().lambda() + .eq(Task::getStart_device_code, devicecode) + .eq(Task::getIs_delete, "0") + .in(Task::getTask_status, "0", "1") + ); + if (ObjectUtil.isEmpty(list)) { + // 调用上位接口 + param.put("device_code", devicecode); + param.put("type", "1"); + param.put("type_dtl", "1"); + acsToWmsService.applyTask(param); + } } } diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java deleted file mode 100644 index b0b3293..0000000 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/BoxStorageManipulatorDeviceDriver.java +++ /dev/null @@ -1,538 +0,0 @@ -package org.nl.acs.device_driver.one_manipulator.box_storage_manipulator; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.common.base.CommonFinalParam; -import org.nl.acs.device.domain.Device; -import org.nl.acs.device.service.DeviceExtraService; -import org.nl.acs.device.service.impl.DeviceExtraServiceImpl; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.FeedLmsRealFailed; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.device_driver.one_conveyor.box_subvolumes_conveyor.BoxSubvolumesConveyorDeviceDriver; -import org.nl.acs.history.ErrorUtil; -import org.nl.acs.history.service.DeviceErrorLogService; -import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl; -import org.nl.acs.instruction.domain.Instruction; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.opc.DeviceAppServiceImpl; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.route.service.impl.RouteLineServiceImpl; -import org.nl.acs.task.enums.TaskTypeEnum; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.config.SpringContextHolder; - -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * 木箱入库行架 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class BoxStorageManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed { - - protected ItemProtocol itemProtocol = new ItemProtocol(this); - - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - - TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); - - InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); - - DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); - - DeviceExtraService deviceExtraService = SpringContextHolder.getBean(DeviceExtraServiceImpl.class); - - DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); - - - int mode = 0; - int last_mode = 0; - int move = 0; - int last_move = 0; - int action = 0; - int last_action = 0; - int error = 0; - int last_error = 0; - int task = 0; - int last_task = 0; - - - int heartbeat = 0; - int last_heartbeat = 0; - int to_command = 0; - int last_to_command = 0; - - int to_target = 0; - int last_to_target = 0; - - int to_onset = 0; - int last_to_onset = 0; - - int to_task = 0; - int last_to_task = 0; - int to_layer = 0; - int last_to_layer = 0; - int to_barcode = 0; - int last_to_barcode = 0; - - Boolean isonline = true; - int hasGoods = 0; - String message = null; - Boolean iserror = false; - private Date instruction_update_time = new Date(); - private int instruction_update_time_out = 1000; - Integer heartbeat_tag; - private Date instruction_require_time = new Date(); - - private int instruction_require_time_out = 3000; - //行架机械手申请任务成功标识 - boolean requireSucess = false; - - private int instruction_finished_time_out; - - int branchProtocol = 0; - private String error_type = "hxhj_error_type"; - - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag; - - String device_code; - - //当前指令 - Instruction inst = null; - - //0 无任务执行 1更新指令状态 2下发电气信号 3允许取货 允许放货 5放货完成 - int now_steps_type = 0; - String notCreateTaskMessage = ""; - String notCreateInstMessage = ""; - String feedMessage = ""; - - - List getDeviceCodeList = null; - - List putDeviceCodeList = null; - - - @Override - public Device getDevice() { - return this.device; - } - - @Override - public void execute() { - String message = null; - try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - move = this.itemProtocol.getMove(); - action = this.itemProtocol.getAction(); - error = this.itemProtocol.getError(); - task = this.itemProtocol.getTask(); - heartbeat = this.itemProtocol.getHeartbeat(); - to_command = this.itemProtocol.getTo_command(); - to_target = this.itemProtocol.getTo_target(); - to_onset = this.itemProtocol.getTo_onset(); - to_task = this.itemProtocol.getTo_task(); - to_layer = this.itemProtocol.getTo_layer(); - to_barcode = this.itemProtocol.getTo_barcode(); - if (mode != last_mode) { - requireSucess = false; - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (move != last_move) { - logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); - } - if (action != last_action) { - logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (task != last_task) { - logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); - } - if (to_command != last_to_command) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); - } - if (to_target != last_to_target) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); - } - if (to_onset != last_to_onset) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_onset:" + last_to_target + "->" + to_target); - } - if (to_task != last_to_task) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); - } - - - // 更新指令状态 - if (mode == 3 && task > 0) { - updateInstructionStatus(); - } - - } catch (Exception var17) { - var17.printStackTrace(); - feedMessage = var17.getMessage(); - logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol)); - - } - - if (mode == 0) { - this.setIsonline(false); - message = "未联机"; - //有报警 - } else if (error != 0) { - this.setIserror(true); - message = "有报警"; - //无报警 - } else { - this.setIsonline(true); - this.setIserror(false); - message = ""; - Instruction instruction = null; - List toInstructions; - - //行架机械手申请任务 - if (mode == 2 && move == 0 && task == 0 && !requireSucess) { - boolean res = applyTask(); - if (res) { - notCreateInstMessage = ""; - notCreateTaskMessage = ""; - feedMessage = ""; - } - } else { - String remark = "未查找任务原因为:"; - if (mode != 2) { - remark = remark + "工作模式(mode)不是待机状态,"; - } - if (move != 0) { - remark = remark + "光电信号(move)为有货状态,"; - } - if (task != 0) { - remark = remark + "当前上报任务号(task)应该为0,"; - if (ObjectUtil.isNotEmpty(this.inst)) { - this.inst = null; - } - } - if (requireSucess) { - remark = remark + "请右击该图标,将请求任务复位标记(requireSucess)改为否。"; - } - this.setNotCreateTaskMessage(remark); - } - - } - last_mode = mode; - last_move = move; - last_action = action; - last_error = error; - last_task = task; - last_heartbeat = heartbeat; - last_to_task = to_task; - last_to_command = to_command; - last_to_target = to_target; - last_to_layer = to_layer; - last_to_barcode = to_barcode; - - } - - private void updateInstructionStatus() { - Date date = new Date(); - if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); - - } else { - this.instruction_update_time = date; - //更改指令状态 - if (task > 0) { - Instruction inst = checkInst(); - if (inst != null) { - if (StrUtil.equals(inst.getInstruction_status(), "0")) { - inst.setInstruction_status(CommonFinalParam.ONE); - inst.setExecute_device_code(this.device_code); - instructionService.update(inst); - } - } - - //放货完成 - if (mode == 3 && action == 4 && move == 0) { - if (inst != null) { - try { - logServer.deviceExecuteLog(this.device_code,"","","放货完成"); - finish_instruction(inst); - Map map = new LinkedHashMap<>(); - map.put("to_command", 5); - this.writing(map); - message = "放货完成"; - } catch (Exception e) { - message = "放货失败"; - e.printStackTrace(); - } - feedMessage = ""; - }else { - feedMessage = "行架机械手:"; - if (mode != 3) { - feedMessage = feedMessage + "工作模式(mode)不为运行中状态,"; - } - if (action != 8) { - feedMessage = feedMessage + "动作信号(action)不为放货完成状态,"; - } - if (move != 0) { - feedMessage = feedMessage + "光电信号(move)不为无货状态,"; - } - if (task == 0) { - feedMessage = feedMessage + "当前上报任务号(task)不应该为0。"; - } - } - } - } - - - } - } - - public synchronized boolean applyTask() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; - } else { - this.instruction_require_time = date; - //找终点为入库输送线工位任务类型为行架的任务 - BoxSubvolumesConveyorDeviceDriver boxOutSubvolumesConveyorDeviceDriver = new BoxSubvolumesConveyorDeviceDriver(); - String deviceCode = boxOutSubvolumesConveyorDeviceDriver.getDevice_code(); - TaskDto taskDto = taskserver.findByEndCodeAndReady(deviceCode, TaskTypeEnum.Box_Storage.getIndex()); - if (ObjectUtil.isNotEmpty(taskDto)) { - - String interactionJson = taskDto.getInteraction_json(); - InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class); - String start_device_code = taskDto.getStart_device_code(); - String next_device_code = taskDto.getNext_device_code(); - Device startDevice = deviceAppService.findDeviceByCode(start_device_code); - Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); - String start_addr = startDevice.getExtraValue().get("address").toString(); - String next_addr = nextDevice.getExtraValue().get("address").toString(); - String taskid = taskDto.getTask_id(); - String taskcode = taskDto.getTask_code(); - String start_point_code = taskDto.getStart_point_code(); - String route_plan_code = taskDto.getRoute_plan_code(); - String next_point_code = taskDto.getNext_point_code(); - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(device_code); - - try { - instructionService.create(instdto); - } catch (Exception e) { - notCreateInstMessage = e.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); - return false; - } - logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" - + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() - + ",指令终点:" + instdto.getNext_device_code() + ",交互参数:" + interactionJsonDTO.toString()); - - - Map map = new LinkedHashMap<>(); - map.put("to_command", 1); - map.put("to_target", next_addr); - map.put("to_onset", start_addr); - map.put("to_task", instdto.getInstruction_code()); - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_weight())) { - map.put("to_wedth", interactionJsonDTO.getItem_to_weight()); - } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_length())) { - map.put("to_length", interactionJsonDTO.getItem_to_length()); - } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_height())) { - map.put("to_height", interactionJsonDTO.getItem_to_height()); - } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_barcode())) { - map.put("to_barcode", interactionJsonDTO.getItem_to_barcode()); - } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_layer())) { - map.put("to_layer", interactionJsonDTO.getItem_to_layer()); - } - - - try { - this.writing(map); - } catch (Exception e) { - logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" - + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() - + ",指令终点:" + instdto.getNext_device_code() + ",交互参数:" + interactionJsonDTO.toString() + ",指令执行失败:" + e.getMessage()); - } - this.setRequireSucess(true); - return true; - } else { - notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; - } - return true; - } - - } - - /** - * 下发 - * @param map - */ - public void writing(Map map) { - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - Map itemMap = new LinkedHashMap<>(); - map.forEach((key, value) -> { - if (ObjectUtil.isNotEmpty(value)) { - itemMap.put(getToParam() + key, value); - } - }); - if (ObjectUtil.isNotEmpty(itemMap)) { - try { - this.checkcontrol(itemMap); - } catch (Exception e) { - throw new RuntimeException(e); - } - logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); - } - } - - public synchronized boolean finish_instruction(Instruction inst) throws Exception { - instructionService.finish(inst); - return true; - } - - /** - * 抽取统一下发电气信号前缀 - * - * @return - */ - public String getToParam() { - return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; - } - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String move = ""; - String action = ""; - String walk_y = ""; - if (this.getMode() == 0) { - mode = "脱机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "待机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } - - if (this.getMove() == 0) { - move = "无货"; - } else if (this.getMove() == 1) { - move = "有货"; - } - - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; - } - jo.put("requireSucess", requireSucess); - if (this.getAction() == 1) { - action = "取货中"; - } else if (this.getAction() == 2) { - action = "取货完成"; - } else if (this.getAction() == 3) { - action = "放货中"; - } else if (this.getAction() == 4) { - action = "放货完成"; - } - - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("action", action); - jo.put("task", task); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("message", this.getMessage()); - jo.put("notCreateTaskMessage", notCreateTaskMessage); - jo.put("notCreateInstMessage", notCreateInstMessage); - jo.put("feedMessage", feedMessage); - jo.put("driver_type", "siemens_conveyor"); - jo.put("is_click", true); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - String requestSucess = data.getString("requireSucess"); - if (StrUtil.equals(requestSucess, "0")) { - this.requireSucess = false; - } else if (StrUtil.equals(requestSucess, "1")) { - this.requireSucess = true; - } - } - - @Override - public JSONObject feedLmsRealFailedInfo() { - JSONObject jo = new JSONObject(); - jo.put("device_code", this.getDevice().getDevice_code()); - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("fault_code", String.valueOf(error)); - jo.put("fault_info", ErrorUtil.getDictDetail(error_type, String.valueOf(this.getError()))); - jo.put("fault_type", error_type); - return jo; - } - - - public Instruction checkInst() { - if (ObjectUtil.isNotEmpty(this.inst)) { - if (this.task > 0) { - if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) { - return this.inst; - } else { - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - return inst; - } - } - } else { - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - return inst; - } - return null; - } -} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java deleted file mode 100644 index 2f193a5..0000000 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/InteractionJsonDTO.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.nl.acs.device_driver.one_manipulator.box_storage_manipulator; - -import lombok.Data; - -@Data -public class InteractionJsonDTO { - - /** - *木箱长度 - */ - private String item_to_length = "to_length"; - /** - *木箱宽度 - */ - private String item_to_weight = "to_weight"; - /** - *木箱高度 - */ - private String item_to_height = "to_height"; - - /** - *下发木箱条码 - */ - private String item_to_barcode = "to_barcode"; - - /** - *下发木箱层数 - */ - private String item_to_layer = "to_layer"; - -} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/ItemProtocol.java deleted file mode 100644 index 45549be..0000000 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/box_storage_manipulator/ItemProtocol.java +++ /dev/null @@ -1,186 +0,0 @@ -package org.nl.acs.device_driver.one_manipulator.box_storage_manipulator; - -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - /** - * 心跳 - */ - public static String item_heartbeat = "heartbeat"; - /** - * 工作模式 - */ - public static String item_mode = "mode"; - /** - * 光电信号 - */ - public static String item_move = "move"; - /** - * 动作信号 - */ - public static String item_action = "action"; - - /** - * 任务号 - */ - public static String item_task = "task"; - /** - * 报警 - */ - public static String item_error = "error"; - /** - * 行走列 - */ - public static String item_walk_y = "walk_y"; - - - /** - * 下发命令 - */ - public static String item_to_command = "to_command"; - /** - * 下发目标站 - */ - public static String item_to_target = "to_target"; - /** - * 下发任务号 - */ - public static String item_to_task = "to_task"; - - - /** - * 下发起始站 - */ - public static String item_to_onset = "to_onset"; - - /** - *木箱长度 - */ - public static String item_to_length = "to_length"; - /** - *木箱宽度 - */ - public static String item_to_weight = "to_weight"; - /** - *木箱高度 - */ - public static String item_to_height = "to_height"; - - /** - *下发木箱条码 - */ - public static String item_to_barcode = "to_barcode"; - - /** - *下发木箱层数 - */ - public static String item_to_layer = "to_layer"; - - private BoxStorageManipulatorDeviceDriver driver; - - public ItemProtocol(BoxStorageManipulatorDeviceDriver driver){ - this.driver=driver; - } - - public int getTo_onset() { - return this.getOpcIntegerValue(item_to_onset); - } - - public int getHeartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public int getMode() { - return this.getOpcIntegerValue(item_mode); - } - - public int getMove() { - return this.getOpcIntegerValue(item_move); - } - - public int getAction() { - return this.getOpcIntegerValue(item_action); - } - - public int getError() { - return this.getOpcIntegerValue(item_error); - } - - public int getTask() { - return this.getOpcIntegerValue(item_task); - } - - - public int getWalk_y() { - return this.getOpcIntegerValue(item_walk_y); - } - - - - public int getTo_task() { - return this.getOpcIntegerValue(item_to_task); - } - - public int getTo_layer() { - return this.getOpcIntegerValue(item_to_layer); - } - - public int getTo_barcode() { - return this.getOpcIntegerValue(item_to_barcode); - } - - public int getTo_command() { - return this.getOpcIntegerValue(item_to_command); - } - - public int getTo_target() { - return this.getOpcIntegerValue(item_to_target); - } - - - - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList<>(); - list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0")); - list.add(new ItemDto(item_mode, "工作模式", "DB1.B1")); - list.add(new ItemDto(item_move, "光电信号", "DB1.B2")); - list.add(new ItemDto(item_action, "动作信号", "DB1.B3")); - list.add(new ItemDto(item_error, "报警信号", "DB1.B5")); - list.add(new ItemDto(item_task, "任务号", "DB1.D6")); - list.add(new ItemDto(item_walk_y, "行走列", "DB1.B4")); - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList<>(); - list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0")); - list.add(new ItemDto(item_to_target, "下发目标站", "DB2.W4")); - list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D6")); - list.add(new ItemDto(item_to_onset, "下发起始站", "DB2.W2")); - list.add(new ItemDto(item_to_length, "木箱长度", "DB601.W14")); - list.add(new ItemDto(item_to_weight, "木箱宽度", "DB601.W16")); - list.add(new ItemDto(item_to_height, "木箱高度", "DB601.W18")); - return list; - } -} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ItemProtocol.java deleted file mode 100644 index 03545c6..0000000 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ItemProtocol.java +++ /dev/null @@ -1,161 +0,0 @@ -package org.nl.acs.device_driver.one_manipulator.return_good_manipulator; - -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - /** - * 心跳 - */ - public static String item_heartbeat = "heartbeat"; - /** - * 工作模式 - */ - public static String item_mode = "mode"; - /** - * 光电信号 - */ - public static String item_move = "move"; - /** - * 动作信号 - */ - public static String item_action = "action"; - - /** - * 任务号 - */ - public static String item_task = "task"; - /** - * 报警 - */ - public static String item_error = "error"; - /** - * 行走列 - */ - public static String item_walk_y = "walk_y"; - - /** - * 下发托盘类型 - */ - public static String item_to_container_type = "to_container_type"; - - - /** - * 下发命令 - */ - public static String item_to_command = "to_command"; - /** - * 下发目标站 - */ - public static String item_to_target = "to_target"; - /** - * 下发任务号 - */ - public static String item_to_task = "to_task"; - - - /** - * 下发起始站 - */ - public static String item_to_onset = "to_onset"; - - - private ReturnGoodManipulatorDeviceDriver driver; - - public ItemProtocol(ReturnGoodManipulatorDeviceDriver driver){ - this.driver=driver; - } - - public int getTo_onset() { - return this.getOpcIntegerValue(item_to_onset); - } - - public int getHeartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public int getMode() { - return this.getOpcIntegerValue(item_mode); - } - - public int getMove() { - return this.getOpcIntegerValue(item_move); - } - - public int getAction() { - return this.getOpcIntegerValue(item_action); - } - - public int getError() { - return this.getOpcIntegerValue(item_error); - } - - public int getTask() { - return this.getOpcIntegerValue(item_task); - } - - - public int getWalk_y() { - return this.getOpcIntegerValue(item_walk_y); - } - - - - public int getTo_task() { - return this.getOpcIntegerValue(item_to_task); - } - - - - public int getTo_command() { - return this.getOpcIntegerValue(item_to_command); - } - - public int getTo_target() { - return this.getOpcIntegerValue(item_to_target); - } - - - - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList<>(); - list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0")); - list.add(new ItemDto(item_mode, "工作模式", "DB1.B1")); - list.add(new ItemDto(item_move, "光电信号", "DB1.B2")); - list.add(new ItemDto(item_action, "动作信号", "DB1.B3")); - list.add(new ItemDto(item_error, "报警信号", "DB1.B5")); - list.add(new ItemDto(item_task, "任务号", "DB1.D6")); - list.add(new ItemDto(item_walk_y, "行走列", "DB1.B4")); - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList<>(); - list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0")); - list.add(new ItemDto(item_to_target, "下发目标站", "DB2.W4")); - list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D6")); - list.add(new ItemDto(item_to_onset, "下发起始站", "DB2.W2")); - list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB102.B8")); - return list; - } -} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDefination.java deleted file mode 100644 index 5d36a01..0000000 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDefination.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.nl.acs.device_driver.one_manipulator.return_good_manipulator; - -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; -import org.nl.acs.device.domain.Device; -import org.nl.acs.device.enums.DeviceType; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; -import org.springframework.stereotype.Service; - -import java.util.LinkedList; -import java.util.List; - -@Service -public class ReturnGoodManipulatorDefination implements OpcDeviceDriverDefination { - @Override - public String getDriverCode() { - return "return_good_manipulator"; - } - - @Override - public String getDriverName() { - return "退货入库行架"; - } - - @Override - public String getDriverDescription() { - return "退货入库行架"; - } - - @Override - public DeviceDriver getDriverInstance(Device device) { - return (new ReturnGoodManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); - } - - @Override - public Class getDeviceDriverType() { - return ReturnGoodManipulatorDeviceDriver.class; - } - - @Override - public List getFitDeviceTypes() { - List types = new LinkedList(); - types.add(DeviceType.robot); - return types; - } - - @Override - public List getReadableItemDtos() { - return ItemProtocol.getReadableItemDtos(); - } - - @Override - public List getWriteableItemDtos() { - return ItemProtocol.getWriteableItemDtos(); - } -} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java deleted file mode 100644 index c96b596..0000000 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/return_good_manipulator/ReturnGoodManipulatorDeviceDriver.java +++ /dev/null @@ -1,478 +0,0 @@ -package org.nl.acs.device_driver.one_manipulator.return_good_manipulator; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.common.base.CommonFinalParam; -import org.nl.acs.device.domain.Device; -import org.nl.acs.device.service.DeviceExtraService; -import org.nl.acs.device.service.impl.DeviceExtraServiceImpl; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.FeedLmsRealFailed; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.device_driver.one_conveyor.box_storage_out_conveyor.BoxStorageOutConveyorDeviceDriver; -import org.nl.acs.history.ErrorUtil; -import org.nl.acs.history.service.DeviceErrorLogService; -import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl; -import org.nl.acs.instruction.domain.Instruction; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.opc.DeviceAppServiceImpl; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.route.service.impl.RouteLineServiceImpl; -import org.nl.acs.task.enums.TaskTypeEnum; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.config.SpringContextHolder; - -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * 退货入库行架 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class ReturnGoodManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed { - - protected ItemProtocol itemProtocol = new ItemProtocol(this); - - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - - TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); - - InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); - - DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); - - DeviceExtraService deviceExtraService = SpringContextHolder.getBean(DeviceExtraServiceImpl.class); - - DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); - - - int mode = 0; - int last_mode = 0; - int move = 0; - int last_move = 0; - int action = 0; - int last_action = 0; - int error = 0; - int last_error = 0; - int task = 0; - int last_task = 0; - - - int heartbeat = 0; - int last_heartbeat = 0; - int to_command = 0; - int last_to_command = 0; - - int to_target = 0; - int last_to_target = 0; - - int to_onset = 0; - int last_to_onset = 0; - - int to_task = 0; - int last_to_task = 0; - int to_layer = 0; - int last_to_layer = 0; - int to_barcode = 0; - int last_to_barcode = 0; - - Boolean isonline = true; - int hasGoods = 0; - String message = null; - Boolean iserror = false; - private Date instruction_update_time = new Date(); - private int instruction_update_time_out = 1000; - Integer heartbeat_tag; - private Date instruction_require_time = new Date(); - - private int instruction_require_time_out = 3000; - //行架机械手申请任务成功标识 - boolean requireSucess = false; - - private int instruction_finished_time_out; - - int branchProtocol = 0; - private String error_type = "hxhj_error_type"; - - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag; - - String device_code; - - //当前指令 - Instruction inst = null; - - //0 无任务执行 1更新指令状态 2下发电气信号 3允许取货 允许放货 5放货完成 - int now_steps_type = 0; - String notCreateTaskMessage = ""; - String notCreateInstMessage = ""; - String feedMessage = ""; - - - List getDeviceCodeList = null; - - List putDeviceCodeList = null; - - - @Override - public Device getDevice() { - return this.device; - } - - @Override - public void execute() { - String message = null; - try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - move = this.itemProtocol.getMove(); - action = this.itemProtocol.getAction(); - error = this.itemProtocol.getError(); - task = this.itemProtocol.getTask(); - heartbeat = this.itemProtocol.getHeartbeat(); - to_command = this.itemProtocol.getTo_command(); - to_target = this.itemProtocol.getTo_target(); - to_onset = this.itemProtocol.getTo_onset(); - to_task = this.itemProtocol.getTo_task(); - if (mode != last_mode) { - requireSucess = false; - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (move != last_move) { - logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); - } - if (action != last_action) { - logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (task != last_task) { - logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); - } - if (to_command != last_to_command) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); - } - if (to_target != last_to_target) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); - } - if (to_onset != last_to_onset) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_onset:" + last_to_target + "->" + to_target); - } - if (to_task != last_to_task) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); - } - - - // 更新指令状态 - if (mode == 3 && task > 0) { - updateInstructionStatus(); - } - - } catch (Exception var17) { - var17.printStackTrace(); - feedMessage = var17.getMessage(); - logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol)); - - } - - if (mode == 0) { - this.setIsonline(false); - message = "未联机"; - //有报警 - } else if (error != 0) { - this.setIserror(true); - message = "有报警"; - //无报警 - } else { - this.setIsonline(true); - this.setIserror(false); - message = ""; - Instruction instruction = null; - List toInstructions; - - //行架机械手申请任务 - if (mode == 2 && move == 0 && task == 0 && !requireSucess) { - boolean res = applyTask(); - if (res) { - notCreateInstMessage = ""; - notCreateTaskMessage = ""; - feedMessage = ""; - } - } else { - String remark = "未查找任务原因为:"; - if (mode != 2) { - remark = remark + "工作模式(mode)不是待机状态,"; - } - if (move != 0) { - remark = remark + "光电信号(move)为有货状态,"; - } - if (task != 0) { - remark = remark + "当前上报任务号(task)应该为0,"; - if (ObjectUtil.isNotEmpty(this.inst)) { - this.inst = null; - } - } - if (requireSucess) { - remark = remark + "请右击该图标,将请求任务复位标记(requireSucess)改为否。"; - } - this.setNotCreateTaskMessage(remark); - } - - } - last_mode = mode; - last_move = move; - last_action = action; - last_error = error; - last_task = task; - last_heartbeat = heartbeat; - last_to_task = to_task; - last_to_command = to_command; - last_to_target = to_target; - last_to_layer = to_layer; - last_to_barcode = to_barcode; - - } - - private void updateInstructionStatus() { - Date date = new Date(); - if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); - - } else { - this.instruction_update_time = date; - //更改指令状态 - if (task > 0) { - Instruction inst = checkInst(); - if (inst != null) { - if (StrUtil.equals(inst.getInstruction_status(), "0")) { - inst.setInstruction_status(CommonFinalParam.ONE); - inst.setExecute_device_code(this.device_code); - instructionService.update(inst); - } - } - } - } - } - - public synchronized boolean applyTask() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; - } else { - this.instruction_require_time = date; - BoxStorageOutConveyorDeviceDriver boxStorageConveyorDeviceDriver = new BoxStorageOutConveyorDeviceDriver(); - String deviceCode = boxStorageConveyorDeviceDriver.getDevice_code(); - TaskDto taskDto = taskserver.findByEndCodeAndReady(deviceCode, TaskTypeEnum.Return_Good.getIndex()); - if (ObjectUtil.isNotEmpty(taskDto)) { - String start_device_code = taskDto.getStart_device_code(); - String next_device_code = taskDto.getNext_device_code(); - Device startDevice = deviceAppService.findDeviceByCode(start_device_code); - Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); - String start_addr = startDevice.getExtraValue().get("address").toString(); - String next_addr = nextDevice.getExtraValue().get("address").toString(); - String taskid = taskDto.getTask_id(); - String taskcode = taskDto.getTask_code(); - String start_point_code = taskDto.getStart_point_code(); - String route_plan_code = taskDto.getRoute_plan_code(); - String next_point_code = taskDto.getNext_point_code(); - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(device_code); - - try { - instructionService.create(instdto); - } catch (Exception e) { - notCreateInstMessage = e.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); - return false; - } - logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" - + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() - + ",指令终点:" + instdto.getNext_device_code() ); - - - Map map = new LinkedHashMap<>(); - map.put("to_command", 1); - map.put("to_target", next_addr); - map.put("to_onset", start_addr); - map.put("to_task", instdto.getInstruction_code()); - - - - try { - this.writing(map); - } catch (Exception e) { - logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" - + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() - + ",指令终点:" + instdto.getNext_device_code() + ",指令执行失败:" + e.getMessage()); - } - this.setRequireSucess(true); - return true; - } else { - notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; - } - return true; - } - - } - - /** - * 下发 - * @param map - */ - public void writing(Map map) { - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - Map itemMap = new LinkedHashMap<>(); - map.forEach((key, value) -> { - if (ObjectUtil.isNotEmpty(value)) { - itemMap.put(getToParam() + key, value); - } - }); - if (ObjectUtil.isNotEmpty(itemMap)) { - try { - this.checkcontrol(itemMap); - } catch (Exception e) { - throw new RuntimeException(e); - } - logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); - } - } - - /** - * 抽取统一下发电气信号前缀 - * - * @return - */ - public String getToParam() { - return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; - } - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String move = ""; - String action = ""; - String walk_y = ""; - if (this.getMode() == 0) { - mode = "脱机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "待机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } - - if (this.getMove() == 0) { - move = "无货"; - } else if (this.getMove() == 1) { - move = "有货"; - } - - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; - } - jo.put("requireSucess", requireSucess); - if (this.getAction() == 1) { - action = "取货中"; - } else if (this.getAction() == 2) { - action = "取货完成"; - } else if (this.getAction() == 3) { - action = "放货中"; - } else if (this.getAction() == 4) { - action = "放货完成"; - } - - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("action", action); - jo.put("task", task); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("message", this.getMessage()); - jo.put("notCreateTaskMessage", notCreateTaskMessage); - jo.put("notCreateInstMessage", notCreateInstMessage); - jo.put("feedMessage", feedMessage); - jo.put("driver_type", "siemens_conveyor"); - jo.put("is_click", true); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - String requestSucess = data.getString("requireSucess"); - if (StrUtil.equals(requestSucess, "0")) { - this.requireSucess = false; - } else if (StrUtil.equals(requestSucess, "1")) { - this.requireSucess = true; - } - } - - @Override - public JSONObject feedLmsRealFailedInfo() { - JSONObject jo = new JSONObject(); - jo.put("device_code", this.getDevice().getDevice_code()); - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("fault_code", String.valueOf(error)); - jo.put("fault_info", ErrorUtil.getDictDetail(error_type, String.valueOf(this.getError()))); - jo.put("fault_type", error_type); - return jo; - } - - - public Instruction checkInst() { - if (ObjectUtil.isNotEmpty(this.inst)) { - if (this.task > 0) { - if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) { - return this.inst; - } else { - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - return inst; - } - } - } else { - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - return inst; - } - return null; - } -} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java deleted file mode 100644 index d9feac1..0000000 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/InteractionJsonDTO.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.nl.acs.device_driver.one_manipulator.trapped_manipulator; - -import lombok.Data; - -@Data -public class InteractionJsonDTO { - - /** - *木箱长度 - */ - private String item_to_length = "to_length"; - /** - *木箱宽度 - */ - private String item_to_weight = "to_weight"; - /** - *木箱高度 - */ - private String item_to_height = "to_height"; - - /** - *下发堆叠模板 - */ - private String item_to_template = "to_template"; - - -} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/ItemProtocol.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/ItemProtocol.java deleted file mode 100644 index 1955166..0000000 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/ItemProtocol.java +++ /dev/null @@ -1,179 +0,0 @@ -package org.nl.acs.device_driver.one_manipulator.trapped_manipulator; - -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; - -import java.util.ArrayList; -import java.util.List; - -@Slf4j -@Data -public class ItemProtocol { - /** - * 心跳 - */ - public static String item_heartbeat = "heartbeat"; - /** - * 工作模式 - */ - public static String item_mode = "mode"; - /** - * 光电信号 - */ - public static String item_move = "move"; - /** - * 动作信号 - */ - public static String item_action = "action"; - - /** - * 任务号 - */ - public static String item_task = "task"; - /** - * 报警 - */ - public static String item_error = "error"; - - - /** - * 下发托盘类型 - */ - public static String item_to_container_type = "to_container_type"; - - - /** - * 下发命令 - */ - public static String item_to_command = "to_command"; - /** - * 下发目标站 - */ - public static String item_to_target = "to_target"; - /** - * 下发任务号 - */ - public static String item_to_task = "to_task"; - - - /** - * 下发起始站 - */ - public static String item_to_onset = "to_onset"; - - /** - *木箱长度 - */ - public static String item_to_length = "to_length"; - /** - *木箱宽度 - */ - public static String item_to_weight = "to_weight"; - /** - *木箱高度 - */ - public static String item_to_height = "to_height"; - - - /** - *下发堆叠模板 - */ - public static String item_to_template = "to_template"; - - - - - private TrappedManipulatorManipulatorDeviceDriver driver; - - public ItemProtocol(TrappedManipulatorManipulatorDeviceDriver driver){ - this.driver=driver; - } - - public int getTo_onset() { - return this.getOpcIntegerValue(item_to_onset); - } - - public int getHeartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public int getMode() { - return this.getOpcIntegerValue(item_mode); - } - - public int getMove() { - return this.getOpcIntegerValue(item_move); - } - - public int getAction() { - return this.getOpcIntegerValue(item_action); - } - - public int getError() { - return this.getOpcIntegerValue(item_error); - } - - public int getTask() { - return this.getOpcIntegerValue(item_task); - } - - - - - - public int getTo_task() { - return this.getOpcIntegerValue(item_to_task); - } - - - - public int getTo_command() { - return this.getOpcIntegerValue(item_to_command); - } - - public int getTo_target() { - return this.getOpcIntegerValue(item_to_target); - } - - - - - Boolean isonline; - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - setIsonline(false); - } else { - setIsonline(true); - return value; - } - return 0; - } - - public static List getReadableItemDtos() { - ArrayList list = new ArrayList<>(); - list.add(new ItemDto(item_heartbeat, "心跳", "DB1.B0")); - list.add(new ItemDto(item_mode, "工作模式", "DB1.B1")); - list.add(new ItemDto(item_move, "光电信号", "DB1.B2")); - list.add(new ItemDto(item_action, "动作信号", "DB1.B3")); - list.add(new ItemDto(item_error, "报警信号", "DB1.B5")); - list.add(new ItemDto(item_task, "任务号", "DB1.D6")); - return list; - } - - public static List getWriteableItemDtos() { - ArrayList list = new ArrayList<>(); - list.add(new ItemDto(item_to_command, "下发命令", "DB2.W0")); - list.add(new ItemDto(item_to_target, "下发目标站", "DB2.W4")); - list.add(new ItemDto(item_to_task, "下发任务号", "DB2.D6")); - list.add(new ItemDto(item_to_onset, "下发起始站", "DB2.W2")); - list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB102.B8")); - list.add(new ItemDto(item_to_length, "木箱长度", "DB601.W10")); - list.add(new ItemDto(item_to_weight, "木箱宽度", "DB601.W12")); - list.add(new ItemDto(item_to_height, "木箱高度", "DB601.W14")); - list.add(new ItemDto(item_to_template, "堆叠模板", "DB601.W16")); - return list; - } -} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java deleted file mode 100644 index b6365b2..0000000 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorDefination.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.nl.acs.device_driver.one_manipulator.trapped_manipulator; - -import org.nl.acs.device.device_driver.standard_inspect.ItemDto; -import org.nl.acs.device.domain.Device; -import org.nl.acs.device.enums.DeviceType; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; -import org.springframework.stereotype.Service; - -import java.util.LinkedList; -import java.util.List; - -@Service -public class TrappedManipulatorDefination implements OpcDeviceDriverDefination { - @Override - public String getDriverCode() { - return "trapped_manipulator"; - } - - @Override - public String getDriverName() { - return "捆扎智能行架"; - } - - @Override - public String getDriverDescription() { - return "捆扎智能行架"; - } - - @Override - public DeviceDriver getDriverInstance(Device device) { - return (new TrappedManipulatorManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); - } - - @Override - public Class getDeviceDriverType() { - return TrappedManipulatorManipulatorDeviceDriver.class; - } - - @Override - public List getFitDeviceTypes() { - List types = new LinkedList(); - types.add(DeviceType.robot); - return types; - } - - @Override - public List getReadableItemDtos() { - return ItemProtocol.getReadableItemDtos(); - } - - @Override - public List getWriteableItemDtos() { - return ItemProtocol.getWriteableItemDtos(); - } -} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java deleted file mode 100644 index ab27b09..0000000 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/device_driver/one_manipulator/trapped_manipulator/TrappedManipulatorManipulatorDeviceDriver.java +++ /dev/null @@ -1,493 +0,0 @@ -package org.nl.acs.device_driver.one_manipulator.trapped_manipulator; - -import cn.hutool.core.date.DateUtil; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.ObjectUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.nl.acs.common.base.CommonFinalParam; -import org.nl.acs.device.domain.Device; -import org.nl.acs.device.service.DeviceExtraService; -import org.nl.acs.device.service.impl.DeviceExtraServiceImpl; -import org.nl.acs.device_driver.DeviceDriver; -import org.nl.acs.device_driver.FeedLmsRealFailed; -import org.nl.acs.device_driver.RouteableDeviceDriver; -import org.nl.acs.device_driver.box_manipulator_site.BoxManipulatorSiteDeviceDriver; -import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; -import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.history.ErrorUtil; -import org.nl.acs.history.service.DeviceErrorLogService; -import org.nl.acs.history.service.impl.DeviceErrorLogServiceImpl; -import org.nl.acs.instruction.domain.Instruction; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.log.service.DeviceExecuteLogService; -import org.nl.acs.monitor.DeviceStageMonitor; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.opc.DeviceAppServiceImpl; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.route.service.impl.RouteLineServiceImpl; -import org.nl.acs.task.enums.TaskTypeEnum; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.config.SpringContextHolder; - -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * 捆扎智能行架 - */ -@Slf4j -@Data -@RequiredArgsConstructor -public class TrappedManipulatorManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed { - - protected ItemProtocol itemProtocol = new ItemProtocol(this); - - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - - TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); - - InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); - - DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); - - DeviceExtraService deviceExtraService = SpringContextHolder.getBean(DeviceExtraServiceImpl.class); - - DeviceErrorLogService errorLogServer = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class); - - - int mode = 0; - int last_mode = 0; - int move = 0; - int last_move = 0; - int action = 0; - int last_action = 0; - int error = 0; - int last_error = 0; - int task = 0; - int last_task = 0; - - - int heartbeat = 0; - int last_heartbeat = 0; - int to_command = 0; - int last_to_command = 0; - - int to_target = 0; - int last_to_target = 0; - - int to_onset = 0; - int last_to_onset = 0; - - int to_task = 0; - int last_to_task = 0; - int to_layer = 0; - int last_to_layer = 0; - int to_barcode = 0; - int last_to_barcode = 0; - - Boolean isonline = true; - int hasGoods = 0; - String message = null; - Boolean iserror = false; - private Date instruction_update_time = new Date(); - private int instruction_update_time_out = 1000; - Integer heartbeat_tag; - private Date instruction_require_time = new Date(); - - private int instruction_require_time_out = 3000; - //行架机械手申请任务成功标识 - boolean requireSucess = false; - - private int instruction_finished_time_out; - - int branchProtocol = 0; - private String error_type = "hxhj_error_type"; - - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag; - - String device_code; - - //当前指令 - Instruction inst = null; - - //0 无任务执行 1更新指令状态 2下发电气信号 3允许取货 允许放货 5放货完成 - int now_steps_type = 0; - String notCreateTaskMessage = ""; - String notCreateInstMessage = ""; - String feedMessage = ""; - - - List getDeviceCodeList = null; - - List putDeviceCodeList = null; - - - @Override - public Device getDevice() { - return this.device; - } - - @Override - public void execute() { - String message = null; - try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - move = this.itemProtocol.getMove(); - action = this.itemProtocol.getAction(); - error = this.itemProtocol.getError(); - task = this.itemProtocol.getTask(); - heartbeat = this.itemProtocol.getHeartbeat(); - to_command = this.itemProtocol.getTo_command(); - to_target = this.itemProtocol.getTo_target(); - to_onset = this.itemProtocol.getTo_onset(); - to_task = this.itemProtocol.getTo_task(); - if (mode != last_mode) { - requireSucess = false; - logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); - } - if (move != last_move) { - logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); - } - if (action != last_action) { - logServer.deviceItemValue(this.device_code, "action", String.valueOf(action)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action); - } - if (error != last_error) { - logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); - } - if (task != last_task) { - logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); - logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); - } - if (to_command != last_to_command) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_command:" + last_to_command + "->" + to_command); - } - if (to_target != last_to_target) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_target:" + last_to_target + "->" + to_target); - } - if (to_onset != last_to_onset) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_onset:" + last_to_target + "->" + to_target); - } - if (to_task != last_to_task) { - logServer.deviceExecuteLog(this.device_code, "", "", "信号to_task:" + last_to_task + "->" + to_task); - } - - - // 更新指令状态 - if (mode == 3 && task > 0) { - updateInstructionStatus(); - } - - } catch (Exception var17) { - var17.printStackTrace(); - feedMessage = var17.getMessage(); - logServer.deviceExecuteLog(this.device_code, "", "", "读取信号值时出现异常:" + var17.getMessage() + ",this.itemProtocol is null:" + ObjectUtil.isEmpty(this.itemProtocol)); - - } - - if (mode == 0) { - this.setIsonline(false); - message = "未联机"; - //有报警 - } else if (error != 0) { - this.setIserror(true); - message = "有报警"; - //无报警 - } else { - this.setIsonline(true); - this.setIserror(false); - message = ""; - Instruction instruction = null; - List toInstructions; - - //行架机械手申请任务 - if (mode == 2 && move == 0 && task == 0 && !requireSucess) { - boolean res = applyTask(); - if (res) { - notCreateInstMessage = ""; - notCreateTaskMessage = ""; - feedMessage = ""; - } - } else { - String remark = "未查找任务原因为:"; - if (mode != 2) { - remark = remark + "工作模式(mode)不是待机状态,"; - } - if (move != 0) { - remark = remark + "光电信号(move)为有货状态,"; - } - if (task != 0) { - remark = remark + "当前上报任务号(task)应该为0,"; - if (ObjectUtil.isNotEmpty(this.inst)) { - this.inst = null; - } - } - if (requireSucess) { - remark = remark + "请右击该图标,将请求任务复位标记(requireSucess)改为否。"; - } - this.setNotCreateTaskMessage(remark); - } - - } - last_mode = mode; - last_move = move; - last_action = action; - last_error = error; - last_task = task; - last_heartbeat = heartbeat; - last_to_task = to_task; - last_to_command = to_command; - last_to_target = to_target; - last_to_layer = to_layer; - last_to_barcode = to_barcode; - - } - - private void updateInstructionStatus() { - Date date = new Date(); - if (date.getTime() - this.instruction_update_time.getTime() < (long) this.instruction_update_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_update_time_out); - - } else { - this.instruction_update_time = date; - //更改指令状态 - if (task > 0) { - Instruction inst = checkInst(); - if (inst != null) { - if (StrUtil.equals(inst.getInstruction_status(), "0")) { - inst.setInstruction_status(CommonFinalParam.ONE); - inst.setExecute_device_code(this.device_code); - instructionService.update(inst); - } - } - } - } - } - - public synchronized boolean applyTask() { - Date date = new Date(); - if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { - log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); - return false; - } else { - this.instruction_require_time = date; - - BoxManipulatorSiteDeviceDriver boxManipulatorSiteDeviceDriver = new BoxManipulatorSiteDeviceDriver(); - String deviceCode = boxManipulatorSiteDeviceDriver.getDevice_code(); - TaskDto taskDto = taskserver.findByEndCodeAndReady(deviceCode, TaskTypeEnum.Truss_Task.getIndex()); - String interactionJson = taskDto.getInteraction_json(); - InteractionJsonDTO interactionJsonDTO = JSON.parseObject(interactionJson, InteractionJsonDTO.class); - if (ObjectUtil.isNotEmpty(taskDto)) { - String start_device_code = taskDto.getStart_device_code(); - String next_device_code = taskDto.getNext_device_code(); - Device startDevice = deviceAppService.findDeviceByCode(start_device_code); - Device nextDevice = deviceAppService.findDeviceByCode(next_device_code); - String start_addr = startDevice.getExtraValue().get("address").toString(); - String next_addr = nextDevice.getExtraValue().get("address").toString(); - String taskid = taskDto.getTask_id(); - String taskcode = taskDto.getTask_code(); - String start_point_code = taskDto.getStart_point_code(); - String route_plan_code = taskDto.getRoute_plan_code(); - String next_point_code = taskDto.getNext_point_code(); - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(device_code); - - try { - instructionService.create(instdto); - } catch (Exception e) { - notCreateInstMessage = e.getMessage(); - logServer.deviceExecuteLog(this.getDevice_code(), "", "", "创建指令时出现异常:" + e.getMessage()); - return false; - } - logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" - + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() - + ",指令终点:" + instdto.getNext_device_code() ); - - - Map map = new LinkedHashMap<>(); - map.put("to_command", 1); - map.put("to_target", next_addr); - map.put("to_onset", start_addr); - map.put("to_task", instdto.getInstruction_code()); - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_weight())) { - map.put("to_wedth", interactionJsonDTO.getItem_to_weight()); - } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_length())) { - map.put("to_length", interactionJsonDTO.getItem_to_length()); - } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_height())) { - map.put("to_height", interactionJsonDTO.getItem_to_height()); - } - if (ObjectUtil.isNotEmpty(interactionJsonDTO.getItem_to_template())) { - map.put("to_template", interactionJsonDTO.getItem_to_template()); - } - - - try { - this.writing(map); - } catch (Exception e) { - logServer.deviceExecuteLog(device_code, "", "", "当前设备:" + device_code + ",下发指令:" - + instdto.getInstruction_code() + ",指令起点:" + instdto.getStart_device_code() - + ",指令终点:" + instdto.getNext_device_code() + ",指令执行失败:" + e.getMessage()); - } - this.setRequireSucess(true); - return true; - } else { - notCreateInstMessage = "未找到关联设备的任务,指令无法创建"; - } - return true; - } - - } - - /** - * 下发 - * @param map - */ - public void writing(Map map) { - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - Map itemMap = new LinkedHashMap<>(); - map.forEach((key, value) -> { - if (ObjectUtil.isNotEmpty(value)) { - itemMap.put(getToParam() + key, value); - } - }); - if (ObjectUtil.isNotEmpty(itemMap)) { - try { - this.checkcontrol(itemMap); - } catch (Exception e) { - throw new RuntimeException(e); - } - logServer.deviceExecuteLog(this.getDevice().getDevice_code(), "", "", "下发多个电气信号:" + itemMap); - } - } - - /** - * 抽取统一下发电气信号前缀 - * - * @return - */ - public String getToParam() { - return this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "."; - } - @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String move = ""; - String action = ""; - String walk_y = ""; - if (this.getMode() == 0) { - mode = "脱机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "待机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } - - if (this.getMove() == 0) { - move = "无货"; - } else if (this.getMove() == 1) { - move = "有货"; - } - - String requireSucess = "0"; - if (this.requireSucess) { - requireSucess = "1"; - } - jo.put("requireSucess", requireSucess); - if (this.getAction() == 1) { - action = "取货中"; - } else if (this.getAction() == 2) { - action = "取货完成"; - } else if (this.getAction() == 3) { - action = "放货中"; - } else if (this.getAction() == 4) { - action = "放货完成"; - } - - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("action", action); - jo.put("task", task); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("message", this.getMessage()); - jo.put("notCreateTaskMessage", notCreateTaskMessage); - jo.put("notCreateInstMessage", notCreateInstMessage); - jo.put("feedMessage", feedMessage); - jo.put("driver_type", "siemens_conveyor"); - jo.put("is_click", true); - return jo; - } - - @Override - public void setDeviceStatus(JSONObject data) { - String requestSucess = data.getString("requireSucess"); - if (StrUtil.equals(requestSucess, "0")) { - this.requireSucess = false; - } else if (StrUtil.equals(requestSucess, "1")) { - this.requireSucess = true; - } - } - - @Override - public JSONObject feedLmsRealFailedInfo() { - JSONObject jo = new JSONObject(); - jo.put("device_code", this.getDevice().getDevice_code()); - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("fault_code", String.valueOf(error)); - jo.put("fault_info", ErrorUtil.getDictDetail(error_type, String.valueOf(this.getError()))); - jo.put("fault_type", error_type); - return jo; - } - - - public Instruction checkInst() { - if (ObjectUtil.isNotEmpty(this.inst)) { - if (this.task > 0) { - if (this.inst.getInstruction_code().equals(String.valueOf(this.task))) { - return this.inst; - } else { - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - return inst; - } - } - } else { - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - return inst; - } - return null; - } -} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/data/one/BaseRequest.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/data/one/BaseRequest.java index 985086b..f338161 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/data/one/BaseRequest.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/data/one/BaseRequest.java @@ -52,7 +52,6 @@ public class BaseRequest { */ private Map parameters = new HashMap(); - /** * 任务类型 */ diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java index 85319c6..882d24f 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java @@ -96,10 +96,13 @@ public interface AcsToWmsService { /** * ACS向WMS申请任务 - * @param request - * @return + * @param request { + * type:1-缠绕机 2- 机械手 + * type_dtl:1-申请取货 2-申请放货 + * } + * @return HttpResponse */ - String applyTask(BaseRequest request); + HttpResponse applyTask(JSONObject request); /** * ACS向WMS反馈任务状态 diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index be591d5..49f4b08 100644 --- a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -116,10 +116,48 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } @Override - public String applyTask(BaseRequest request) { - return null; - } + public HttpResponse applyTask(JSONObject request) { + try { + MDC.put(log_file_type, log_type); + String wmsurl = paramService.findByCode(AcsConfig.WMSURL).getValue(); + HttpResponse result2 = null; + log.info("applyTask-----请求参数{}", request.toString()); + + AddressDto addressDto = addressService.findByCode("applyTask"); + String methods_url = addressDto.getMethods_url(); + try { + result2 = HttpRequest.post(wmsurl + methods_url) + .addInterceptor(tLogHutoolhttpInterceptor) + .header(Header.USER_AGENT, "Hutool http") + .header("Authorization", token).body(String.valueOf(request)) + .execute(); + LuceneLogDto luceneLogDto = new LuceneLogDto(4,"applyTask", String.valueOf(result2.getStatus()), + String.valueOf(request), String.valueOf(result2.body()), "ACS向WMS申请任务"); + luceneLogService.interfaceExecuteLog(luceneLogDto); + } catch (Exception e) { + String msg = e.getMessage(); + //网络不通 + log.info("applyTask-----输出参数{}", msg); + } + + String type = ""; + if (ObjectUtil.isNotEmpty(result2) && result2.getStatus() == 200) { + type = "info"; + JSONObject jo = JSONObject.parseObject(result2.body()); + log.info("applyTask-----输出参数{}", jo.toString()); + LuceneLogDto luceneLogDto = new LuceneLogDto(4,"feedTaskStatus", String.valueOf(result2.getStatus()), + String.valueOf(request), String.valueOf(result2.body()), "ACS向WMS申请任务"); + luceneLogService.interfaceExecuteLog(luceneLogDto); + return result2; + } else { + type = "error"; + } + return null; + } finally { + MDC.remove(log_file_type); + } + } @Override public HttpResponse feedTaskStatus(JSONArray data) { diff --git a/acs/nladmin-ui/src/views/acs/device/config.vue b/acs/nladmin-ui/src/views/acs/device/config.vue index b5a4ca8..4d9e97a 100644 --- a/acs/nladmin-ui/src/views/acs/device/config.vue +++ b/acs/nladmin-ui/src/views/acs/device/config.vue @@ -139,9 +139,11 @@ import primary_device from '@/views/acs/device/driver/primary_device.vue' import carton_labeling_machine from '@/views/acs/device/driver/carton_labeling_machine.vue' import stretch_wrapper from '@/views/acs/device/driver/stretch_wrapper' import pallet_dispenser from '@/views/acs/device/driver/pallet_dispenser' +import robot_arm from '@/views/acs/device/driver/robot_arm' export default { name: 'DeviceConfig', components: { + robot_arm, stretch_wrapper, pallet_dispenser, standard_autodoor, @@ -250,7 +252,6 @@ export default { }, methods: { changeDriver(val) { - debugger this.currentComponent = val } } diff --git a/acs/nladmin-ui/src/views/acs/device/driver/robot_arm.vue b/acs/nladmin-ui/src/views/acs/device/driver/robot_arm.vue new file mode 100644 index 0000000..5460b71 --- /dev/null +++ b/acs/nladmin-ui/src/views/acs/device/driver/robot_arm.vue @@ -0,0 +1,364 @@ + + + + +