Browse Source

update

tags/v0
zhaohe 1 year ago
parent
commit
4cd1ca3013
  1. 30
      src/main/java/a8k/a8k_can_protocol/ModuleId.java
  2. 91
      src/main/java/a8k/base_hardware/A8kCanBusService.java
  3. 101
      src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java
  4. 12
      src/main/java/a8k/service/hardware/MotorTubeRackMoveCtrlService.java
  5. 4
      src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java

30
src/main/java/a8k/a8k_can_protocol/ModuleId.java

@ -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";

91
src/main/java/a8k/base_hardware/A8kCanBusService.java

@ -52,21 +52,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<A8kPacket> receiptQueue = new LinkedBlockingQueue<A8kPacket>(); //
boolean isWaitingReceipt = false; //
int waitingReceiptIndex = 0;//
boolean isWaitingReceipt = false; //
int waitingReceiptIndex = 0;//
// 发送包的packetIndex
int packetIndex = 0;//
// 调试标志位
boolean debugFlag = false;//
boolean debugFlag = false;//
// websocket自动重连时间
Timer autoConnectTimer = new Timer();//
Timer autoConnectTimer = new Timer();//
@PostConstruct
public void init() throws URISyntaxException {
@ -111,8 +111,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 +120,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);
@ -296,51 +295,67 @@ public class A8kCanBusService {
}
}
public void waitForMod(Integer moduleId, Integer acitionOvertime) throws InterruptedException, HardwareException {
long startedAt = System.currentTimeMillis();
do {
try {
var status = getModuleStatus(moduleId);
if (status == ModuleStatus.IDLE) {
break;
} else if (status == ModuleStatus.ERROR) {
throw new HardwareException(moduleId, moduleGetError(moduleId));
}
} catch (HardwareException ignored) {
}
long now = System.currentTimeMillis();
if (now - startedAt > acitionOvertime) {
throw new HardwareException(moduleId, 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 +389,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 +399,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 +417,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 +472,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);

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

@ -48,9 +48,11 @@ public class DeviceInitializationCtrlService {
* 7. 试管架平移电机复位
* 8. 板夹仓平移电机复位
* 9. 板夹仓推杆电机复位
* 10.
*
*/
final Integer actionOvertime = 5000;
@Resource
A8kCanBusService canBus;
@ -58,49 +60,78 @@ public class DeviceInitializationCtrlService {
SamplesPreProcessModuleCtrlParamsService samplesPreProcessModuleCtrlParams;
private void hardwareStaticInit() {
/*
* 复位思路
* 硬件初始化:
* 1.使能所有舵机
* 2.打开必要的电源
* 3.使能所有电机
*/
// public static final int HbotM = 11;//机械臂XY
// public static final int PlatesBoxYM = 21;//板夹仓移动电机
// public static final int PlatesBoxPusherM = 22;//板夹仓推杆电机
// public static final int ShakeModClampingM = 31;//试管固定夹爪电机
// public static final int ShakeModGripperZM = 32;//摇匀升降电机
// public static final int ShakeModShakeM = 33;//试管摇匀电机
// public static final int ShakeModGripperYM = 34;//摇匀前后电机
// 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 IncubatorRotateCtrlM = 71;//孵育盘旋转
// public static final int PipetteModZMotor = 81;//机械臂Z
// public static final int OptModScannerMotor = 91;//板卡扫描电机
// public static final int OptModPullM = 92;//板卡推杆电机
//
// public static final int ShakeModGripperSV = 35;//摇匀试管帽夹爪
// public static final int ShakeModTubeScanerClampingSV = 36;//试管架旋转固定舵机
// public static final int ShakeModTubeScanerRotateSV = 37;//试管架旋转舵机
}
public AppErrorCode initializeDevice() {
logger.info("Initializing device ...");
try {
// canBus.getIOState(IOId.THChDetecterOuter,);
/*
* 复位思路
* 硬件初始化:
* 1.使能所有舵机
* 2.打开必要的电源
* 3.使能所有电机
*
* 检查
* 1.试管平移通道是否有障碍
* 2.板夹仓盖子是否盖上
* 3.推杆卡板光电是否触发
* 4.拉杆卡板光电是否触发
* 5.回收站光电是否被触发
*
*
* 复位
* 1.
*
*
* 清空设备
*
*
*
*/
canBus.stepMotorEasyMoveToZero(ModuleId.ShakeModGripperZM);
canBus.waitForMod(ModuleId.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;
}

12
src/main/java/a8k/service/hardware/MotorTubeRackMoveCtrlService.java

@ -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(ModuleId.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(ModuleId.FeedingModScannerMod, CmdId.kcode_scaner_read_scaner_result, new Integer[]{});
this.a8kCanBusService.callcmd(ModuleId.FeedingModScannerMod, CmdId.kcode_scaner_stop_scan, new Integer[]{});
var contentBytes = response.getCmdContent();
return new String(contentBytes);
}
@ -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(ModuleId.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(ModuleId.FeedingModScannerMod, CmdId.kcode_scaner_read_scaner_result, new Integer[]{});
this.a8kCanBusService.callcmd(ModuleId.FeedingModScannerMod, CmdId.kcode_scaner_stop_scan, new Integer[]{});
var contentBytes = response.getCmdContent();
return new String(contentBytes);
}

4
src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java

@ -358,14 +358,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(ModuleId.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(ModuleId.WbTubeFanMod, CmdId.kfan_controler_set_speed, 0);
}
/**

Loading…
Cancel
Save