|
|
@ -1,9 +1,24 @@ |
|
|
|
package com.iflytop.digester; |
|
|
|
import com.iflytop.digester.deviceinstance.Device; |
|
|
|
import com.iflytop.digester.underframework.UfActuatorCmdExecutor; |
|
|
|
import com.iflytop.digester.underframework.UfApplication; |
|
|
|
import com.iflytop.digester.underframework.UfCmdSnippetExecutor; |
|
|
|
import com.iflytop.digester.underframework.dao.model.UfMdbNotification; |
|
|
|
import com.iflytop.digester.underframework.dao.model.UfMdbOption; |
|
|
|
import com.iflytop.digester.underframework.dao.model.UfMdbRuntimeVariable; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
public class StartResetTaskThread extends Thread { |
|
|
|
// logger |
|
|
|
public static final Logger LOG = LoggerFactory.getLogger(StartResetTaskThread.class); |
|
|
|
// 是否需要放置异常处理试管架 |
|
|
|
private Boolean isErrorTubeRackRequired = true; |
|
|
|
// pause lock |
|
|
|
private final Object pauseLock = new Object(); |
|
|
|
|
|
|
|
@Override |
|
|
|
public void run() { |
|
|
@ -11,57 +26,15 @@ public class StartResetTaskThread extends Thread { |
|
|
|
device.setStatus("preparing"); |
|
|
|
this.setProgressMessage("设备初始化..."); |
|
|
|
|
|
|
|
UfCmdSnippetExecutor.execute("StartResetInitDevices"); |
|
|
|
|
|
|
|
try { |
|
|
|
Thread.sleep(5000); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
|
|
|
|
// this.getDevice().getIO().setValue("LightRed", 1); |
|
|
|
// |
|
|
|
// this.setProgressMessage("设备初始化 : 关闭设备门"); |
|
|
|
// DiActMotor doorMotor = this.getActuator(MyDevice.ACT_DOOR_MOTOR, DiActMotor.class); |
|
|
|
// doorMotor.setEnable(true); |
|
|
|
// MoveDoorClose.execute(this.getDevice()); |
|
|
|
// |
|
|
|
// this.setProgressMessage("设备初始化 : 加液臂复位"); |
|
|
|
// DiActMotor liquidMotor = this.getActuator(MyDevice.ACT_LIQUID_MOTOR, DiActMotor.class); |
|
|
|
// liquidMotor.setEnable(true); |
|
|
|
// liquidMotor.reset(); |
|
|
|
// liquidMotor.moveTo("LiquidArmStandby"); |
|
|
|
// |
|
|
|
// this.setProgressMessage("设备初始化 : 关闭夹爪"); |
|
|
|
// DiActServo transferClipServo = this.getActuator(MyDevice.ACT_TRANSFER_CLIP_SERVO, DiActServo.class); |
|
|
|
// transferClipServo.setEnable(true); |
|
|
|
// transferClipServo.moveTo("TransClipServoClose"); |
|
|
|
// |
|
|
|
// this.setProgressMessage("设备初始化 : 搬运机械臂上下移动复位"); |
|
|
|
// DiActMotor transUdMotor = this.getActuator(MyDevice.ACT_TRANSFER_UD_MOTOR, DiActMotor.class); |
|
|
|
// transUdMotor.setEnable(true); |
|
|
|
// transUdMotor.reset(); |
|
|
|
// transUdMotor.moveTo("TransUdMotorStandby"); |
|
|
|
// |
|
|
|
// this.setProgressMessage("设备初始化 : 搬运机械臂左右移动复位"); |
|
|
|
// DiActMotor transLrMotor = this.getActuator(MyDevice.ACT_TRANSFER_LR_MOTOR, DiActMotor.class); |
|
|
|
// transLrMotor.setEnable(true); |
|
|
|
// transLrMotor.reset(); |
|
|
|
// transLrMotor.setMoveOffset("TransLrMotorGlobalOffset"); |
|
|
|
// transLrMotor.moveTo("TransLrMotorStandby"); |
|
|
|
// |
|
|
|
// // @TODO : http://127.0.0.1:5566/issues/39 |
|
|
|
// this.setProgressMessage("设备初始化 : 加液转盘复位"); |
|
|
|
// DiActMotor liquidPlateMotor = this.getActuator(MyDevice.ACT_LIQUID_PLATE_MOTOR, DiActMotor.class); |
|
|
|
// liquidPlateMotor.setEnable(true); |
|
|
|
// liquidPlateMotor.reset(); |
|
|
|
// |
|
|
|
// // @TODO : http://127.0.0.1:5566/issues/40 |
|
|
|
// this.setProgressMessage("设备初始化 : 加热盘转盘复位"); |
|
|
|
// DiActMotor heatPlateMotor = this.getActuator(MyDevice.ACT_HEAT_PLATE_MOTOR, DiActMotor.class); |
|
|
|
// heatPlateMotor.setEnable(true); |
|
|
|
// heatPlateMotor.reset(); |
|
|
|
// heatPlateMotor.moveTo("HeatPlateStandby"); |
|
|
|
// |
|
|
|
// this.setupHeatingSlotCover(); |
|
|
|
this.setupHeatingSlotCover(); |
|
|
|
// this.setupPeristalticPump(); |
|
|
|
// |
|
|
|
// this.setProgressMessage("设备初始化 : 相机"); |
|
|
@ -146,63 +119,60 @@ public class StartResetTaskThread extends Thread { |
|
|
|
// MoveDoorClose.execute(this.getDevice()); |
|
|
|
// } |
|
|
|
// |
|
|
|
// /** |
|
|
|
// * 清理试管架 |
|
|
|
// * @issue : <a href="http://127.0.0.1:5566/issues/85">无法获取加液位置是否存在试管架</a> |
|
|
|
// */ |
|
|
|
// private void setupHeatingSlotCover() { |
|
|
|
// boolean isDoorOpen = false; |
|
|
|
// Integer errorSlotIndex = this.getDevice().getEnv().getProperty("app.errorSlotIndex",Integer.class); |
|
|
|
// |
|
|
|
// for ( int i=0; i<5; i++ ) { |
|
|
|
// this.setProgressMessage("设备初始化 : 检查试管架 " + (i+1) + "/5"); |
|
|
|
// String key = "HeatingPlateMotorSlotCover_" + i; |
|
|
|
// DiActServo heatSlotCoverServo = this.getActuator(key, DiActServo.class); |
|
|
|
// heatSlotCoverServo.setEnable(true); |
|
|
|
// var currentPos = heatSlotCoverServo.getCurrentPos(); |
|
|
|
// LOG.info("HeatingPlateMotorSlotCover #{} : current pos = {}", i, currentPos); |
|
|
|
// |
|
|
|
// // 如果是空的,则初始化位置后继续下一步 |
|
|
|
// var rackExistsPos = heatSlotCoverServo.getLocationValue("HeatingPlateMotorSlotCoverRackExists"); |
|
|
|
// if ( currentPos > rackExistsPos ) { |
|
|
|
// heatSlotCoverServo.setCurrentPosAsMiddle(); |
|
|
|
// continue; |
|
|
|
// } |
|
|
|
// |
|
|
|
// // 如果是空试管架, 又是异常区域则不处理, 因为异常区域始终要有个试管架 |
|
|
|
// var emptyRackExistsPos = heatSlotCoverServo.getLocationValue("HeatingPlateMotorSlotCoverEmptyRackExists"); |
|
|
|
// if ( currentPos > emptyRackExistsPos && null != errorSlotIndex && errorSlotIndex == i ) { // 异常区域存在空试管架 |
|
|
|
// this.isErrorTubeRackRequired = false; |
|
|
|
// continue; |
|
|
|
// } |
|
|
|
// |
|
|
|
// var moveToLiquidPlate = new MoveMoveTubeRackFromHeatPlateToLiquidPlate(); |
|
|
|
// moveToLiquidPlate.setDevice(this.getDevice()); |
|
|
|
// moveToLiquidPlate.slotIndex = i; |
|
|
|
// moveToLiquidPlate.updateSlotStatus = false; |
|
|
|
// moveToLiquidPlate.run(); |
|
|
|
// |
|
|
|
// if ( !isDoorOpen ) { |
|
|
|
// MoveDoorOpen.execute(this.getDevice()); |
|
|
|
// isDoorOpen = true; |
|
|
|
// } |
|
|
|
// |
|
|
|
// heatSlotCoverServo.moveTo("HeatingPlateMotorSlotCoverEmpty"); |
|
|
|
// heatSlotCoverServo.setEnable(false); |
|
|
|
// |
|
|
|
// // 等待取出试管架 |
|
|
|
// DiMdbNotification.taskAction(this, "TaskStartResetErrorTubeRackTakeOut"); |
|
|
|
// this.waitAction("TaskStartResetErrorTubeRackTakeOut"); |
|
|
|
// LOG.info("HeatingPlateMotorSlotCover #{} : take out", i); |
|
|
|
// |
|
|
|
// heatSlotCoverServo.setEnable(true); |
|
|
|
// heatSlotCoverServo.setCurrentPosAsMiddle(); |
|
|
|
// } |
|
|
|
// |
|
|
|
// if ( isDoorOpen ) { |
|
|
|
// MoveDoorClose.execute(this.getDevice()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
/** |
|
|
|
* 清理试管架 |
|
|
|
* @issue : <a href="http://127.0.0.1:5566/issues/85">无法获取加液位置是否存在试管架</a> |
|
|
|
*/ |
|
|
|
private void setupHeatingSlotCover() { |
|
|
|
boolean isDoorOpen = false; |
|
|
|
Integer errorSlotIndex = UfApplication.getApp().getEnv().getProperty("app.errorSlotIndex", Integer.class); |
|
|
|
|
|
|
|
for ( int i=0; i<5; i++ ) { |
|
|
|
this.setProgressMessage("设备初始化 : 检查试管架 " + (i+1) + "/5"); |
|
|
|
UfCmdSnippetExecutor.execute(String.format("HeatingSlotCoverEnable.%d",i)); |
|
|
|
var actuatorKey = String.format("HeatingPlateMotorSlotCover_%d", i); |
|
|
|
var currentPosStr = UfActuatorCmdExecutor.execute(actuatorKey, "motor_read_pos"); |
|
|
|
var currentPos = Integer.parseInt(currentPosStr); |
|
|
|
LOG.info("HeatingPlateMotorSlotCover #{} : current pos = {}", i, currentPos); |
|
|
|
|
|
|
|
// 如果是空的,则初始化位置后继续下一步 |
|
|
|
var rackExistsPos = UfMdbOption.getInteger("HeatingPlateMotorSlotCoverRackExists", 0); |
|
|
|
if ( currentPos > rackExistsPos ) { |
|
|
|
UfActuatorCmdExecutor.execute(actuatorKey, "motor_easy_set_current_pos", "2047"); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// 如果是空试管架, 又是异常区域则不处理, 因为异常区域始终要有个试管架 |
|
|
|
var emptyRackExistsPos = UfMdbOption.getInteger("HeatingPlateMotorSlotCoverEmptyRackExists", 0); |
|
|
|
if ( currentPos > emptyRackExistsPos && null != errorSlotIndex && errorSlotIndex == i ) { // 异常区域存在空试管架 |
|
|
|
this.isErrorTubeRackRequired = false; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// 将试管架移至加液盘 |
|
|
|
UfCmdSnippetExecutor.execute(String.format("TubeRackMoveToLiquidPlate.%d", i)); |
|
|
|
// 打开柜门 |
|
|
|
if ( !isDoorOpen ) { |
|
|
|
UfCmdSnippetExecutor.execute("DoorOpen"); |
|
|
|
isDoorOpen = true; |
|
|
|
} |
|
|
|
// 禁用该区位密封盖,用于后续重置状态 |
|
|
|
UfCmdSnippetExecutor.execute(String.format("HeatingSlotCoverDisable.%d", i)); |
|
|
|
|
|
|
|
// 等待取出试管架 |
|
|
|
UfMdbNotification.action("StartResetTubeRackTakeOut", new HashMap<>()); |
|
|
|
this.waitAction("TaskStartResetErrorTubeRackTakeOut"); |
|
|
|
LOG.info("HeatingPlateMotorSlotCover #{} : take out", i); |
|
|
|
|
|
|
|
// 重新启用密封盖 |
|
|
|
UfCmdSnippetExecutor.execute(String.format("HeatingSlotCoverEnable.%d", i)); |
|
|
|
UfCmdSnippetExecutor.execute(String.format("HeatingSlotCoverServoSetCurPosAsMiddle.%d", i)); |
|
|
|
} |
|
|
|
|
|
|
|
if ( isDoorOpen ) { |
|
|
|
UfCmdSnippetExecutor.execute("DoorClose"); |
|
|
|
} |
|
|
|
} |
|
|
|
// |
|
|
|
// // 异常处理位试管架取出 |
|
|
|
// public void actionErrorTubeRackTakeOut() { |
|
|
@ -241,6 +211,26 @@ public class StartResetTaskThread extends Thread { |
|
|
|
// action.finish(); |
|
|
|
// } |
|
|
|
|
|
|
|
// wait for continue |
|
|
|
private void waitAction( String key ) { |
|
|
|
LOG.info("Start reset wait for action : {}", key); |
|
|
|
synchronized (pauseLock) { |
|
|
|
try { |
|
|
|
pauseLock.wait(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// execute action |
|
|
|
public void executeAction( String key ) { |
|
|
|
LOG.info("Start reset execute action : {}", key); |
|
|
|
synchronized (pauseLock) { |
|
|
|
pauseLock.notifyAll(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// set progress message |
|
|
|
private void setProgressMessage(String message) { |
|
|
|
UfMdbRuntimeVariable.setString(message, "device.start.message"); |
|
|
|