|
@ -6,6 +6,7 @@ import com.qyft.ms.app.common.constant.WebSocketMessageType; |
|
|
import com.qyft.ms.app.common.generator.PathGenerator; |
|
|
import com.qyft.ms.app.common.generator.PathGenerator; |
|
|
import com.qyft.ms.app.common.result.CMDResultCode; |
|
|
import com.qyft.ms.app.common.result.CMDResultCode; |
|
|
import com.qyft.ms.app.model.entity.OperationLog; |
|
|
import com.qyft.ms.app.model.entity.OperationLog; |
|
|
|
|
|
import com.qyft.ms.app.model.entity.SysSettings; |
|
|
import com.qyft.ms.app.model.form.CMDForm; |
|
|
import com.qyft.ms.app.model.form.CMDForm; |
|
|
import com.qyft.ms.app.model.vo.ExecutionResult; |
|
|
import com.qyft.ms.app.model.vo.ExecutionResult; |
|
|
import com.qyft.ms.device.service.DeviceTcpCMDService; |
|
|
import com.qyft.ms.device.service.DeviceTcpCMDService; |
|
@ -30,6 +31,7 @@ public class CMDService { |
|
|
private final DeviceTcpCMDService deviceTcpCMDService; |
|
|
private final DeviceTcpCMDService deviceTcpCMDService; |
|
|
private final OperationLogService operationLogService; |
|
|
private final OperationLogService operationLogService; |
|
|
private final MatrixCraftService matrixCraftService; |
|
|
private final MatrixCraftService matrixCraftService; |
|
|
|
|
|
private final ISysSettingsService sysSettingsService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initExecutorThread(List<Supplier<Boolean>> cmdList, CMDForm form) { |
|
|
private void initExecutorThread(List<Supplier<Boolean>> cmdList, CMDForm form) { |
|
@ -150,78 +152,93 @@ public class CMDService { |
|
|
Map<String, Object> params = form.getParams(); |
|
|
Map<String, Object> params = form.getParams(); |
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
// 托盘位置 |
|
|
// 托盘位置 |
|
|
Map<String, Integer> trayPosition = new HashMap<>(); |
|
|
|
|
|
trayPosition.put("x", 0); |
|
|
|
|
|
trayPosition.put("y", 0); |
|
|
|
|
|
trayPosition.put("z", 0); |
|
|
|
|
|
int space = (Integer) params.get("space"); |
|
|
|
|
|
|
|
|
List<SysSettings> slidePositionList = sysSettingsService.getSlidePositionList(); |
|
|
List<Map<String, Integer>> position = (List<Map<String, Integer>>) params.get("position"); |
|
|
List<Map<String, Integer>> position = (List<Map<String, Integer>>) params.get("position"); |
|
|
Map<String, Integer> p1 = position.get(0); |
|
|
|
|
|
Map<String, Integer> p2 = position.get(1); |
|
|
|
|
|
// 托盘点位 x y z |
|
|
|
|
|
int left = trayPosition.get("x")+ p1.get("x"); |
|
|
|
|
|
int right = trayPosition.get("x") + p2.get("x"); |
|
|
|
|
|
int top = trayPosition.get("y") + p2.get("y"); |
|
|
|
|
|
int bottom = trayPosition.get("y") + p1.get("y"); |
|
|
|
|
|
// 获取轨迹list |
|
|
|
|
|
int direction = (Integer) params.get("direction"); |
|
|
|
|
|
List<Point> horizontalPath = generatePathPoints( |
|
|
|
|
|
left, right, bottom, top, space, direction == 1 ? PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN : PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
if (position == null) { |
|
|
|
|
|
throw new RuntimeException("position参数错误"); |
|
|
|
|
|
} |
|
|
|
|
|
for (int i = 0; i < position.size(); i++) { |
|
|
|
|
|
Map<String, Integer> p = position.get(i); |
|
|
|
|
|
|
|
|
// 将三通阀转至喷涂管路 |
|
|
|
|
|
cmdList.add(deviceTcpCMDService::switchThreeWayValveToSpray); |
|
|
|
|
|
// 设置指定轴的电机的运行速度 |
|
|
|
|
|
int setMotorSpeed = (Integer) params.get("setMotorSpeed"); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("x", setMotorSpeed)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("y", setMotorSpeed)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("z", setMotorSpeed)); |
|
|
|
|
|
// 移动到指定高度(位置) |
|
|
|
|
|
int height = (Integer) params.get("height"); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("z",trayPosition.get("z") + height )); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("x", left)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("y", top)); |
|
|
|
|
|
|
|
|
if (p.get("x1") == null || p.get("y1") == null || p.get("x2") == null || p.get("y2") == null || p.get("index") == null) { |
|
|
|
|
|
throw new RuntimeException("position参数错误"); |
|
|
|
|
|
} |
|
|
|
|
|
// 玻片的位置 |
|
|
|
|
|
String p1 = slidePositionList.get(p.get("index")).getValue(); |
|
|
|
|
|
String[] p1s = p1.split(","); |
|
|
|
|
|
int x = Integer.parseInt(p1s[0]); |
|
|
|
|
|
int y = Integer.parseInt(p1s[1]); |
|
|
|
|
|
int z = Integer.parseInt(p1s[2]); |
|
|
|
|
|
|
|
|
// 是否加电 电压 |
|
|
|
|
|
Object voltage = params.get("voltage"); |
|
|
|
|
|
if (voltage instanceof Integer) { |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.turnOnHighVoltage( (Integer) voltage)); |
|
|
|
|
|
} |
|
|
|
|
|
// 开启喷嘴阀 |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.controlValve("Nozzle", true)); |
|
|
|
|
|
// 推注射泵 |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.turnOnSyringePump(100, "right", 5000)); |
|
|
|
|
|
|
|
|
// 玻片范围的实际位置 |
|
|
|
|
|
// 托盘点位 x y z |
|
|
|
|
|
int left =x+ p.get("x1"); |
|
|
|
|
|
int right = x+ p.get("x2"); |
|
|
|
|
|
int top = y+ p.get("y1"); |
|
|
|
|
|
int bottom = y+ p.get("y2"); |
|
|
|
|
|
|
|
|
// 插入日志 |
|
|
|
|
|
cmdList.add( () -> { |
|
|
|
|
|
OperationLog operationLog = new OperationLog(); |
|
|
|
|
|
operationLog.setStatus(0); |
|
|
|
|
|
operationLog.setMatrixId((Long) params.get("matrixCraftId")); |
|
|
|
|
|
operationLog.setMatrixInfo(JSON.toJSONString(params)); |
|
|
|
|
|
operationLogService.add(operationLog); |
|
|
|
|
|
return true; |
|
|
|
|
|
}); |
|
|
|
|
|
// 执行轨迹 |
|
|
|
|
|
double curX = left; |
|
|
|
|
|
double curY = top; |
|
|
|
|
|
for (Point point : horizontalPath) { |
|
|
|
|
|
double nextX = (int) point.getX(); |
|
|
|
|
|
double nextY = (int) point.getY(); |
|
|
|
|
|
double distanceX = nextX - curX; |
|
|
|
|
|
double distanceY = nextY - curY; |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("x", distanceX)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("y", distanceY)); |
|
|
|
|
|
curX = nextX; |
|
|
|
|
|
curY = nextY; |
|
|
|
|
|
|
|
|
int space = (Integer) params.get("space"); |
|
|
|
|
|
int direction = (Integer) params.get("direction"); |
|
|
|
|
|
List<Point> horizontalPath = generatePathPoints( |
|
|
|
|
|
left, right, bottom, top, space, direction == 1 ? PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN : PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 将三通阀转至喷涂管路 |
|
|
|
|
|
cmdList.add(deviceTcpCMDService::switchThreeWayValveToSpray); |
|
|
|
|
|
// 设置指定轴的电机的运行速度 |
|
|
|
|
|
int movementSpeed = (Integer) params.get("movementSpeed"); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("x", movementSpeed)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("y", movementSpeed)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed("z", movementSpeed)); |
|
|
|
|
|
// 移动到指定高度(位置) |
|
|
|
|
|
int height = (Integer) params.get("height"); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("z",z + height )); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("x", left)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("y", top)); |
|
|
|
|
|
|
|
|
|
|
|
// 是否加电 电压 |
|
|
|
|
|
Object voltage = params.get("voltage"); |
|
|
|
|
|
if (voltage instanceof Integer) { |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.turnOnHighVoltage( (Integer) voltage)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 开启喷嘴阀 |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.controlValve("Nozzle", true)); |
|
|
|
|
|
// 推注射泵 |
|
|
|
|
|
// TODO 这里不管 |
|
|
|
|
|
int matrixFlowVelocity = (int) params.get("matrixFlowVelocity"); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.syringePumpMoveAtSpeed(matrixFlowVelocity)); |
|
|
|
|
|
|
|
|
|
|
|
// 插入日志 |
|
|
|
|
|
if(i == 0) { |
|
|
|
|
|
cmdList.add( () -> { |
|
|
|
|
|
OperationLog operationLog = new OperationLog(); |
|
|
|
|
|
operationLog.setStatus(0); |
|
|
|
|
|
operationLog.setMatrixId((Long) params.get("matrixCraftId")); |
|
|
|
|
|
operationLog.setMatrixInfo(JSON.toJSONString(params)); |
|
|
|
|
|
operationLogService.add(operationLog); |
|
|
|
|
|
return true; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 执行轨迹 |
|
|
|
|
|
for (Point point : horizontalPath) { |
|
|
|
|
|
double nextX = (int) point.getX(); |
|
|
|
|
|
double nextY = (int) point.getY(); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("x", nextX)); |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("y", nextY)); |
|
|
|
|
|
} |
|
|
|
|
|
// 停止喷涂 |
|
|
|
|
|
cmdList.add(deviceTcpCMDService::turnOffSyringePump); |
|
|
|
|
|
// 关闭喷嘴阀 |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.controlValve("Nozzle", true)); |
|
|
} |
|
|
} |
|
|
// 停止喷涂 |
|
|
|
|
|
cmdList.add(deviceTcpCMDService::turnOffSyringePump); |
|
|
|
|
|
// 关闭喷嘴阀 |
|
|
|
|
|
cmdList.add(() -> deviceTcpCMDService.controlValve("Nozzle", true)); |
|
|
|
|
|
// 回到原点 |
|
|
// 回到原点 |
|
|
cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("X")); |
|
|
cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("X")); |
|
|
cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Y")); |
|
|
cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Y")); |
|
|
cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Z")); |
|
|
cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Z")); |
|
|
|
|
|
|
|
|
// 结束日志 |
|
|
// 结束日志 |
|
|
cmdList.add( () -> { |
|
|
cmdList.add( () -> { |
|
|
OperationLog operationLog = operationLogService.getIng(); |
|
|
OperationLog operationLog = operationLogService.getIng(); |
|
|