Browse Source

调整加热逻辑,增加预热、降温的逻辑

修复部分工艺问题
master
白凤吉 2 months ago
parent
commit
ee2ba4f213
  1. 48
      src/main/java/com/iflytop/gd/app/command/control/MoveToHeatAreaCommand.java
  2. 51
      src/main/java/com/iflytop/gd/app/command/control/MoveToSolutionAreaCommand.java
  3. 5
      src/main/java/com/iflytop/gd/app/controller/TestController.java
  4. 5
      src/main/java/com/iflytop/gd/app/core/CraftsContext.java
  5. 6
      src/main/java/com/iflytop/gd/app/model/bo/status/device/HeatModuleState.java
  6. 32
      src/main/java/com/iflytop/gd/app/model/vo/HeatCountdownVO.java
  7. 32
      src/main/java/com/iflytop/gd/app/service/api/CraftsService.java
  8. 6
      src/main/java/com/iflytop/gd/app/service/api/TestService.java
  9. 3
      src/main/java/com/iflytop/gd/app/service/api/TrayService.java
  10. 240
      src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java
  11. 65
      src/main/java/com/iflytop/gd/app/service/device/DeviceInitService.java
  12. 59
      src/main/java/com/iflytop/gd/app/service/device/module/HeatModuleService.java
  13. 5
      src/main/java/com/iflytop/gd/app/service/scheduled/FetchTemperatureScheduledTask.java
  14. 5
      src/main/java/com/iflytop/gd/app/service/scheduled/HeatCountdownScheduledTask.java
  15. 4
      src/main/java/com/iflytop/gd/common/enums/HeatingType.java

48
src/main/java/com/iflytop/gd/app/command/control/MoveToHeatAreaCommand.java

@ -2,6 +2,9 @@ package com.iflytop.gd.app.command.control;
import com.iflytop.gd.app.core.BaseCommandHandler;
import com.iflytop.gd.app.model.bo.Point3D;
import com.iflytop.gd.app.model.bo.status.device.HeatModuleState;
import com.iflytop.gd.app.model.bo.status.device.SolutionModuleState;
import com.iflytop.gd.app.model.bo.status.device.TrayState;
import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.service.api.DevicePositionService;
import com.iflytop.gd.app.service.device.DeviceCommandTempUtilService;
@ -49,6 +52,27 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler {
}
String heatId = cmdDTO.getStringParam("heatId");
HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId);
//校验目标加热位是否有托盘
try {
deviceStateService.getCommandMutexState().get().setMoveToHeatAreaCommandExecuting(true);
HeatModuleState heatModuleState = deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode);
if(heatModuleState.getTrayStatus() == 1){
throw new AppException(ResultCode.TARGET_HEAT_MODULE_OCCUPIED);
}
// Boolean heatModuleTray = heatModuleService.heatModuleSensorState(heatModuleCode);
// if (heatModuleTray) {
// throw new AppException(ResultCode.TARGET_HEAT_MODULE_OCCUPIED);
// }
SolutionModuleState solutionModuleState = deviceStateService.getDeviceState().getSolutionModule();
if(solutionModuleState.getTrayStatus() == 0){
throw new AppException(ResultCode.SOLUTION_MODULE_NO_TRAY);
}
} catch (Exception e) {
deviceStateService.getCommandMutexState().get().setMoveToHeatAreaCommandExecuting(false);
throw e;
}
double clawCapPick = devicePositionService.getPosition(DevicePositionCode.clawCapPick).getDistance(); //获取拍子夹取距离
double clawCapGrip = devicePositionService.getPosition(DevicePositionCode.clawCapGrip).getDistance(); //获取拍子夹紧距离
double clawTrayPick = devicePositionService.getPosition(DevicePositionCode.clawTrayPick).getDistance();//获取夹爪托盘夹取距离
@ -66,51 +90,39 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler {
Point3D heatAreaCapClawPointPoint3D = heatModuleService.getHeatAreaCapClawPointPoint3D(heatModuleCode);//获取指定加热模块拍子上方点位
Point3D capStorageCapClawPoint3D = devicePositionService.getPosition(DevicePositionCode.capStorageCapClawPoint).getPoint3D();//获取拍子存放区上方点位;
//校验目标加热位是否有托盘
try {
deviceStateService.getCommandMutexState().get().setMoveToHeatAreaCommandExecuting(true);
// Boolean heatModuleTray = heatModuleService.heatModuleSensorState(heatModuleCode);
// if (heatModuleTray) {
// throw new AppException(ResultCode.TARGET_HEAT_MODULE_OCCUPIED);
// }
} catch (Exception e) {
deviceStateService.getCommandMutexState().get().setMoveToHeatAreaCommandExecuting(false);
throw e;
}
return runAsync(() -> {
try {
// TrayState trayState = deviceStateService.getTrayInSolutionModule();
TrayState trayState = deviceStateService.getDeviceState().getTrayInSolutionModule();
trayState.setHeatModuleId(heatModuleCode);
capModuleService.capUpBalanceNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand());//提升拍子存放区至拍子夹取的高度
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D); //将机械臂移动至加液模块上方
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开准备夹取托盘
gantryModuleService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayGrip);//将夹爪收紧夹住托盘
deviceCommandTempUtilService.moveTrayHeatModuleAvoidDownNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand(), null);//TODO 结构有问题临时避让 开始移动托盘之前先降下所有加热模块
gantryModuleService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
deviceStateService.getDeviceState().getSolutionModule().setTrayStatus(0);//加液模块是否有托盘
// deviceCommandTempUtilService.moveTrayHeatModuleAvoidDown(cmdDTO.getCommandId(), cmdDTO.getCommand(), null);//TODO 结构有问题临时避让 开始移动托盘之前先降下所有加热模块
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将携带托盘的机械臂移动至加热模块上方
// deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLift);//抬升加热位托盘
deviceCommandTempUtilService.moveTrayHeatModuleAvoidUpNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode);Thread.sleep(3200);//TODO 结构有问题临时避让 完毕可以升起了顺带提升目标加热模块
gantryModuleService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使托盘落入加热模块
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开释放托盘
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayStatus(1);//加热模块是否存在托盘
trayState.setInHeatModule(true);
gantryModuleService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
deviceCommandTempUtilService.moveTrayHeatModuleAvoidDownNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand(), null);//TODO 结构有问题临时避让 开始移动托盘之前先降下所有加热模块
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开准备夹取拍子
gantryModuleService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹爪落入拍子升降模块拍子孔位
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapGrip);//将夹爪收紧夹住拍子
gantryModuleService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaCapClawPointPoint3D);//将携带拍子的机械臂移动至加热模块拍子上方
capModuleService.capUpBalanceNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区
deviceCommandTempUtilService.moveTrayHeatModuleAvoidUpNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode);Thread.sleep(4000);//TODO 结构有问题临时避让 完毕可以升起了顺带提升目标加热模块
gantryModuleService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹拍子落入加热模块
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开释放拍子
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setCapExist(true);//加热模块是否存在拍子
gantryModuleService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
// trayState.setHeatModuleId(heatModuleId);
// trayState.setInHeatModule(true);
// heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLower);//下降加热模块托盘
// deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(0);//加热模块托盘升降状态
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
} finally {
deviceStateService.getDeviceState().getGantryArm().setIdle(true);

51
src/main/java/com/iflytop/gd/app/command/control/MoveToSolutionAreaCommand.java

@ -2,6 +2,9 @@ package com.iflytop.gd.app.command.control;
import com.iflytop.gd.app.core.BaseCommandHandler;
import com.iflytop.gd.app.model.bo.Point3D;
import com.iflytop.gd.app.model.bo.status.device.HeatModuleState;
import com.iflytop.gd.app.model.bo.status.device.SolutionModuleState;
import com.iflytop.gd.app.model.bo.status.device.TrayState;
import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.service.api.DevicePositionService;
import com.iflytop.gd.app.service.device.DeviceCommandTempUtilService;
@ -52,6 +55,27 @@ public class MoveToSolutionAreaCommand extends BaseCommandHandler {
}
String heatId = cmdDTO.getStringParam("heatId");
HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId);
//校验目标加热位是否有托盘
try {
deviceStateService.getCommandMutexState().get().setMoveToSolutionAreaCommandExecuting(true);
HeatModuleState heatModuleState = deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode);
if(heatModuleState.getTrayStatus() == 0){
throw new AppException(ResultCode.TARGET_HEAT_MODULE_NO_TRAY);
}
// Boolean heatModuleTray = heatModuleService.heatModuleSensorState(heatModuleCode);
// if (!heatModuleTray) {
// throw new AppException(ResultCode.TARGET_HEAT_MODULE_NO_TRAY);
// }
SolutionModuleState solutionModuleState = deviceStateService.getDeviceState().getSolutionModule();
if(solutionModuleState.getTrayStatus() == 1){
throw new AppException(ResultCode.SOLUTION_MODULE_OCCUPIED);
}
} catch (Exception e) {
deviceStateService.getCommandMutexState().get().setMoveToSolutionAreaCommandExecuting(false);
throw e;
}
double clawCapPick = devicePositionService.getPosition(DevicePositionCode.clawCapPick).getDistance(); //获取拍子夹取距离
double clawCapGrip = devicePositionService.getPosition(DevicePositionCode.clawCapGrip).getDistance(); //获取拍子夹紧距离
double clawTrayPick = devicePositionService.getPosition(DevicePositionCode.clawTrayPick).getDistance();//获取夹爪托盘夹取距离
@ -69,52 +93,41 @@ public class MoveToSolutionAreaCommand extends BaseCommandHandler {
Point3D heatAreaCapClawPointPoint3D = heatModuleService.getHeatAreaCapClawPointPoint3D(heatModuleCode);//获取指定加热模块拍子上方点位
Point3D capStorageCapClawPoint3D = devicePositionService.getPosition(DevicePositionCode.capStorageCapClawPoint).getPoint3D();//获取拍子存放区上方点位;
//校验目标加热位是否有托盘
try {
deviceStateService.getCommandMutexState().get().setMoveToSolutionAreaCommandExecuting(true);
// Boolean heatModuleTray = heatModuleService.heatModuleSensorState(heatModuleCode);
// if (!heatModuleTray) {
// throw new AppException(ResultCode.TARGET_HEAT_MODULE_NO_TRAY);
// }
} catch (Exception e) {
deviceStateService.getCommandMutexState().get().setMoveToSolutionAreaCommandExecuting(false);
throw e;
}
return runAsync(() -> {
try {
// TrayState trayState = deviceStateService.getTrayInSolutionModule();
TrayState trayState = deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleCode);
solutionModuleService.requestSolutionModule();//申请使用加液区并等待
capModuleService.capUpBalanceNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand()); //提升拍子存放区至拍子夹取的高度
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaCapClawPointPoint3D);//将机械臂移动至加热模块拍子上方
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(1);//将加热模块托盘状态改为抬起
heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLift);//抬升指定加热位托盘
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开准备夹取拍子
gantryModuleService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹爪落入加热模块拍子孔位
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapGrip);//将夹爪收紧夹住拍子
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setCapExist(false);//加热模块是否存在拍子
capModuleService.capMotorMoveByNumNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand(), -1);//拍子存放模块下降1个拍子位置
gantryModuleService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0); Thread.sleep(2000);//抬升z轴
deviceCommandTempUtilService.moveTrayHeatModuleAvoidDownNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand(), null);//TODO 结构有问题临时避让 开始移动托盘之前先降下所有加热模块
gantryModuleService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0); Thread.sleep(4000);//抬升z轴
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//将携带拍子的机械臂移动至存放区上方
deviceCommandTempUtilService.moveTrayHeatModuleAvoidUpNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand(), null);//TODO 临时避 恢复抬起状态
gantryModuleService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹拍子落入存放区
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawCapPick);//将夹爪打开释放夹取的拍子
gantryModuleService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayClawPoint3D);//将机械臂移动至加热模块上方
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(1);//将加热模块托盘状态改为抬起
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开准备夹取托盘
gantryModuleService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayGrip);//将夹爪收紧夹住托盘
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayStatus(0);//加热模块是否存在托盘
// trayState.setInHeatModule(false);//托盘是否在加热模块中
trayState.setInHeatModule(false);
deviceCommandTempUtilService.moveTrayHeatModuleAvoidDownNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode);//TODO 临时避让下降
gantryModuleService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);Thread.sleep(2500);//抬升z轴
// deviceCommandUtilService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleId, trayLower);//下降加热模块托盘
// deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 0);//加热模块托盘升降状态
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D); //将携带托盘的机械臂移动至加液模块上方
// deviceCommandTempUtilService.moveTrayHeatModuleAvoidUpNoWait(cmdDTO.getCommandId(), cmdDTO.getCommand(), null, heatModuleCode);//TODO 临时避 恢复抬起状态
deviceCommandTempUtilService.moveTrayHeatModuleAvoidUp(null, heatModuleCode);//TODO 临时避 恢复抬起状态
gantryModuleService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使托盘落入加液模块
// trayState.setInSolutionModule(true);//托盘是否在加液模块中
deviceStateService.getDeviceState().getSolutionModule().setTrayStatus(1);//加液模块是否存在托盘
trayState.setInSolutionModule(true);
gantryModuleService.clawMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), clawTrayPick);//将夹爪打开释放托盘
gantryModuleService.gantryZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//抬升z轴
gantryModuleService.gantryMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方

5
src/main/java/com/iflytop/gd/app/controller/TestController.java

@ -8,6 +8,7 @@ import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.app.service.device.module.CapModuleService;
import com.iflytop.gd.app.service.device.module.OtherModuleService;
import com.iflytop.gd.common.enums.HeatModuleCode;
import com.iflytop.gd.common.enums.HeatingType;
import com.iflytop.gd.common.result.Result;
import com.iflytop.gd.hardware.exception.HardwareException;
import io.swagger.v3.oas.annotations.Operation;
@ -108,8 +109,8 @@ public class TestController {
@Operation(summary = "设置当前温度")
@PostMapping("/set-temperature")
public Result<?> setTemperature(HeatModuleCode code, Double temperature) throws Exception {
testService.setTemperature(code, temperature);
public Result<?> setTemperature(HeatModuleCode code, Double temperature, HeatingType heatingType) throws Exception {
testService.setTemperature(code, temperature, heatingType);
return Result.success();
}
}

5
src/main/java/com/iflytop/gd/app/core/CraftsContext.java

@ -3,7 +3,6 @@ package com.iflytop.gd.app.core;
import cn.hutool.json.JSONUtil;
import com.iflytop.gd.app.model.bo.CraftsStep;
import com.iflytop.gd.app.model.bo.status.device.CraftsState;
import com.iflytop.gd.app.model.bo.status.device.TrayState;
import com.iflytop.gd.app.model.entity.Crafts;
import com.iflytop.gd.app.model.entity.Ores;
import com.iflytop.gd.app.service.crafts.CraftsStepService;
@ -83,6 +82,8 @@ public class CraftsContext implements Runnable {
try {
Message<CraftEvents> startMsg = MessageBuilder.withPayload(CraftEvents.START).build();
Mono.from(sm.sendEvent(Mono.just(startMsg))).block();
craftsStepService.start(this);
for (; currentIndex < craftsStepList.size(); currentIndex++) {
if (sm.getState().getId() == CraftStates.STOPPED) break;
CraftsStep step = craftsStepList.get(currentIndex);
@ -103,7 +104,7 @@ public class CraftsContext implements Runnable {
}
}
if (sm.getState().getId() == CraftStates.RUNNING) {
craftsStepService.finish(heatModuleCode);//工艺执行完毕将托盘移动至加液模块
craftsStepService.finish(this);
Message<CraftEvents> finishMsg = MessageBuilder.withPayload(CraftEvents.FINISH).build();
Mono.from(sm.sendEvent(Mono.just(finishMsg))).block();
}

6
src/main/java/com/iflytop/gd/app/model/bo/status/device/HeatModuleState.java

@ -29,9 +29,9 @@ public class HeatModuleState {
@Schema(description = "当前加热类型")
private HeatingType heatingType = HeatingType.stop;
@Schema(description = "是否正在加热,true为正在加热,false为未加热")//可能去掉这个状态
private boolean heating = false;
//
// @Schema(description = "是否正在加热,true为正在加热,false为未加热")//可能去掉这个状态
// private boolean heating = false;
@Schema(description = "是否启动散热,true为正在散热,false为未在散热")
private boolean fanOpen = false;

32
src/main/java/com/iflytop/gd/app/model/vo/HeatCountdownVO.java

@ -1,32 +0,0 @@
package com.iflytop.gd.app.model.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.iflytop.gd.app.model.entity.Solutions;
import com.iflytop.gd.common.enums.HeatModuleCode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Schema(description = "加热倒计时")
@Data
public class HeatCountdownVO {
@Schema(description = "加热模块code")
private HeatModuleCode heatModuleCode;
@Schema(description = "加热剩余秒数格式化显示")
private String countdownStr;
@Schema(description = "加热剩余秒数")
private Integer countdown;
@Schema(description = "开始加热时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;
@Schema(description = "结束加热时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime;
}

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

@ -4,10 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytop.gd.app.core.CraftsContext;
import com.iflytop.gd.app.mapper.CraftsMapper;
import com.iflytop.gd.app.model.bo.status.device.CraftsState;
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.bo.status.device.TubeState;
import com.iflytop.gd.app.model.bo.status.device.*;
import com.iflytop.gd.app.model.dto.StartCraftsDTO;
import com.iflytop.gd.app.model.entity.Crafts;
import com.iflytop.gd.app.model.entity.Ores;
@ -101,6 +98,18 @@ public class CraftsService extends ServiceImpl<CraftsMapper, Crafts> {
public synchronized SetCraftsVO startCrafts(StartCraftsDTO startCraftsDTO) {
long craftId = startCraftsDTO.getCraftId();
HeatModuleCode heatModuleCode = startCraftsDTO.getHeatId();
SolutionModuleState solutionModuleState = deviceStateService.getDeviceState().getSolutionModule();
if (solutionModuleState.getTrayStatus() == 0) {
throw new AppException(ResultCode.SOLUTION_MODULE_NO_TRAY);
}
TrayState trayState = deviceStateService.getDeviceState().getTrayInSolutionModule();
if(trayState.getCrafts() != null){
throw new AppException(ResultCode.SOLUTION_MODULE_OCCUPIED);
}
HeatModuleState heatModuleState = deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode);
if (heatModuleState != null && heatModuleState.getTrayStatus() == 1) {
throw new AppException(ResultCode.TARGET_HEAT_MODULE_OCCUPIED);
}
Crafts craft = this.getById(craftId);
if (craft == null) {
throw new AppException(ResultCode.INVALID_PARAMETER);
@ -109,18 +118,16 @@ public class CraftsService extends ServiceImpl<CraftsMapper, Crafts> {
if (ores == null) {
throw new AppException(ResultCode.INVALID_PARAMETER);
}
if (deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0) {
throw new AppException(ResultCode.SOLUTION_MODULE_NO_TRAY);
}
//判断是否指定加热区id
if (heatModuleCode == null) {
//如果没有指定加热区id则自动获取一个
HeatModuleState heatModuleState = heatModuleService.getIdleHeatModule();
if (heatModuleState == null) {
HeatModuleState autoHeatModuleState = heatModuleService.getIdleHeatModule(craft);
if (autoHeatModuleState == null) {
log.error("自动分配工艺失败,无空闲加热模块。");
throw new AppException(ResultCode.HEAT_MODULE_NO_IDLE);
} else {
heatModuleCode = heatModuleState.getModuleCode();
heatModuleCode = autoHeatModuleState.getModuleCode();
}
} else {
// if (futureMap.containsKey(heatModuleCode)) {//校验指定加热模块是否正在执行工艺
@ -141,12 +148,11 @@ public class CraftsService extends ServiceImpl<CraftsMapper, Crafts> {
// clearCraftContext(heatModuleCode);
// }
TrayState trayState = deviceStateService.getDeviceState().getTrayInSolutionModule();
//配置可操作试管
TubeState[] tubeStateArr = trayState.getTubes();
List<Integer> needTubeNumArr = Arrays.stream(startCraftsDTO.getTubes()).boxed() .toList();
List<Integer> needTubeNumArr = Arrays.stream(startCraftsDTO.getTubes()).boxed().toList();
for (TubeState tubeState : tubeStateArr) {
if(!needTubeNumArr.contains(tubeState.getTubeNum())){
if (!needTubeNumArr.contains(tubeState.getTubeNum())) {
tubeState.setNeedAddSolution(false);
}
}

6
src/main/java/com/iflytop/gd/app/service/api/TestService.java

@ -3,6 +3,7 @@ package com.iflytop.gd.app.service.api;
import com.iflytop.gd.app.model.dto.AllSensorDTO;
import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.common.enums.HeatModuleCode;
import com.iflytop.gd.common.enums.HeatingType;
import com.iflytop.gd.hardware.exception.HardwareException;
import com.iflytop.gd.hardware.service.GDDeviceStatusService;
import com.iflytop.gd.hardware.type.IO.InputIOMId;
@ -41,12 +42,13 @@ public class TestService {
return allSensorDTOList;
}
public void reset(){
public void reset() {
deviceStateService.getCommandMutexState().get().reset();
deviceStateService.getDeviceState().reset();
}
public void setTemperature(HeatModuleCode code, Double temperature){
public void setTemperature(HeatModuleCode code, Double temperature, HeatingType heatingType) {
deviceStateService.getDeviceState().getHeatModuleByCode(code).setHeatingType(heatingType);
deviceStateService.getDeviceState().getHeatModuleByCode(code).setTemperature(temperature);
}

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

@ -42,8 +42,9 @@ public class TrayService {
deviceStateService.getDeviceState().getSolutionModule().setTrayStatus(1);
deviceStateService.getDeviceState().getSolutionModule().setIdle(false);
return trayState;
}else{
throw new AppException(ResultCode.SOLUTION_MODULE_OCCUPIED);
}
return null;
}
/**

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

@ -2,12 +2,15 @@ package com.iflytop.gd.app.service.crafts;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.iflytop.gd.app.core.CraftsContext;
import com.iflytop.gd.app.core.CraftsDebugGenerator;
import com.iflytop.gd.app.model.bo.CraftsStep;
import com.iflytop.gd.app.model.bo.Point3D;
import com.iflytop.gd.app.model.bo.status.device.TrayState;
import com.iflytop.gd.app.model.bo.status.device.TubeState;
import com.iflytop.gd.app.model.entity.Container;
import com.iflytop.gd.app.model.entity.Crafts;
import com.iflytop.gd.app.service.api.ContainerService;
import com.iflytop.gd.app.service.api.DevicePositionService;
import com.iflytop.gd.app.service.device.DeviceCommandTempUtilService;
@ -68,14 +71,47 @@ public class CraftsStepService {
}
/**
* 工艺开始执行前
*/
public void start(CraftsContext craftsContext) throws Exception {
HeatModuleCode heatModuleCode = craftsContext.getHeatModuleCode();
Crafts craft = craftsContext.getCraft();
List<CraftsStep> craftsStepList = JSONUtil.parseArray(craft.getSteps()).toList(CraftsStep.class);
Double targetTemperature = null;
for (CraftsStep craftsStep : craftsStepList) {
if ("startHeating".equals(craftsStep.getMethod())) {
targetTemperature = craftsStep.getParams().getDouble("temperature");
break;
}
}
if (targetTemperature != null) {//工艺执行前动态调节温度
Double temperature = deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature();
if (temperature > targetTemperature) {
heatModuleService.fanStart(heatModuleCode);
} else {
heatModuleService.heatRodOpen(heatModuleCode, targetTemperature);
}
}
}
/**
* 工艺执行完毕
*/
public void finish(CraftsContext craftsContext) throws Exception {
moveToSolutionModule(craftsContext.getHeatModuleCode());
//蜂鸣器提示
// otherModuleService.craftsFinishBeepRemind();
}
/**
* 将托盘从加热区移动至加液区并且添加溶液
*/
private boolean addLiquid(HeatModuleCode heatModuleCode, JSONObject params) throws Exception {
if((deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0 )
if ((deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0)
&& deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTrayStatus() == 0) {
throw new AppException(ResultCode.CRAFT_NO_TRAY);
}
if((deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0 )
if ((deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0)
&& deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTrayStatus() == 1) {
moveToSolutionModule(heatModuleCode);
}
@ -84,8 +120,8 @@ public class CraftsStepService {
TubeState[] tubeArray = trayState.getTubes();
for (TubeState tubeState : tubeArray) {
int tubeNum = tubeState.getTubeNum();
if(tubeNum > 0){
log.info("工艺{},移动加液机械臂到指定试管",heatModuleCode);
if (tubeNum > 0) {
log.info("工艺{},移动加液机械臂到指定试管", heatModuleCode);
solutionModuleService.dualRobotMovePoint(tubeNum);//移动加液机械臂到指定试管
List<CommandFuture> futuresList = new ArrayList<>();
for (int i = 0; i < addLiquidList.size(); i++) {
@ -98,8 +134,8 @@ public class CraftsStepService {
}
AcidPumpDeviceCode acidPumpDevice = AcidPumpDeviceCode.valueOf(container.getPumpId());//
int scale = container.getScale() == null ? 120 : container.getScale();//系数
log.info("工艺{},添加溶液",heatModuleCode);
CommandFuture deviceCommandFuture = solutionModuleService.acidPumpMoveBy(acidPumpDevice, volume * ((double) scale /100));//添加溶液
log.info("工艺{},添加溶液", heatModuleCode);
CommandFuture deviceCommandFuture = solutionModuleService.acidPumpMoveBy(acidPumpDevice, volume * ((double) scale / 100));//添加溶液
futuresList.add(deviceCommandFuture);
}
CommandUtil.wait(futuresList.toArray(new CommandFuture[0]));
@ -117,10 +153,10 @@ public class CraftsStepService {
moveToSolutionModule(heatModuleCode);
}
Integer second = params.getInt("second");
log.info("工艺{},开始摇匀",heatModuleCode);
log.info("工艺{},开始摇匀", heatModuleCode);
solutionModuleService.shakeStart();//开始摇匀
delay(second);
log.info("工艺{},停止摇匀",heatModuleCode);
log.info("工艺{},停止摇匀", heatModuleCode);
solutionModuleService.shakeStop();//停止摇匀
return true;
}
@ -132,25 +168,41 @@ public class CraftsStepService {
double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); //获取加热位抬升托盘位置
double trayLower = devicePositionService.getPosition(DevicePositionCode.trayLower).getDistance(); //获取托盘升降下降距离位置
moveToHeatModule(heatModuleCode);
Double temperature = params.getDouble("temperature");
Double targetTemperature = params.getDouble("temperature");
Integer second = params.getInt("second");
log.info("工艺{},加热中",heatModuleCode);
heatModuleService.heatRodOpen(heatModuleCode, temperature);//开始加热
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.thermostatic);
//达到目标温度后才算开始加热
log.info("工艺{},等待升温",heatModuleCode);
while (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature() + 1 < temperature) {
delay(1);
Double temperature = deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature();
if (temperature > targetTemperature) {
log.info("工艺{},开启风扇降温中", heatModuleCode);
heatModuleService.fanStart(heatModuleCode);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.cooling);
log.info("工艺{},等待降温", heatModuleCode);
while (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature() - 1 > targetTemperature) {
delay(1);
}
heatModuleService.fanClose(heatModuleCode);
heatModuleService.heatRodOpen(heatModuleCode, targetTemperature);
} else {
log.info("工艺{},开启加热棒", heatModuleCode);
heatModuleService.heatRodOpen(heatModuleCode, targetTemperature);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.warm_up);
log.info("工艺{},等待升温", heatModuleCode);
while (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature() + 1 < targetTemperature) {
delay(1);
}
}
log.info("工艺{},恒温中",heatModuleCode);
log.info("工艺{},恒温中", heatModuleCode);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.constant);
log.info("工艺{},降下托盘",heatModuleCode);
heatModuleService.heaterMotorMove(heatModuleCode, trayLower);//降下托盘
log.info("工艺{},温度合适,下降加热模块托盘", heatModuleCode);
heatModuleService.heaterMotorMove(heatModuleCode, trayLower);//下降加热模块托盘
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(0);//加热模块托盘升降状态
delay(second);
log.info("工艺{},停止加热",heatModuleCode);
log.info("工艺{},加热完成", heatModuleCode);
heatModuleService.heatRodClose(heatModuleCode);//停止加热
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.finish);
log.info("工艺{},抬升加热位托盘",heatModuleCode);
log.info("工艺{},抬升加热位托盘", heatModuleCode);
heatModuleService.heaterMotorMove(heatModuleCode, trayLift);//抬升加热位托盘
return true;
}
@ -184,15 +236,6 @@ public class CraftsStepService {
}
/**
* 工艺执行完毕
*/
public void finish(HeatModuleCode heatModuleCode) throws Exception {
moveToSolutionModule(heatModuleCode);
//蜂鸣器提示
// otherModuleService.craftsFinishBeepRemind();
}
/**
* 将托盘移至加热
*/
private void moveToHeatModule(HeatModuleCode heatModuleCode) throws Exception {
@ -213,66 +256,66 @@ public class CraftsStepService {
Point3D heatAreaCapClawPointPoint3D = heatModuleService.getHeatAreaCapClawPointPoint3D(heatModuleCode);//获取指定加热模块拍子上方点位
Point3D capStorageCapClawPoint3D = devicePositionService.getPosition(DevicePositionCode.capStorageCapClawPoint).getPoint3D();//获取拍子存放区上方点位;
log.info("工艺{},提升拍子存放区至拍子夹取的高度",heatModuleCode);
TrayState trayState = deviceStateService.getDeviceState().getTrayInSolutionModule();
log.info("工艺{},提升拍子存放区至拍子夹取的高度", heatModuleCode);
capModuleService.capUpBalanceNoWait();//提升拍子存放区至拍子夹取的高度
log.info("工艺{},将机械臂移动至加液模块上方",heatModuleCode);
log.info("工艺{},将机械臂移动至加液模块上方", heatModuleCode);
gantryModuleService.gantryMove(liquidAreaTrayPoint3D); //将机械臂移动至加液模块上方
log.info("工艺{},将夹爪打开,准备夹取托盘",heatModuleCode);
log.info("工艺{},将夹爪打开,准备夹取托盘", heatModuleCode);
gantryModuleService.clawMove(clawTrayPick);//将夹爪打开准备夹取托盘
log.info("工艺{},下降z轴,使夹爪落入托盘孔位",heatModuleCode);
log.info("工艺{},下降z轴,使夹爪落入托盘孔位", heatModuleCode);
gantryModuleService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位
log.info("工艺{},将夹爪收紧,夹住托盘",heatModuleCode);
log.info("工艺{},将夹爪收紧,夹住托盘", heatModuleCode);
gantryModuleService.clawMove(clawTrayGrip);//将夹爪收紧夹住托盘
log.info("工艺{},抬升z轴",heatModuleCode);
log.info("工艺{},抬升z轴", heatModuleCode);
deviceCommandTempUtilService.moveTrayHeatModuleAvoidDownNoWait(null);//TODO 结构有问题临时避让 开始移动托盘之前先降下所有加热模块
gantryModuleService.gantryZMove(0);//抬升z轴
deviceStateService.getDeviceState().getSolutionModule().setTrayStatus(0);//加液模块是否有托盘
deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleCode).setInSolutionModule(false);
// deviceCommandTempUtilService.moveTrayHeatModuleAvoidDown(null);//TODO 结构有问题临时避让 开始移动托盘之前先降下所有加热模块
log.info("工艺{},将携带托盘的机械臂移动至4号加热模块上方",heatModuleCode);
log.info("工艺{},将携带托盘的机械臂移动至4号加热模块上方", heatModuleCode);
gantryModuleService.gantryMove(heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方
log.info("工艺{},将携带托盘的机械臂移动至加热模块上方",heatModuleCode);
log.info("工艺{},将携带托盘的机械臂移动至加热模块上方", heatModuleCode);
gantryModuleService.gantryMove(heatAreaTrayClawPoint3D);//将携带托盘的机械臂移动至加热模块上方
// deviceCommandUtilService.heaterMotorMove( heatModuleId, trayLift);//抬升加热位托盘 TODO 结构有问题临时避让 屏蔽
log.info("工艺{},临时避让完毕,升起",heatModuleCode);
deviceCommandTempUtilService.moveTrayHeatModuleAvoidUpNoWait(heatModuleCode);Thread.sleep(3200);//TODO 结构有问题临时避让 完毕可以升起了顺带提升目标加热模块
log.info("工艺{},下降z轴,使托盘落入加热模块",heatModuleCode);
log.info("工艺{},临时避让完毕,升起", heatModuleCode);
deviceCommandTempUtilService.moveTrayHeatModuleAvoidUpNoWait(heatModuleCode);
Thread.sleep(3200);//TODO 结构有问题临时避让 完毕可以升起了顺带提升目标加热模块
log.info("工艺{},下降z轴,使托盘落入加热模块", heatModuleCode);
gantryModuleService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使托盘落入加热模块
log.info("工艺{},将夹爪打开,释放托盘",heatModuleCode);
log.info("工艺{},将夹爪打开,释放托盘", heatModuleCode);
gantryModuleService.clawMove(clawTrayPick);//将夹爪打开释放托盘
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayStatus(1);//加热模块是否存在托盘
deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleCode).setInHeatModule(true);
log.info("工艺{},抬升z轴",heatModuleCode);
log.info("工艺{},抬升z轴", heatModuleCode);
gantryModuleService.gantryZMove(0);//抬升z轴
log.info("工艺{},移动机械臂至拍子存放区上方",heatModuleCode);
log.info("工艺{},移动机械臂至拍子存放区上方", heatModuleCode);
gantryModuleService.gantryMove(capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
log.info("工艺{},将夹爪打开,准备夹取拍子",heatModuleCode);
deviceCommandTempUtilService.moveTrayHeatModuleAvoidDownNoWait(null);//TODO 结构有问题临时避让 开始移动托盘之前先降下所有加热模块
log.info("工艺{},将夹爪打开,准备夹取拍子", heatModuleCode);
gantryModuleService.clawMove(clawCapPick);//将夹爪打开准备夹取拍子
log.info("工艺{},下降z轴,使夹爪落入拍子升降模块拍子孔位",heatModuleCode);
log.info("工艺{},下降z轴,使夹爪落入拍子升降模块拍子孔位", heatModuleCode);
gantryModuleService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹爪落入拍子升降模块拍子孔位
log.info("工艺{},将夹爪收紧,夹住拍子",heatModuleCode);
log.info("工艺{},将夹爪收紧,夹住拍子", heatModuleCode);
gantryModuleService.clawMove(clawCapGrip);//将夹爪收紧夹住拍子
log.info("工艺{},抬升z轴",heatModuleCode);
log.info("工艺{},抬升z轴", heatModuleCode);
gantryModuleService.gantryZMove(0);//抬升z轴
log.info("工艺{},将携带拍子的机械臂移动至加热模块拍子上方",heatModuleCode);
log.info("工艺{},将携带拍子的机械臂移动至加热模块拍子上方", heatModuleCode);
gantryModuleService.gantryMove(heatAreaCapClawPointPoint3D);//将携带拍子的机械臂移动至加热模块拍子上方
log.info("工艺{},提升拍子存放区",heatModuleCode);
log.info("工艺{},提升拍子存放区", heatModuleCode);
capModuleService.capUpBalanceNoWait(); //提升拍子存放区
log.info("工艺{},下降z轴,使夹拍子落入加热模块",heatModuleCode);
deviceCommandTempUtilService.moveTrayHeatModuleAvoidUpNoWait(heatModuleCode);
Thread.sleep(4000);//TODO 结构有问题临时避让 完毕可以升起了顺带提升目标加热模块
log.info("工艺{},下降z轴,使夹拍子落入加热模块", heatModuleCode);
gantryModuleService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹拍子落入加热模块
log.info("工艺{},将夹爪打开,释放拍子",heatModuleCode);
log.info("工艺{},将夹爪打开,释放拍子", heatModuleCode);
gantryModuleService.clawMove(clawCapPick);//将夹爪打开释放拍子
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setCapExist(true);//加热模块是否存在拍子
log.info("工艺{},抬升z轴",heatModuleCode);
log.info("工艺{},抬升z轴", heatModuleCode);
gantryModuleService.gantryZMove(0);//抬升z轴
// trayState.setHeatModuleId(heatModuleId);
// trayState.setInHeatModule(true);
log.info("工艺{},下降加热模块托盘",heatModuleCode);
heatModuleService.heaterMotorMove(heatModuleCode, trayLower);//下降加热模块托盘
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(0);//加热模块托盘升降状态
log.info("工艺{},移动机械臂至拍子存放区上方",heatModuleCode);
log.info("工艺{},移动机械臂至拍子存放区上方", heatModuleCode);
gantryModuleService.gantryMove(capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
log.info("工艺{},释放加液区",heatModuleCode);
log.info("工艺{},释放加液区", heatModuleCode);
solutionModuleService.releaseSolutionModule();//释放加液区
}
@ -298,70 +341,69 @@ public class CraftsStepService {
Point3D capStorageCapClawPoint3D = devicePositionService.getPosition(DevicePositionCode.capStorageCapClawPoint).getPoint3D();//获取拍子存放区上方点位;
// TrayState trayState = deviceStateService.getTrayInSolutionModule();
log.info("工艺{},申请使用加液区并等待",heatModuleCode);
TrayState trayState = deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleCode);
log.info("工艺{},申请使用加液区并等待", heatModuleCode);
solutionModuleService.requestSolutionModule();//申请使用加液区并等待
log.info("工艺{},提升拍子存放区至拍子夹取的高度",heatModuleCode);
log.info("工艺{},提升拍子存放区至拍子夹取的高度", heatModuleCode);
capModuleService.capUpBalanceNoWait(); //提升拍子存放区至拍子夹取的高度
log.info("工艺{},将机械臂移动至加热模块拍子上方",heatModuleCode);
log.info("工艺{},将机械臂移动至加热模块拍子上方", heatModuleCode);
gantryModuleService.gantryMove(heatAreaCapClawPointPoint3D);//将机械臂移动至加热模块拍子上方
log.info("工艺{},抬升指定加热位托盘",heatModuleCode);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(1);//将加热模块托盘状态改为抬起
log.info("工艺{},抬升指定加热位托盘", heatModuleCode);
heatModuleService.heaterMotorMove(heatModuleCode, trayLift);//抬升指定加热位托盘
log.info("工艺{},将夹爪打开,准备夹取拍子",heatModuleCode);
log.info("工艺{},将夹爪打开,准备夹取拍子", heatModuleCode);
gantryModuleService.clawMove(clawCapPick);//将夹爪打开准备夹取拍子
log.info("工艺{},下降z轴,使夹爪落入加热模块拍子孔位",heatModuleCode);
log.info("工艺{},下降z轴,使夹爪落入加热模块拍子孔位", heatModuleCode);
gantryModuleService.gantryZMove(heatModuleCapMoveHeight);//下降z轴,使夹爪落入加热模块拍子孔位
log.info("工艺{},将夹爪收紧,夹住拍子",heatModuleCode);
log.info("工艺{},将夹爪收紧,夹住拍子", heatModuleCode);
gantryModuleService.clawMove(clawCapGrip);//将夹爪收紧夹住拍子
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setCapExist(false);//加热模块是否存在拍子
log.info("工艺{},拍子存放模块下降1个拍子位置",heatModuleCode);
log.info("工艺{},拍子存放模块下降1个拍子位置", heatModuleCode);
capModuleService.capMotorMoveByNumNoWait(-1);//拍子存放模块下降1个拍子位置
log.info("工艺{},抬升z轴",heatModuleCode);
gantryModuleService.gantryZMove(0); Thread.sleep(2000);//抬升z轴
log.info("工艺{},将携带拍子的机械臂移动至存放区上方",heatModuleCode);
deviceCommandTempUtilService.moveTrayHeatModuleAvoidDownNoWait(null);//TODO 结构有问题临时避让 开始移动托盘之前先降下所有加热模块
log.info("工艺{},抬升z轴", heatModuleCode);
gantryModuleService.gantryZMove(0);
Thread.sleep(4000);//抬升z轴
log.info("工艺{},将携带拍子的机械臂移动至存放区上方", heatModuleCode);
gantryModuleService.gantryMove(capStorageCapClawPoint3D);//将携带拍子的机械臂移动至存放区上方
log.info("工艺{},下降z轴,使夹拍子落入存放区",heatModuleCode);
deviceCommandTempUtilService.moveTrayHeatModuleAvoidUpNoWait(null);//TODO 临时避 恢复抬起状态
log.info("工艺{},下降z轴,使夹拍子落入存放区", heatModuleCode);
gantryModuleService.gantryZMove(capModuleCapMoveHeight);//下降z轴,使夹拍子落入存放区
log.info("工艺{},将夹爪打开,释放夹取的拍子",heatModuleCode);
log.info("工艺{},将夹爪打开,释放夹取的拍子", heatModuleCode);
gantryModuleService.clawMove(clawCapPick);//将夹爪打开释放夹取的拍子
log.info("工艺{},抬升z轴",heatModuleCode);
log.info("工艺{},抬升z轴", heatModuleCode);
gantryModuleService.gantryZMove(0);//抬升z轴
log.info("工艺{},将机械臂移动至加热模块上方",heatModuleCode);
log.info("工艺{},将机械臂移动至加热模块上方", heatModuleCode);
gantryModuleService.gantryMove(heatAreaTrayClawPoint3D);//将机械臂移动至加热模块上方
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(1);//将加热模块托盘状态改为抬起
log.info("工艺{},将夹爪打开,准备夹取托盘",heatModuleCode);
log.info("工艺{},将夹爪打开,准备夹取托盘", heatModuleCode);
gantryModuleService.clawMove(clawTrayPick);//将夹爪打开准备夹取托盘
log.info("工艺{},下降z轴,使夹爪落入托盘孔位",heatModuleCode);
log.info("工艺{},下降z轴,使夹爪落入托盘孔位", heatModuleCode);
gantryModuleService.gantryZMove(heatModuleTrayMoveHeight);//下降z轴,使夹爪落入托盘孔位
log.info("工艺{},将夹爪收紧,夹住托盘",heatModuleCode);
log.info("工艺{},将夹爪收紧,夹住托盘", heatModuleCode);
gantryModuleService.clawMove(clawTrayGrip);//将夹爪收紧夹住托盘
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayStatus(0);//加热模块是否存在托盘
deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleCode).setInHeatModule(false);
// trayState.setInHeatModule(false);//托盘是否在加热模块中
log.info("工艺{},临时避让下降",heatModuleCode);
trayState.setInHeatModule(false);
log.info("工艺{},临时避让下降", heatModuleCode);
deviceCommandTempUtilService.moveTrayHeatModuleAvoidDownNoWait(heatModuleCode);//TODO 临时避让下降
log.info("工艺{},抬升z轴",heatModuleCode);
gantryModuleService.gantryZMove(0);Thread.sleep(2500);//抬升z轴
// deviceCommandUtilService.heaterMotorMove( heatModuleId, trayLower);//下降加热模块托盘
// deviceStateService.setHeatModuleStateTrayUp(heatModuleId, 0);//加热模块托盘升降状态
log.info("工艺{},将携带托盘的机械臂移动至4号加热模块上方",heatModuleCode);
log.info("工艺{},抬升z轴", heatModuleCode);
gantryModuleService.gantryZMove(0);
Thread.sleep(2500);//抬升z轴
log.info("工艺{},将携带托盘的机械臂移动至4号加热模块上方", heatModuleCode);
gantryModuleService.gantryMove(heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方
log.info("工艺{},将携带托盘的机械臂移动至加液模块上方",heatModuleCode);
log.info("工艺{},将携带托盘的机械臂移动至加液模块上方", heatModuleCode);
gantryModuleService.gantryMove(liquidAreaTrayPoint3D); //将携带托盘的机械臂移动至加液模块上方
log.info("工艺{},临时避 恢复抬起状态",heatModuleCode);
log.info("工艺{},临时避 恢复抬起状态", heatModuleCode);
deviceCommandTempUtilService.moveTrayHeatModuleAvoidUp(null, heatModuleCode);//TODO 临时避 恢复抬起状态
log.info("工艺{},下降z轴,使托盘落入加液模块",heatModuleCode);
log.info("工艺{},下降z轴,使托盘落入加液模块", heatModuleCode);
gantryModuleService.gantryZMove(solutionModuleTrayMoveHeight);//下降z轴,使托盘落入加液模块
// trayState.setInSolutionModule(true);//托盘是否在加液模块中
deviceStateService.getDeviceState().getSolutionModule().setTrayStatus(1);//加液模块是否存在托盘
deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleCode).setInSolutionModule(true);
log.info("工艺{},将夹爪打开,释放托盘",heatModuleCode);
trayState.setInSolutionModule(true);
log.info("工艺{},将夹爪打开,释放托盘", heatModuleCode);
gantryModuleService.clawMove(clawTrayPick);//将夹爪打开释放托盘
log.info("工艺{},抬升z轴",heatModuleCode);
log.info("工艺{},抬升z轴", heatModuleCode);
gantryModuleService.gantryZMove(0);//抬升z轴
log.info("工艺{},移动机械臂至拍子存放区上方",heatModuleCode);
log.info("工艺{},移动机械臂至拍子存放区上方", heatModuleCode);
gantryModuleService.gantryMove(capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方
}
}

65
src/main/java/com/iflytop/gd/app/service/device/DeviceInitService.java

@ -1,5 +1,6 @@
package com.iflytop.gd.app.service.device;
import ch.qos.logback.core.joran.conditional.ThenAction;
import cn.hutool.json.JSONUtil;
import com.iflytop.gd.app.model.bo.DeviceInitializationData;
import com.iflytop.gd.app.model.bo.status.device.DeviceState;
@ -59,43 +60,46 @@ public class DeviceInitService {
private final ObjectProvider<HeatModuleState> heatModuleStateProvider;
private final ObjectProvider<SolutionContainerState> solutionContainerStateProvider;
private final AppEventBusService eventBus;
private boolean isLink = false;
@PostConstruct
public void init() {
eventBus.regListener(this::onAppEvent);
}
private void onAppEvent(AppEvent event) {
if (event instanceof A8kCanBusOnConnectEvent) {
new Thread(() -> {
try {
log.info("初始化开始");
CompletableFuture.runAsync(() -> {
try {
tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.BLUE);
} catch (HardwareException e) {
log.error("设备初始化灯光失败,Color.BLUE", e);
}
});
initDeviceState();
initDeviceSetData();
initOvertime();
initEnable();
new Thread(() -> {
try {
log.info("初始化开始");
CompletableFuture.runAsync(() -> {
try {
tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.GREEN);
tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.BLUE);
} catch (HardwareException e) {
log.error("设备初始化灯光失败,Color.GREEN", e);
log.error("设备初始化灯光失败,Color.BLUE", e);
}
deviceStateService.getDeviceState().setInitComplete(true);
log.info("初始化完毕");
} catch (Exception e) {
try {
tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.RED);
} catch (Exception ignored) {
}
log.error("设备初始化失败", e);
});
initDeviceState();
initDeviceSetData();
initOvertime();
initEnable();
try {
tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.GREEN);
} catch (HardwareException e) {
log.error("设备初始化灯光失败,Color.GREEN", e);
}
}).start();
deviceStateService.getDeviceState().setInitComplete(true);
log.info("初始化完毕");
} catch (Exception e) {
try {
tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.RED);
} catch (Exception ignored) {
}
log.error("设备初始化失败", e);
}
}).start();
}
private void onAppEvent(AppEvent event) {
if (event instanceof A8kCanBusOnConnectEvent) {
isLink = true;
}
}
@ -146,6 +150,9 @@ public class DeviceInitService {
}
public void initDeviceSetData() throws Exception {
while (!isLink){
Thread.sleep(100);
}
if (deviceStateService.getDeviceState().isVirtual() || deviceStateService.getDeviceState().isInitComplete()) {
return;
}

59
src/main/java/com/iflytop/gd/app/service/device/module/HeatModuleService.java

@ -1,7 +1,10 @@
package com.iflytop.gd.app.service.device.module;
import cn.hutool.json.JSONUtil;
import com.iflytop.gd.app.model.bo.CraftsStep;
import com.iflytop.gd.app.model.bo.Point3D;
import com.iflytop.gd.app.model.bo.status.device.HeatModuleState;
import com.iflytop.gd.app.model.entity.Crafts;
import com.iflytop.gd.app.model.entity.DevicePosition;
import com.iflytop.gd.app.service.api.DevicePositionService;
import com.iflytop.gd.app.service.device.DeviceCommandService;
@ -19,6 +22,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 加热模块
*/
@ -128,6 +133,13 @@ public class HeatModuleService {
/**
* 开启风扇
*/
public void fanStart(HeatModuleCode heatModuleId) throws Exception {
fanStart(null, null, heatModuleId);
}
/**
* 开启风扇
*/
public void fanStart(String commandId, String command, HeatModuleCode heatModuleId) throws Exception {
DeviceCommandBundle deviceCommand;
switch (heatModuleId) {
@ -146,6 +158,13 @@ public class HeatModuleService {
/**
* 关闭风扇
*/
public void fanClose(HeatModuleCode heatModuleId) throws Exception {
fanClose(null, null, heatModuleId);
}
/**
* 关闭风扇
*/
public void fanClose(String commandId, String command, HeatModuleCode heatModuleId) throws Exception {
DeviceCommandBundle deviceCommand;
switch (heatModuleId) {
@ -211,13 +230,45 @@ public class HeatModuleService {
/**
* 获取一个空闲加热区
*/
public HeatModuleState getIdleHeatModule() {
for (HeatModuleState heatModuleState : deviceStateService.getDeviceState().getHeatModule()) {
if(heatModuleState.getTrayStatus() == 0 && !heatModuleState.isCapExist()){
return heatModuleState;
public HeatModuleState getIdleHeatModule(Crafts craft) {
List<CraftsStep> craftsStepList = JSONUtil.parseArray(craft.getSteps()).toList(CraftsStep.class);
Double targetTemperature = null;
for (CraftsStep craftsStep : craftsStepList) {
if ("startHeating".equals(craftsStep.getMethod())) {
targetTemperature = craftsStep.getParams().getDouble("temperature");
break;
}
}
if (targetTemperature != null) {
return getHeatModuleState(targetTemperature);
} else {
for (HeatModuleState heatModuleState : deviceStateService.getDeviceState().getHeatModule()) {
if (heatModuleState.getTrayStatus() == 0 && !heatModuleState.isCapExist()) {
return heatModuleState;
}
}
}
return null;
}
private HeatModuleState getHeatModuleState(Double targetTemperature) {
HeatModuleState closestHeatModule = null;
double minDifference = Double.MAX_VALUE; // 初始化最小差值为最大值
// 遍历所有 HeatModuleState找出当前温度与目标温度最接近的一个
for (HeatModuleState heatModuleState : deviceStateService.getDeviceState().getHeatModule()) {
if (heatModuleState.getTrayStatus() == 0 && !heatModuleState.isCapExist()) {
Double currentTemperature = heatModuleState.getTemperature();
if (currentTemperature != null) {
double difference = Math.abs(currentTemperature - targetTemperature); // 计算差值的绝对值
if (difference < minDifference) {
minDifference = difference;
closestHeatModule = heatModuleState;
}
}
}
}
return closestHeatModule;
}
}

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

@ -3,6 +3,7 @@ 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.common.enums.HeatingType;
import com.iflytop.gd.hardware.service.GDDeviceStatusService;
import com.iflytop.gd.hardware.type.driver.HeaterRodSlavedId;
import lombok.RequiredArgsConstructor;
@ -44,8 +45,8 @@ public class FetchTemperatureScheduledTask {
} else {//虚拟模式随便写个值
List<HeatModuleState> heatModuleStateList = deviceStateService.getDeviceState().getHeatModule();
for (HeatModuleState heatModuleState : heatModuleStateList) {
if (heatModuleState.isHeating()) {
heatModuleState.setTemperature(heatModuleState.getTargetTemperature());
if (heatModuleState.getHeatingType() != HeatingType.stop) {
heatModuleState.setTemperature(heatModuleState.getTemperature());
} else {
heatModuleState.setTemperature(26.0);
}

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

@ -2,15 +2,12 @@ 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;
import com.iflytop.gd.app.service.device.module.HeatModuleService;
import com.iflytop.gd.app.ws.server.WebSocketSender;
import com.iflytop.gd.common.enums.HeatingType;
import com.iflytop.gd.common.enums.data.DevicePositionCode;
import com.iflytop.gd.common.utils.LocalDateTimeUtil;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
@ -18,8 +15,6 @@ import org.springframework.stereotype.Service;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/**
* 加热时间到自动抬起

4
src/main/java/com/iflytop/gd/common/enums/HeatingType.java

@ -13,6 +13,10 @@ public enum HeatingType {
*/
warm_up,
/**
* 降温中
*/
cooling,
/**
* 加热中
*/
thermostatic,

Loading…
Cancel
Save