From ba3d7a4f99dd3330d12a6831df06975a8a5146da Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Mon, 21 Nov 2022 13:54:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=83=98=E7=AE=B1=E6=9C=BA=E6=A2=B0=E6=89=8B?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HongXiangConveyorDefination.java | 2 +- .../HongXiangConveyorDeviceDriver.java | 83 ++++++-- .../hongxiang_device/ItemProtocol.java | 58 +++-- .../OvenGantryManipulatorDeviceDriver.java | 200 +++++++++++++++++- .../service/InstructionService.java | 2 + .../service/impl/InstructionServiceImpl.java | 11 + .../org/nl/acs/task/service/TaskService.java | 8 + .../task/service/impl/TaskServiceImpl.java | 16 ++ 8 files changed, 345 insertions(+), 35 deletions(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDefination.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDefination.java index 146426552..52d2e0459 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDefination.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDefination.java @@ -11,7 +11,7 @@ import java.util.LinkedList; import java.util.List; /** - * 豪凯自动对接线 + * 烘箱设备对接位 */ @Service public class HongXiangConveyorDefination implements OpcDeviceDriverDefination { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java index e8cda45db..d06f7e571 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/HongXiangConveyorDeviceDriver.java @@ -65,12 +65,37 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple private Date instruction_apply_time = new Date(); private int instruction_require_time_out = 3000; - int heartbeat = 0; - int mode = 0; - int move = 0; - int action = 0; - int error = 0; - int task = 0; + public int heartbeat = 0; + public int mode = 0; + public int move = 0; + public int action = 0; + public int error = 0; + public int door = 0; + public int temperature = 0; + public int countdown = 0; + public int finish = 0; + public int task = 0; + public int error1 = 0; + public int material = 0; + public int consumption = 0; + public int voltage = 0; + public int current = 0; + + public int last_heartbeat = 0; + public int last_mode = 0; + public int last_move = 0; + public int last_action = 0; + public int last_error = 0; + public int last_door = 0; + public int last_temperature = 0; + public int last_countdown = 0; + public int last_finish = 0; + public int last_task = 0; + public int last_error1 = 0; + public int last_material = 0; + public int last_consumption = 0; + public int last_voltage = 0; + public int last_current = 0; Boolean isonline = true; @@ -79,10 +104,6 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple //1-执行任务;2-取货完成;3-放货完成; int flag; - int last_mode = 0; - int last_move = 0; - int last_error = 0; - String device_code; @Override @@ -100,11 +121,19 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple device_code = this.getDeviceCode(); heartbeat = this.itemProtocol.getItem_heartbeat(); mode = this.itemProtocol.getItem_mode(); - move = this.itemProtocol.getItem_mode(); - error = this.itemProtocol.getItem_error(); - task = this.itemProtocol.getItem_task(); + move = this.itemProtocol.getItem_move(); action = this.itemProtocol.getItem_action(); - + error = this.itemProtocol.getItem_error(); + door = this.itemProtocol.getItem_door(); + temperature = this.itemProtocol.getItem_temperature(); + countdown = this.itemProtocol.getItem_countdown(); + finish = this.itemProtocol.getItem_finish(); + task = this.itemProtocol.getItem_task(); + error1 = this.itemProtocol.getItem_error1(); + material = this.itemProtocol.getItem_material(); + consumption = this.itemProtocol.getItem_consumption(); + voltage = this.itemProtocol.getItem_voltage(); + current = this.itemProtocol.getItem_current(); if (mode != last_mode) { this.setRequireSucess(false); @@ -140,7 +169,18 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple last_mode = mode; last_move = move; + last_action = action; last_error = error; + last_door = door; + last_temperature = temperature; + last_countdown = countdown; + last_finish = finish; + last_task = task; + last_error1 = error1; + last_material = material; + last_consumption = consumption; + last_voltage = voltage; + last_current = current; } @@ -162,7 +202,7 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.ItemProtocol.item_to_command; + + "." +ItemProtocol.item_to_command; String opcservcerid = this.getDevice().getOpc_server_id(); Server server = ReadUtil.getServer(opcservcerid); Map itemMap = new HashMap(); @@ -170,6 +210,19 @@ public class HongXiangConveyorDeviceDriver extends AbstractOpcDeviceDriver imple ReadUtil.write(itemMap, server); } + 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(); + + itemMap.put(to_param, value); +// itemMap.put(to_param, Integer.parseInt(value)); + ReadUtil.write(itemMap, server); + } + public void writing(int type, int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + org.nl.acs.device_driver.basedriver.cargo_lift_conveyor.ItemProtocol.item_to_command; diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java index 7ad6020fe..d81216a18 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/hongxiang_device/ItemProtocol.java @@ -43,29 +43,51 @@ public class ItemProtocol { this.driver = driver; } - public int getItem_heartbeat() { + public int getItem_heartbeat(){ return this.getOpcIntegerValue(item_heartbeat); - } - - public int getItem_mode() { + } ; + public int getItem_mode(){ return this.getOpcIntegerValue(item_mode); - } - - public int getItem_move() { + } ; + public int getItem_move(){ return this.getOpcIntegerValue(item_move); - } - - public int getItem_error() { - return this.getOpcIntegerValue(item_error); - } - - public int getItem_action() { + } ; + public int getItem_action(){ return this.getOpcIntegerValue(item_action); - } - - public int getItem_task() { + }; + public int getItem_error(){ + return this.getOpcIntegerValue(item_error); + } ; + public int getItem_door(){ + return this.getOpcIntegerValue(item_door); + } ; + public int getItem_temperature(){ + return this.getOpcIntegerValue(item_temperature); + } ; + public int getItem_countdown(){ + return this.getOpcIntegerValue(item_countdown); + } ; + public int getItem_finish(){ + return this.getOpcIntegerValue(item_finish); + } ; + public int getItem_task(){ return this.getOpcIntegerValue(item_task); - } + } ; + public int getItem_error1(){ + return this.getOpcIntegerValue(item_error1); + } ; + public int getItem_material(){ + return this.getOpcIntegerValue(item_material); + } ; + public int getItem_consumption(){ + return this.getOpcIntegerValue(item_consumption); + } ; + public int getItem_voltage(){ + return this.getOpcIntegerValue(item_voltage); + } ; + public int getItem_current(){ + return this.getOpcIntegerValue(item_current); + } ; Boolean isonline; diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java index 965b8b834..69bbf1e52 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/oven_manipulator/OvenGantryManipulatorDeviceDriver.java @@ -13,6 +13,7 @@ import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; import org.nl.acs.device.service.DeviceService; import org.nl.acs.device_driver.DeviceDriver; import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.basedriver.hongxiang_device.HongXiangConveyorDeviceDriver; import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; import org.nl.acs.ext.wms.service.AcsToWmsService; @@ -25,6 +26,7 @@ import org.nl.acs.opc.DeviceAppService; import org.nl.acs.opc.DeviceAppServiceImpl; import org.nl.acs.route.service.RouteLineService; import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; import org.nl.modules.wql.util.SpringContextHolder; import org.openscada.opc.lib.da.Server; import org.springframework.beans.factory.annotation.Autowired; @@ -115,6 +117,9 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i error = this.itemProtocol.getError(); task = this.itemProtocol.getTask(); if (mode != last_mode) { + if (mode == 2) { + this.setRequireSucess(false); + } logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); } @@ -139,6 +144,99 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); } + //更改任务状态 + if (task > 0) { + //inst_message + Instruction inst1 = instructionService.findByCodeFromCache(String.valueOf(task)); + if (inst1 != null) { + if (StrUtil.equals(inst1.getInstruction_status(), "0")) { + inst1.setInstruction_status("1"); + instructionService.update(inst1); + TaskDto taskDto = taskserver.findByCode(inst1.getTask_code()); + JSONArray array = new JSONArray(); + JSONObject map = new JSONObject(); + map.put("task_id", taskDto.getExt_task_id()); + map.put("task_status", "1"); + array.add(map); + acsToWmsService.feedbackTaskStatusToWms(array); + } + } + } + + //申请取货 判断取货位是否有货 有货就下发允许取货命令 + if (mode == 3 && action == 1 && move == 0 && task > 0) { + Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task)); + if (ObjectUtil.isNotEmpty(inst2)) { + String start_device_code = inst2.getStart_device_code(); + Device device = appService.findDeviceByCode(start_device_code); + HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; + if (device.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { + hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver(); + hongXiangConveyorDeviceDriver.writing("to_door", "1"); + if (hongXiangConveyorDeviceDriver.getDoor() == 1 && hongXiangConveyorDeviceDriver.getAction() == 1 && hongXiangConveyorDeviceDriver.getError1() == 0) { + this.writing("to_command", "2"); + } + } else { + this.writing("to_command", "2"); + } + } + } + + //申请放货 + if (mode == 3 && action == 3 && move == 1 && task > 0) { + Instruction instructionDto = instructionService.findByCode(String.valueOf(task)); + String next_device_code = instructionDto.getNext_device_code(); + Device nextDevice = appService.findDeviceByCode(next_device_code); + HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; + if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { + hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver(); + hongXiangConveyorDeviceDriver.writing("to_door", "1"); + if (hongXiangConveyorDeviceDriver.getDoor() == 1 && hongXiangConveyorDeviceDriver.getAction() == 1 && hongXiangConveyorDeviceDriver.getError1() == 0) { + this.writing("to_command", "3"); + } + } else { + this.writing("to_command", "3"); + } + } + + //放货完成 + if (mode == 3 && action == 4 && move == 0 && task > 0) { + Instruction inst2 = instructionService.findByCodeFromCache(String.valueOf(task)); + if (inst2 != null) { + if (StrUtil.equals(inst2.getInstruction_status(), "1")) { + try { + finish_instruction(inst2); + } catch (Exception e) { + e.printStackTrace(); + } + TaskDto taskDto = taskserver.findByCode(inst2.getTask_code()); + JSONArray array = new JSONArray(); + JSONObject map = new JSONObject(); + map.put("task_id", taskDto.getTask_id()); + map.put("task_status", "2"); + array.add(map); + acsToWmsService.feedbackTaskStatusToWms(array); + String next_device_code = taskDto.getNext_device_code(); + String start_device_code = taskDto.getStart_device_code(); + Device startDevice = appService.findDeviceByCode(start_device_code); + Device nextDevice = appService.findDeviceByCode(next_device_code); + HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; + if (startDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { + hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startDevice.getDeviceDriver(); + hongXiangConveyorDeviceDriver.writing("to_door", "0"); + } + if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { + hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver(); + hongXiangConveyorDeviceDriver.writing("to_door", "0"); + } + this.writing("to_command", "0"); + this.writing("to_onset", "0"); + this.writing("to_target", "0"); + this.writing("to_task", "0"); + } + } + } + } catch (Exception var17) { return; } @@ -165,6 +263,11 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i Instruction instruction = null; List toInstructions; + //行架机械手申请任务 + if (mode == 2 && move == 0 && task == 0 && !requireSucess) { + applyTask(); + } + } last_mode = mode; last_move = move; @@ -175,7 +278,6 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i } - public boolean exe_error() { if (this.error == 0) { return true; @@ -185,6 +287,102 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i } } + + /** + * 申请任务 + * + * @param + */ + 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; + //抓取工位 + List getDeviceCodeList = this.getExtraDeviceCodes("get_device_code"); + //放货工位 + List putDeviceCodeList = this.getExtraDeviceCodes("put_device_code"); + TaskDto task = null; + for (int i = 0; i < getDeviceCodeList.size(); i++) { + String startDeviceCode = getDeviceCodeList.get(i); + List taskDtos = taskserver.queryTaskByDeviceCodeAndStatus(startDeviceCode); + if (ObjectUtil.isNotEmpty(taskDtos)) { + TaskDto taskDto = taskDtos.get(0); + Instruction instruction = instructionService.findByTaskcode(taskDto.getTask_code()); + instruction.setInstruction_status("1"); + instruction.setUpdate_time(DateUtil.now()); + instructionService.update(instruction); + int start_addrIndex = getDeviceCodeList.indexOf(instruction.getStart_device_code()); + int next_addrIndex = putDeviceCodeList.indexOf(instruction.getNext_device_code()); + writing("to_onset", String.valueOf(start_addrIndex)); + writing("to_target", String.valueOf(next_addrIndex)); + writing("to_task", instruction.getInstruction_code()); + writing("to_command", "1"); + this.setRequireSucess(true); + return true; + } else { + List taskDtoList = taskserver.queryTaskByDeviceCode(startDeviceCode); + if (ObjectUtil.isNotEmpty(taskDtoList)) { + task = taskDtoList.get(0); + } + if (ObjectUtil.isNotEmpty(task)) break; + } + } + if (!ObjectUtil.isEmpty(task)) { + String taskid = task.getTask_id(); + String taskcode = task.getTask_code(); + String vehiclecode = task.getVehicle_code(); + String priority = task.getPriority(); + String start_point_code = task.getStart_point_code(); + String start_device_code = task.getStart_device_code(); + String route_plan_code = task.getRoute_plan_code(); + String next_point_code = task.getNext_point_code(); + String next_device_code = task.getNext_device_code(); + + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(task.getRemark()); + instdto.setMaterial(task.getMaterial()); + instdto.setQuantity(task.getQuantity()); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + instdto.setVehicle_code(vehiclecode); + 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.setPriority(priority); + instdto.setInstruction_status("1"); + instdto.setExecute_device_code(start_point_code); + + try { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + } + //创建指令后修改任务状态 + task.setTask_status("1"); + task.setUpdate_time(DateUtil.now()); + taskserver.update(task); + //根据获取托盘信息返回的结果 得到对应抓取工位/放货工位设备编码所在的索引位置 + int start_addrIndex = getDeviceCodeList.indexOf(start_device_code); + int next_addrIndex = putDeviceCodeList.indexOf(next_device_code); + writing("to_onset", String.valueOf(start_addrIndex)); + writing("to_target", String.valueOf(next_addrIndex)); + writing("to_task", instdto.getInstruction_code()); + writing("to_command", "1"); + this.setRequireSucess(true); + } + return true; + } + } + public boolean exe_business() { return true; } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java index b3fc00495..feeb0221a 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java @@ -86,6 +86,8 @@ public interface InstructionService { */ Instruction findByTaskcode(String code); + Instruction findByTaskcodeAndStatus(String code); + /** * 根据任务id查询 * diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 081d3f8b2..cc96d9210 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -224,6 +224,17 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu return obj; } + @Override + public Instruction findByTaskcodeAndStatus(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("task_code ='" + code + "' and instruction_status = '0'").uniqueResult(0); + if (ObjectUtil.isNotEmpty(json)){ + final Instruction obj = json.toJavaObject(Instruction.class); + return obj; + } + return null; + } + @Override public Instruction findByTaskid(String id, String wherecaluse) { if (!StrUtil.isEmpty(wherecaluse)) { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java index 10400b96d..1e4f1cac8 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java @@ -104,6 +104,14 @@ public interface TaskService { */ List queryTaskByDeviceCode(String device_code); + /** + * 根据设备号和任务状态查询 + * @param device_code + * @return + */ + List queryTaskByDeviceCodeAndStatus(String device_code); + + /** * 根据关联编号查询非立刻下发的关联任务 */ diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index 440082783..8bf5c9a5f 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -273,6 +273,22 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { return list; } + @Override + public List queryTaskByDeviceCodeAndStatus(String device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getStart_device_code().equals(device_code) && StrUtil.equals(task.getTask_status(), "1")) { + Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if (ObjectUtil.isNotEmpty(instruction)){ + list.add(task); + } + } + } + return list; + } + @Override public TaskDto queryTaskByLinkNum(String link_num) { return null;