|
|
@ -5,19 +5,24 @@ import com.qyft.ms.app.device.spray.SprayTaskExecutor; |
|
|
|
import com.qyft.ms.app.device.status.SprayTask; |
|
|
|
import com.qyft.ms.system.common.annotation.CommandMapping; |
|
|
|
import com.qyft.ms.system.common.constant.CommandStatus; |
|
|
|
import com.qyft.ms.system.common.device.command.CommandFuture; |
|
|
|
import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; |
|
|
|
import com.qyft.ms.system.common.device.command.FrontCommand; |
|
|
|
import com.qyft.ms.system.common.utils.CheckedRunnable; |
|
|
|
import com.qyft.ms.system.common.utils.LambdaUtil; |
|
|
|
import com.qyft.ms.system.core.handler.BaseCommandHandler; |
|
|
|
import com.qyft.ms.system.model.bo.DeviceCommand; |
|
|
|
import com.qyft.ms.system.model.form.FrontCmdControlForm; |
|
|
|
import com.qyft.ms.system.service.device.DeviceCommandService; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; |
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
@ -36,6 +41,7 @@ public class MatrixSprayStart extends BaseCommandHandler { |
|
|
|
private static final ExecutorService singleExecutor = Executors.newSingleThreadExecutor(); |
|
|
|
|
|
|
|
private final SprayTaskExecutor sprayTaskExecutor; |
|
|
|
private final DeviceCommandService deviceCommandService; |
|
|
|
|
|
|
|
private static boolean nonNullCheck(ResponseBodyEmitter emitter, String cmdId, String cmdCode, |
|
|
|
String matrixPathType, |
|
|
@ -122,21 +128,9 @@ public class MatrixSprayStart extends BaseCommandHandler { |
|
|
|
|
|
|
|
if (nonNullCheck(emitter, matrixPathType, form.getCmdId(), form.getCmdCode(), motorZHeight, gasPressure, volume, highVoltage, spacing, movingSpeed, times, positionList)) |
|
|
|
return; |
|
|
|
// 2. xyz回原点 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorZPositionSet(0.0),//z轴回原点 |
|
|
|
DeviceCommandGenerator.motorXPositionSet(0.0),//x轴回原点 |
|
|
|
DeviceCommandGenerator.motorYPositionSet(0.0));//y轴回原点 |
|
|
|
// 3. 设定喷涂参数 |
|
|
|
sprayTask.setSprayParam(matrixPathType, motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, spacing, movingSpeed, times, positionList); |
|
|
|
// 4.开启三通阀到喷嘴管路 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.threeWayValveOpenSyringePipeline());//打开三通阀喷嘴管路 |
|
|
|
// 5.移动z轴到玻片上方 |
|
|
|
Double height = 101.2 - motorZHeight;//TODO 101.2是玻片高度,这个应该从数据库中获取 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorZPositionSet(height));//移动z轴到指定高度 |
|
|
|
// 6.是否加电 设定电压 |
|
|
|
if (highVoltage) {//加电 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.highVoltageOpen(highVoltageValue));//开启高压 |
|
|
|
} |
|
|
|
|
|
|
|
// 7.循环喷涂区域 |
|
|
|
Double[][] slideArr = { //TODO 每个玻片的位置,应当从数据库获取 |
|
|
|
{18.08, 0.0}, |
|
|
@ -144,6 +138,7 @@ public class MatrixSprayStart extends BaseCommandHandler { |
|
|
|
{72.08, 0.0}, |
|
|
|
{99.08, 0.0} |
|
|
|
}; |
|
|
|
|
|
|
|
for (Map<String, Object> position : positionList) { |
|
|
|
int index = (int) position.get("index"); //index 第几个玻片 |
|
|
|
Double[] upperLeft = {((Number) position.get("x1")).doubleValue(), ((Number) position.get("y1")).doubleValue()}; //范围左上角 x1,y1 |
|
|
@ -156,8 +151,6 @@ public class MatrixSprayStart extends BaseCommandHandler { |
|
|
|
double right = slideCompleteUCSX + lowerRight[0]; |
|
|
|
double top = slideCompleteUCSY + upperLeft[1]; |
|
|
|
double bottom = slideCompleteUCSY + lowerRight[1]; |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorXPositionSet(slide[0]),//移动x轴到玻片原点 |
|
|
|
DeviceCommandGenerator.motorYPositionSet(slide[1]));//移动y轴到玻片原点 |
|
|
|
if ("horizontal".equals(matrixPathType)) {//喷涂路径类型 horizontal 横向 | vertical 纵向 | grid 网格先横向后纵向 |
|
|
|
for (int i = 0; i < times; i++) { |
|
|
|
double topReal = top; |
|
|
@ -172,20 +165,14 @@ public class MatrixSprayStart extends BaseCommandHandler { |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN |
|
|
|
); |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.nozzleValveOpen(),//开启喷嘴阀 |
|
|
|
DeviceCommandGenerator.syringePumpForward(volume));//推动移动注射泵 |
|
|
|
|
|
|
|
List<List<DeviceCommand>> deviceCommandList = new ArrayList<>(); |
|
|
|
for (PathGenerator.Points p : pathList) {//喷针移动目标位置 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorXPositionSet(p.getX()),//移动x轴 |
|
|
|
DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴 |
|
|
|
} |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.nozzleValveClose(),//关闭喷嘴阀 |
|
|
|
DeviceCommandGenerator.syringePumpStop());//停止推动注射泵 |
|
|
|
|
|
|
|
if (i + 1 != times) { //如果不是最后一次,执行完毕后回到玻片原点 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorXPositionSet(slide[0]),//移动x轴到玻片原点 |
|
|
|
DeviceCommandGenerator.motorYPositionSet(slide[1]));//移动y轴到玻片原点 |
|
|
|
List<DeviceCommand> deviceCommands = new ArrayList<>(); |
|
|
|
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴 |
|
|
|
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴 |
|
|
|
deviceCommandList.add(deviceCommands); |
|
|
|
} |
|
|
|
sprayTask.getSpraySteps().add(deviceCommandList); |
|
|
|
} |
|
|
|
} else if ("vertical".equals(matrixPathType)) { |
|
|
|
for (int i = 0; i < times; i++) { |
|
|
@ -201,20 +188,14 @@ public class MatrixSprayStart extends BaseCommandHandler { |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT |
|
|
|
); |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.nozzleValveOpen(),//开启喷嘴阀 |
|
|
|
DeviceCommandGenerator.syringePumpForward(volume));//推动移动注射泵 |
|
|
|
|
|
|
|
List<List<DeviceCommand>> deviceCommandList = new ArrayList<>(); |
|
|
|
for (PathGenerator.Points p : pathList) {//喷针移动目标位置 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorXPositionSet(p.getX()),//移动x轴 |
|
|
|
DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴 |
|
|
|
} |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.nozzleValveClose(),//关闭喷嘴阀 |
|
|
|
DeviceCommandGenerator.syringePumpStop());//停止推动注射泵 |
|
|
|
|
|
|
|
if (i + 1 != times) { //如果不是最后一次,执行完毕后回到玻片原点 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorXPositionSet(slide[0]),//移动x轴到玻片原点 |
|
|
|
DeviceCommandGenerator.motorYPositionSet(slide[1]));//移动y轴到玻片原点 |
|
|
|
List<DeviceCommand> deviceCommands = new ArrayList<>(); |
|
|
|
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴 |
|
|
|
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴 |
|
|
|
deviceCommandList.add(deviceCommands); |
|
|
|
} |
|
|
|
sprayTask.getSpraySteps().add(deviceCommandList); |
|
|
|
} |
|
|
|
} else if ("grid".equals(matrixPathType)) { |
|
|
|
for (int i = 0; i < times; i++) { |
|
|
@ -234,47 +215,36 @@ public class MatrixSprayStart extends BaseCommandHandler { |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT |
|
|
|
); |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.nozzleValveOpen(),//开启喷嘴阀 |
|
|
|
DeviceCommandGenerator.syringePumpForward(volume));//推动移动注射泵 |
|
|
|
|
|
|
|
List<List<DeviceCommand>> deviceCommandList = new ArrayList<>(); |
|
|
|
for (PathGenerator.Points p : pathList) {//喷针移动目标位置 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorXPositionSet(p.getX()),//移动x轴 |
|
|
|
DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴 |
|
|
|
List<DeviceCommand> deviceCommands = new ArrayList<>(); |
|
|
|
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴 |
|
|
|
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴 |
|
|
|
deviceCommandList.add(deviceCommands); |
|
|
|
} |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.nozzleValveClose(),//关闭喷嘴阀 |
|
|
|
DeviceCommandGenerator.syringePumpStop());//停止推动注射泵 |
|
|
|
sprayTask.getSpraySteps().add(deviceCommandList); |
|
|
|
|
|
|
|
pathList = PathGenerator.generatePathPoints( |
|
|
|
leftReal, rightReal, topReal, bottomReal, |
|
|
|
spacing, |
|
|
|
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT |
|
|
|
); |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.nozzleValveOpen(),//开启喷嘴阀 |
|
|
|
DeviceCommandGenerator.syringePumpForward(volume));//推动移动注射泵 |
|
|
|
deviceCommandList = new ArrayList<>(); |
|
|
|
for (PathGenerator.Points p : pathList) {//喷针移动目标位置 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorXPositionSet(p.getX()),//移动x轴 |
|
|
|
DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴 |
|
|
|
} |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.nozzleValveClose(),//关闭喷嘴阀 |
|
|
|
DeviceCommandGenerator.syringePumpStop());//停止推动注射泵 |
|
|
|
|
|
|
|
if (i + 1 != times) { //如果不是最后一次,执行完毕后回到玻片原点 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorXPositionSet(slide[0]),//移动x轴到玻片原点 |
|
|
|
DeviceCommandGenerator.motorYPositionSet(slide[1]));//移动y轴到玻片原点 |
|
|
|
List<DeviceCommand> deviceCommands = new ArrayList<>(); |
|
|
|
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴 |
|
|
|
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴 |
|
|
|
deviceCommandList.add(deviceCommands); |
|
|
|
} |
|
|
|
sprayTask.getSpraySteps().add(deviceCommandList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// 8.关高压电 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.highVoltageClose());//关闭高压电 |
|
|
|
// 9. xyz回原点 |
|
|
|
sprayTask.addStep(DeviceCommandGenerator.motorZPositionSet(0.0),//z轴回原点 |
|
|
|
DeviceCommandGenerator.motorXPositionSet(0.0),//x轴回原点 |
|
|
|
DeviceCommandGenerator.motorYPositionSet(0.0));//y轴回原点 |
|
|
|
// 10. 启动喷涂线程,开始喷涂 |
|
|
|
sprayTaskExecutor.startTask(); |
|
|
|
|
|
|
|
emitter.send(FrontCommand.backstage(form.getCmdId(), form.getCmdCode(), CommandStatus.SEND, "开始喷涂"), MediaType.APPLICATION_JSON); |
|
|
|
emitter.send(FrontCommand.backstage(form.getCmdId(), form.getCmdCode(), CommandStatus.SEND, "开启喷涂线程"), MediaType.APPLICATION_JSON); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|