Browse Source

fix:业务指令修改

master
王梦远 2 months ago
parent
commit
f3c7d06229
  1. 56
      src/main/java/com/iflytop/sgs/app/cmd/control/CleanStartCommand.java
  2. 45
      src/main/java/com/iflytop/sgs/app/cmd/control/LiquidAddCommand.java
  3. 43
      src/main/java/com/iflytop/sgs/app/cmd/control/LiquidReduceCommand.java
  4. 8
      src/main/java/com/iflytop/sgs/common/cmd/DeviceCommandGenerator.java
  5. 5
      src/main/java/com/iflytop/sgs/common/enums/SystemConfigCode.java
  6. 1
      src/main/java/com/iflytop/sgs/common/enums/cmd/CmdAction.java

56
src/main/java/com/iflytop/sgs/app/cmd/control/CleanStartCommand.java

@ -1,22 +1,28 @@
package com.iflytop.sgs.app.cmd.control;
import cn.hutool.core.lang.Assert;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.bo.Point3D;
import com.iflytop.sgs.app.model.bo.status.device.TrayState;
import com.iflytop.sgs.app.model.bo.status.device.TubeState;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.api.DevicePositionService;
import com.iflytop.sgs.app.service.api.SystemConfigService;
import com.iflytop.sgs.app.service.device.DeviceStateService;
import com.iflytop.sgs.app.service.device.module.HeatModuleService;
import com.iflytop.sgs.app.service.device.module.SolutionModuleService;
import com.iflytop.sgs.app.service.device.module.TransferModuleService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import com.iflytop.sgs.common.enums.SystemConfigCode;
import com.iflytop.sgs.common.enums.ValveStateCode;
import com.iflytop.sgs.common.enums.data.DevicePositionCode;
import com.iflytop.sgs.common.exception.AppException;
import com.iflytop.sgs.common.result.ResultCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
@ -30,47 +36,43 @@ public class CleanStartCommand extends BaseCommandHandler {
private final SolutionModuleService solutionModuleService;
private final DevicePositionService devicePositionService;
private final TransferModuleService transferModuleService;
private final DeviceStateService deviceStateService;
private final HeatModuleService heatModuleService;
private final SystemConfigService systemConfigService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
//清洗次数
Integer cycle = cmdDTO.getIntegerParam("cycle");
String targetHeatModuleCodeStr = cmdDTO.getStringParam("heatModuleCode");
HeatModuleCode targetHeatModuleCode = HeatModuleCode.valueOf(targetHeatModuleCodeStr);//目标加热模块
//TODO 判断目标加热模块传感器是否有托盘如果没有托盘的话提示错误
Point3D targetHeatModuleTrayClawPoint3D = heatModuleService.getHeatModuleTrayClawPoint3D(targetHeatModuleCode);//获取目标加热模块托盘夹取点
Double transferModuleXPickTrayMoveDistance = devicePositionService.getPosition(DevicePositionCode.transferModuleXPickTrayMoveDistance).getDistance();//获取转运模块X轴拿取托盘进出卡槽移动距离
Double transferModuleZPickTrayDownPositon = devicePositionService.getPosition(DevicePositionCode.transferModuleZPickTrayDownPositon).getPositon();//获取转运模块Z轴拿取托盘时下降的高度位置
//TODO 需要先更新一下托盘状态 状态码新增转运模块是否有托盘
Assert.isTrue(deviceStateService.getDeviceState().getTransferModule().isTrayStatus(),()->new AppException(ResultCode.TARGET_HEAT_MODULE_NO_TRAY));
double cleanWaterVolume= Double.parseDouble(systemConfigService.getSystemConfigValueByCode(SystemConfigCode.volume_clean));//清洁时加水的量
double waterScale= Double.parseDouble(systemConfigService.getSystemConfigValueByCode(SystemConfigCode.scale_water));//水转换系数
double pumpPosition= Double.parseDouble(systemConfigService.getSystemConfigValueByCode(SystemConfigCode.number_reduce));//抽液时蠕动泵移动
Double solutionModuleMotorDownInTubeExtPositon = devicePositionService.getPosition(DevicePositionCode.solutionModuleMotorDownInTubeExtPositon).getPositon();//加液模块电机下降进入试管抽取位置
Integer cycle = cmdDTO.getIntegerParam("cycle");//清洗次数
Point3D liquidAreaTrayPoint3D = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D();//获取加液时托盘位置点
Double trayTubeHorizontalSpacingDistance = devicePositionService.getPosition(DevicePositionCode.trayTubeHorizontalSpacingDistance).getDistance();//获取托盘试管水平间距
Double solutionModuleMotorDownInTubeAddPositon = devicePositionService.getPosition(DevicePositionCode.solutionModuleMotorDownInTubeAddPositon).getPositon();//加液模块电机下降进入试管加液位置
TrayState trayState = deviceStateService.getDeviceState().getTrayByHeatModuleCode(targetHeatModuleCode);
List<TrayState> trayStates=deviceStateService.getDeviceState().getTrays();//所有的托盘
TrayState trayState=trayStates.stream().filter(TrayState::isInSolutionPositon).findFirst().get();//加液位的托盘
return runAsync(() -> {
transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), targetHeatModuleTrayClawPoint3D.getX() + transferModuleXPickTrayMoveDistance);//将X轴移动至夹取点 + 移动距离
transferModuleService.transferZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), transferModuleZPickTrayDownPositon);//将Z轴下降至托盘夹取点高度
transferModuleService.transferXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), -transferModuleXPickTrayMoveDistance);//X轴进入卡槽
transferModuleService.transferZMoveZero(cmdDTO.getCommandId(), cmdDTO.getCommand());//Z轴抬升至最高
transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D.getX());//将X轴移动至加液时托盘位置点
solutionModuleService.liquidValveSwitch(cmdDTO.getCommandId(), cmdDTO.getCommand(), ValveStateCode.waste);//电磁阀对应通道打开
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(),solutionModuleMotorDownInTubeExtPositon);//加液模块下降进入试管抽取位置
solutionModuleService.liquidPumpMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), pumpPosition);
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(),0.0);//加液模块上升
solutionModuleService.liquidValveSwitch(cmdDTO.getCommandId(), cmdDTO.getCommand(), ValveStateCode.water);//电磁阀对应通道打开
for (int i = 0; i < cycle; i++) {
for(TubeState tubeState : trayState.getTubes()){ //TODO 切换阀门加液取等操作没完成以后再考虑应该是先对所有列进行加液然后从头再依次抽取
for(TubeState tubeState : trayState.getTubes()){
if(tubeState.isAddSolution() && tubeState.isExists()){
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(),solutionModuleMotorDownInTubeAddPositon);//加液模块下降进入试管
//TODO
transferModuleService.transferXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), -trayTubeHorizontalSpacingDistance);//X轴依次按照试管间距移动
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(),solutionModuleMotorDownInTubeExtPositon);//加液模块下降进入试管抽取位置
solutionModuleService.liquidPumpMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), cleanWaterVolume*waterScale);
//todo 线程sleep指定时间
solutionModuleService.liquidPumpMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), -cleanWaterVolume*waterScale);
double distance=(tubeState.getColumnNum()-1)*trayTubeHorizontalSpacingDistance;
transferModuleService.transferXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), -distance);//X轴依次按照试管间距移动
}
}
}
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(),0);//加液模块上升至最高移出试管
transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), targetHeatModuleTrayClawPoint3D.getX());//将X轴移动至之前的加热模块上方
transferModuleService.transferZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), transferModuleZPickTrayDownPositon);//Z轴下降至夹取点使托盘落入石墨加热盘
transferModuleService.transferXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), transferModuleXPickTrayMoveDistance);//X轴移出卡槽
transferModuleService.transferZMoveZero(cmdDTO.getCommandId(), cmdDTO.getCommand());//Z轴抬升至最高
});
}
}

45
src/main/java/com/iflytop/sgs/app/cmd/control/LiquidAddCommand.java

@ -2,11 +2,14 @@ package com.iflytop.sgs.app.cmd.control;
import cn.hutool.core.lang.Assert;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.bo.Point3D;
import com.iflytop.sgs.app.model.bo.status.device.TransferModuleState;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.model.entity.Solutions;
import com.iflytop.sgs.app.service.api.DevicePositionService;
import com.iflytop.sgs.app.service.api.SolutionsService;
import com.iflytop.sgs.app.service.api.SystemConfigService;
import com.iflytop.sgs.app.service.device.DeviceStateService;
import com.iflytop.sgs.app.service.device.module.SolutionModuleService;
@ -35,35 +38,37 @@ public class LiquidAddCommand extends BaseCommandHandler {
private final DevicePositionService devicePositionService;
private final TransferModuleService transferModuleService;
private final SystemConfigService systemConfigService;
private final SolutionsService solutionsService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
//todo "params": {
// "columns":[{"column":1,"solutionId":1,"volume":10},
// {"column":2,"solutionId":2,"volume":10},
// {"column":3,"solutionId":3,"volume":10}]
// }
String solution = cmdDTO.getStringParam("solution");
ValveStateCode valveStateCode = ValveStateCode.valueOf(solution);//解析加液通道
double volume = cmdDTO.getDoubleParam("column");//解析加液量
JSONArray jsonArray = cmdDTO.getJSONArrayParam("index");//解析加液列
Double scale = Double.valueOf(systemConfigService.getSystemConfigValueByCode(valveStateCode.getSystemConfigCode()));//获取转换系数
Double position = volume * scale;
Point3D liquidAreaTrayPoint = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D(); //获取加液区上方点位
Double solutionModuleMotorDownInTubeAddPositon = devicePositionService.getPosition(DevicePositionCode.solutionModuleMotorDownInTubeAddPositon).getPositon(); //加液模块电机下降进入试管加液位置
Double trayTubeHorizontalSpacingDistance = devicePositionService.getPosition(DevicePositionCode.trayTubeHorizontalSpacingDistance).getDistance(); //加液模块电机下降进入试管加液位置
return runAsync(() -> {
solutionModuleService.liquidValveSwitch(cmdDTO.getCommandId(), cmdDTO.getCommand(), valveStateCode);//电磁阀对应通道打开
JSONArray jsonArray = cmdDTO.getJSONArrayParam("columns");//获取参数
Assert.notNull(jsonArray, () -> new AppException(ResultCode.INVALID_PARAMETER));//解析参数
TransferModuleState transferModuleState = deviceStateService.getDeviceState().getTransferModule();//获取机械臂状态
Assert.isTrue(transferModuleState.isTrayStatus(), () -> new AppException(ResultCode.OPERATION_NOT_ALLOWED));//判断机械臂是否有托盘
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//加液机械臂上升
transferModuleService.transferMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint);//移动至加液位置
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), solutionModuleMotorDownInTubeAddPositon);//加液机械臂下降
//开始加液
Point3D liquidAreaTrayPoint = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D(); //获取加液区上方点位
Double solutionModuleMotorDownInTubeAddPositon = devicePositionService.getPosition(DevicePositionCode.solutionModuleMotorDownInTubeAddPositon).getPositon(); //加液模块电机下降进入试管加液位置
Double trayTubeHorizontalSpacingDistance = devicePositionService.getPosition(DevicePositionCode.trayTubeHorizontalSpacingDistance).getDistance(); //加液模块电机下降进入试管加液位置
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
Integer solutionId = jsonObject.getInt("solutionId");//溶液Id
Integer column = jsonObject.getInt("column");//列数
double volume = jsonObject.getDouble("volume");//
Solutions solutions = solutionsService.getById(solutionId);//获取溶液
ValveStateCode valveStateCode = ValveStateCode.valueOf(solutions.getName());//根据溶液获取电磁阀code
double scale = Double.parseDouble(systemConfigService.getSystemConfigValueByCode(valveStateCode.getSystemConfigCode()));//根据溶液获取转换比
double position = volume * scale;//加液泵的转数
solutionModuleService.liquidValveSwitch(cmdDTO.getCommandId(), cmdDTO.getCommand(), valveStateCode);//电磁阀对应通道打开
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//加液机械臂上升
transferModuleService.transferMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint);//移动至加液位置
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), solutionModuleMotorDownInTubeAddPositon);//加液机械臂下降
solutionModuleService.liquidPumpMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), position);//加液
transferModuleService.transferXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), -trayTubeHorizontalSpacingDistance);//机械臂左移试管间距
double distance = (column - 1) * trayTubeHorizontalSpacingDistance;//机械臂左移距离
transferModuleService.transferXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), -distance);//机械臂左移试管间距
}
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//加液机械臂上升
transferModuleService.transferMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint);//移动至加液位置

43
src/main/java/com/iflytop/sgs/app/cmd/control/LiquidReduceCommand.java

@ -5,6 +5,8 @@ import cn.hutool.json.JSONArray;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.bo.Point3D;
import com.iflytop.sgs.app.model.bo.status.device.TransferModuleState;
import com.iflytop.sgs.app.model.bo.status.device.TrayState;
import com.iflytop.sgs.app.model.bo.status.device.TubeState;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.api.DevicePositionService;
import com.iflytop.sgs.app.service.api.SystemConfigService;
@ -12,6 +14,7 @@ import com.iflytop.sgs.app.service.device.DeviceStateService;
import com.iflytop.sgs.app.service.device.module.SolutionModuleService;
import com.iflytop.sgs.app.service.device.module.TransferModuleService;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.SystemConfigCode;
import com.iflytop.sgs.common.enums.ValveStateCode;
import com.iflytop.sgs.common.enums.data.DevicePositionCode;
import com.iflytop.sgs.common.exception.AppException;
@ -20,6 +23,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
@ -38,27 +42,28 @@ public class LiquidReduceCommand extends BaseCommandHandler {
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
//todo 无参数
double volume=cmdDTO.getDoubleParam("column");//解析加液量
JSONArray jsonArray =cmdDTO.getJSONArrayParam("index");//解析加液列
Double position = volume;//蠕动泵移动距离
Point3D liquidAreaTrayPoint = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D(); //获取加液区上方点位
Double solutionModuleMotorDownInTubeExtPositon = devicePositionService.getPosition(DevicePositionCode.solutionModuleMotorDownInTubeExtPositon).getPositon(); //加液模块电机下降进入试管抽液位置
Double trayTubeHorizontalSpacingDistance = devicePositionService.getPosition(DevicePositionCode.trayTubeHorizontalSpacingDistance).getDistance(); //加液模块电机下降进入试管加液位置
//todo 需要更新一下传感器的状态
Assert.isTrue(deviceStateService.getDeviceState().getTransferModule().isTrayStatus(), () -> new AppException(ResultCode.TARGET_HEAT_MODULE_NO_TRAY));//机械臂是否有托盘
Point3D liquidAreaTrayPoint3D = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D();//获取加液时托盘位置点
Double trayTubeHorizontalSpacingDistance = devicePositionService.getPosition(DevicePositionCode.trayTubeHorizontalSpacingDistance).getDistance();//获取托盘试管水平间距
Double solutionModuleMotorDownInTubeExtPositon = devicePositionService.getPosition(DevicePositionCode.solutionModuleMotorDownInTubeExtPositon).getPositon();//加液模块电机下降进入试管抽取位置
List<TrayState> trayStates = deviceStateService.getDeviceState().getTrays();//所有的托盘
TrayState trayState = trayStates.stream().filter(TrayState::isInSolutionPositon).findFirst().get();//加液位的托盘
double reduceNumber= Double.parseDouble(systemConfigService.getSystemConfigValueByCode(SystemConfigCode.number_reduce));
return runAsync(() -> {
solutionModuleService.liquidValveSwitch(cmdDTO.getCommandId(),cmdDTO.getCommand(), ValveStateCode.waste);//电磁阀废液通道打开
TransferModuleState transferModuleState=deviceStateService.getDeviceState().getTransferModule();//获取机械臂状态
Assert.isTrue(transferModuleState.isTrayStatus(),()->new AppException(ResultCode.OPERATION_NOT_ALLOWED));//判断机械臂是否有托盘
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//加液机械臂上升
transferModuleService.transferMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint);//移动至加液位置
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), solutionModuleMotorDownInTubeExtPositon);//加液机械臂下降
for (int i = 0; i < jsonArray.size(); i++) {
solutionModuleService.liquidPumpMove(cmdDTO.getCommandId(),cmdDTO.getCommand(),-position);//加液
transferModuleService.transferXMoveBy(cmdDTO.getCommandId(),cmdDTO.getCommand(),-trayTubeHorizontalSpacingDistance);//机械臂左移试管间距
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0.0);//加液模块上升
transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D.getX());//将X轴移动至加液时托盘位置点
solutionModuleService.liquidValveSwitch(cmdDTO.getCommandId(), cmdDTO.getCommand(), ValveStateCode.waste);//电磁阀对应通道打开
for (TubeState tubeState : trayState.getTubes()) {
if (tubeState.isAddSolution() && tubeState.isExists()) {
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), solutionModuleMotorDownInTubeExtPositon);//加液模块下降进入试管
solutionModuleService.liquidPumpMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), -reduceNumber);//抽液
double distance = (tubeState.getColumnNum() - 1) * trayTubeHorizontalSpacingDistance;
transferModuleService.transferXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), -distance);//X轴依次按照试管间距移动
}
}
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//加液机械臂上升
transferModuleService.transferMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint);//移动至加液位置
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//加液模块上升至最高移出试管
transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D.getX());//将X轴移动至加液时托盘位置
});
}
}

8
src/main/java/com/iflytop/sgs/common/cmd/DeviceCommandGenerator.java

@ -462,6 +462,14 @@ public class DeviceCommandGenerator {
}
/**
* 获取托盘状态 todo 文档action是heater_tray
*
*/
public static DeviceCommandBundle getTrayStatus() {
return getInfoCmd(CmdDevice.sensor, "获取托盘状态");
}
/**
* 控制设备电机指令
*/
private static DeviceCommandBundle controlMotorCmd(CmdDevice device, CmdAction action, DeviceCommandParams params, String commandName) {

5
src/main/java/com/iflytop/sgs/common/enums/SystemConfigCode.java

@ -13,7 +13,10 @@ public enum SystemConfigCode {
scale_thick("浓硝酸转换系数"),
scale_water("水转换系数"),
scale_waste("废水转换系数"),
scale_vacant("空气转换系数");
scale_vacant("空气转换系数"),
volume_clean("清洁时加水的量"),
number_reduce("抽液时机蠕动泵的转数");
private String description;

1
src/main/java/com/iflytop/sgs/common/enums/cmd/CmdAction.java

@ -6,4 +6,5 @@ public enum CmdAction {
open, close, stop, start, set, get,
open_power, close_power, open_circle, close_circle,
open_heart, close_heart, open_cool, close_cool, take_photo,
heater_tray,
}
Loading…
Cancel
Save