Browse Source

feat: 喷涂逻辑

master
guoapeng 5 months ago
parent
commit
980a5d29a4
  1. BIN
      matrix-spray.db
  2. 143
      src/main/java/com/qyft/ms/app/service/CMDService.java
  3. 1
      src/main/java/com/qyft/ms/app/service/ISysSettingsService.java
  4. 23
      src/main/java/com/qyft/ms/app/service/impl/ISysSettingsServiceImpl.java
  5. 2
      src/main/java/com/qyft/ms/device/common/constant/DeviceCommands.java
  6. 19
      src/main/java/com/qyft/ms/device/service/DeviceTcpCMDService.java
  7. 2
      src/main/resources/application.yml

BIN
matrix-spray.db

143
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.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();

1
src/main/java/com/qyft/ms/app/service/ISysSettingsService.java

@ -14,4 +14,5 @@ import java.util.List;
*/ */
public interface ISysSettingsService extends IService<SysSettings> { public interface ISysSettingsService extends IService<SysSettings> {
List<SysSettings> getSlidePositionList();
} }

23
src/main/java/com/qyft/ms/app/service/impl/ISysSettingsServiceImpl.java

@ -1,16 +1,15 @@
package com.qyft.ms.app.service.impl; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qyft.ms.app.mapper.SysSettingsMapper; 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.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 com.qyft.ms.app.service.ISysSettingsService;
import jakarta.annotation.PostConstruct;
import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -19,6 +18,20 @@ import java.util.List;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class ISysSettingsServiceImpl extends ServiceImpl<SysSettingsMapper, SysSettings> implements ISysSettingsService { public class ISysSettingsServiceImpl extends ServiceImpl<SysSettingsMapper, SysSettings> implements ISysSettingsService {
private final SysSettingsMapper sysSettingsMapper;
// 玻片位置
@Getter
List<SysSettings> slidePositionList;
// 电机速度
@Getter
List<SysSettings> motorSpeedList;
@PostConstruct
public void init() {
QueryWrapper<SysSettings> queryWrapper = new QueryWrapper<>();
queryWrapper.in("code", "slide_position");
Long parentId = sysSettingsMapper.selectOne(queryWrapper).getParentId();
slidePositionList = sysSettingsMapper.selectList(new QueryWrapper<SysSettings>().eq("parent_id", parentId));
motorSpeedList = sysSettingsMapper.selectList(new QueryWrapper<SysSettings>().eq("parent_id", new QueryWrapper<SysSettings>().eq("code", "speed")));
}
} }

2
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 PUSH_VOLUME = "pushVolume";
public static final String ROTATE = "rotate"; public static final String ROTATE = "rotate";
public static final String SYRINGE_PUMP_MOVE_AT_SPEED = "syringePumpMoveAtSpeed";
public static final String SYRINGE_PUMP_STOP = "syringePumpstop";
} }

19
src/main/java/com/qyft/ms/device/service/DeviceTcpCMDService.java

@ -267,4 +267,23 @@ public class DeviceTcpCMDService {
params.put("time", time); params.put("time", time);
return this.putTask(DeviceCommands.ROTATE, params); return this.putTask(DeviceCommands.ROTATE, params);
} }
/**
* 注射泵指定速度运动
* @param speed mm/s 正值负值 代表方向
*/
public boolean syringePumpMoveAtSpeed(int speed) {
Map<String, Object> 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);
}
} }

2
src/main/resources/application.yml

@ -34,7 +34,7 @@ jwt:
#与设备TCP链接 #与设备TCP链接
tcp: tcp:
enable: false # 是否开启 TCP 连接
enable: true # 是否开启 TCP 连接
host: 192.168.1.130 host: 192.168.1.130
port: 9080 port: 9080
reconnect: 5000 # 断线重连间隔(单位:毫秒) reconnect: 5000 # 断线重连间隔(单位:毫秒)

Loading…
Cancel
Save