|
|
@ -24,6 +24,7 @@ import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
@ -74,31 +75,42 @@ public class SprayTaskExecutor { |
|
|
|
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.START, "喷涂任务开始执行")); |
|
|
|
int reCurrentStep = sprayTask.getCurrentStep(); |
|
|
|
int currentStep = 0; //当前喷涂步骤 |
|
|
|
int sprayCount = 0; |
|
|
|
int sprayNum = 1; |
|
|
|
int currentIndex = 0; |
|
|
|
for (SprayTaskStep sprayTaskStep : sprayTask.getSprayTaskStepList()) {//循环进行多次喷涂 |
|
|
|
//先移动到玻片位置 |
|
|
|
DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskStep.getIndex()][0], 20.0); |
|
|
|
DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskStep.getIndex()][1], 20.0); |
|
|
|
CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand); |
|
|
|
CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand); |
|
|
|
|
|
|
|
SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper<SysSettings>().eq(SysSettings::getCode, "slide_height")); |
|
|
|
Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue()); |
|
|
|
Double height = slideHeight - sprayTask.getSprayParams().getMotorZHeight();//下降z轴高度 |
|
|
|
DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0); |
|
|
|
CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); |
|
|
|
commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture); |
|
|
|
if(!sprayTask.isFirstImmobility()){ |
|
|
|
//先移动到玻片位置 |
|
|
|
DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskStep.getIndex()][0], 20.0); |
|
|
|
DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskStep.getIndex()][1], 20.0); |
|
|
|
CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand); |
|
|
|
CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand); |
|
|
|
|
|
|
|
SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper<SysSettings>().eq(SysSettings::getCode, "slide_height")); |
|
|
|
Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue()); |
|
|
|
Double height = slideHeight - sprayTask.getSprayParams().getMotorZHeight();//下降z轴高度 |
|
|
|
DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0); |
|
|
|
CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); |
|
|
|
commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture); |
|
|
|
}else{ |
|
|
|
sprayTask.setFirstImmobility(false); |
|
|
|
} |
|
|
|
|
|
|
|
DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume());//推动移动注射泵 |
|
|
|
CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand); |
|
|
|
commandWait(syringePumpForwardCommandFuture); |
|
|
|
Thread.sleep(100); |
|
|
|
|
|
|
|
sprayTask.setSuspendable(true);//可以暂停,单次喷涂范围内可以进行暂停 |
|
|
|
deviceStatus.setSuspendable(true); |
|
|
|
double cacheXPoint = -1; |
|
|
|
double cacheYPoint = -1; |
|
|
|
DecimalFormat df = new DecimalFormat("#.##"); |
|
|
|
|
|
|
|
for (int i = 0; i < sprayTaskStep.getSpraySteps().size(); i++) {//单次喷涂 |
|
|
|
if(currentIndex != sprayTaskStep.getIndex()) { |
|
|
|
sprayNum = 0; |
|
|
|
currentIndex = sprayTaskStep.getIndex(); |
|
|
|
} |
|
|
|
if (currentStep < reCurrentStep) { |
|
|
|
currentStep++; |
|
|
|
continue; |
|
|
@ -112,6 +124,9 @@ public class SprayTaskExecutor { |
|
|
|
double aXPoint = (double) xSprayStepCommands.getParam().get("position"); |
|
|
|
double aYPoint = (double) ySprayStepCommands.getParam().get("position"); |
|
|
|
|
|
|
|
xSprayStepCommands.getParam().put("position", Double.parseDouble(df.format(aXPoint))); |
|
|
|
ySprayStepCommands.getParam().put("position", Double.parseDouble(df.format(aYPoint))); |
|
|
|
|
|
|
|
if (cacheXPoint != aXPoint) { |
|
|
|
CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands); |
|
|
|
commandFutureList.add(commandFuture); |
|
|
@ -123,38 +138,31 @@ public class SprayTaskExecutor { |
|
|
|
cacheYPoint = aYPoint; |
|
|
|
} |
|
|
|
CommandFuture[] commandFutureArray = commandFutureList.toArray(new CommandFuture[0]); |
|
|
|
Point2D currentPoint; |
|
|
|
Point2D nextPoint = null; |
|
|
|
if (i != 0) { |
|
|
|
List<DeviceCommand> currentSprayStepCommands = sprayTaskStep.getSpraySteps().get(i - 1); |
|
|
|
double currentXPoint = (Double) currentSprayStepCommands.get(0).getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0]; |
|
|
|
double currentYPoint = 75.5 - (Double) currentSprayStepCommands.get(1).getParam().get("position"); |
|
|
|
currentPoint = new Point2D(currentXPoint, currentYPoint); |
|
|
|
double nextXPoint = (Double) xSprayStepCommands.getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0]; |
|
|
|
double nextYPoint = 75.5 - (Double) ySprayStepCommands.getParam().get("position"); |
|
|
|
nextPoint = new Point2D(nextXPoint, nextYPoint); |
|
|
|
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, currentPoint, nextPoint); |
|
|
|
webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO); |
|
|
|
} |
|
|
|
|
|
|
|
double currentXPoint = Double.parseDouble(df.format((Double) xSprayStepCommands.getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0])); |
|
|
|
double currentYPoint = Double.parseDouble(df.format(75.5 - (Double) ySprayStepCommands.getParam().get("position"))); |
|
|
|
Point2D currentPoint = new Point2D(currentXPoint, currentYPoint); |
|
|
|
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, sprayCount, currentPoint); |
|
|
|
webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO); |
|
|
|
|
|
|
|
commandWait(commandFutureArray); |
|
|
|
currentStep++; |
|
|
|
sprayTask.setCurrentStep(currentStep);//将当前的喷涂进度缓存 |
|
|
|
if (nextPoint != null) { |
|
|
|
//将当前点位缓存 |
|
|
|
SprayTaskSprayed sprayTaskSprayed = new SprayTaskSprayed(); |
|
|
|
sprayTaskSprayed.setNumber(sprayNum); |
|
|
|
sprayTaskSprayed.setIndex(sprayTaskStep.getIndex()); |
|
|
|
sprayTaskSprayed.setSprayedPoints(new Point2D(nextPoint.getX(), nextPoint.getY())); |
|
|
|
sprayTask.addSprayTaskSprayed(sprayTaskSprayed); |
|
|
|
} |
|
|
|
//将当前点位缓存 |
|
|
|
SprayTaskSprayed sprayTaskSprayed = new SprayTaskSprayed(); |
|
|
|
sprayTaskSprayed.setNumber(sprayNum); |
|
|
|
sprayTaskSprayed.setIndex(sprayTaskStep.getIndex()); |
|
|
|
sprayTaskSprayed.setSprayCount(sprayCount); |
|
|
|
sprayTaskSprayed.setSprayedPoints(new Point2D(Double.parseDouble(df.format(aXPoint - slideArr[sprayTaskStep.getIndex()][0])), Double.parseDouble(df.format(75.5 - aYPoint)))); |
|
|
|
sprayTask.addSprayTaskSprayed(sprayTaskSprayed); |
|
|
|
} |
|
|
|
sprayTask.setSuspendable(false);//不可暂停 |
|
|
|
deviceStatus.setSuspendable(false); |
|
|
|
|
|
|
|
|
|
|
|
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵 |
|
|
|
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand); |
|
|
|
commandWait(syringePumpStopCommandFuture); |
|
|
|
sprayCount++; |
|
|
|
sprayNum++; |
|
|
|
} |
|
|
|
|
|
|
|