diff --git a/matrix-spray.db b/matrix-spray.db index a6c8bca..04f1459 100644 Binary files a/matrix-spray.db and b/matrix-spray.db differ diff --git a/src/main/java/com/qyft/ms/app/service/CMDService.java b/src/main/java/com/qyft/ms/app/service/CMDService.java index fa5cd05..43af010 100644 --- a/src/main/java/com/qyft/ms/app/service/CMDService.java +++ b/src/main/java/com/qyft/ms/app/service/CMDService.java @@ -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.result.CMDResultCode; 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.vo.ExecutionResult; import com.qyft.ms.device.service.DeviceTcpCMDService; @@ -30,6 +31,7 @@ public class CMDService { private final DeviceTcpCMDService deviceTcpCMDService; private final OperationLogService operationLogService; private final MatrixCraftService matrixCraftService; + private final ISysSettingsService sysSettingsService; private void initExecutorThread(List> cmdList, CMDForm form) { @@ -150,78 +152,93 @@ public class CMDService { Map params = form.getParams(); List> cmdList = new ArrayList<>(); // 托盘位置 - Map trayPosition = new HashMap<>(); - trayPosition.put("x", 0); - trayPosition.put("y", 0); - trayPosition.put("z", 0); - int space = (Integer) params.get("space"); + List slidePositionList = sysSettingsService.getSlidePositionList(); List> position = (List>) params.get("position"); - Map p1 = position.get(0); - Map 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 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 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 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("Y")); cmdList.add(() -> deviceTcpCMDService.motorMoveToHome("Z")); + // 结束日志 cmdList.add( () -> { OperationLog operationLog = operationLogService.getIng(); diff --git a/src/main/java/com/qyft/ms/app/service/ISysSettingsService.java b/src/main/java/com/qyft/ms/app/service/ISysSettingsService.java index d69a9c3..eede7ff 100644 --- a/src/main/java/com/qyft/ms/app/service/ISysSettingsService.java +++ b/src/main/java/com/qyft/ms/app/service/ISysSettingsService.java @@ -14,4 +14,5 @@ import java.util.List; */ public interface ISysSettingsService extends IService { + List getSlidePositionList(); } diff --git a/src/main/java/com/qyft/ms/app/service/impl/ISysSettingsServiceImpl.java b/src/main/java/com/qyft/ms/app/service/impl/ISysSettingsServiceImpl.java index 7810189..478767b 100644 --- a/src/main/java/com/qyft/ms/app/service/impl/ISysSettingsServiceImpl.java +++ b/src/main/java/com/qyft/ms/app/service/impl/ISysSettingsServiceImpl.java @@ -1,16 +1,15 @@ package com.qyft.ms.app.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.qyft.ms.app.mapper.SysSettingsMapper; -import com.qyft.ms.app.model.dto.SysSettingsDTO; import com.qyft.ms.app.model.entity.SysSettings; -import com.qyft.ms.app.model.vo.SysSettingResult; -import com.qyft.ms.app.model.vo.SysSettingVO; import com.qyft.ms.app.service.ISysSettingsService; +import jakarta.annotation.PostConstruct; +import lombok.Getter; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.List; /** @@ -19,6 +18,20 @@ import java.util.List; @Service @RequiredArgsConstructor public class ISysSettingsServiceImpl extends ServiceImpl implements ISysSettingsService { + private final SysSettingsMapper sysSettingsMapper; + // 玻片位置 + @Getter + List slidePositionList; + // 电机速度 + @Getter + List motorSpeedList; - + @PostConstruct + public void init() { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("code", "slide_position"); + Long parentId = sysSettingsMapper.selectOne(queryWrapper).getParentId(); + slidePositionList = sysSettingsMapper.selectList(new QueryWrapper().eq("parent_id", parentId)); + motorSpeedList = sysSettingsMapper.selectList(new QueryWrapper().eq("parent_id", new QueryWrapper().eq("code", "speed"))); + } } diff --git a/src/main/java/com/qyft/ms/device/common/constant/DeviceCommands.java b/src/main/java/com/qyft/ms/device/common/constant/DeviceCommands.java index d14dbf3..533bbde 100644 --- a/src/main/java/com/qyft/ms/device/common/constant/DeviceCommands.java +++ b/src/main/java/com/qyft/ms/device/common/constant/DeviceCommands.java @@ -35,5 +35,7 @@ public class DeviceCommands { // 推送指定容量的液体 public static final String PUSH_VOLUME = "pushVolume"; public static final String ROTATE = "rotate"; + public static final String SYRINGE_PUMP_MOVE_AT_SPEED = "syringePumpMoveAtSpeed"; + public static final String SYRINGE_PUMP_STOP = "syringePumpstop"; } \ No newline at end of file diff --git a/src/main/java/com/qyft/ms/device/service/DeviceTcpCMDService.java b/src/main/java/com/qyft/ms/device/service/DeviceTcpCMDService.java index 1f857b3..009f7c7 100644 --- a/src/main/java/com/qyft/ms/device/service/DeviceTcpCMDService.java +++ b/src/main/java/com/qyft/ms/device/service/DeviceTcpCMDService.java @@ -267,4 +267,23 @@ public class DeviceTcpCMDService { params.put("time", time); return this.putTask(DeviceCommands.ROTATE, params); } + + /** + * 注射泵指定速度运动 + * @param speed mm/s 正值负值 代表方向 + */ + + public boolean syringePumpMoveAtSpeed(int speed) { + Map params = new HashMap<>(); + params.put("speed", speed); + return this.putTask(DeviceCommands.SYRINGE_PUMP_MOVE_AT_SPEED, params); + } + + /** + * 注射泵停止移动 + * + */ + public boolean syringePumpstop() { + return this.putTask(DeviceCommands.SYRINGE_PUMP_STOP); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index bbdac81..6d803b8 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -34,7 +34,7 @@ jwt: #与设备TCP链接 tcp: - enable: false # 是否开启 TCP 连接 + enable: true # 是否开启 TCP 连接 host: 192.168.1.130 port: 9080 reconnect: 5000 # 断线重连间隔(单位:毫秒)