diff --git a/src/main/java/a8k/a8k_can_protocol/IOId.java b/src/main/java/a8k/a8k_can_protocol/IOId.java index 7de3363..f49ab35 100644 --- a/src/main/java/a8k/a8k_can_protocol/IOId.java +++ b/src/main/java/a8k/a8k_can_protocol/IOId.java @@ -16,11 +16,11 @@ public enum IOId { //转盘逻辑相关光电 //钩板电机,零点光电,终点光电 - PullerMZeroPPS(ModuleType.ktmc_step_motor,ModuleId.OptModPullM,0), - PullerMEndPPS(ModuleType.ktmc_step_motor,ModuleId.OptModPullM,1), + PullerMZeroPPS(ModuleType.ktmc_step_motor, ModId.OptModPullM,0), + PullerMEndPPS(ModuleType.ktmc_step_motor, ModId.OptModPullM,1), //推板电机,零点光电,终点光电 - PusherMZeroPPS(ModuleType.ktmc_step_motor,ModuleId.PlatesBoxPusherM,0), - PusherMEndPPS(ModuleType.ktmc_step_motor,ModuleId.PlatesBoxPusherM,1), + PusherMZeroPPS(ModuleType.ktmc_step_motor, ModId.PlatesBoxPusherM,0), + PusherMEndPPS(ModuleType.ktmc_step_motor, ModId.PlatesBoxPusherM,1), ; diff --git a/src/main/java/a8k/a8k_can_protocol/MId.java b/src/main/java/a8k/a8k_can_protocol/MId.java new file mode 100644 index 0000000..eeb0843 --- /dev/null +++ b/src/main/java/a8k/a8k_can_protocol/MId.java @@ -0,0 +1,120 @@ +package a8k.a8k_can_protocol; + +public enum MId { + NotSet(0, "未设置"),// + HbotBoard(10, "机械臂板模块"),// + HbotM(11, "机械臂XY"),// + // + PlatesBoxBoard(20, "板夹仓模块"),// + PlatesBoxYM(21, "板夹仓移动电机"),// + PlatesBoxPusherM(22, "板夹仓推杆电机"),// + PlatesBoxScanner(23, "板夹仓扫码模组"),// + // + ShakeModBoard(30, "摇匀模组板"),// + ShakeModClampingM(31, "试管固定夹爪电机"),// + ShakeModGripperZM(32, "摇匀升降电机"),// + ShakeModShakeM(33, "试管摇匀电机"),// + ShakeModGripperYM(34, "摇匀前后电机"),// + ShakeModGripperSV(35, "摇匀试管帽夹爪"),// + ShakeModTubeScanerClampingSV(36, "试管架旋转固定舵机"),// + ShakeModTubeScanerRotateSV(37, "试管架旋转舵机"),// + // + PlatesBoxTCMBoard(40, "反应板夹温度控制板"),// + PlatesBoxTCM(41, "反应板夹温度控制模块"),// + WbTubeFanMod(42, "气溶胶风扇"),// + // + IncubatorTCMBoard(50, "温度控制"),// + IncubatorTCM(51, "温度控制"),// + // + FeedingModBoard(60, "出入料模块"),// + FeedingModInfeedM(61, "入料电机"),// + FeedingModXM(62, "试管架平移电机"),// + FeedingModOutfeedM(63, "出料电机"),// + FeedingModScannerMod(64, "试管架扫码器"),// + // + IncubatorRotateBoard(70, "孵育盘旋转板"),// + IncubatorRotateCtrlM(71, "孵育盘旋转"),// + // + PipetteModBoard(80, "机械臂Z轴板"),// + PipetteModZM(81, "机械臂Z"),// + PipetteMod(82, "移液枪"),// + PipetteModCodeScanner(83, "物料扫码器"),// + // + OptModBoard(90, "光学模组板"),// + OptModScannerM(91, "板卡扫描电机"),// + OptModPullM(92, "板卡推杆电机"),// + OptMod(93, "扫描仪"),// + // + A8kIdCardReaderBoard(100, "A8K读卡器板"),// + A8kIdCardReader(101, "A8K读卡器"),// + ; + + + final public String chname; + final public int index; + + MId(int index, String chname) { + this.chname = chname; + this.index = index; + } + + public int toInt() { + return index; + } + + public static MId valueOf(Integer val) { + return valueOf(val.intValue()); + } + + public static MId valueOf(int val) { + return switch (val) { + case 0 -> NotSet; + case 10 -> HbotBoard; + case 11 -> HbotM; + // + case 20 -> PlatesBoxBoard; + case 21 -> PlatesBoxYM; + case 22 -> PlatesBoxPusherM; + case 23 -> PlatesBoxScanner; + // + case 30 -> ShakeModBoard; + case 31 -> ShakeModClampingM; + case 32 -> ShakeModGripperZM; + case 33 -> ShakeModShakeM; + case 34 -> ShakeModGripperYM; + case 35 -> ShakeModGripperSV; + case 36 -> ShakeModTubeScanerClampingSV; + case 37 -> ShakeModTubeScanerRotateSV; + // + case 40 -> PlatesBoxTCMBoard; + case 41 -> PlatesBoxTCM; + case 42 -> WbTubeFanMod; + // + case 50 -> IncubatorTCMBoard; + case 51 -> IncubatorTCM; + // + case 60 -> FeedingModBoard; + case 61 -> FeedingModInfeedM; + case 62 -> FeedingModXM; + case 63 -> FeedingModOutfeedM; + case 64 -> FeedingModScannerMod; + // + case 70 -> IncubatorRotateBoard; + case 71 -> IncubatorRotateCtrlM; + // + case 80 -> PipetteModBoard; + case 81 -> PipetteModZM; + case 82 -> PipetteMod; + case 83 -> PipetteModCodeScanner; + // + case 90 -> OptModBoard; + case 91 -> OptModScannerM; + case 92 -> OptModPullM; + case 93 -> OptMod; + // + case 100 -> A8kIdCardReaderBoard; + case 101 -> A8kIdCardReader; + default -> NotSet; + }; + } +} diff --git a/src/main/java/a8k/a8k_can_protocol/ModuleId.java b/src/main/java/a8k/a8k_can_protocol/ModId.java similarity index 78% rename from src/main/java/a8k/a8k_can_protocol/ModuleId.java rename to src/main/java/a8k/a8k_can_protocol/ModId.java index 4af9bcd..5910fb0 100644 --- a/src/main/java/a8k/a8k_can_protocol/ModuleId.java +++ b/src/main/java/a8k/a8k_can_protocol/ModId.java @@ -1,6 +1,6 @@ package a8k.a8k_can_protocol; -public class ModuleId { +public class ModId { public static final int HbotBoard = 10;//机械臂板模块 @@ -22,29 +22,29 @@ public class ModuleId { public static final int PlatesBoxTCMBoard = 40;//反应板夹温度控制板 public static final int PlatesBoxTCM = 41;//反应板夹温度控制模块 - public static final int WbTubeFanModule = 42;//气溶胶风扇 + public static final int WbTubeFanMod = 42;//气溶胶风扇 public static final int IncubatorTCMBoard = 50;//温度控制 public static final int IncubatorTCM = 51;//温度控制 - public static final int FeedingModBoard = 60;//出入料模块 - public static final int FeedingModInfeedM = 61;//入料电机 - public static final int FeedingModXM = 62;//试管架平移电机 - public static final int FeedingModOutfeedM = 63;//出料电机 - public static final int FeedingModScannerM = 64;//试管架扫码器 + public static final int FeedingModBoard = 60;//出入料模块 + public static final int FeedingModInfeedM = 61;//入料电机 + public static final int FeedingModXM = 62;//试管架平移电机 + public static final int FeedingModOutfeedM = 63;//出料电机 + public static final int FeedingModScannerMod = 64;//试管架扫码器 public static final int IncubatorRotateBoard = 70;//孵育盘旋转板 public static final int IncubatorRotateCtrlM = 71;//孵育盘旋转 public static final int PipetteModBoard = 80;//机械臂Z轴板 - public static final int PipetteModZMotor = 81;//机械臂Z + public static final int PipetteModZM = 81;//机械臂Z public static final int PipetteMod = 82;//移液枪 public static final int PipetteModCodeScanner = 83;//物料扫码器 - public static final int OptModBoard = 90;//光学模组板 - public static final int OptModScannerMotor = 91;//板卡扫描电机 - public static final int OptModPullM = 92;//板卡推杆电机 - public static final int OptMod = 93;//扫描仪 + public static final int OptModBoard = 90;//光学模组板 + public static final int OptModScannerM = 91;//板卡扫描电机 + public static final int OptModPullM = 92;//板卡推杆电机 + public static final int OptMod = 93;//扫描仪 public static final int A8kIdCardReaderBoard = 100; //A8K读卡器板 public static final int A8kIdCardReader = 101; //A8K读卡器 @@ -68,22 +68,22 @@ public class ModuleId { case ShakeModTubeScanerRotateSV -> "ShakeModTubeScanerRotateSV"; case PlatesBoxTCMBoard -> "PlatesBoxTCMBoard"; case PlatesBoxTCM -> "PlatesBoxTCM"; - case WbTubeFanModule -> "WbTubeFanModule"; + case WbTubeFanMod -> "WbTubeFanMod"; case IncubatorTCMBoard -> "IncubatorTCMBoard"; case IncubatorTCM -> "IncubatorTCM"; case FeedingModBoard -> "FeedingModBoard"; case FeedingModInfeedM -> "FeedingModInfeedM"; case FeedingModXM -> "FeedingModXM"; case FeedingModOutfeedM -> "FeedingModOutfeedM"; - case FeedingModScannerM -> "FeedingModScannerM"; + case FeedingModScannerMod -> "FeedingModScannerMod"; case IncubatorRotateBoard -> "IncubatorRotateBoard"; case IncubatorRotateCtrlM -> "IncubatorRotateCtrlM"; case PipetteModBoard -> "PipetteModBoard"; - case PipetteModZMotor -> "PipetteModZMotor"; + case PipetteModZM -> "PipetteModZM"; case PipetteMod -> "PipetteMod"; case PipetteModCodeScanner -> "PipetteModCodeScanner"; case OptModBoard -> "OptModBoard"; - case OptModScannerMotor -> "OptModScannerMotor"; + case OptModScannerM -> "OptModScannerM"; case OptModPullM -> "OptModPullM"; case OptMod -> "OptMod"; case A8kIdCardReaderBoard -> "A8kIdCardReaderBoard"; diff --git a/src/main/java/a8k/appbean/AppErrorCode.java b/src/main/java/a8k/appbean/AppErrorCode.java index 6dc2408..fc5b8ae 100644 --- a/src/main/java/a8k/appbean/AppErrorCode.java +++ b/src/main/java/a8k/appbean/AppErrorCode.java @@ -7,24 +7,21 @@ public enum AppErrorCode { LargeBufferNotEnough("大瓶缓冲液不足", 3), // PasswdError("密码错误", 4), // UserDoesNotExist("用户不存在", 5), // - GripperPosError("抓手舵机位置异常", 6), // - GripperLiftMotorPosError("抓手升降电机位置异常", 8), // - GripperHorizontalMovementMotorPosError("抓手前后移动舵机位置异常", 9),// + GripperMPosError("抓手舵机位置异常", 6), // + GripperZMPosError("抓手升降电机位置异常", 8), // + GripperYMPosError("抓手前后移动舵机位置异常", 9),// TubesInShakeModule("摇匀模组位置有试管", 10),// + PlateStuckDetectorSensorTrigger("卡板检查光电触发", 11),// ; - final private String chName; final private int errorIndex; - public int mid; - private AppErrorCode(String chname, int errorIndex) { this.chName = chname; this.errorIndex = errorIndex; } - public String getChName() { return chName; } diff --git a/src/main/java/a8k/appbean/HardwareException.java b/src/main/java/a8k/appbean/HardwareException.java index a5976d0..d2aae14 100644 --- a/src/main/java/a8k/appbean/HardwareException.java +++ b/src/main/java/a8k/appbean/HardwareException.java @@ -1,7 +1,7 @@ package a8k.appbean; import a8k.a8k_can_protocol.Errorcode; -import a8k.a8k_can_protocol.ModuleId; +import a8k.a8k_can_protocol.ModId; public class HardwareException extends Exception { // 构造函数 @@ -14,9 +14,7 @@ public class HardwareException extends Exception { } public HardwareException(int moduleId, int HardwareErrorCode) { - super(String.format("Module ID %s has error code %s", ModuleId.ModuleId2Name(moduleId), Errorcode.toString(HardwareErrorCode))); - this.moduleId = moduleId; - this.errorCode = HardwareErrorCode; + super(String.format("Module ID %s has error code %s", ModId.ModuleId2Name(moduleId), Errorcode.toString(HardwareErrorCode))); } int getModuleId() { diff --git a/src/main/java/a8k/appbean/ecode/AppEcode.java b/src/main/java/a8k/appbean/ecode/AppEcode.java new file mode 100644 index 0000000..bf0303a --- /dev/null +++ b/src/main/java/a8k/appbean/ecode/AppEcode.java @@ -0,0 +1,29 @@ +package a8k.appbean.ecode; + +import a8k.a8k_can_protocol.MId; +import a8k.appbean.AppErrorCode; + +public class AppEcode { + AppErrorCode errorCode; + MId mid; + + + public AppEcode(AppErrorCode errorCode, MId mid) { + this.errorCode = errorCode; + this.mid = mid; + } + + public AppEcode(AppErrorCode errorCode) { + this.errorCode = errorCode; + this.mid = MId.NotSet; + } + + public boolean isOk() { + return errorCode == AppErrorCode.Success; + } + + public MId getMid() { + return mid; + } + +} diff --git a/src/main/java/a8k/base_hardware/A8kCanBusService.java b/src/main/java/a8k/base_hardware/A8kCanBusService.java index 156a167..a8ae7ec 100644 --- a/src/main/java/a8k/base_hardware/A8kCanBusService.java +++ b/src/main/java/a8k/base_hardware/A8kCanBusService.java @@ -1,6 +1,7 @@ package a8k.base_hardware; import a8k.a8k_can_protocol.*; +import a8k.a8k_can_protocol.MId; import a8k.appbean.HardwareException; import a8k.appbean.appevent.A8kHardwareReport; import a8k.service.AppEventBusService; @@ -52,21 +53,21 @@ public class A8kCanBusService { @Autowired private AppEventBusService eventBusService; - public String uri; // assign by application.yml + public String uri; // assign by application.yml private WebSocketClient client; // 接收回执上下文 public BlockingQueue receiptQueue = new LinkedBlockingQueue(); // - boolean isWaitingReceipt = false; // - int waitingReceiptIndex = 0;// + boolean isWaitingReceipt = false; // + int waitingReceiptIndex = 0;// // 发送包的packetIndex int packetIndex = 0;// // 调试标志位 - boolean debugFlag = true;// + boolean debugFlag = true;// // websocket自动重连时间 - Timer autoConnectTimer = new Timer();// + Timer autoConnectTimer = new Timer();// @PostConstruct public void init() throws URISyntaxException { @@ -111,8 +112,7 @@ public class A8kCanBusService { client.connect(); } catch (IllegalStateException e) { } - } else if (client.getReadyState().equals(ReadyState.CLOSING) - || client.getReadyState().equals(ReadyState.CLOSED)) { + } else if (client.getReadyState().equals(ReadyState.CLOSING) || client.getReadyState().equals(ReadyState.CLOSED)) { client.reconnect(); } } @@ -121,8 +121,8 @@ public class A8kCanBusService { } private A8kPacket packParamsToPacket(Integer moduleId, Integer cmdId, Integer[] params) { - int subCmdId = cmdId & 0xFF; - int mainCmdId = (cmdId >> 8) & 0xFFFF; + int subCmdId = cmdId & 0xFF; + int mainCmdId = (cmdId >> 8) & 0xFFFF; int bufferSize = 2 + 2 + 1 + 1 + 2 + 4 * params.length; // PacketIndex - MainCmdId - SubCmdId - CmdType - // ModuleId - Parameters ByteBuffer buffer = ByteBuffer.allocate(bufferSize); @@ -141,139 +141,139 @@ public class A8kCanBusService { // // module opeation // - public void modulePing(int id) throws HardwareException { - callcmd(id, CmdId.kmodule_ping); + public void modulePing(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kmodule_ping); } - public void moduleStop(int id) throws HardwareException { - callcmd(id, CmdId.kmodule_stop); + public void moduleStop(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kmodule_stop); } - public ModuleStatus getModuleStatus(int id) throws HardwareException { - var packet = callcmd(id, CmdId.kmodule_get_status); + public ModuleStatus getModuleStatus(MId id) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.kmodule_get_status); return ModuleStatus.valueOf(packet.getContentI32(0)); } - public void moduleSetReg(int id, RegIndex regindex, int reg) throws HardwareException { - callcmd(id, CmdId.kmodule_set_reg, regindex.ordinal(), reg); + public void moduleSetReg(MId id, RegIndex regindex, int reg) throws HardwareException { + callcmd(id.toInt(), CmdId.kmodule_set_reg, regindex.ordinal(), reg); } - public int moduleGetReg(int id, RegIndex regindex) throws HardwareException { - var packet = callcmd(id, CmdId.kmodule_get_reg, regindex.ordinal()); + public int moduleGetReg(MId id, RegIndex regindex) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.kmodule_get_reg, regindex.ordinal()); return packet.getContentI32(0); } - public int moduleGetError(int id) throws HardwareException { - var packet = callcmd(id, CmdId.kmodule_get_error); + public int moduleGetError(MId id) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.kmodule_get_error); return packet.getContentI32(0); } - public void moduleClearError(int id) throws HardwareException { - callcmd(id, CmdId.kmodule_clear_error); + public void moduleClearError(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kmodule_clear_error); } - public void moduleActiveCfg(int id) throws HardwareException { - callcmd(id, CmdId.kmodule_active_cfg); + public void moduleActiveCfg(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kmodule_active_cfg); } // // stepMotor // - public void stepMotorEnable(int mid, int enable) throws HardwareException { - callcmd(mid, CmdId.kstep_motor_enable, enable); + public void stepMotorEnable(MId mid, int enable) throws HardwareException { + callcmd(mid.toInt(), CmdId.kstep_motor_enable, enable); } - public int stepMotorReadPos(int id) throws HardwareException { - A8kPacket packet = callcmd(id, CmdId.kstep_motor_read_pos); + public int stepMotorReadPos(MId id) throws HardwareException { + A8kPacket packet = callcmd(id.toInt(), CmdId.kstep_motor_read_pos); return packet.getContentI32(0); } - public void stepMotorEasyRotate(int id, int direction) throws HardwareException { - callcmd(id, CmdId.kstep_motor_easy_rotate, direction); + public void stepMotorEasyRotate(MId id, int direction) throws HardwareException { + callcmd(id.toInt(), CmdId.kstep_motor_easy_rotate, direction); } - public void stepMotorEasyMoveBy(int id, int dpos) throws HardwareException { - callcmd(id, CmdId.kstep_motor_easy_move_by, dpos); + public void stepMotorEasyMoveBy(MId id, int dpos) throws HardwareException { + callcmd(id.toInt(), CmdId.kstep_motor_easy_move_by, dpos); } - public void stepMotorEasyMoveTo(int id, int pos) throws HardwareException { - callcmd(id, CmdId.kstep_motor_easy_move_to, pos); + public void stepMotorEasyMoveTo(MId id, int pos) throws HardwareException { + callcmd(id.toInt(), CmdId.kstep_motor_easy_move_to, pos); } - public void stepMotorEasyMoveToZero(int id) throws HardwareException { - callcmd(id, CmdId.kstep_motor_easy_move_to_zero); + public void stepMotorEasyMoveToZero(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kstep_motor_easy_move_to_zero); } - public void stepMotorEasySetCurrentPos(int id, int pos) throws HardwareException { - callcmd(id, CmdId.kstep_motor_easy_set_current_pos, pos); + public void stepMotorEasySetCurrentPos(MId id, int pos) throws HardwareException { + callcmd(id.toInt(), CmdId.kstep_motor_easy_set_current_pos, pos); } - public void stepMotorEasyMoveToIo(int id, int io) throws HardwareException { - callcmd(id, CmdId.kstep_motor_easy_move_to_io, io); + public void stepMotorEasyMoveToIo(MId id, int io) throws HardwareException { + callcmd(id.toInt(), CmdId.kstep_motor_easy_move_to_io, io); } - public void stepMotorStop(int id) throws HardwareException { - callcmd(id, CmdId.kstep_motor_stop); + public void stepMotorStop(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kstep_motor_stop); } - public void stepMotorActiveCfg(int id) throws HardwareException { - callcmd(id, CmdId.kstep_motor_active_cfg); + public void stepMotorActiveCfg(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kstep_motor_active_cfg); } - public int stepMotorReadIoState(int id) throws HardwareException { - var packet = callcmd(id, CmdId.kstep_motor_read_io_state); + public int stepMotorReadIoState(MId id) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.kstep_motor_read_io_state); return packet.getContentI32(0); } - public void stepMotorEasyMoveToEndPoint(int id) throws HardwareException { - callcmd(id, CmdId.kstep_motor_easy_move_to_end_point); + public void stepMotorEasyMoveToEndPoint(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kstep_motor_easy_move_to_end_point); } - public void stepMotorEasyReciprocatingMotion(int id, int startpos, int endpos, int times) throws HardwareException { - callcmd(id, CmdId.kstep_motor_easy_reciprocating_motion, startpos, endpos, times); + public void stepMotorEasyReciprocatingMotion(MId id, int startpos, int endpos, int times) throws HardwareException { + callcmd(id.toInt(), CmdId.kstep_motor_easy_reciprocating_motion, startpos, endpos, times); } // // MINI_SERVO // - public void miniServoEnable(int id, int enable) throws HardwareException { - callcmd(id, CmdId.kmini_servo_enable, enable); + public void miniServoEnable(MId id, int enable) throws HardwareException { + callcmd(id.toInt(), CmdId.kmini_servo_enable, enable); } - public int miniServoReadPos(int id) throws HardwareException { - var packet = callcmd(id, CmdId.kmini_servo_read_pos); + public int miniServoReadPos(MId id) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.kmini_servo_read_pos); return packet.getContentI32(0); } - public void miniServoActiveCfg(int id) throws HardwareException { - callcmd(id, CmdId.kmini_servo_active_cfg); + public void miniServoActiveCfg(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kmini_servo_active_cfg); } - public void miniServoStop(int id) throws HardwareException { - callcmd(id, CmdId.kmini_servo_stop); + public void miniServoStop(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kmini_servo_stop); } - public void miniServoSetMidPoint(int id) throws HardwareException { - callcmd(id, CmdId.kmini_servo_set_mid_point); + public void miniServoSetMidPoint(MId id) throws HardwareException { + callcmd(id.toInt(), CmdId.kmini_servo_set_mid_point); } - public int miniServoReadIoState(int id) throws HardwareException { - var packet = callcmd(id, CmdId.kmini_servo_read_io_state); + public int miniServoReadIoState(MId id) throws HardwareException { + var packet = callcmd(id.toInt(), CmdId.kmini_servo_read_io_state); return packet.getContentI32(0); } - public void miniServoMoveTo(int id, int pos) throws HardwareException { - callcmd(id, CmdId.kmini_servo_move_to, pos); + public void miniServoMoveTo(MId id, int pos) throws HardwareException { + callcmd(id.toInt(), CmdId.kmini_servo_move_to, pos); } - public void miniServoRotate(int id, int direction) throws HardwareException { - callcmd(id, CmdId.kmini_servo_rotate, direction); + public void miniServoRotate(MId id, int direction) throws HardwareException { + callcmd(id.toInt(), CmdId.kmini_servo_rotate, direction); } - public void miniServoRotateWithTorque(int id, int torque) throws HardwareException { - callcmd(id, CmdId.kmini_servo_rotate_with_torque, torque); + public void miniServoRotateWithTorque(MId id, int torque) throws HardwareException { + callcmd(id.toInt(), CmdId.kmini_servo_rotate_with_torque, torque); } public boolean getIOState(IOId ioid) throws HardwareException { @@ -296,51 +296,67 @@ public class A8kCanBusService { } } + public void waitForMod(MId mid, Integer acitionOvertime) throws InterruptedException, HardwareException { + long startedAt = System.currentTimeMillis(); + do { + try { + var status = getModuleStatus(mid); + if (status == ModuleStatus.IDLE) { + break; + } else if (status == ModuleStatus.ERROR) { + throw new HardwareException(mid.toInt(), moduleGetError(mid)); + } + } catch (HardwareException ignored) { + } + long now = System.currentTimeMillis(); + if (now - startedAt > acitionOvertime) { + throw new HardwareException(mid.toInt(), Errorcode.kovertime); + } + + Thread.sleep(100); + } while (true); + + } + public A8kPacket callcmd(Integer moduleId, Integer cmdId) throws HardwareException { - return this.callcmd(moduleId, cmdId, new Integer[] {}); + return this.callcmd(moduleId, cmdId, new Integer[]{}); } public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0) throws HardwareException { - return this.callcmd(moduleId, cmdId, new Integer[] { p0 }); + return this.callcmd(moduleId, cmdId, new Integer[]{p0}); } public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1) throws HardwareException { - return this.callcmd(moduleId, cmdId, new Integer[] { p0, p1 }); + return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1}); } - public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2) - throws HardwareException { - return this.callcmd(moduleId, cmdId, new Integer[] { p0, p1, p2 }); + public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2) throws HardwareException { + return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1, p2}); } - public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3) - throws HardwareException { - return this.callcmd(moduleId, cmdId, new Integer[] { p0, p1, p2, p3 }); + public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3) throws HardwareException { + return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1, p2, p3}); } - public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3, - Integer acitionOvertime) throws HardwareException, InterruptedException { - this.callblockcmd(moduleId, cmdId, new Integer[] { p0, p1, p2, p3 }, acitionOvertime); + + public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3, Integer acitionOvertime) throws HardwareException, InterruptedException { + this.callblockcmd(moduleId, cmdId, new Integer[]{p0, p1, p2, p3}, acitionOvertime); } - public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, - Integer acitionOvertime) throws HardwareException, InterruptedException { - this.callblockcmd(moduleId, cmdId, new Integer[] { p0, p1, p2 }, acitionOvertime); + public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer acitionOvertime) throws HardwareException, InterruptedException { + this.callblockcmd(moduleId, cmdId, new Integer[]{p0, p1, p2}, acitionOvertime); } - public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer acitionOvertime) - throws HardwareException, InterruptedException { - this.callblockcmd(moduleId, cmdId, new Integer[] { p0, p1 }, acitionOvertime); + public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer acitionOvertime) throws HardwareException, InterruptedException { + this.callblockcmd(moduleId, cmdId, new Integer[]{p0, p1}, acitionOvertime); } - public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer acitionOvertime) - throws HardwareException, InterruptedException { - this.callblockcmd(moduleId, cmdId, new Integer[] { p0 }, acitionOvertime); + public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer acitionOvertime) throws HardwareException, InterruptedException { + this.callblockcmd(moduleId, cmdId, new Integer[]{p0}, acitionOvertime); } - public void callblockcmd(Integer moduleId, Integer cmdId, Integer acitionOvertime) - throws HardwareException, InterruptedException { - this.callblockcmd(moduleId, cmdId, new Integer[] {}, acitionOvertime); + public void callblockcmd(Integer moduleId, Integer cmdId, Integer acitionOvertime) throws HardwareException, InterruptedException { + this.callblockcmd(moduleId, cmdId, new Integer[]{}, acitionOvertime); } // TODO @@ -374,8 +390,7 @@ public class A8kCanBusService { return null; } - public void callblockcmd(Integer moduleId, Integer cmdId, Integer[] params, int acitionOvertime) - throws HardwareException, InterruptedException { + public void callblockcmd(Integer moduleId, Integer cmdId, Integer[] params, int acitionOvertime) throws HardwareException, InterruptedException { var packet = this.packParamsToPacket(moduleId, cmdId, params); this.sendCmdAutoResend(packet, A8kPacket.CMD_OVERTIME); @@ -385,7 +400,7 @@ public class A8kCanBusService { long startedAt = System.currentTimeMillis(); do { - var pack = this.callcmd(moduleId, CmdId.kmodule_get_status, new Integer[] {}); + var pack = this.callcmd(moduleId, CmdId.kmodule_get_status, new Integer[]{}); var status = pack.getContentI32(0); if (0 == status) { break; @@ -403,7 +418,7 @@ public class A8kCanBusService { private A8kPacket sendCmd(A8kPacket pack, int overtime) throws HardwareException { pack.setPacketIndex(packetIndex); waitingReceiptIndex = packetIndex; - packetIndex = packetIndex + 1; + packetIndex = packetIndex + 1; if (packetIndex > 10000) { packetIndex = 1; } @@ -458,8 +473,7 @@ public class A8kCanBusService { logger.info("RX {}:({})", packet, rx); } - if (packet.getPacketType() == A8kPacket.PACKET_TYPE_ACK - || packet.getPacketType() == A8kPacket.PACKET_TYPE_ERROR_ACK) { + if (packet.getPacketType() == A8kPacket.PACKET_TYPE_ACK || packet.getPacketType() == A8kPacket.PACKET_TYPE_ERROR_ACK) { if (isWaitingReceipt) { if (waitingReceiptIndex == packet.getPacketIndex()) { receiptQueue.add(packet); diff --git a/src/main/java/a8k/controller/TmpTestController.java b/src/main/java/a8k/controller/TmpTestController.java index 4359310..2a7e4a7 100644 --- a/src/main/java/a8k/controller/TmpTestController.java +++ b/src/main/java/a8k/controller/TmpTestController.java @@ -1,7 +1,7 @@ package a8k.controller; import a8k.a8k_can_protocol.CmdId; -import a8k.a8k_can_protocol.ModuleId; +import a8k.a8k_can_protocol.ModId; import a8k.appbean.AppErrorCode; import a8k.appbean.HardwareException; import a8k.base_hardware.A8kCanBusService; @@ -58,8 +58,8 @@ public class TmpTestController { @GetMapping("/tmp-test/a8k-can-bus-service-call") @ResponseBody public String a8kCanBusServiceCall() throws HardwareException, InterruptedException { - this.a8kCanBusService.callcmd(ModuleId.ShakeModTubeScanerRotateSV, CmdId.kmini_servo_enable, new Integer[]{1}); - this.a8kCanBusService.callblockcmd(ModuleId.FeedingModInfeedM, CmdId.kstep_motor_easy_move_by, new Integer[]{5000}, 20000); + this.a8kCanBusService.callcmd(ModId.ShakeModTubeScanerRotateSV, CmdId.kmini_servo_enable, new Integer[]{1}); + this.a8kCanBusService.callblockcmd(ModId.FeedingModInfeedM, CmdId.kstep_motor_easy_move_by, new Integer[]{5000}, 20000); return "OK"; } diff --git a/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java b/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java index db1fc28..d986083 100644 --- a/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java +++ b/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java @@ -1,8 +1,10 @@ package a8k.service.ctrl_service; -import a8k.a8k_can_protocol.ModuleId; +import a8k.a8k_can_protocol.IOId; +import a8k.a8k_can_protocol.MId; import a8k.appbean.AppErrorCode; import a8k.appbean.HardwareException; +import a8k.appbean.ecode.AppEcode; import a8k.base_hardware.A8kCanBusService; import a8k.service.db.dao.SamplesPreProcessModuleCtrlParamsService; import jakarta.annotation.Resource; @@ -10,6 +12,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; + @Component public class DeviceInitializationCtrlService { public static final Logger logger = LoggerFactory.getLogger(DeviceInitializationCtrlService.class); @@ -23,7 +26,6 @@ public class DeviceInitializationCtrlService { * 2.试管夹紧 * 3.抓手平移 * 4.抓手 - * 0. * 1. 抓手尝试移动到夹紧位置,等待一定时间,如果没有移动到夹紧位置,则返回错误。 * 2. 试管夹紧电机归零,超时一定时间,没有归零,则返回错误。 * 3. 抓手平移电机,移动到待机位,如果移动不到,则返回错误。 @@ -48,9 +50,11 @@ public class DeviceInitializationCtrlService { * 7. 试管架平移电机复位 * 8. 板夹仓平移电机复位 * 9. 板夹仓推杆电机复位 - * 10. * */ + + final Integer actionOvertime = 5000; + @Resource A8kCanBusService canBus; @@ -58,49 +62,78 @@ public class DeviceInitializationCtrlService { SamplesPreProcessModuleCtrlParamsService samplesPreProcessModuleCtrlParams; + private AppErrorCode hardwareStaticInit() throws HardwareException { + /* + * 硬件初始化: + * 1.使能所有舵机 + * 2.打开必要的电源 + * 3.使能所有电机 + */ + + //使能所有电机 + canBus.stepMotorEnable(MId.HbotM, 1); + canBus.stepMotorEnable(MId.PlatesBoxYM, 1); + canBus.stepMotorEnable(MId.ShakeModClampingM, 1); + canBus.stepMotorEnable(MId.ShakeModGripperZM, 1); + canBus.stepMotorEnable(MId.ShakeModShakeM, 1); + canBus.stepMotorEnable(MId.ShakeModGripperYM, 1); + canBus.stepMotorEnable(MId.FeedingModInfeedM, 1); + canBus.stepMotorEnable(MId.FeedingModXM, 1); + canBus.stepMotorEnable(MId.FeedingModOutfeedM, 1); + canBus.stepMotorEnable(MId.PipetteModZM, 1); + canBus.stepMotorEnable(MId.OptModPullM, 1); + + //使能所有舵机 + canBus.miniServoEnable(MId.ShakeModGripperSV, 1); + canBus.miniServoEnable(MId.ShakeModTubeScanerClampingSV, 1); + canBus.miniServoEnable(MId.ShakeModTubeScanerRotateSV, 1); + + //打开必要的电源 + canBus.setIOState(IOId.RecycleBinOverflowPPSPowerCtrl, true); + return AppErrorCode.Success; + } + + private AppEcode checkDeviceState() throws HardwareException { + /* + * 初始化前检查: + * 1. 试管平移通道是否有障碍 + * 2. 板夹仓盖子是否盖上 + * 3. 板夹推杆是否在原点 + * 4. 板夹拉取是否在终点或者原点 + */ + + //试管平移通道是否有障碍 + boolean var = canBus.getIOState(IOId.THChInterPPS); + if (var) + return new AppEcode(AppErrorCode.PlateStuckDetectorSensorTrigger); + + + return new AppEcode(AppErrorCode.Success); + + } + + public AppErrorCode initializeDevice() { logger.info("Initializing device ..."); try { -// canBus.getIOState(IOId.THChDetecterOuter,); + /* + * 复位思路 + * 硬件初始化: + * 检查 + * 复位 + * 清空耗材 + */ - canBus.stepMotorEasyMoveToZero(ModuleId.ShakeModGripperZM); + canBus.stepMotorEasyMoveToZero(MId.ShakeModGripperZM); + canBus.waitForMod(MId.ShakeModGripperZM, actionOvertime); } catch (HardwareException e) { + logger.error("HardwareException"); + throw new RuntimeException(e); + } catch (InterruptedException e) { + logger.error("InterruptedException"); throw new RuntimeException(e); } -// this.a8kCanBusService.callblockcmd( -// ModuleId.ServoTubeCapClipModule, -// CmdId.kmini_servo_move_to, -// params.getGripperServo_standbyPos(), -// params.getActionOvertime() -// ); -// -// this.a8kCanBusService.callblockcmd( -// ModuleId.MotorTubeMoveUpDownModule, -// CmdId.kstep_motor_easy_move_to_zero, -// params.getMoveToZeroOvertime() -// ); -// -// this.a8kCanBusService.callblockcmd( -// ModuleId.ServoTubeMoveFrontBackModule, -// CmdId.kmini_servo_move_to, -// params.getHorizontalMotor_standbyPos(), -// params.getActionOvertime() -// ); -// -// this.a8kCanBusService.callblockcmd( -// ModuleId.MotorTubeShakeModule, -// CmdId.kstep_motor_easy_move_to_zero, -// params.getMoveToZeroOvertime() -// ); -// -// this.a8kCanBusService.callblockcmd( -// ModuleId.MotorTubeScanClampModule, -// CmdId.kstep_motor_easy_move_to_zero, -// params.getMoveToZeroOvertime() -// ); -// - return AppErrorCode.Success; } diff --git a/src/main/java/a8k/service/hardware/MotorTubeRackMoveCtrlService.java b/src/main/java/a8k/service/hardware/MotorTubeRackMoveCtrlService.java index ebdb54c..242e07c 100644 --- a/src/main/java/a8k/service/hardware/MotorTubeRackMoveCtrlService.java +++ b/src/main/java/a8k/service/hardware/MotorTubeRackMoveCtrlService.java @@ -52,24 +52,24 @@ public class MotorTubeRackMoveCtrlService { public void moveToZeroWhenDeviceSetup() throws HardwareException, InterruptedException { var params = this.serviceParameterDao.getParameter(); - this.a8kCanBusService.callblockcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_easy_move_to_zero, new Integer[]{}, params.moveToZeroOvertime); + this.a8kCanBusService.callblockcmd(ModId.FeedingModXM, CmdId.kstep_motor_easy_move_to_zero, new Integer[]{}, params.moveToZeroOvertime); } public void moveToZero() throws HardwareException, InterruptedException { var params = this.serviceParameterDao.getParameter(); - var beforePosResponse = this.a8kCanBusService.callcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_read_pos, new Integer[]{0}); + var beforePosResponse = this.a8kCanBusService.callcmd(ModId.FeedingModXM, CmdId.kstep_motor_read_pos, new Integer[]{0}); var beforePos = beforePosResponse.getContentI32(0); - this.a8kCanBusService.callblockcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_easy_move_to_zero, new Integer[]{}, params.moveToZeroOvertime); - var afterPosResponse = this.a8kCanBusService.callcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_read_pos, new Integer[]{0}); + this.a8kCanBusService.callblockcmd(ModId.FeedingModXM, CmdId.kstep_motor_easy_move_to_zero, new Integer[]{}, params.moveToZeroOvertime); + var afterPosResponse = this.a8kCanBusService.callcmd(ModId.FeedingModXM, CmdId.kstep_motor_read_pos, new Integer[]{0}); var afterPos = afterPosResponse.getContentI32(0); var distance = beforePos - afterPos; - var dval = a8kCanBusService.module_read_reg(ModuleId.FeedingModXM, RegIndex.kreg_step_motor_dpos); + var dval = a8kCanBusService.module_read_reg(ModId.FeedingModXM, RegIndex.kreg_step_motor_dpos); if (Math.abs(dval - distance) > params.horizontalMotorLostStepThresholdVal) { - throw new HardwareException(ModuleId.FeedingModXM, Errorcode.kstep_motor_lost_step); + throw new HardwareException(ModId.FeedingModXM, Errorcode.kstep_motor_lost_step); } //先通过move_to 指令移动到零点 @@ -92,7 +92,7 @@ public class MotorTubeRackMoveCtrlService { */ public void moveTubeRackToEnterPos() throws HardwareException, InterruptedException { var params = this.serviceParameterDao.getParameter(); - this.a8kCanBusService.callblockcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{params.tubeRackEnterPos}, params.actionOvertime); + this.a8kCanBusService.callblockcmd(ModId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{params.tubeRackEnterPos}, params.actionOvertime); } /** @@ -100,7 +100,7 @@ public class MotorTubeRackMoveCtrlService { */ public void moveTubeRackToExitPos() throws HardwareException, InterruptedException { var params = this.serviceParameterDao.getParameter(); - this.a8kCanBusService.callblockcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{params.tubeExistJudgmentPos}, params.actionOvertime); + this.a8kCanBusService.callblockcmd(ModId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{params.tubeExistJudgmentPos}, params.actionOvertime); } /** @@ -108,7 +108,7 @@ public class MotorTubeRackMoveCtrlService { */ public void moveTubeRackToScanPos() throws HardwareException, InterruptedException { var params = this.serviceParameterDao.getParameter(); - this.a8kCanBusService.callblockcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{params.tubeRackScanCodePos}, params.actionOvertime); + this.a8kCanBusService.callblockcmd(ModId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{params.tubeRackScanCodePos}, params.actionOvertime); } /** @@ -116,10 +116,10 @@ public class MotorTubeRackMoveCtrlService { */ public String moveTubeRackToScanPosAndScan() throws HardwareException, InterruptedException { this.moveTubeRackToScanPos(); - this.a8kCanBusService.callcmd(ModuleId.FeedingModScannerM, CmdId.kcode_scaner_start_scan, new Integer[]{}); + this.a8kCanBusService.callcmd(ModId.FeedingModScannerMod, CmdId.kcode_scaner_start_scan, new Integer[]{}); Thread.sleep(500); - var response = this.a8kCanBusService.callcmd(ModuleId.FeedingModScannerM, CmdId.kcode_scaner_read_scaner_result, new Integer[]{}); - this.a8kCanBusService.callcmd(ModuleId.FeedingModScannerM, CmdId.kcode_scaner_stop_scan, new Integer[]{}); + var response = this.a8kCanBusService.callcmd(ModId.FeedingModScannerMod, CmdId.kcode_scaner_read_scaner_result, new Integer[]{}); + this.a8kCanBusService.callcmd(ModId.FeedingModScannerMod, CmdId.kcode_scaner_stop_scan, new Integer[]{}); var contentBytes = response.getCmdContent(); return new String(contentBytes); } @@ -138,7 +138,7 @@ public class MotorTubeRackMoveCtrlService { var params = this.serviceParameterDao.getParameter(); var tubeInfo = this.tubeInfoDao.getTubeInfo(tubeType); var scanPos = params.tubeScanPos + tubeIndex * tubeInfo.tubeSpacing; - this.a8kCanBusService.callblockcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{scanPos}, params.actionOvertime); + this.a8kCanBusService.callblockcmd(ModId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{scanPos}, params.actionOvertime); } /** @@ -149,10 +149,10 @@ public class MotorTubeRackMoveCtrlService { public String moveTubeToScanPosAndScan(String tubeType, Integer tubeIndex) throws HardwareException, InterruptedException { this.moveTubeToScanPos(tubeType, tubeIndex); - this.a8kCanBusService.callcmd(ModuleId.FeedingModScannerM, CmdId.kcode_scaner_start_scan, new Integer[]{}); + this.a8kCanBusService.callcmd(ModId.FeedingModScannerMod, CmdId.kcode_scaner_start_scan, new Integer[]{}); Thread.sleep(500); - var response = this.a8kCanBusService.callcmd(ModuleId.FeedingModScannerM, CmdId.kcode_scaner_read_scaner_result, new Integer[]{}); - this.a8kCanBusService.callcmd(ModuleId.FeedingModScannerM, CmdId.kcode_scaner_stop_scan, new Integer[]{}); + var response = this.a8kCanBusService.callcmd(ModId.FeedingModScannerMod, CmdId.kcode_scaner_read_scaner_result, new Integer[]{}); + this.a8kCanBusService.callcmd(ModId.FeedingModScannerMod, CmdId.kcode_scaner_stop_scan, new Integer[]{}); var contentBytes = response.getCmdContent(); return new String(contentBytes); } @@ -166,7 +166,7 @@ public class MotorTubeRackMoveCtrlService { var params = this.serviceParameterDao.getParameter(); var tubeInfo = this.tubeInfoDao.getTubeInfo(tubeType); var detectPos = params.tubeHeighJudgmentPos + tubeIndex * tubeInfo.tubeSpacing; - this.a8kCanBusService.callblockcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{detectPos}, params.actionOvertime); + this.a8kCanBusService.callblockcmd(ModId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{detectPos}, params.actionOvertime); } /** @@ -178,7 +178,7 @@ public class MotorTubeRackMoveCtrlService { var params = this.serviceParameterDao.getParameter(); var tubeInfo = this.tubeInfoDao.getTubeInfo(tubeType); var pos = params.tubePreProcessPos + tubeIndex * tubeInfo.tubeSpacing; - this.a8kCanBusService.callblockcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{pos}, params.actionOvertime); + this.a8kCanBusService.callblockcmd(ModId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{pos}, params.actionOvertime); } // @@ -194,16 +194,16 @@ public class MotorTubeRackMoveCtrlService { var params = this.serviceParameterDao.getParameter(); var tubeInfo = this.tubeInfoDao.getTubeInfo(tubeType); var pos = params.tubeRackExitPos + tubeIndex * tubeInfo.tubeSpacing; - this.a8kCanBusService.callblockcmd(ModuleId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{pos}, params.actionOvertime); + this.a8kCanBusService.callblockcmd(ModId.FeedingModXM, CmdId.kstep_motor_easy_move_to, new Integer[]{pos}, params.actionOvertime); } public boolean isTubeRackInEnterPos() throws HardwareException { - var response = this.a8kCanBusService.callcmd(ModuleId.FeedingModBoard, CmdId.kxymotor_read_inio, new Integer[]{3}); + var response = this.a8kCanBusService.callcmd(ModId.FeedingModBoard, CmdId.kxymotor_read_inio, new Integer[]{3}); return response.getContentI32(0) == 1; } public boolean isTubeRackInExitPos() throws HardwareException { - var response = this.a8kCanBusService.callcmd(ModuleId.FeedingModBoard, CmdId.kxymotor_read_inio, new Integer[]{5}); + var response = this.a8kCanBusService.callcmd(ModId.FeedingModBoard, CmdId.kxymotor_read_inio, new Integer[]{5}); return response.getContentI32(0) == 1; } @@ -214,7 +214,7 @@ public class MotorTubeRackMoveCtrlService { */ public boolean getMoveChannelPhotoelectricState(int photoelectricIndex) throws HardwareException { var index = 0 == photoelectricIndex ? 2 : 1; - var response = this.a8kCanBusService.callcmd(ModuleId.FeedingModBoard, CmdId.kxymotor_read_inio, new Integer[]{index}); + var response = this.a8kCanBusService.callcmd(ModId.FeedingModBoard, CmdId.kxymotor_read_inio, new Integer[]{index}); return response.getContentI32(0) == 1; } @@ -228,7 +228,7 @@ public class MotorTubeRackMoveCtrlService { */ public void scanClampModuleCompress() throws HardwareException, InterruptedException { var params = this.serviceParameterDao.getParameter(); - this.a8kCanBusService.callblockcmd(ModuleId.ShakeModTubeScanerClampingSV, CmdId.kmini_servo_move_to, new Integer[]{params.scanCodeClampPos}, params.actionOvertime); + this.a8kCanBusService.callblockcmd(ModId.ShakeModTubeScanerClampingSV, CmdId.kmini_servo_move_to, new Integer[]{params.scanCodeClampPos}, params.actionOvertime); } /** @@ -236,7 +236,7 @@ public class MotorTubeRackMoveCtrlService { */ public void scanClampModuleReset() throws HardwareException, InterruptedException { var params = this.serviceParameterDao.getParameter(); - this.a8kCanBusService.callblockcmd(ModuleId.ShakeModTubeScanerClampingSV, CmdId.kmini_servo_move_to, new Integer[]{params.scanCodeReleasePos}, params.actionOvertime); + this.a8kCanBusService.callblockcmd(ModId.ShakeModTubeScanerClampingSV, CmdId.kmini_servo_move_to, new Integer[]{params.scanCodeReleasePos}, params.actionOvertime); } diff --git a/src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java b/src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java index 172b107..c7d7c88 100644 --- a/src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java +++ b/src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java @@ -1,7 +1,7 @@ package a8k.service.hardware; import a8k.a8k_can_protocol.CmdId; -import a8k.a8k_can_protocol.ModuleId; +import a8k.a8k_can_protocol.ModId; import a8k.appbean.A8kTubeType; import a8k.appbean.AppErrorCode; import a8k.appbean.HardwareException; @@ -36,33 +36,33 @@ public class SamplesPreProcessModuleCtrlService { public void moveToZero() throws HardwareException, InterruptedException { var params = this.samplesPreProcessModuleCtrlParamsService; this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_move_to, params.getGripperServo_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to_zero, params.getMoveToZeroOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModShakeM, + ModId.ShakeModShakeM, CmdId.kstep_motor_easy_move_to_zero, params.getMoveToZeroOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModClampingM, + ModId.ShakeModClampingM, CmdId.kstep_motor_easy_move_to_zero, params.getMoveToZeroOvertime() ); @@ -79,27 +79,27 @@ public class SamplesPreProcessModuleCtrlService { */ public void enableModule(Boolean enable) throws HardwareException { this.a8kCanBusService.callcmd( - ModuleId.ShakeModShakeM, + ModId.ShakeModShakeM, CmdId.kstep_motor_enable, enable ? 1 : 0 ); this.a8kCanBusService.callcmd( - ModuleId.ShakeModClampingM, + ModId.ShakeModClampingM, CmdId.kstep_motor_enable, enable ? 1 : 0 ); this.a8kCanBusService.callcmd( - ModuleId.ShakeModClampingM, + ModId.ShakeModClampingM, CmdId.kstep_motor_enable, enable ? 1 : 0 ); this.a8kCanBusService.callcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_enable, enable ? 1 : 0 ); this.a8kCanBusService.callcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_enable, enable ? 1 : 0 ); @@ -133,7 +133,7 @@ public class SamplesPreProcessModuleCtrlService { public AppErrorCode takeTube(String tubeType, Boolean judgeCapExist) throws HardwareException, InterruptedException { var params = this.samplesPreProcessModuleCtrlParamsService; this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_takeCapPos(), params.getActionOvertime() @@ -145,27 +145,27 @@ public class SamplesPreProcessModuleCtrlService { motorUdTubeTaskPos = params.getZMotor_HighBloodTakeCapHeight(); } this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, motorUdTubeTaskPos, params.getActionOvertime() ); if ( judgeCapExist ) { - this.a8kCanBusService.callcmd( - ModuleId.ShakeModGripperSV, + this.a8kCanBusService.callblockcmd( + ModId.ShakeModClampingM, CmdId.kmini_servo_rotate_with_torque, params.getGripperServo_takeCapTorque() ); UfCommon.delay(3000); this.a8kCanBusService.callcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_stop, 1 ); UfCommon.delay(1000); var pos = this.a8kCanBusService.callcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_read_pos ); if ( pos.getContentI32(0) > params.getGripperServo_hatDeterminesPosThres() ) { @@ -174,63 +174,63 @@ public class SamplesPreProcessModuleCtrlService { } this.a8kCanBusService.callcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_rotate_with_torque, params.getGripperServo_takeCapTorque() ); UfCommon.delay(3000); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, 0, params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_takePushCapPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModShakeM, + ModId.ShakeModShakeM, CmdId.kstep_motor_easy_move_to, params.getShakeMotor_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModClampingM, + ModId.ShakeModClampingM, CmdId.kstep_motor_easy_move_to, params.getTubeClampMotor_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, params.getZMotor_placeShakeHeight(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_move_to, params.getGripperServo_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, 0, params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_standbyPos(), params.getActionOvertime() @@ -254,15 +254,15 @@ public class SamplesPreProcessModuleCtrlService { public AppErrorCode takeTubeCap( String tubeType ) throws HardwareException, InterruptedException { var params = this.samplesPreProcessModuleCtrlParamsService; this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_takePushCapPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperSV, - CmdId.kmini_servo_move_to, + ModId.ShakeModGripperSV, + CmdId.kstep_motor_easy_move_to, params.getGripperServo_standbyPos(), params.getActionOvertime() ); @@ -273,28 +273,28 @@ public class SamplesPreProcessModuleCtrlService { motorUdTakeCapPos = params.getZMotor_HighBloodTakeCapHeight(); } this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, motorUdTakeCapPos, params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_move_to, params.getGripperServo_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, 0, params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_standbyPos(), params.getActionOvertime() @@ -308,14 +308,14 @@ public class SamplesPreProcessModuleCtrlService { public void pushBackTubeCapAndTakeBakTube(String tubeType) throws HardwareException, InterruptedException { var params = this.samplesPreProcessModuleCtrlParamsService; this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_takePushCapPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_move_to, params.getGripperServo_standbyPos(), params.getActionOvertime() @@ -327,21 +327,21 @@ public class SamplesPreProcessModuleCtrlService { motorUdTakeCapPos = params.getZMotor_HighBloodTakeCapHeight(); } this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, motorUdTakeCapPos, params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_move_to, params.getGripperServo_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, 0, params.getActionOvertime() @@ -349,7 +349,7 @@ public class SamplesPreProcessModuleCtrlService { // 前后移至试管架取试管位置 this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_takeCapPos(), params.getActionOvertime() @@ -361,15 +361,15 @@ public class SamplesPreProcessModuleCtrlService { motorUdTubePutPos = params.getZMotor_HighBloodTakeCapHeight(); } this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, - motorUdTubePutPos, + motorUdTubePutPos, params.getActionOvertime() ); // 夹爪张开 this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_move_to, params.getGripperServo_standbyPos(), params.getActionOvertime() @@ -377,7 +377,7 @@ public class SamplesPreProcessModuleCtrlService { // 升降电机复位 this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, 0, params.getActionOvertime() @@ -385,7 +385,7 @@ public class SamplesPreProcessModuleCtrlService { // 前后电机复位 this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_standbyPos(), params.getActionOvertime() @@ -409,7 +409,7 @@ public class SamplesPreProcessModuleCtrlService { var startPos = standByPos - shakeDegree/2; var endPos = standByPos + shakeDegree/2; this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModShakeM, + ModId.ShakeModShakeM, CmdId.kstep_motor_easy_reciprocating_motion, startPos, endPos, @@ -423,14 +423,14 @@ public class SamplesPreProcessModuleCtrlService { */ public void openAerosolFan() throws HardwareException { var params = this.samplesPreProcessModuleCtrlParamsService; - this.a8kCanBusService.callcmd(ModuleId.WbTubeFanModule, CmdId.kfan_controler_set_speed, params.getAerosolFanLevel()); + this.a8kCanBusService.callcmd(ModId.WbTubeFanMod, CmdId.kfan_controler_set_speed, params.getAerosolFanLevel()); } /** * 关闭气溶胶风扇 */ public void closeAerosolFan() throws HardwareException { - this.a8kCanBusService.callcmd(ModuleId.WbTubeFanModule, CmdId.kfan_controler_set_speed, 0); + this.a8kCanBusService.callcmd(ModId.WbTubeFanMod, CmdId.kfan_controler_set_speed, 0); } /** @@ -439,29 +439,29 @@ public class SamplesPreProcessModuleCtrlService { public void moduleResetWhenPowerOn() throws HardwareException, InterruptedException { var params = this.samplesPreProcessModuleCtrlParamsService; this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_move_to, params.getGripperServo_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to_zero, params.getMoveToZeroOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModClampingM, + ModId.ShakeModClampingM, CmdId.kstep_motor_easy_move_to_zero, params.getMoveToZeroOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModShakeM, + ModId.ShakeModShakeM, CmdId.kstep_motor_easy_move_to_zero, params.getMoveToZeroOvertime() ); @@ -473,47 +473,47 @@ public class SamplesPreProcessModuleCtrlService { public void moduleRuntimeReset() throws HardwareException, InterruptedException { var params = this.samplesPreProcessModuleCtrlParamsService; this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperSV, + ModId.ShakeModGripperSV, CmdId.kmini_servo_move_to, params.getGripperServo_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to, 0, params.getMoveToZeroOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperZM, + ModId.ShakeModGripperZM, CmdId.kstep_motor_easy_move_to_zero, params.getMoveToZeroOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModGripperYM, + ModId.ShakeModGripperYM, CmdId.kmini_servo_move_to, params.getHorizontalMotor_standbyPos(), params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModClampingM, + ModId.ShakeModClampingM, CmdId.kstep_motor_easy_move_to, 0, params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModClampingM, + ModId.ShakeModClampingM, CmdId.kstep_motor_easy_move_to_zero, params.getMoveToZeroOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModShakeM, + ModId.ShakeModShakeM, CmdId.kstep_motor_easy_move_to, 0, params.getActionOvertime() ); this.a8kCanBusService.callblockcmd( - ModuleId.ShakeModShakeM, + ModId.ShakeModShakeM, CmdId.kstep_motor_easy_move_to_zero, params.getMoveToZeroOvertime() );