白凤吉 2 months ago
parent
commit
066e26bd39
  1. 2
      src/main/java/com/iflytop/gd/app/model/bo/status/device/DeviceState.java
  2. 13
      src/main/java/com/iflytop/gd/app/model/bo/status/device/TrayState.java
  3. 7
      src/main/java/com/iflytop/gd/app/model/bo/status/device/TubeState.java
  4. 4
      src/main/java/com/iflytop/gd/app/model/dto/StartCraftsDTO.java
  5. 1
      src/main/java/com/iflytop/gd/app/service/api/CraftsService.java
  6. 5
      src/main/java/com/iflytop/gd/app/service/api/TrayService.java
  7. 14
      src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java
  8. 49
      src/main/java/com/iflytop/gd/app/service/device/module/SolutionModuleService.java
  9. 17
      src/main/java/com/iflytop/gd/app/service/scheduled/FetchTemperatureScheduledTask.java
  10. 38
      src/main/java/com/iflytop/gd/app/service/scheduled/HeatCountdownScheduledTask.java
  11. 2
      src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java

2
src/main/java/com/iflytop/gd/app/model/bo/status/device/DeviceState.java

@ -75,7 +75,7 @@ public class DeviceState {
public synchronized TrayState getTrayStateByHeatModuleCode(HeatModuleCode heatModuleCode) {
for (TrayState t : tray) {
if (t.getHeatModuleId().equals(heatModuleCode)) {
if (heatModuleCode.equals(t.getHeatModuleId())) {
return t;
}
}

13
src/main/java/com/iflytop/gd/app/model/bo/status/device/TrayState.java

@ -1,13 +1,22 @@
package com.iflytop.gd.app.model.bo.status.device;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.iflytop.gd.common.enums.HeatModuleCode;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.PostConstruct;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Schema(description = "托盘")
@Data
@Component
@Scope("prototype")
@RequiredArgsConstructor
@JsonIgnoreProperties(value = {"advisors", "frozen", "preFiltered", "proxyTargetClass", "targetSource", "exposeProxy", "advisorCount", "proxiedInterfaces", "targetClass"})
public class TrayState {
@Schema(description = "托盘唯一id")
private String uuid = UUID.randomUUID().toString();
@ -27,11 +36,13 @@ public class TrayState {
@Schema(description = "当前托盘的工艺")
private CraftsState crafts = null;
public TrayState() {
@PostConstruct
private void init(){
for (int i = 0; i < tubes.length; i++) {
TubeState tubeState = new TubeState();
tubeState.setTubeNum(i + 1);
tubes[i] = tubeState;
}
}
}

7
src/main/java/com/iflytop/gd/app/model/bo/status/device/TubeState.java

@ -9,12 +9,13 @@ public class TubeState {
@Schema(description = "试管编号")
private int tubeNum;
@Schema(description = "是否需要添加溶液 true需要")
private boolean addSolution = true;
@Schema(description = "是否添加过溶液 true添加过")
private boolean addSolution = false;
private boolean existSolution = false;
@Schema(description = "是否存在试管 true存在")
private boolean exists = true;
@Schema(description = "是否需要添加溶液 true需要")
private boolean needAddSolution = true;
}

4
src/main/java/com/iflytop/gd/app/model/dto/StartCraftsDTO.java

@ -1,5 +1,6 @@
package com.iflytop.gd.app.model.dto;
import com.iflytop.gd.app.model.bo.status.device.TubeState;
import com.iflytop.gd.common.enums.HeatModuleCode;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
@ -16,4 +17,7 @@ public class StartCraftsDTO {
@Schema(description = "加热区id,非必填,如果不传递则自动分配加热区")
private HeatModuleCode heatId;
@Schema(description = "试管")
private TubeState[] tubes;
}

1
src/main/java/com/iflytop/gd/app/service/api/CraftsService.java

@ -157,6 +157,7 @@ public class CraftsService extends ServiceImpl<CraftsMapper, Crafts> {
craftsState.setOres(ores);
craftsState.setState(CraftStates.READY);
craftsState.setCurrentIndex(0);
trayState.setHeatModuleId(heatModuleCode);
trayState.setCrafts(craftsState);
SetCraftsVO setCraftsVO = new SetCraftsVO();

5
src/main/java/com/iflytop/gd/app/service/api/TrayService.java

@ -1,10 +1,12 @@
package com.iflytop.gd.app.service.api;
import com.iflytop.gd.app.model.bo.status.device.HeatModuleState;
import com.iflytop.gd.app.model.bo.status.device.TrayState;
import com.iflytop.gd.app.model.vo.SetTrayTubeVO;
import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.app.service.device.module.SolutionModuleService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.stereotype.Service;
import java.util.List;
@ -17,12 +19,13 @@ import java.util.List;
public class TrayService {
private final DeviceStateService deviceStateService;
private final SolutionModuleService solutionModuleService;
private final ObjectProvider<TrayState> trayStateObjectProvider;
/**
* 放入了新托盘
*/
public synchronized TrayState trayIn() {
TrayState trayState = new TrayState();
TrayState trayState = trayStateObjectProvider.getObject();
trayState.setInSolutionModule(true);
deviceStateService.getDeviceState().getTray().add(trayState);
deviceStateService.getDeviceState().getSolutionModule().setTrayStatus(1);

14
src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java

@ -75,6 +75,15 @@ public class CraftsStepService {
&& deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTrayStatus() == 1) {
moveToSolutionModule(heatModuleCode);
}
JSONArray tubeNums = params.getJSONArray("tubeNums");
for (int i = 0; i < tubeNums.size(); i++) {
JSONObject tubeSol = tubeNums.getJSONObject(i);
Integer tubeNum = tubeSol.getInt("tubeNum");
}
JSONArray tubeSolList = params.getJSONArray("tubeSolList");
for (int i = 0; i < tubeSolList.size(); i++) {
JSONObject tubeSol = tubeSolList.getJSONObject(i);
@ -90,9 +99,7 @@ public class CraftsStepService {
}
AcidPumpDeviceCode acidPumpDevice = AcidPumpDeviceCode.valueOf(container.getPumpId());//
int scale = container.getScale() == null ? 120 : container.getScale();//系数
webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatModuleCode.toString(), "移动加液机械臂到指定试管", tubeNum));
solutionModuleService.dualRobotMovePoint(tubeNum);//移动加液机械臂到指定试管
webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatModuleCode.toString(), "添加溶液", addLiquid));
CommandFuture deviceCommandFuture = solutionModuleService.acidPumpMoveBy(acidPumpDevice, volume * ((double) scale /100));//添加溶液
CommandUtil.wait(deviceCommandFuture);
}
@ -131,9 +138,10 @@ public class CraftsStepService {
while (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature() + 1 < temperature) {
delay(1);
}
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.constant);
delay(second);
heatModuleService.heatRodClose(heatModuleCode);//停止加热
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.stop);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.finish);
heatModuleService.heaterMotorMove(heatModuleCode, trayLift);//抬升加热位托盘
return true;
}

49
src/main/java/com/iflytop/gd/app/service/device/module/SolutionModuleService.java

@ -85,29 +85,60 @@ public class SolutionModuleService {
* 双轴械臂 移动至指定试管
*/
public void dualRobotMovePoint(int index) throws Exception {
liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, index);
if (!deviceStateService.getDeviceState().isVirtual()) {
liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, index);
} else {
new Thread(() -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}).start();
}
}
/**
* 加液机械臂回原点
*/
public void dualRobotOrigin() throws Exception {
liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, 0);
if (!deviceStateService.getDeviceState().isVirtual()) {
liquidDistributionArmDriver.liquidDistributionArmMoveToBlock(LiquidArmMId.LiquidDistributionArm, 0);
} else {
new Thread(() -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}).start();
}
}
/**
* 加液机械臂回原点
*/
public void dualRobotOrigin(String commandId, String command, CmdAxis cmdAxis) throws Exception {
if (cmdAxis == CmdAxis.joint1) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.dualRobotJoint1Origin();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(commandId, command, deviceCommand);
CommandUtil.wait(deviceCommandFuture);
if (!deviceStateService.getDeviceState().isVirtual()) {
if (cmdAxis == CmdAxis.joint1) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.dualRobotJoint1Origin();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(commandId, command, deviceCommand);
CommandUtil.wait(deviceCommandFuture);
} else {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.dualRobotJoint2Origin();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(commandId, command, deviceCommand);
CommandUtil.wait(deviceCommandFuture);
}
} else {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.dualRobotJoint2Origin();
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(commandId, command, deviceCommand);
CommandUtil.wait(deviceCommandFuture);
new Thread(() -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}).start();
}
}

17
src/main/java/com/iflytop/gd/app/service/scheduled/FetchTemperatureScheduledTask.java

@ -1,5 +1,6 @@
package com.iflytop.gd.app.service.scheduled;
import com.iflytop.gd.app.model.bo.status.device.HeatModuleState;
import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.common.enums.HeatModuleCode;
import com.iflytop.gd.hardware.service.GDDeviceStatusService;
@ -9,6 +10,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor
@ -39,12 +42,14 @@ public class FetchTemperatureScheduledTask {
deviceStateService.getDeviceState().getHeatModuleByCode(HeatModuleCode.heat_module_06).setTemperature(heatModule06Temperature);
} else {//虚拟模式随便写个值
// List<HeatModuleState> heatModuleStateList = deviceStateService.getDeviceState().getHeatModule();
// for (HeatModuleState heatModuleState : heatModuleStateList) {
// if (heatModuleState.isHeating()) {
// deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleState.getModuleCode()).setTemperature(123.0);
// }
// }
List<HeatModuleState> heatModuleStateList = deviceStateService.getDeviceState().getHeatModule();
for (HeatModuleState heatModuleState : heatModuleStateList) {
if (heatModuleState.isHeating()) {
heatModuleState.setTemperature(heatModuleState.getTargetTemperature());
} else {
heatModuleState.setTemperature(26.0);
}
}
}
} catch (Exception e) {
log.error("定时采集加热棒温度错误", e);

38
src/main/java/com/iflytop/gd/app/service/scheduled/HeatCountdownScheduledTask.java

@ -1,6 +1,7 @@
package com.iflytop.gd.app.service.scheduled;
import com.iflytop.gd.app.model.bo.status.device.HeatModuleState;
import com.iflytop.gd.app.model.bo.status.device.TrayState;
import com.iflytop.gd.app.model.vo.HeatCountdownVO;
import com.iflytop.gd.app.service.api.DevicePositionService;
import com.iflytop.gd.app.service.device.DeviceStateService;
@ -21,7 +22,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* 加热倒计
* 加热时间到自动抬起
*/
@Slf4j
@Service
@ -36,8 +37,12 @@ public class HeatCountdownScheduledTask {
public void fetchTemperature() {
try {
LocalDateTime now = LocalDateTime.now();
List<HeatCountdownVO> heatCountdownVOList = new ArrayList<>();
for (HeatModuleState heatModuleState : deviceStateService.getDeviceState().getHeatModule()) {
//工艺除外
TrayState trayState = deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleState.getModuleCode());
if (trayState != null && trayState.getCrafts() != null) {
continue;
}
if (heatModuleState.getHeatingType() == HeatingType.thermostatic) {//如果这个加热模块在加热中
if (heatModuleState.getTemperature() + 1 > heatModuleState.getHeatTemperature()) {//当前温度达到目标温度允许有1度以内的误差
heatModuleState.setStartHeatTime(now);
@ -55,34 +60,15 @@ public class HeatCountdownScheduledTask {
//关闭加棒
heatModuleService.heatRodClose(heatModuleState.getModuleCode());
//还原状态
// heatModuleState.setStartHeatTime(null);
// heatModuleState.setTargetTime(null);
// heatModuleState.setWarmUpTemperature(null);
// heatModuleState.setHeatTemperature(null);
// heatModuleState.setTargetTemperature(null);
heatModuleState.setStartHeatTime(null);//开始加热时间
heatModuleState.setTargetTime(null);//加热器目标加热时间
heatModuleState.setWarmUpTemperature(null);//加热器预热温度
heatModuleState.setHeatTemperature(null);//加热器加热温度
heatModuleState.setTargetTemperature(null);//加热器目标温度
heatModuleState.setHeatingType(HeatingType.finish);
// HeatCountdownVO heatCountdownVO = new HeatCountdownVO();
// heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode());
// heatCountdownVO.setCountdown((int) diffSeconds);
// heatCountdownVO.setCountdownStr("加热完毕");
// heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime());
// heatCountdownVO.setEndTime(endTime);
// heatCountdownVOList.add(heatCountdownVO);
} else {//加热中 推送倒计时
// HeatCountdownVO heatCountdownVO = new HeatCountdownVO();
// heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode());
// heatCountdownVO.setCountdown((int) diffSeconds);
// heatCountdownVO.setCountdownStr(LocalDateTimeUtil.formatSecondsToHMS(diffSeconds));
// heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime());
// heatCountdownVO.setEndTime(endTime);
// heatCountdownVOList.add(heatCountdownVO);
}
}
}
if (!heatCountdownVOList.isEmpty()) {
webSocketSender.pushHeatCountdown(heatCountdownVOList);
}
} catch (Exception e) {
log.error("加热倒计时错误", e);
}

2
src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java

@ -16,7 +16,7 @@ public class WebSocketSender {
websocketResult.setType(type);
websocketResult.setData(data);
WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult));
log.info("WS::{}", JSONUtil.toJsonStr(websocketResult));
// log.info("WS::{}", JSONUtil.toJsonStr(websocketResult));
}
public void pushCraftsDebug(Object data) {

Loading…
Cancel
Save