|
|
@ -67,41 +67,24 @@ public class SprayTaskExecutor { |
|
|
|
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.DEVICE_ERROR, "设备正在喷涂,请先停止喷涂")); |
|
|
|
return; |
|
|
|
} |
|
|
|
Position slidePosition1 = positionService.getOne(new LambdaQueryWrapper<Position>().eq(Position::getPointCode, "slide_position1")); |
|
|
|
Position slidePosition2 = positionService.getOne(new LambdaQueryWrapper<Position>().eq(Position::getPointCode, "slide_position2")); |
|
|
|
Position slidePosition3 = positionService.getOne(new LambdaQueryWrapper<Position>().eq(Position::getPointCode, "slide_position3")); |
|
|
|
Position slidePosition4 = positionService.getOne(new LambdaQueryWrapper<Position>().eq(Position::getPointCode, "slide_position4")); |
|
|
|
Double[][] slideArr = { |
|
|
|
{slidePosition1.getX(), slidePosition1.getY()}, |
|
|
|
{slidePosition2.getX(), slidePosition2.getY()}, |
|
|
|
{slidePosition3.getX(), slidePosition3.getY()}, |
|
|
|
{slidePosition4.getX(), slidePosition4.getY()} |
|
|
|
}; |
|
|
|
|
|
|
|
taskThread = new Thread(() -> { |
|
|
|
try { |
|
|
|
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.START, "喷涂任务开始执行")); |
|
|
|
List<SprayTaskParams> sprayTaskParams = sprayTask.getSprayTaskParams(); |
|
|
|
|
|
|
|
DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline();//打开三通阀注射器管路 |
|
|
|
CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), threeWayValveOpenSyringePipelineCommand); |
|
|
|
commandWait(threeWayValveOpenSyringePipelineCommandFuture); |
|
|
|
|
|
|
|
DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen();//开启喷嘴阀 |
|
|
|
CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveOpenCommand); |
|
|
|
commandWait(nozzleValveOpenCommandFuture); |
|
|
|
|
|
|
|
int currentStep = 0; //当前喷涂步骤 |
|
|
|
int sprayCount = 0; |
|
|
|
int sprayNum = 1; |
|
|
|
int currentIndex = 0; |
|
|
|
int currentStep = 0; //不管是暂停还是新的线程,记录当前线程喷涂步骤序号 |
|
|
|
int sprayNum = 1; //当前玻片是第几次喷涂 |
|
|
|
for (SprayTaskParams sprayTaskParam : sprayTaskParams) {//循环玻片 |
|
|
|
if (sprayTask.getCurrentIndex() != null && sprayTaskParam.getIndex() > sprayTask.getCurrentIndex()) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
sprayTask.setCurrentIndex(sprayTaskParam.getIndex()); |
|
|
|
for (SprayTimes sprayTimes : sprayTaskParam.getTimes()) {//每个拨片有多次喷涂,循环每次喷涂 |
|
|
|
sprayTask.setSprayTimes(sprayTimes); |
|
|
|
Double[] slide = slideArr[sprayTaskParam.getIndex()];//获取玻片的坐标 |
|
|
|
|
|
|
|
List<SprayTaskStep> sprayTaskStepList = getSprayPath(sprayTaskParam.getIndex(), sprayTimes);//计算本次喷涂的路线 |
|
|
|
//先移动到玻片位置 |
|
|
|
//先移动到玻片左上角位置 |
|
|
|
DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskParam.getIndex()][0], 20.0); |
|
|
|
DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskParam.getIndex()][1], 20.0); |
|
|
|
CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand); |
|
|
@ -113,10 +96,31 @@ public class SprayTaskExecutor { |
|
|
|
DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0); |
|
|
|
CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); |
|
|
|
commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture); |
|
|
|
Thread.sleep(100); |
|
|
|
|
|
|
|
DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline();//打开三通阀注射器管路 |
|
|
|
CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), threeWayValveOpenSyringePipelineCommand); |
|
|
|
|
|
|
|
DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen();//开启喷嘴阀 |
|
|
|
CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveOpenCommand); |
|
|
|
commandWait(threeWayValveOpenSyringePipelineCommandFuture, nozzleValveOpenCommandFuture); |
|
|
|
|
|
|
|
delay(500); |
|
|
|
//判断是否有暂停的点位,如果有则还原暂停时的点位 |
|
|
|
Point3D currentPausedPoint = sprayTask.getCurrentPausedPoint(); |
|
|
|
if (currentPausedPoint != null) { |
|
|
|
DeviceCommand motorXRestoreCommand = DeviceCommandGenerator.motorXPositionSet(currentPausedPoint.x, 20.0); |
|
|
|
DeviceCommand motorYRestoreCommand = DeviceCommandGenerator.motorYPositionSet(currentPausedPoint.y, 20.0); |
|
|
|
DeviceCommand motorZRestoreCommand = DeviceCommandGenerator.motorZPositionSet(currentPausedPoint.z, 20.0); |
|
|
|
CommandFuture motorXRestoreCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXRestoreCommand); |
|
|
|
CommandFuture motorYRestoreCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYRestoreCommand); |
|
|
|
CommandFuture motorZRestoreCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZRestoreCommand); |
|
|
|
commandWait(motorXRestoreCommandFuture, motorYRestoreCommandFuture, motorZRestoreCommandFuture); |
|
|
|
sprayTask.setCurrentPausedPoint(null); |
|
|
|
} |
|
|
|
|
|
|
|
//因为走的是折现,所以单词指令只需要移动x或y,缓存上一个点位用来判断本次是走x还是y |
|
|
|
double cacheXPoint = -1; |
|
|
|
double cacheYPoint = -1; |
|
|
|
sprayNum++; |
|
|
|
for (SprayTaskStep sprayTaskStep : sprayTaskStepList) {//因为田字格喷涂其实是两次 |
|
|
|
if (sprayTimes.getHighVoltage()) {//加电 |
|
|
|
DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(sprayTimes.getHighVoltageValue());//开启高压 |
|
|
@ -128,6 +132,10 @@ public class SprayTaskExecutor { |
|
|
|
CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand); |
|
|
|
commandWait(syringePumpForwardCommandFuture); |
|
|
|
for (int i = 0; i < sprayTaskStep.getSprayPathPointList().size(); i++) {//循环路线 |
|
|
|
if (currentStep < sprayTask.getCurrentStep()) { |
|
|
|
currentStep++; |
|
|
|
continue; |
|
|
|
} |
|
|
|
Point2D currentPoint = sprayTaskStep.getSprayPathPointList().get(i); |
|
|
|
List<CommandFuture> commandFutureList = new ArrayList<>(); |
|
|
|
if (cacheXPoint != currentPoint.x) { |
|
|
@ -142,19 +150,19 @@ public class SprayTaskExecutor { |
|
|
|
commandFutureList.add(commandFuture); |
|
|
|
cacheYPoint = currentPoint.y; |
|
|
|
} |
|
|
|
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskParam.getIndex(), sprayNum, sprayCount, currentPoint); |
|
|
|
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskParam.getIndex(), sprayNum, currentPoint); |
|
|
|
webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO);//向前端推送当前路径 |
|
|
|
|
|
|
|
CommandFuture[] commandFutureArray = commandFutureList.toArray(new CommandFuture[0]); |
|
|
|
commandWait(commandFutureArray); |
|
|
|
currentStep++;//当前喷涂步数自增 |
|
|
|
currentStep++;//当前喷涂步数。因为暂停可能本次路线还没走完,所以这里只有在走完一次路线后才会自增 |
|
|
|
sprayTask.setCurrentStep(currentStep); |
|
|
|
} |
|
|
|
//一次喷涂完毕后停止推注射泵 |
|
|
|
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵 |
|
|
|
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand); |
|
|
|
commandWait(syringePumpStopCommandFuture); |
|
|
|
} |
|
|
|
sprayCount++; |
|
|
|
sprayNum++; |
|
|
|
} |
|
|
|
} |
|
|
@ -176,6 +184,10 @@ public class SprayTaskExecutor { |
|
|
|
CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZOriginCommand); |
|
|
|
commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture); |
|
|
|
|
|
|
|
SprayTask.getInstance().clear(); |
|
|
|
deviceStatus.setSpraying(false);//是否正在进行喷涂 |
|
|
|
deviceStatus.setPaused(false);//是否暂停 |
|
|
|
|
|
|
|
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SUCCESS, "喷涂任务执行成功")); |
|
|
|
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束")); |
|
|
|
} catch (InterruptedException e) { |
|
|
@ -184,13 +196,10 @@ public class SprayTaskExecutor { |
|
|
|
log.info("喷涂任务失败", e); |
|
|
|
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.FAIL, "喷涂任务执行失败")); |
|
|
|
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束")); |
|
|
|
|
|
|
|
SprayTask.getInstance().clear(); |
|
|
|
deviceStatus.setSpraying(false);//是否正在进行喷涂 |
|
|
|
deviceStatus.setPaused(false);//是否暂停 |
|
|
|
} finally { |
|
|
|
SprayTask.getInstance().clear(); |
|
|
|
deviceStatus.setSpraying(false); |
|
|
|
deviceStatus.setPaused(false); |
|
|
|
deviceStatus.setSuspendable(false); |
|
|
|
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SEND, "喷涂任务线程退出")); |
|
|
|
// 在线程结束后将 taskThread 设置为 null,保证状态一致和资源释放 |
|
|
|
synchronized (this) { |
|
|
@ -272,4 +281,11 @@ public class SprayTaskExecutor { |
|
|
|
return sprayTaskStepList; |
|
|
|
} |
|
|
|
|
|
|
|
private void delay(long millisecond) { |
|
|
|
try { |
|
|
|
Thread.sleep(millisecond); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |