Browse Source

添加通用硬件操作

tags/v0
zhaohe 1 year ago
parent
commit
73b83cbfee
  1. 3
      src/main/java/a8k/appbean/HardwareException.java
  2. 6
      src/main/java/a8k/appbean/ecode/AppEcode.java
  3. 23
      src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java
  4. 126
      src/main/java/a8k/service/hardware/CommonHardwareOpeartion.java
  5. BIN
      zhaohe_app.db

3
src/main/java/a8k/appbean/HardwareException.java

@ -19,11 +19,12 @@ public class HardwareException extends Exception {
this.moduleId = moduleId; this.moduleId = moduleId;
} }
int getModuleId() {
public int getModuleId() {
return moduleId; return moduleId;
} }
public int getErrorCode() { public int getErrorCode() {
return errorCode; return errorCode;
} }
} }

6
src/main/java/a8k/appbean/ecode/AppEcode.java

@ -2,6 +2,7 @@ package a8k.appbean.ecode;
import a8k.a8k_can_protocol.MId; import a8k.a8k_can_protocol.MId;
import a8k.a8k_can_protocol.A8kEcode; import a8k.a8k_can_protocol.A8kEcode;
import a8k.appbean.HardwareException;
public class AppEcode { public class AppEcode {
public A8kEcode errorCode; public A8kEcode errorCode;
@ -13,6 +14,11 @@ public class AppEcode {
this.mid = mid; this.mid = mid;
} }
public AppEcode(HardwareException e) {
this.errorCode = A8kEcode.valueOf(e.getErrorCode());
this.mid = MId.valueOf(e.getModuleId());
}
public AppEcode(A8kEcode errorCode) { public AppEcode(A8kEcode errorCode) {
this.errorCode = errorCode; this.errorCode = errorCode;
this.mid = MId.NotSet; this.mid = MId.NotSet;

23
src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java

@ -7,6 +7,7 @@ import a8k.appbean.HardwareException;
import a8k.appbean.ecode.AppEcode; import a8k.appbean.ecode.AppEcode;
import a8k.base_hardware.A8kCanBusService; import a8k.base_hardware.A8kCanBusService;
import a8k.service.db.dao.SamplesPreProcessModuleCtrlParamsService; import a8k.service.db.dao.SamplesPreProcessModuleCtrlParamsService;
import a8k.service.hardware.CommonHardwareOpeartion;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -24,6 +25,9 @@ public class DeviceInitializationCtrlService {
A8kCanBusService canBus; A8kCanBusService canBus;
@Resource @Resource
CommonHardwareOpeartion hardwareOpeartion;
@Resource
SamplesPreProcessModuleCtrlParamsService samplesPreProcessModuleCtrlParams; SamplesPreProcessModuleCtrlParamsService samplesPreProcessModuleCtrlParams;
@ -35,6 +39,7 @@ public class DeviceInitializationCtrlService {
* 3.使能所有电机 * 3.使能所有电机
*/ */
hardwareOpeartion.enableAllMotor();
//打开必要的电源 //打开必要的电源
canBus.setIOState(IOId.RecycleBinOverflowPPSPowerCtrl, true); canBus.setIOState(IOId.RecycleBinOverflowPPSPowerCtrl, true);
@ -165,10 +170,10 @@ public class DeviceInitializationCtrlService {
} }
//复位设备 //复位设备
// ecode = moveMotorToZero();
// if (!ecode.isOk()) {
// return ecode;
// }
ecode = moveMotorToZero();
if (!ecode.isOk()) {
return ecode;
}
//清空耗材 //清空耗材
@ -177,10 +182,16 @@ public class DeviceInitializationCtrlService {
logger.error("HardwareException %s", e); logger.error("HardwareException %s", e);
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
logger.error("InterruptedException");
logger.error("InterruptedException", e);
throw new RuntimeException(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); return new AppEcode(A8kEcode.Success);
} }

126
src/main/java/a8k/service/hardware/CommonHardwareOpeartion.java

@ -0,0 +1,126 @@
package a8k.service.hardware;
import a8k.a8k_can_protocol.A8kEcode;
import a8k.a8k_can_protocol.MId;
import a8k.appbean.HardwareException;
import a8k.appbean.ecode.AppEcode;
import a8k.base_hardware.A8kCanBusService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
@Component
public class CommonHardwareOpeartion {
@Resource
A8kCanBusService canBus;
public AppEcode enableAllMotorNoExcep() {
try {
enableAllMotor();
} catch (HardwareException e) {
return new AppEcode(e);
}
return new AppEcode(A8kEcode.Success);
}
public AppEcode disableAllMotorNoExcep() {
try {
enableAllMotor();
} catch (HardwareException e) {
return new AppEcode(e);
}
return new AppEcode(A8kEcode.Success);
}
public void enableAllMotor() throws HardwareException {
//进出料初始化
canBus.stepMotorEnable(MId.FeedingModInfeedM, 1);
canBus.stepMotorEnable(MId.FeedingModXM, 1);
canBus.stepMotorEnable(MId.FeedingModOutfeedM, 1);
//摇匀模组初始化
canBus.stepMotorEnable(MId.ShakeModClampingM, 1);
canBus.stepMotorEnable(MId.ShakeModGripperZM, 1);
canBus.stepMotorEnable(MId.ShakeModShakeM, 1);
canBus.miniServoEnable(MId.ShakeModGripperYM, 1);
canBus.miniServoEnable(MId.ShakeModGripperSV, 1);
canBus.miniServoEnable(MId.ShakeModTubeScanerClampingSV, 1);
canBus.miniServoEnable(MId.ShakeModTubeScanerRotateSV, 1);
//板夹仓初始化
canBus.stepMotorEnable(MId.PlatesBoxYM, 1);
canBus.stepMotorEnable(MId.PlatesBoxPusherM, 1);
//光学模组初始化
canBus.stepMotorEnable(MId.OptModPullM, 1);
canBus.stepMotorEnable(MId.OptModScannerM, 1);
//HBot初始化
canBus.stepMotorEnable(MId.HbotM, 1);
canBus.stepMotorEnable(MId.PipetteModZM, 1);
//转盘归零
canBus.stepMotorEnable(MId.IncubatorRotateCtrlM, 1);
}
public void disableAllMotor() throws HardwareException {
//进出料初始化
canBus.stepMotorEnable(MId.FeedingModInfeedM, 0);
canBus.stepMotorEnable(MId.FeedingModXM, 0);
canBus.stepMotorEnable(MId.FeedingModOutfeedM, 0);
//摇匀模组初始化
canBus.stepMotorEnable(MId.ShakeModClampingM, 0);
canBus.stepMotorEnable(MId.ShakeModGripperZM, 0);
canBus.stepMotorEnable(MId.ShakeModShakeM, 0);
canBus.miniServoEnable(MId.ShakeModGripperYM, 0);
canBus.miniServoEnable(MId.ShakeModGripperSV, 0);
canBus.miniServoEnable(MId.ShakeModTubeScanerClampingSV, 0);
canBus.miniServoEnable(MId.ShakeModTubeScanerRotateSV, 0);
//板夹仓初始化
canBus.stepMotorEnable(MId.PlatesBoxYM, 0);
canBus.stepMotorEnable(MId.PlatesBoxPusherM, 0);
//光学模组初始化
canBus.stepMotorEnable(MId.OptModPullM, 0);
canBus.stepMotorEnable(MId.OptModScannerM, 0);
//HBot初始化
canBus.stepMotorEnable(MId.HbotM, 0);
canBus.stepMotorEnable(MId.PipetteModZM, 0);
//转盘归零
canBus.stepMotorEnable(MId.IncubatorRotateCtrlM, 0);
}
public void stopAllMOtor() {
//进出料初始化
try {canBus.moduleStop(MId.FeedingModInfeedM);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.FeedingModXM);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.FeedingModOutfeedM);} catch (HardwareException ignored) {}
//摇匀模组初始化
try {canBus.moduleStop(MId.ShakeModClampingM);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.ShakeModGripperZM);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.ShakeModShakeM);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.ShakeModGripperYM);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.ShakeModGripperSV);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.ShakeModTubeScanerClampingSV);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.ShakeModTubeScanerRotateSV);} catch (HardwareException ignored) {}
//板夹仓初始化
try {canBus.moduleStop(MId.PlatesBoxYM);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.PlatesBoxPusherM);} catch (HardwareException ignored) {}
//光学模组初始化
try {canBus.moduleStop(MId.OptModPullM);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.OptModScannerM);} catch (HardwareException ignored) {}
//HBot初始化
try {canBus.moduleStop(MId.HbotM);} catch (HardwareException ignored) {}
try {canBus.moduleStop(MId.PipetteModZM);} catch (HardwareException ignored) {}
//转盘归零
try {canBus.moduleStop(MId.IncubatorRotateCtrlM);} catch (HardwareException ignored) {}
}
}

BIN
zhaohe_app.db

Loading…
Cancel
Save