|
|
@ -4,35 +4,51 @@ 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.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.entity.Container; |
|
|
|
import com.iflytop.gd.app.model.entity.Crafts; |
|
|
|
import com.iflytop.gd.app.model.entity.Photos; |
|
|
|
import com.iflytop.gd.app.service.api.ContainerService; |
|
|
|
import com.iflytop.gd.app.service.api.DevicePositionService; |
|
|
|
import com.iflytop.gd.app.service.api.PhotosService; |
|
|
|
import com.iflytop.gd.app.service.device.DeviceCommandTempUtilService; |
|
|
|
import com.iflytop.gd.app.service.device.DeviceStateService; |
|
|
|
import com.iflytop.gd.app.service.device.module.*; |
|
|
|
import com.iflytop.gd.app.service.device.module.CapModuleService; |
|
|
|
import com.iflytop.gd.app.service.device.module.GantryModuleService; |
|
|
|
import com.iflytop.gd.app.service.device.module.HeatModuleService; |
|
|
|
import com.iflytop.gd.app.service.device.module.SolutionModuleService; |
|
|
|
import com.iflytop.gd.app.ws.server.WebSocketSender; |
|
|
|
import com.iflytop.gd.common.command.CommandFuture; |
|
|
|
import com.iflytop.gd.common.enums.AcidPumpDeviceCode; |
|
|
|
import com.iflytop.gd.common.enums.HeatModuleCode; |
|
|
|
import com.iflytop.gd.common.enums.HeatingType; |
|
|
|
import com.iflytop.gd.common.enums.PhotoModeType; |
|
|
|
import com.iflytop.gd.common.enums.data.DevicePositionCode; |
|
|
|
import com.iflytop.gd.common.exception.AppException; |
|
|
|
import com.iflytop.gd.common.result.ResultCode; |
|
|
|
import com.iflytop.gd.common.utils.CommandUtil; |
|
|
|
import com.iflytop.gd.hardware.drivers.CameraBaslerDriver; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Paths; |
|
|
|
import java.nio.file.StandardCopyOption; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
/** |
|
|
|
* 工艺步骤执行服务 |
|
|
@ -51,7 +67,13 @@ public class CraftsStepService { |
|
|
|
private final DevicePositionService devicePositionService; |
|
|
|
private final DeviceStateService deviceStateService; |
|
|
|
private final DeviceCommandTempUtilService deviceCommandTempUtilService; |
|
|
|
private final OtherModuleService otherModuleService; |
|
|
|
private final CameraBaslerDriver cameraBaslerDriver; |
|
|
|
private final PhotosService photosService; |
|
|
|
|
|
|
|
@Value("${photo.url}") |
|
|
|
private String url; |
|
|
|
@Value("${photo.path}") |
|
|
|
private String path; |
|
|
|
|
|
|
|
/** |
|
|
|
* 执行单个工艺步骤 |
|
|
@ -224,7 +246,7 @@ public class CraftsStepService { |
|
|
|
heatModuleService.fanClose(heatModuleCode);//工艺加热前,尝试关闭风扇 |
|
|
|
heatModuleState.setFanOpen(false); |
|
|
|
} |
|
|
|
if(heatModuleState.getTrayUp() == 0){ |
|
|
|
if (heatModuleState.getTrayUp() == 0) { |
|
|
|
log.info("工艺{},温度不达标,抬起托盘等待升温", heatModuleCode); |
|
|
|
heatModuleService.heaterMotorMove(heatModuleCode, trayLift);//抬升加热位托盘 |
|
|
|
heatModuleState.setTrayUp(1);//加热模块托盘升降状态 |
|
|
@ -293,12 +315,56 @@ public class CraftsStepService { |
|
|
|
if (deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() == 0) { |
|
|
|
moveToSolutionModule(heatModuleCode); |
|
|
|
} |
|
|
|
webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatModuleCode.toString(), "开启补光灯", 100.0)); |
|
|
|
Path directoryPath = Paths.get(path + "/temp"); |
|
|
|
try (Stream<Path> paths = Files.list(directoryPath)) { |
|
|
|
paths.forEach(file -> { |
|
|
|
try { |
|
|
|
Files.delete(file); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("工艺删除文件时发生错误", e); |
|
|
|
} |
|
|
|
}); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("工艺读取目录时发生错误", e); |
|
|
|
} |
|
|
|
solutionModuleService.fillLightOpen(100.0); |
|
|
|
webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatModuleCode.toString(), "拍照", null)); |
|
|
|
solutionModuleService.takePhoto();//拍照 |
|
|
|
webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatModuleCode.toString(), "关闭补光灯", null)); |
|
|
|
solutionModuleService.fillLightClose();//关闭补光灯 |
|
|
|
String fileName = System.currentTimeMillis() + ".png"; |
|
|
|
String tempFilePath = "/temp/" + fileName; |
|
|
|
String filePath = path + tempFilePath; |
|
|
|
try { |
|
|
|
cameraBaslerDriver.enable(); |
|
|
|
cameraBaslerDriver.saveColorImg(filePath); |
|
|
|
} finally { |
|
|
|
cameraBaslerDriver.disable(); |
|
|
|
solutionModuleService.fillLightClose(); |
|
|
|
} |
|
|
|
String todayDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
|
|
|
String tempPath = "/temp/" + fileName; |
|
|
|
String imagePath = "/data/" + todayDate + "/" + fileName; |
|
|
|
try { |
|
|
|
Path sourcePath = Paths.get(path + tempPath); |
|
|
|
Path targetPath = Paths.get(path + imagePath); |
|
|
|
Path targetDirectory = targetPath.getParent(); |
|
|
|
if (!Files.exists(targetDirectory)) { |
|
|
|
Files.createDirectories(targetDirectory); |
|
|
|
} |
|
|
|
Files.move(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); |
|
|
|
log.info("工艺照片文件已成功移动!"); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("工艺照片文件已成功移动失败 ", e); |
|
|
|
throw new AppException(ResultCode.SYSTEM_ERROR); |
|
|
|
} |
|
|
|
TrayState trayState = deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleCode); |
|
|
|
CraftsState crafts = trayState.getCrafts(); |
|
|
|
|
|
|
|
Photos photos = new Photos(); |
|
|
|
photos.setMode(PhotoModeType.crafts); |
|
|
|
photos.setOreId(crafts.getCraft().getId()); |
|
|
|
photos.setCraftsId(crafts.getCraft().getId()); |
|
|
|
photos.setOreName(crafts.getCraft().getName()); |
|
|
|
photos.setCraftsName(crafts.getCraft().getName()); |
|
|
|
photos.setImagePath(imagePath); |
|
|
|
photosService.save(photos); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -477,7 +543,7 @@ public class CraftsStepService { |
|
|
|
log.info("工艺{},临时避让下降", heatModuleCode); |
|
|
|
deviceCommandTempUtilService.moveTrayHeatModuleAvoidDownNoWait(heatModuleCode);//TODO 临时避让下降 |
|
|
|
log.info("工艺{},抬升z轴", heatModuleCode); |
|
|
|
gantryModuleService.gantryZMove(0); |
|
|
|
gantryModuleService.gantryZMoveZero();//抬升z轴 |
|
|
|
Thread.sleep(2500);//抬升z轴 |
|
|
|
log.info("工艺{},将携带托盘的机械臂移动至4号加热模块上方", heatModuleCode); |
|
|
|
// gantryModuleService.gantryMove(heatArea4TrayClawPoint3D);//将携带托盘的机械臂移动至4号加热模块上方 |
|
|
@ -492,7 +558,7 @@ public class CraftsStepService { |
|
|
|
log.info("工艺{},将夹爪打开,释放托盘", heatModuleCode); |
|
|
|
gantryModuleService.clawMove(clawTrayPick);//将夹爪打开,释放托盘 |
|
|
|
log.info("工艺{},抬升z轴", heatModuleCode); |
|
|
|
gantryModuleService.gantryZMove(0);//抬升z轴 |
|
|
|
gantryModuleService.gantryZMoveZero();//抬升z轴 |
|
|
|
log.info("工艺{},移动机械臂至拍子存放区上方", heatModuleCode); |
|
|
|
gantryModuleService.gantryXYMove(capStorageCapClawPoint3D);//移动机械臂至拍子存放区上方 |
|
|
|
} |
|
|
|