From 425cb661422579cf85d560d8f490aa7239cd1c80 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 22 Jul 2024 11:02:39 +0800 Subject: [PATCH] update --- .../java/a8k/base_hardware/A8kCanBusService.java | 24 +++++ .../DeviceInitializationCtrlService.java | 108 ++++++++++----------- .../service/hardware/CommonHardwareOpeartion.java | 35 ++++++- 3 files changed, 112 insertions(+), 55 deletions(-) diff --git a/src/main/java/a8k/base_hardware/A8kCanBusService.java b/src/main/java/a8k/base_hardware/A8kCanBusService.java index 682fb9b..d6320c2 100644 --- a/src/main/java/a8k/base_hardware/A8kCanBusService.java +++ b/src/main/java/a8k/base_hardware/A8kCanBusService.java @@ -139,6 +139,10 @@ public class A8kCanBusService { return new A8kPacket(buffer.array()); } + + + + // // module opeation // @@ -178,6 +182,26 @@ public class A8kCanBusService { callcmd(id.toInt(), CmdId.kmodule_active_cfg); } +// public static final int kxymotor_enable = 0x0301; +// public static final int kxymotor_move_by = 0x0302; +// public static final int kxymotor_move_to = 0x0303; +// public static final int kxymotor_move_to_zero = 0x0304; +// public static final int kxymotor_read_pos = 0x0306; +// public static final int kxymotor_read_inio_index_in_stm32 = 0x0307; +// public static final int kxymotor_read_inio = 0x0308; +// public static final int kxymotor_set_pos = 0x0309; +// public static final int kxymotor_motor_move_by_direct = 0x030a; +// public static final int kxymotor_read_enc_direct = 0x030b; + + public void hbotEnable(MId mid, int enable) throws HardwareException { + callcmd(mid.toInt(), CmdId.kxymotor_enable, enable); + } + + + + + + // // stepMotor // diff --git a/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java b/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java index e1af2e4..05795b7 100644 --- a/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java +++ b/src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java @@ -25,12 +25,64 @@ public class DeviceInitializationCtrlService { A8kCanBusService canBus; @Resource - CommonHardwareOpeartion hardwareOpeartion; + CommonHardwareOpeartion commonHardOpera; @Resource SamplesPreProcessModuleCtrlParamsService samplesPreProcessModuleCtrlParams; + public AppEcode initializeDevice() { + logger.info("Initializing device ..."); + try { + /* + * 复位思路 + * 硬件初始化: + * 检查 + * 复位 + * 清空耗材 + */ + + AppEcode ecode; + //硬件光电初始化 + ecode = hardwareStaticInit(); + if (!ecode.isOk()) { + return ecode; + } + + //检查设备状态 + ecode = checkDeviceState(); + if (!ecode.isOk()) { + return ecode; + } + + //复位设备 +// ecode = moveMotorToZero(); +// if (!ecode.isOk()) { +// return ecode; +// } + //清空耗材 + + + } catch (HardwareException e) { + logger.error("HardwareException %s", e); + throw new RuntimeException(e); + } catch (InterruptedException e) { + logger.error("InterruptedException", e); + throw new RuntimeException(e); + } finally { + try { + canBus.stepMotorEnable(MId.ShakeModClampingM, 1); + canBus.stepMotorEasyMoveBy(MId.ShakeModClampingM, 2); + canBus.waitForMod(MId.ShakeModClampingM, actionOvertime); + commonHardOpera.forceStopAndDisableAllMOtor(); + } catch (HardwareException | InterruptedException ignored) { + } + } + + return new AppEcode(A8kEcode.Success); + } + + private AppEcode hardwareStaticInit() throws HardwareException, InterruptedException { /* * 硬件初始化: @@ -39,7 +91,7 @@ public class DeviceInitializationCtrlService { * 3.使能所有电机 */ - hardwareOpeartion.enableAllMotor(); + commonHardOpera.enableAllMotor(); //打开必要的电源 canBus.setIOState(IOId.RecycleBinOverflowPPSPowerCtrl, true); @@ -145,56 +197,4 @@ public class DeviceInitializationCtrlService { } - public AppEcode initializeDevice() { - logger.info("Initializing device ..."); - try { - /* - * 复位思路 - * 硬件初始化: - * 检查 - * 复位 - * 清空耗材 - */ - - AppEcode ecode; - //硬件光电初始化 - ecode = hardwareStaticInit(); - if (!ecode.isOk()) { - return ecode; - } - - //检查设备状态 - ecode = checkDeviceState(); - if (!ecode.isOk()) { - return ecode; - } - - //复位设备 - ecode = moveMotorToZero(); - if (!ecode.isOk()) { - return ecode; - } - - //清空耗材 - - - } catch (HardwareException e) { - logger.error("HardwareException %s", e); - throw new RuntimeException(e); - } catch (InterruptedException e) { - logger.error("InterruptedException", e); - throw new RuntimeException(e); - } finally { - try { - canBus.stepMotorEnable(MId.ShakeModClampingM, 1); - canBus.stepMotorEasyMoveBy(MId.ShakeModClampingM, 2); - canBus.waitForMod(MId.ShakeModClampingM, actionOvertime); - } catch (HardwareException | InterruptedException ignored) { - } - } - - return new AppEcode(A8kEcode.Success); - } - - } diff --git a/src/main/java/a8k/service/hardware/CommonHardwareOpeartion.java b/src/main/java/a8k/service/hardware/CommonHardwareOpeartion.java index a575990..b063580 100644 --- a/src/main/java/a8k/service/hardware/CommonHardwareOpeartion.java +++ b/src/main/java/a8k/service/hardware/CommonHardwareOpeartion.java @@ -97,7 +97,8 @@ public class CommonHardwareOpeartion { } - public void stopAllMOtor() { + public void forceStopAndDisableAllMOtor() { + //StopAllMotor //进出料初始化 try {canBus.moduleStop(MId.FeedingModInfeedM);} catch (HardwareException ignored) {} try {canBus.moduleStop(MId.FeedingModXM);} catch (HardwareException ignored) {} @@ -122,5 +123,37 @@ public class CommonHardwareOpeartion { //转盘归零 try {canBus.moduleStop(MId.IncubatorRotateCtrlM);} catch (HardwareException ignored) {} + //Disable all motor + //进出料初始化 + try {canBus.stepMotorEnable(MId.FeedingModInfeedM, 0);} catch (HardwareException ignored) {} + try {canBus.stepMotorEnable(MId.FeedingModXM, 0);} catch (HardwareException ignored) {} + try {canBus.stepMotorEnable(MId.FeedingModOutfeedM, 0);} catch (HardwareException ignored) {} + + //摇匀模组初始化 + try {canBus.stepMotorEnable(MId.ShakeModClampingM, 0);} catch (HardwareException ignored) {} + try {canBus.stepMotorEnable(MId.ShakeModGripperZM, 0);} catch (HardwareException ignored) {} + try {canBus.stepMotorEnable(MId.ShakeModShakeM, 0);} catch (HardwareException ignored) {} + try {canBus.miniServoEnable(MId.ShakeModGripperYM, 0);} catch (HardwareException ignored) {} + try {canBus.miniServoEnable(MId.ShakeModGripperSV, 0);} catch (HardwareException ignored) {} + try {canBus.miniServoEnable(MId.ShakeModTubeScanerClampingSV, 0);} catch (HardwareException ignored) {} + try {canBus.miniServoEnable(MId.ShakeModTubeScanerRotateSV, 0);} catch (HardwareException ignored) {} + + //板夹仓初始化 + try {canBus.stepMotorEnable(MId.PlatesBoxYM, 0);} catch (HardwareException ignored) {} + try {canBus.stepMotorEnable(MId.PlatesBoxPusherM, 0);} catch (HardwareException ignored) {} + + //光学模组初始化 + try {canBus.stepMotorEnable(MId.OptModPullM, 0);} catch (HardwareException ignored) {} + try {canBus.stepMotorEnable(MId.OptModScannerM, 0);} catch (HardwareException ignored) {} + + //HBot初始化 + try {canBus.stepMotorEnable(MId.HbotM, 0);} catch (HardwareException ignored) {} + try {canBus.stepMotorEnable(MId.PipetteModZM, 0);} catch (HardwareException ignored) {} + + //转盘归零 + try {canBus.stepMotorEnable(MId.IncubatorRotateCtrlM, 0);} catch (HardwareException ignored) {} + } + + }