From 1b2b5bb36c2f721d324187dba7ef7c3c16d1f18f Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 17 Oct 2024 17:31:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A2=E6=B5=8B=E7=89=A9=E8=B4=A8=E5=92=8C?= =?UTF-8?q?=E5=B0=8F=E7=93=B6=E7=BC=93=E5=86=B2=E6=B6=B2=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E6=A0=A1=E5=87=86=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.db | Bin 225280 -> 225280 bytes .../java/a8k/hardware/A8kModParamInitializer.java | 4 +- .../HbotLittleBottleConsumableCalibration.java | 31 ++++++--- .../app/devicedriver/pos/HbotConsumablePosMgr.java | 33 +++++----- .../service/db/LowerDeviceParameterDBService.java | 69 ++++++++++++++------- src/main/java/a8k/service/db/type/Parameter.java | 13 ++-- .../a8k/service/db/utils/PosParameterReader.java | 20 ++++++ src/main/java/a8k/type/HbotConsumablePosParam.java | 2 +- src/main/java/a8k/utils/ZJsonHelper.java | 42 +++++++++++++ src/main/java/a8k/utils/ZSqliteJdbcHelper.java | 11 ++++ 10 files changed, 169 insertions(+), 56 deletions(-) diff --git a/app.db b/app.db index da2892a4277c31c711e4b175368683fc071ac54b..a2b79c9d6ddd449a47137cb88d2a784fcd6f034e 100644 GIT binary patch delta 6475 zcmeHMYfx0z9lv|e?%sVb@>*bdBdi1$?ql!nUJ!P9DiHxi8eb@g#H2xSlqh}Nnm8ub z(k7bicsizWP*F50HNi$F(N5ZFKXf`x>|{E0s+o{h#I#M@FP%=RZTi2L-M#lNWWuLT zKfug|{l9+afBvs?_wd}5{kbXov8-fnk|2lxJbrkV5`^W!@#QSZO}^1RvhAP&csl1p z_)X+FA3C!gA3M%Fo^i1D&+PBokJwx7X|@k-=WM%dy!GGKUs%6uZM6Kya^14uLYx0& zK4ac&_Lx33-83CFb((Uhzff1HeU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fC6uanZHamA{v1Ss& zYBqg+U=xHmPbMO(+0^!ejeKA5w?w5C-Oxi|_4VML|!W)_xl7sv*$nWEI6k5o);}fJV5%{7Z7p^$dc$K8NLX%uk%e90Lvy^)huYbsdG< ze`KGsueF`Gea+TOoV5Pa`iOOh6(he(`iKuL_gOa4kI@5kf%7@%QD>i%cKp_HYN@bb zfFOI++_Eu~2Wl#>$}J%z%ynuBgUJ{c)}#{#i=xe({uBCGxriLXguG;<&qbY!7;I|J zqw878MIIIj&EcF6Ao{*T(MQF0llqU4iu^7fNb$GQ*cWKCxjx}Qx=ZA z@|0!fVuuu6)kI#UC4V`UBUsSPa>hQVSwU_omkwOOZPKqU$T^>F=0mz4ZtFoX)N;Pm z`wm`I!G;( littleBottleConsumableRefPoint = new java.util.ArrayList<>(); - LittleBottleConsumablePosInfo littleBottleConsumablePosInfo; @ExtApiFn(name = "开始标定小瓶坐标", group = "标定小瓶XY坐标", order = 30) public void startCalibrateLittleBottleGroup(LittleBottleConsumableType type) throws AppException { - littleBottleConsumablePosInfo = null; littleBottleConsumableRefPoint = new java.util.ArrayList<>(); littleBottleConsumableType = type; moveToZero(); @@ -104,9 +102,9 @@ public class HbotLittleBottleConsumableCalibration { public Object addLittleBottleGroupRefPoint(ConsumableGroup group, Integer off0To24) throws AppException { enableModule(); Pos2d xypos = hbotModule.readPos(); - pipetteCtrlModule.zMotorMeasureDistance(); - Integer z = pipetteCtrlModule.zMotorReadMeasureDistanceResult(); - LittleBottleConsumableRefPoint littleBufferRefPoint = new LittleBottleConsumableRefPoint(group, off0To24, new Pos3d(xypos.x, xypos.y, z)); +// pipetteCtrlModule.zMotorMeasureDistance(); +// Integer z = pipetteCtrlModule.zMotorReadMeasureDistanceResult(); + LittleBottleConsumableRefPoint littleBufferRefPoint = new LittleBottleConsumableRefPoint(group, off0To24, new Pos3d(xypos.x, xypos.y, 0)); this.littleBottleConsumableRefPoint.add(littleBufferRefPoint); disableModule(); ObjectNode node = ZJsonHelper.createObjectNode(); @@ -115,8 +113,15 @@ public class HbotLittleBottleConsumableCalibration { return node; } + @ExtApiFn(name = "移除最后一个参考点", group = "标定小瓶XY坐标", order = 32) + public void removeTheLastLittleBottleGroupRefPoint() { + if (!littleBottleConsumableRefPoint.isEmpty()) { + littleBottleConsumableRefPoint.remove(littleBottleConsumableRefPoint.size() - 1); + } + } - @ExtApiFn(name = "计算坐标", group = "标定小瓶XY坐标", order = 32) + + @ExtApiFn(name = "读取坐标计算结果", group = "标定小瓶XY坐标", order = 33) public LittleBottleConsumablePosInfo computeLittleBottlePosInfo() { //计算y0,所有group==0,1,2,同时0<=off<5的点,求平均 Double[] y = new Double[2]; @@ -191,7 +196,7 @@ public class HbotLittleBottleConsumableCalibration { var oldposInfo = hbotConsumablePosMgr.getLittleBottleConsumablePosInfo(littleBottleConsumableType); - littleBottleConsumablePosInfo = new LittleBottleConsumablePosInfo(); + var littleBottleConsumablePosInfo = new LittleBottleConsumablePosInfo(); littleBottleConsumablePosInfo.g0_000 = new Pos3d(x[0].intValue(), y[0].intValue(), oldposInfo.g0_000.z); littleBottleConsumablePosInfo.g1_000 = new Pos3d(x[1].intValue(), y[0].intValue(), oldposInfo.g1_000.z); littleBottleConsumablePosInfo.g2_000 = new Pos3d(x[2].intValue(), y[0].intValue(), oldposInfo.g2_000.z); @@ -203,12 +208,12 @@ public class HbotLittleBottleConsumableCalibration { return littleBottleConsumablePosInfo; } - @ExtApiFn(name = "保存计算结果", group = "标定小瓶XY坐标", order = 33) + @ExtApiFn(name = "保存计算结果", group = "标定小瓶XY坐标", order = 34) public void saveLittleBottleConsumablePosInfo() throws AppException { - hbotConsumablePosMgr.setLittleBottleConsumablePosInfo(littleBottleConsumableType, littleBottleConsumablePosInfo); + hbotConsumablePosMgr.setLittleBottleConsumablePosInfo(littleBottleConsumableType, computeLittleBottlePosInfo()); } - @ExtApiFn(name = "读取所有参考点", group = "标定小瓶XY坐标", order = 33) + @ExtApiFn(name = "读取所有参考点", group = "标定小瓶XY坐标", order = 35) public Object readAllRefPoint() throws AppException { return littleBottleConsumableRefPoint; } @@ -220,20 +225,26 @@ public class HbotLittleBottleConsumableCalibration { @ExtApiFn(name = "校准.小瓶穿孔Z轴位置", group = "标定Z轴", order = 101) public void setLittleBSPierceZPos() throws AppException { + enableModule(); pipetteCtrlModule.zMotorMeasureDistance(); hbotConsumablePosMgr.setParam(HbotConsumablePosParam.LittleBSPierceZPos, pipetteCtrlModule.zMotorReadMeasureDistanceResult()); + disableModule(); } @ExtApiFn(name = "校准.小瓶取样Z轴位置", group = "标定Z轴", order = 102) public void setLittleBSSampleZPos() throws AppException { + enableModule(); pipetteCtrlModule.zMotorMeasureDistance(); hbotConsumablePosMgr.setParam(HbotConsumablePosParam.LittleBSSampleZPos, pipetteCtrlModule.zMotorReadMeasureDistanceResult()); + disableModule(); } @ExtApiFn(name = "校准.探测物质取样Z轴位置", group = "标定Z轴", order = 103) public void setProbeSubstanceSampleZPos() throws AppException { + enableModule(); pipetteCtrlModule.zMotorMeasureDistance(); hbotConsumablePosMgr.setParam(HbotConsumablePosParam.ProbeSubstanceSampleZPos, pipetteCtrlModule.zMotorReadMeasureDistanceResult()); + disableModule(); } diff --git a/src/main/java/a8k/service/app/devicedriver/pos/HbotConsumablePosMgr.java b/src/main/java/a8k/service/app/devicedriver/pos/HbotConsumablePosMgr.java index 15aa554..1b3a947 100644 --- a/src/main/java/a8k/service/app/devicedriver/pos/HbotConsumablePosMgr.java +++ b/src/main/java/a8k/service/app/devicedriver/pos/HbotConsumablePosMgr.java @@ -35,12 +35,16 @@ public class HbotConsumablePosMgr { LowerDeviceParameterDBService lowerDeviceParameterDBService; PosParameterReader posReader = null; - static Integer nowParaVersion = 3; + static Integer nowParaVersion = 2; @PostConstruct void initialize() { posReader = lowerDeviceParameterDBService.getReader(this.getClass()); Integer paraVersion = posReader.getVersion(); + + for (HbotConsumablePosParam param : HbotConsumablePosParam.values()) { + posReader.setParamChName(param, param.chName); + } if (!nowParaVersion.equals(paraVersion)) { paramReset(); } @@ -57,7 +61,7 @@ public class HbotConsumablePosMgr { posReader.updatePos(HbotConsumablePosParam.TipGroup1_000Pos, new Pos3d()); posReader.updatePos(HbotConsumablePosParam.TipGroup1_SpaceingX, 0.0); - posReader.updatePos(HbotConsumablePosParam.TipGroup2_SpaceingY, 0.0); + posReader.updatePos(HbotConsumablePosParam.TipGroup1_SpaceingY, 0.0); posReader.updatePos(HbotConsumablePosParam.TipGroup2_000Pos, new Pos3d()); posReader.updatePos(HbotConsumablePosParam.TipGroup2_SpaceingX, 0.0); @@ -88,19 +92,15 @@ public class HbotConsumablePosMgr { posReader.updatePos(HbotConsumablePosParam.LargeBuffer_DX, 0.0); posReader.updatePos(HbotConsumablePosParam.LargeBuffer_DY, 0.0); + posReader.updatePos(HbotConsumablePosParam.LittleBSPierceZPos, 0.0); + posReader.updatePos(HbotConsumablePosParam.LittleBSSampleZPos, 0.0); + posReader.updatePos(HbotConsumablePosParam.ProbeSubstanceSampleZPos, 0.0); + posReader.updatePos(HbotConsumablePosParam.LargeBSSSampleZPos, 0.0); } - public List getParams() { - List list = new java.util.ArrayList<>(); - for (HbotConsumablePosParam param : HbotConsumablePosParam.values()) { - ObjectNode posNode = ZJsonHelper.createObjectNode(); - posNode.put("pos", ZJsonHelper.createObjectNode(posReader.getPos(param.name(), Pos3d.class))); - posNode.put("name", param.name()); - posNode.put("chName", param.chName); - list.add(posNode); - } - return list; + public Object getParams() { + return posReader.getParams(); } @@ -127,13 +127,14 @@ public class HbotConsumablePosMgr { tipDyPos = HbotConsumablePosParam.TipGroup2_SpaceingY; } - Assert.isTrue(tip000Pos != null,"tip000Pos != null"); + Assert.isTrue(tip000Pos != null, "tip000Pos != null"); posReader.updatePos(tip000Pos, tip000); posReader.updatePos(tipDxPos, dx); posReader.updatePos(tipDyPos, dy); } + public LittleBottleConsumablePosInfo getLittleBufferGroupPosInfo() { LittleBottleConsumablePosInfo info = new LittleBottleConsumablePosInfo(); info.g0_000 = posReader.getPos(HbotConsumablePosParam.LittleBufferGroup0_000Pos, Pos3d.class); @@ -227,9 +228,9 @@ public class HbotConsumablePosMgr { dx = posReader.getPos(HbotConsumablePosParam.TipGroup2_SpaceingX, Double.class); dy = posReader.getPos(HbotConsumablePosParam.TipGroup2_SpaceingY, Double.class); } - Assert.isTrue(tip000 != null,"tip000 != null"); - Assert.isTrue(dx != null,"dx != null"); - Assert.isTrue(dy != null,"dy != null"); + Assert.isTrue(tip000 != null, "tip000 != null"); + Assert.isTrue(dx != null, "dx != null"); + Assert.isTrue(dy != null, "dy != null"); int xoff = tipoff % 12; int yoff = tipoff / 12; diff --git a/src/main/java/a8k/service/db/LowerDeviceParameterDBService.java b/src/main/java/a8k/service/db/LowerDeviceParameterDBService.java index f4376be..24a9a93 100644 --- a/src/main/java/a8k/service/db/LowerDeviceParameterDBService.java +++ b/src/main/java/a8k/service/db/LowerDeviceParameterDBService.java @@ -2,6 +2,7 @@ package a8k.service.db; import a8k.service.db.type.Parameter; import a8k.service.db.utils.PosParameterReader; +import a8k.utils.ZJsonHelper; import a8k.utils.ZSqliteJdbcHelper; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -37,6 +38,23 @@ public class LowerDeviceParameterDBService { return (Parameter) ZSqliteJdbcHelper.rowMapper(rs, tClass); } + public void setParamChName(String service, String key, String chName) { + Parameter parameter = getParam(service, key); + if (parameter == null) { + parameter = new Parameter(); + parameter.service = service; + parameter.key = key; + parameter.chName = chName; + ZSqliteJdbcHelper.addObj(jdbcTemplate, tableName, tClass, parameter); + } else { + if (parameter.chName.equals(chName)) { + return; + } + parameter.chName = chName; + ZSqliteJdbcHelper.updateObj(jdbcTemplate, tableName, tClass, parameter); + } + + } public T getParam(String service, String key, Class tClass) { List list = jdbcTemplate.query("select * from " + tableName + " where service = ? and key = ?;", this::rowMapper, service, key); @@ -45,38 +63,43 @@ public class LowerDeviceParameterDBService { } Parameter parameter = list.get(0); - try { - return new ObjectMapper().readValue(parameter.val, tClass); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); + return ZJsonHelper.objectFromJson(parameter.val, tClass); + } + + public Parameter getParam(String service, String key) { + List list = jdbcTemplate.query("select * from " + tableName + " where service = ? and key = ?;", this::rowMapper, service, key); + if (list.isEmpty()) { + return null; } + + return list.get(0); + } + + public List getParams(String service) { + return jdbcTemplate.query("select * from " + tableName + " where service = ?;", this::rowMapper, service); } public void updateParam(String service, String key, Object pos) { logger.info("updateParam: service={}, key={}, pos={}", service, key, pos); - try { - ObjectMapper objectMapper = new ObjectMapper(); - List list = jdbcTemplate.query("select * from " + tableName + " where service = ? and key = ?;", this::rowMapper, service, key); - if (list.isEmpty()) { - Parameter parameter = new Parameter(); - parameter.service = service; - parameter.key = key; - parameter.val = objectMapper.writeValueAsString(pos); - parameter.valType = pos.getClass().getSimpleName(); - ZSqliteJdbcHelper.addObj(jdbcTemplate, tableName, tClass, parameter); - return; - } - - Parameter parameter = list.get(0); - parameter.val = objectMapper.writeValueAsString(pos); + ObjectMapper objectMapper = new ObjectMapper(); + List list = jdbcTemplate.query("select * from " + tableName + " where service = ? and key = ?;", this::rowMapper, service, key); + if (list.isEmpty()) { + Parameter parameter = new Parameter(); parameter.service = service; parameter.key = key; + parameter.val = ZJsonHelper.createObjectNode(pos); parameter.valType = pos.getClass().getSimpleName(); - ZSqliteJdbcHelper.updateObj(jdbcTemplate, tableName, tClass, parameter); - - } catch (JsonProcessingException e) { - throw new RuntimeException(e); + ZSqliteJdbcHelper.addObj(jdbcTemplate, tableName, tClass, parameter); + return; } + + Parameter parameter = list.get(0); + parameter.val = ZJsonHelper.createObjectNode(pos); + parameter.service = service; + parameter.key = key; + parameter.valType = pos.getClass().getSimpleName(); + ZSqliteJdbcHelper.updateObj(jdbcTemplate, tableName, tClass, parameter); + } public void tryInitParam(String service, String key, Object pos) { diff --git a/src/main/java/a8k/service/db/type/Parameter.java b/src/main/java/a8k/service/db/type/Parameter.java index 12a0af0..3bac380 100644 --- a/src/main/java/a8k/service/db/type/Parameter.java +++ b/src/main/java/a8k/service/db/type/Parameter.java @@ -1,9 +1,12 @@ package a8k.service.db.type; +import com.fasterxml.jackson.databind.node.ObjectNode; + public class Parameter { - public int id; - public String service; - public String key; - public String valType; - public String val; + public int id; + public String service; + public String key; + public String valType; + public ObjectNode val; + public String chName; } diff --git a/src/main/java/a8k/service/db/utils/PosParameterReader.java b/src/main/java/a8k/service/db/utils/PosParameterReader.java index a256417..2b039ff 100644 --- a/src/main/java/a8k/service/db/utils/PosParameterReader.java +++ b/src/main/java/a8k/service/db/utils/PosParameterReader.java @@ -1,6 +1,9 @@ package a8k.service.db.utils; import a8k.service.db.LowerDeviceParameterDBService; +import a8k.service.db.type.Parameter; + +import java.util.List; public class PosParameterReader { Class service; @@ -19,6 +22,19 @@ public class PosParameterReader { return lowerDeviceParameterDBService.getParam(this.service.getSimpleName(), key.name(), tClass); } + public Parameter getParamer(String key) { + return lowerDeviceParameterDBService.getParam(this.service.getSimpleName(), key); + } + + public Parameter getParamer(Enum key) { + return lowerDeviceParameterDBService.getParam(this.service.getSimpleName(), key.name()); + } + + public void setParamChName(Enum key, String chName) { + lowerDeviceParameterDBService.setParamChName(service.getSimpleName(), key.name(), chName); + } + + public void updatePos(String key, Object pos) { lowerDeviceParameterDBService.updateParam(service.getSimpleName(), key, pos); } @@ -38,4 +54,8 @@ public class PosParameterReader { public void setVersion(Integer version) { lowerDeviceParameterDBService.setParamVersion(service.getSimpleName(), version); } + + public List getParams() { + return lowerDeviceParameterDBService.getParams(service.getSimpleName()); + } } diff --git a/src/main/java/a8k/type/HbotConsumablePosParam.java b/src/main/java/a8k/type/HbotConsumablePosParam.java index 7368d39..1ae446f 100644 --- a/src/main/java/a8k/type/HbotConsumablePosParam.java +++ b/src/main/java/a8k/type/HbotConsumablePosParam.java @@ -37,7 +37,7 @@ public enum HbotConsumablePosParam { LargeBuffer_DY("大瓶缓冲液的Y间距"), LittleBSPierceZPos("小瓶缓冲液刺破Z坐标"), - LittleBSSampleZPos("小瓶缓冲液刺破取样Z坐标"), + LittleBSSampleZPos("小瓶缓冲液取样Z坐标"), ProbeSubstanceSampleZPos("探测物质取样Z坐标"), LargeBSSSampleZPos("大瓶缓冲液取样Z坐标"), diff --git a/src/main/java/a8k/utils/ZJsonHelper.java b/src/main/java/a8k/utils/ZJsonHelper.java index 8dfe5c6..73a4b94 100644 --- a/src/main/java/a8k/utils/ZJsonHelper.java +++ b/src/main/java/a8k/utils/ZJsonHelper.java @@ -20,9 +20,51 @@ public class ZJsonHelper { return new ObjectMapper().createObjectNode(); } + public static T objectFromJson(ObjectNode node, Class tClass) { + ObjectMapper mapper = new ObjectMapper(); + + if (tClass.getTypeName().equals(Integer.class.getTypeName())) { + return (T) Integer.valueOf(node.get("value").asInt()); + } + if (tClass.getTypeName().equals(String.class.getTypeName())) { + return (T) node.get("value").asText(); + } + if (tClass.getTypeName().equals(Boolean.class.getTypeName())) { + return (T) Boolean.valueOf(node.get("value").asBoolean()); + } + if (tClass.getTypeName().equals(Double.class.getTypeName())) { + return (T) Double.valueOf(node.get("value").asDouble()); + } + if (tClass.getTypeName().equals(Float.class.getTypeName())) { + return (T) Float.valueOf(node.get("value").floatValue()); + } + + + try { + return (T) mapper.treeToValue(node, tClass); + } catch (Exception e) { + throw new RuntimeException(e); + } + } public static ObjectNode createObjectNode(Object obj) { ObjectMapper ObjectMapper = new ObjectMapper(); + if (obj instanceof Integer) { + return ObjectMapper.createObjectNode().put("value", (Integer) obj); + } + if (obj instanceof String) { + return ObjectMapper.createObjectNode().put("value", (String) obj); + } + if (obj instanceof Boolean) { + return ObjectMapper.createObjectNode().put("value", (Boolean) obj); + } + if (obj instanceof Double) { + return ObjectMapper.createObjectNode().put("value", (Double) obj); + } + if (obj instanceof Float) { + return ObjectMapper.createObjectNode().put("value", (Float) obj); + } return ObjectMapper.valueToTree(obj); } + } diff --git a/src/main/java/a8k/utils/ZSqliteJdbcHelper.java b/src/main/java/a8k/utils/ZSqliteJdbcHelper.java index 8102246..613a949 100644 --- a/src/main/java/a8k/utils/ZSqliteJdbcHelper.java +++ b/src/main/java/a8k/utils/ZSqliteJdbcHelper.java @@ -2,6 +2,7 @@ package a8k.utils; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.springframework.jdbc.core.JdbcTemplate; import java.lang.reflect.InvocationTargetException; @@ -90,6 +91,13 @@ public class ZSqliteJdbcHelper { field.set(obj, null); else field.set(obj, new Date(rs.getLong(field.getName()))); + } else if (field.getType().equals(ObjectNode.class)) { + ObjectMapper objectMapper = new ObjectMapper(); + try { + field.set(obj, objectMapper.readTree(rs.getString(field.getName()))); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } } else if (field.getType().isEnum()) { Method methodValueOf = null; try { @@ -139,6 +147,9 @@ public class ZSqliteJdbcHelper { args.add(date.getTime()); } else if (field.getType().isEnum()) { args.add(field.get(obj).toString()); + } else if (field.getType().equals(ObjectNode.class)) { + ObjectMapper objectMapper = new ObjectMapper(); + args.add(objectMapper.writeValueAsString(field.get(obj))); } else { ObjectMapper objectMapper = new ObjectMapper(); args.add(objectMapper.writeValueAsString(field.get(obj)));