diff --git a/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugDisabledAllMotorCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugDisabledAllMotorCommand.java index 36adefa..0467936 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugDisabledAllMotorCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugDisabledAllMotorCommand.java @@ -18,7 +18,7 @@ import java.util.concurrent.CompletableFuture; @Slf4j @Component @RequiredArgsConstructor -@CommandDebugMapping("debug_disabled_all_motor") +@CommandDebugMapping("disable_all_motor") public class DebugDisabledAllMotorCommand extends BaseCommandHandler { private final DeviceCommandService deviceCommandService; diff --git a/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugEnableAllMotorCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugEnableAllMotorCommand.java index 2997407..c08b430 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugEnableAllMotorCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugEnableAllMotorCommand.java @@ -18,7 +18,7 @@ import java.util.concurrent.CompletableFuture; @Slf4j @Component @RequiredArgsConstructor -@CommandDebugMapping("debug_enable_all_motor") +@CommandDebugMapping("enable_all_motor") public class DebugEnableAllMotorCommand extends BaseCommandHandler { private final DeviceCommandService deviceCommandService; @Override diff --git a/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugStopAllMotorCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugStopAllMotorCommand.java index 5f979e1..609d99d 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugStopAllMotorCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugStopAllMotorCommand.java @@ -18,7 +18,7 @@ import java.util.concurrent.CompletableFuture; @Slf4j @Component @RequiredArgsConstructor -@CommandDebugMapping("debug_stop_all_motor") +@CommandDebugMapping("stop_all_motor") public class DebugStopAllMotorCommand extends BaseCommandHandler { private final DeviceCommandService deviceCommandService; diff --git a/src/main/java/com/iflytop/sgs/app/controller/MotorController.java b/src/main/java/com/iflytop/sgs/app/controller/MotorController.java index a3dbba8..daa407e 100644 --- a/src/main/java/com/iflytop/sgs/app/controller/MotorController.java +++ b/src/main/java/com/iflytop/sgs/app/controller/MotorController.java @@ -22,24 +22,23 @@ import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @Slf4j public class MotorController { - - private DeviceSensorService deviceSensorService; + private final DeviceSensorService deviceSensorService; @Operation(summary = "获取当前电机位置") @GetMapping("/position/{motor}") public Result getPosition(@PathVariable String motor) { - if(motor.equals("Transfer")){ + if (motor.equals("Transfer")) { try { - double xPosition=deviceSensorService.getXYServoPosition(DevicePartId.XSV); - double zPosition=deviceSensorService.getXYServoPosition(DevicePartId.ZM); - String position=String.format("%.2f,0,%.2f",xPosition,zPosition); + double xPosition = deviceSensorService.getXYServoPosition(DevicePartId.XSV); + double zPosition = deviceSensorService.getMotorPosition(DevicePartId.ZM); + String position = String.format("%.2f,0,%.2f", xPosition, zPosition); return Result.success(position); } catch (HardwareException e) { throw new RuntimeException(e); } - }else{ + } else { DevicePartId devicePartId = DevicePartId.valueOf(motor); Double position; try { diff --git a/src/main/java/com/iflytop/sgs/app/service/device/DeviceInitService.java b/src/main/java/com/iflytop/sgs/app/service/device/DeviceInitService.java index 3ab9bab..593746b 100644 --- a/src/main/java/com/iflytop/sgs/app/service/device/DeviceInitService.java +++ b/src/main/java/com/iflytop/sgs/app/service/device/DeviceInitService.java @@ -103,6 +103,20 @@ public class DeviceInitService { //蠕动泵 DeviceCommandBundle liquidPumpEnableDeviceCommandBundle = DeviceCommandGenerator.liquidPumpEnable(); deviceCommandService.sendCommand(liquidPumpEnableDeviceCommandBundle); + + //开抱闸 + DeviceCommandBundle doorOpenClampDeviceCommandBundle = DeviceCommandGenerator.doorOpenClamp(); + deviceCommandService.sendCommand(doorOpenClampDeviceCommandBundle); + + DeviceCommandBundle transferZOpenClampDeviceCommandBundle = DeviceCommandGenerator.transferZOpenClamp(); + deviceCommandService.sendCommand(transferZOpenClampDeviceCommandBundle); + + DeviceCommandBundle transferXOpenClampDeviceCommandBundle = DeviceCommandGenerator.transferXOpenClamp(); + deviceCommandService.sendCommand(transferXOpenClampDeviceCommandBundle); + + DeviceCommandBundle liquidMotorOpenClampDeviceCommandBundle = DeviceCommandGenerator.liquidMotorOpenClamp(); + deviceCommandService.sendCommand(liquidMotorOpenClampDeviceCommandBundle); + } diff --git a/src/main/java/com/iflytop/sgs/common/enums/data/DevicePositionCode.java b/src/main/java/com/iflytop/sgs/common/enums/data/DevicePositionCode.java index 2900f1b..fa52d7c 100644 --- a/src/main/java/com/iflytop/sgs/common/enums/data/DevicePositionCode.java +++ b/src/main/java/com/iflytop/sgs/common/enums/data/DevicePositionCode.java @@ -17,11 +17,11 @@ public enum DevicePositionCode { * 溶液首次预充距离 * */ solutionPreFillDistance(DevicePositionType.DISTANCE, "溶液首次预充距离"), - /* + /** * 稀硝酸预充距离 * */ thinPreFillDistance(DevicePositionType.DISTANCE,"稀硝酸预充距离"), - /* + /** * 浓硝酸预充距离 * */ thickPreFillDistance(DevicePositionType.DISTANCE,"浓硝酸预充距离"), diff --git a/src/main/java/com/iflytop/sgs/hardware/comm/can/A8kCanBusService.java b/src/main/java/com/iflytop/sgs/hardware/comm/can/A8kCanBusService.java index 7eab70d..716b198 100644 --- a/src/main/java/com/iflytop/sgs/hardware/comm/can/A8kCanBusService.java +++ b/src/main/java/com/iflytop/sgs/hardware/comm/can/A8kCanBusService.java @@ -19,134 +19,136 @@ import java.net.URISyntaxException; @Component @Slf4j public class A8kCanBusService implements CanBusService { - @Resource - A8kCanBusConnection connection; - @Resource - ActionOvertimeConstant actionOvertimeConstant; - - @Value("${device.enableCanBus}") - Boolean enableCanBus; - - @PostConstruct - public void init() throws URISyntaxException { - if (enableCanBus) { - connection.connect(); - }else{ - log.warn("canBus is disabled"); - } - } - - public Boolean ping(MId id) { - return connection.ping(id); - } - - /** - * 强制关闭websocket连接,让其与canbus服务重连 - */ - public void forceShutdown() { - connection.close(); - } - - // - // BASE_OPERATION - // - - public A8kPacket callcmd(MId moduleId, CmdId cmdId, Integer... param) throws HardwareException { - return connection.callcmd(moduleId, cmdId, param); - } - - public A8kPacket callcmd2(MId moduleId, CmdId cmdId, Integer overtime, Integer... params) throws HardwareException { - return connection.callcmd2(moduleId, cmdId, overtime, params); - } - - synchronized public A8kPacket send(A8kPacket pack, int overtime) throws HardwareException { - return connection.send(pack, overtime); - } - - // - // MODULE FUNCTION - // - - public void moduleStop(MId id) throws HardwareException { - connection.callcmd(id, CmdId.module_stop); - } - - public void moduleStopNoException(MId id) { - try { - moduleStop(id); - } catch (HardwareException ignored) { - } - } - - public ModuleStatus moduleGetStatus(MId id) throws HardwareException { - return connection.moduleGetStatus(id); - } - public void moduleSetRegByApp(String id, String regindex, Integer reg) throws HardwareException { - MId mId=MId.valueOf(id); - RegIndex regIndex=RegIndex.valueOf(reg); - this.moduleSetReg(mId,regIndex,reg); - } - /** - * 设置各动作超时时间 - */ - @Override - public void initOvertime() { + @Resource + A8kCanBusConnection connection; + @Resource + ActionOvertimeConstant actionOvertimeConstant; + + @Value("${device.enableCanBus}") + Boolean enableCanBus; + + @PostConstruct + public void init() throws URISyntaxException { + if (enableCanBus) { + connection.connect(); + } else { + log.warn("canBus is disabled"); + } + } + + public Boolean ping(MId id) { + return connection.ping(id); + } + + /** + * 强制关闭websocket连接,让其与canbus服务重连 + */ + public void forceShutdown() { + connection.close(); + } + + // + // BASE_OPERATION + // + + public A8kPacket callcmd(MId moduleId, CmdId cmdId, Integer... param) throws HardwareException { + return connection.callcmd(moduleId, cmdId, param); + } + + public A8kPacket callcmd2(MId moduleId, CmdId cmdId, Integer overtime, Integer... params) throws HardwareException { + return connection.callcmd2(moduleId, cmdId, overtime, params); + } + + synchronized public A8kPacket send(A8kPacket pack, int overtime) throws HardwareException { + return connection.send(pack, overtime); + } + + // + // MODULE FUNCTION + // + + public void moduleStop(MId id) throws HardwareException { + connection.callcmd(id, CmdId.module_stop); + } + + public void moduleStopNoException(MId id) { + try { + moduleStop(id); + } catch (HardwareException ignored) { + } + } + + public ModuleStatus moduleGetStatus(MId id) throws HardwareException { + return connection.moduleGetStatus(id); + } + + public void moduleSetRegByApp(String id, String regindex, Integer reg) throws HardwareException { + MId mId = MId.valueOf(id); + RegIndex regIndex = RegIndex.valueOf(regindex); + this.moduleSetReg(mId, regIndex, reg); + } + + /** + * 设置各动作超时时间 + */ + @Override + public void initOvertime() { actionOvertimeConstant.pushNewConfig(StepMotorMId.DoorM, CmdId.step_motor_easy_move_to_zero, 30 * 1000); actionOvertimeConstant.pushNewConfig(StepMotorMId.LiquidM, CmdId.step_motor_easy_move_to_zero, 30 * 1000); actionOvertimeConstant.pushNewConfig(StepMotorMId.LiquidPumpM, CmdId.step_motor_easy_move_to_zero, 30 * 1000); actionOvertimeConstant.pushNewConfig(StepMotorMId.ZM, CmdId.step_motor_easy_move_to_zero, 30 * 1000); - } - - public void moduleSetReg(MId id, RegIndex regindex, Integer reg) throws HardwareException { - connection.callcmd2(id, CmdId.module_set_reg, 100, regindex.index, reg); - } - - public Integer moduleGetReg(MId id, RegIndex regindex) throws HardwareException { - var packet = connection.callcmd2(id, CmdId.module_get_reg, 100, regindex.index); - return packet.getContentI32(0); - } - - public A8kEcode moduleGetError(MId id) throws HardwareException { - var packet = connection.callcmd(id, CmdId.module_get_error); - return A8kEcode.fromInt(packet.getContentI32(0)); - } - - public Integer moduleGetDetailError(MId id) throws HardwareException { - return connection.callcmd(id, CmdId.module_get_detail_error).getContentI32(0); - } - - public Integer moduleReadVersion(MId id) throws HardwareException { - return connection.callcmd(id, CmdId.module_get_version).getContentI32(0); - } - - public ModuleType moduleReadType(MId id) throws HardwareException { - var packet = connection.callcmd(id, CmdId.module_get_type); - return ModuleType.of(packet.getContentI32(0)); - } - - public void waitForMod(MId mid, Integer acitionOvertime) throws HardwareException { - long startedAt = System.currentTimeMillis(); - CmdId action = connection.getLastTxCmd(mid); - do { - ModuleStatus statu = moduleGetStatus(mid); - if (statu == ModuleStatus.IDLE) { - break; - } else if (statu == ModuleStatus.ERROR) { - log.error("{} waitting for action {} , catch error {}, defail ecode {}", mid, action, moduleGetError(mid), moduleGetDetailError(mid)); - throw HardwareException.of(new AEHardwareError(moduleGetError(mid), mid, action)); - } - long now = System.currentTimeMillis(); - if (now - startedAt > acitionOvertime) { - log.error("{} waitting for action {} overtime({})", mid, action, acitionOvertime); - moduleStopNoException(mid); - throw HardwareException.of(new AEHardwareError(A8kEcode.LOW_ERROR_ACTION_OVERTIME, mid, action)); - } - OS.hsleep(30); - } while (true); - } - - public boolean isConnect() { - return connection.isOpen(); - } + } + + public void moduleSetReg(MId id, RegIndex regindex, Integer reg) throws HardwareException { + connection.callcmd2(id, CmdId.module_set_reg, 100, regindex.index, reg); + } + + public Integer moduleGetReg(MId id, RegIndex regindex) throws HardwareException { + var packet = connection.callcmd2(id, CmdId.module_get_reg, 100, regindex.index); + return packet.getContentI32(0); + } + + public A8kEcode moduleGetError(MId id) throws HardwareException { + var packet = connection.callcmd(id, CmdId.module_get_error); + return A8kEcode.fromInt(packet.getContentI32(0)); + } + + public Integer moduleGetDetailError(MId id) throws HardwareException { + return connection.callcmd(id, CmdId.module_get_detail_error).getContentI32(0); + } + + public Integer moduleReadVersion(MId id) throws HardwareException { + return connection.callcmd(id, CmdId.module_get_version).getContentI32(0); + } + + public ModuleType moduleReadType(MId id) throws HardwareException { + var packet = connection.callcmd(id, CmdId.module_get_type); + return ModuleType.of(packet.getContentI32(0)); + } + + public void waitForMod(MId mid, Integer acitionOvertime) throws HardwareException { + long startedAt = System.currentTimeMillis(); + CmdId action = connection.getLastTxCmd(mid); + do { + ModuleStatus statu = moduleGetStatus(mid); + if (statu == ModuleStatus.IDLE) { + break; + } else if (statu == ModuleStatus.ERROR) { + log.error("{} waitting for action {} , catch error {}, defail ecode {}", mid, action, moduleGetError(mid), moduleGetDetailError(mid)); + throw HardwareException.of(new AEHardwareError(moduleGetError(mid), mid, action)); + } + long now = System.currentTimeMillis(); + if (now - startedAt > acitionOvertime) { + log.error("{} waitting for action {} overtime({})", mid, action, acitionOvertime); + moduleStopNoException(mid); + throw HardwareException.of(new AEHardwareError(A8kEcode.LOW_ERROR_ACTION_OVERTIME, mid, action)); + } + OS.hsleep(30); + } while (true); + } + + public boolean isConnect() { + return connection.isOpen(); + } } diff --git a/src/main/resources/sql/init.sql b/src/main/resources/sql/init.sql index 4354f3f..2f5cd32 100644 --- a/src/main/resources/sql/init.sql +++ b/src/main/resources/sql/init.sql @@ -35,26 +35,6 @@ CREATE TABLE IF NOT EXISTS device_position create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -INSERT OR IGNORE INTO device_position (id, name, code, type, position) -VALUES ('1', '预充防滴落距离', 'antiDripDistance', 'DISTANCE', '0'), - ('2', '溶液首次预充距离', 'solutionPreFillDistance', 'DISTANCE', '10'), - ('3', '稀硝酸预充距离', 'thinPreFillDistance', 'DISTANCE', '10'), - ('4', '浓硝酸预充距离', 'thickPreFillDistance', 'DISTANCE', '10'), - ('5', '蒸馏水预充距离', 'waterPreFillDistance', 'DISTANCE', '10'), - ('6', '托盘试管水平间距', 'trayTubeHorizontalSpacingDistance', 'DISTANCE', '10'), - ('7', '转运模块X轴拿取托盘进出卡槽移动距离', 'transferModuleXPickTrayMoveDistance', 'DISTANCE', '3'), - ('8', '加液模块电机下降进入试管加液位置', 'solutionModuleMotorDownInTubeAddPositon', 'POSITION', '2'), - ('9', '加液模块电机下降进入试管抽取位置', 'solutionModuleMotorDownInTubeExtPositon', 'POSITION', '5'), - ('10', '转运模块Z轴拿取托盘时起下降的高度位置', 'transferModuleZPickTrayDownPositon', 'POSITION', '2'), - ('11', '开门位置', 'doorOpenPosition', 'POSITION', '10'), - ('12', '关门位置', 'doorClosePosition', 'POSITION', '0'), - ('13', '上料区托盘夹爪位置点', 'feedAreaTrayPoint', 'POINT_3D', '10,10,10'), - ('14', '加液时托盘位置点', 'liquidAreaTrayPoint', 'POINT_3D', '10,10,10'), - ('15', '加热区1托盘夹爪位置点', 'heatArea1TrayClawPoint', 'POINT_3D', '10,10,10'), - ('16', '加热区2托盘夹爪位置点', 'heatArea2TrayClawPoint', 'POINT_3D', '10,10,10'), - ('17', '加热区3托盘夹爪位置点', 'heatArea3TrayClawPoint', 'POINT_3D', '10,10,10'), - ('18', '加热区4托盘夹爪位置点', 'heatArea4TrayClawPoint', 'POINT_3D', '10,10,10'); - -- 系统配置 表 CREATE TABLE IF NOT EXISTS system_config