Browse Source

调整初始化方式为引导

master
白凤吉 2 months ago
parent
commit
cf62dfaf30
  1. 62
      src/main/java/com/iflytop/sgs/app/cmd/selftest/MoveTestCommand.java
  2. 65
      src/main/java/com/iflytop/sgs/app/cmd/selftest/TrayOutCommand.java
  3. 9
      src/main/java/com/iflytop/sgs/app/controller/SelfTestController.java
  4. 16
      src/main/java/com/iflytop/sgs/app/core/SelfMoveTestGenerator.java
  5. 23
      src/main/java/com/iflytop/sgs/app/model/vo/GetRequireOutTrayVO.java
  6. 18
      src/main/java/com/iflytop/sgs/app/service/device/SelfTestService.java
  7. 3
      src/main/java/com/iflytop/sgs/app/ws/server/WebSocketSender.java
  8. 4
      src/main/java/com/iflytop/sgs/common/constant/WebSocketMessageType.java

62
src/main/java/com/iflytop/sgs/app/cmd/selftest/MoveTestCommand.java

@ -0,0 +1,62 @@
package com.iflytop.sgs.app.cmd.selftest;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.core.SelfMoveTestGenerator;
import com.iflytop.sgs.app.model.bo.Point3D;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.api.DevicePositionService;
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.app.ws.server.WebSocketSender;
import com.iflytop.sgs.common.annotation.CommandMapping;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import com.iflytop.sgs.common.enums.data.DevicePositionCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 自检移动测试
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("move_test")//业务指令注解
public class MoveTestCommand extends BaseCommandHandler {
private final SolutionModuleService solutionModuleService;
private final TransferModuleService transferModuleService;
private final HeatModuleService heatModuleService;
private final DeviceStateService deviceStateService;
private final DevicePositionService devicePositionService;
private final WebSocketSender webSocketService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
HeatModuleCode annealHeatModuleCode = HeatModuleCode.heat_module_04;
Double transferModuleZPickTrayDownPositon = devicePositionService.getPosition(DevicePositionCode.transferModuleZPickTrayDownPositon).getPositon();//获取转运模块Z轴拿取托盘时下降的高度位置
Point3D annealHeatModuleTrayClawPoint3D = heatModuleService.getHeatModuleTrayClawPoint3D(annealHeatModuleCode);//获取退火加热模块托盘夹取点
Double solutionModuleMotorDownInTubeExtPositon = devicePositionService.getPosition(DevicePositionCode.solutionModuleMotorDownInTubeExtPositon).getPositon();//加液模块电机下降进入试管抽取位置
Point3D liquidAreaTrayPoint3D = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D();//获取加液时托盘位置点
Point3D feedAreaTrayPoint3D = devicePositionService.getPosition(DevicePositionCode.feedAreaTrayPoint).getPoint3D();//获取上料区托盘夹爪位置点
return runAsync(() -> {
webSocketService.pushSelfMoveTest(SelfMoveTestGenerator.generateJson(cmdDTO.getCommandId(), cmdDTO.getCommand(), "1、各项传感器正常", 25));
transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), annealHeatModuleTrayClawPoint3D.getX());//将X轴移动至托盘夹取点
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), solutionModuleMotorDownInTubeExtPositon);//加液模块下降进入试管抽取位置
solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0);//加液机械臂上升
webSocketService.pushSelfMoveTest(SelfMoveTestGenerator.generateJson(cmdDTO.getCommandId(), cmdDTO.getCommand(), "2、加液模块升降电机检测完毕", 50));
transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D.getX());//将X轴移动至加液时托盘位置点
transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), feedAreaTrayPoint3D.getX());//将X轴移动至上料区位置点
webSocketService.pushSelfMoveTest(SelfMoveTestGenerator.generateJson(cmdDTO.getCommandId(), cmdDTO.getCommand(), "3、x轴电机检测完毕", 75));
transferModuleService.transferZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), transferModuleZPickTrayDownPositon);//Z轴下降至夹取点使托盘落入上料区
transferModuleService.transferZMoveZero(cmdDTO.getCommandId(), cmdDTO.getCommand());//Z轴抬升至最高
webSocketService.pushSelfMoveTest(SelfMoveTestGenerator.generateJson(cmdDTO.getCommandId(), cmdDTO.getCommand(), "4、z轴电机检测完毕", 100));
});
}
}

65
src/main/java/com/iflytop/sgs/app/cmd/selftest/TrayOutCommand.java

@ -0,0 +1,65 @@
package com.iflytop.sgs.app.cmd.selftest;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.bo.Point3D;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.api.DevicePositionService;
import com.iflytop.sgs.app.service.device.DeviceStateService;
import com.iflytop.sgs.app.service.device.module.DoorModuleService;
import com.iflytop.sgs.app.service.device.module.HeatModuleService;
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.data.DevicePositionCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 移除一个托盘
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandMapping("tray_out")//业务指令注解
public class TrayOutCommand extends BaseCommandHandler {
private final DoorModuleService doorModuleService;
private final TransferModuleService transferModuleService;
private final HeatModuleService heatModuleService;
private final DevicePositionService devicePositionService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
String targetHeatModuleCodeStr = cmdDTO.getStringParam("heatModuleCode");
HeatModuleCode targetHeatModuleCode = HeatModuleCode.valueOf(targetHeatModuleCodeStr);
Double doorOpenPosition = devicePositionService.getPosition(DevicePositionCode.doorOpenPosition).getDistance();//获取开门位置
Point3D targetHeatModuleTrayClawPoint3D = heatModuleService.getHeatModuleTrayClawPoint3D(targetHeatModuleCode);//获取目标加热模块托盘夹取点
Double transferModuleXPickTrayMoveDistance = devicePositionService.getPosition(DevicePositionCode.transferModuleXPickTrayMoveDistance).getDistance();//获取转运模块X轴拿取托盘进出卡槽移动距离
Double transferModuleZPickTrayDownPositon = devicePositionService.getPosition(DevicePositionCode.transferModuleZPickTrayDownPositon).getPositon();//获取转运模块Z轴拿取托盘时下降的高度位置
Point3D feedAreaTrayPoint3D = devicePositionService.getPosition(DevicePositionCode.feedAreaTrayPoint).getPoint3D();//获取上料区托盘夹爪位置点
return runAsync(() -> {
if (!deviceStateService.getDeviceState().getDoorModule().isOpen()) {
doorModuleService.doorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), doorOpenPosition);
deviceStateService.getDeviceState().getDoorModule().setOpen(true);
}
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轴进入卡槽
deviceStateService.getDeviceState().getHeatModuleByCode(targetHeatModuleCode).setTrayStatus(false);//设定目标加热模块托盘状态
deviceStateService.getDeviceState().getTrayByHeatModuleCode(targetHeatModuleCode).setInHeatModule(false);//设定托盘不在加热模块中
deviceStateService.getDeviceState().getTransferModule().setTrayStatus(true);//设定托盘在机械臂上
transferModuleService.transferZMoveZero(cmdDTO.getCommandId(), cmdDTO.getCommand());//Z轴抬升至最高
transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), feedAreaTrayPoint3D.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轴抬升至最高
deviceStateService.getDeviceState().getSolutionModule().setFeedAreaTrayStatus(true);//设定上料区托盘状态
});
}
}

9
src/main/java/com/iflytop/sgs/app/controller/SelfTestController.java

@ -1,6 +1,7 @@
package com.iflytop.sgs.app.controller;
import com.iflytop.sgs.app.model.bo.status.SelfTestState;
import com.iflytop.sgs.app.model.vo.GetRequireOutTrayVO;
import com.iflytop.sgs.app.service.device.DeviceStateService;
import com.iflytop.sgs.app.service.device.SelfTestService;
import com.iflytop.sgs.common.result.Result;
@ -13,6 +14,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Tag(name = "自检")
@RestController
@RequestMapping("/api/self-test")
@ -28,6 +31,12 @@ public class SelfTestController {
return Result.success(selfTestService.getSelfTestState());
}
@Operation(summary = "是否存在需要移除的托盘")
@GetMapping("/require-out-tray")
public Result<List<GetRequireOutTrayVO>> getRequireOutTray() {
return Result.success(selfTestService.getRequireOutTray());
}
@Operation(summary = "自检完毕")
@PostMapping("/finish")
public Result<?> selfTestFinish(){

16
src/main/java/com/iflytop/sgs/app/core/SelfMoveTestGenerator.java

@ -0,0 +1,16 @@
package com.iflytop.sgs.app.core;
import cn.hutool.json.JSONObject;
public class SelfMoveTestGenerator {
public static JSONObject generateJson(String commandId, String command, String title, Object schedule) {
JSONObject jsonObject = new JSONObject();
jsonObject.set("commandId", commandId);
jsonObject.set("command", command);
jsonObject.set("title", title);
jsonObject.set("schedule", schedule);
return jsonObject;
}
}

23
src/main/java/com/iflytop/sgs/app/model/vo/GetRequireOutTrayVO.java

@ -0,0 +1,23 @@
package com.iflytop.sgs.app.model.vo;
import com.iflytop.sgs.common.enums.HeatModuleCode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "是否存在需要移除的托盘")
@Data
public class GetRequireOutTrayVO {
@Schema(description = "加热模块CODE")
private HeatModuleCode moduleCode;
@Schema(description = "是否存在托盘")
private boolean trayExist;
public GetRequireOutTrayVO(HeatModuleCode moduleCode, boolean trayExist) {
this.moduleCode = moduleCode;
this.trayExist = trayExist;
}
}

18
src/main/java/com/iflytop/sgs/app/service/device/SelfTestService.java

@ -1,16 +1,34 @@
package com.iflytop.sgs.app.service.device;
import com.iflytop.sgs.app.model.bo.status.SelfTestState;
import com.iflytop.sgs.app.model.bo.status.device.HeatModuleState;
import com.iflytop.sgs.app.model.vo.GetRequireOutTrayVO;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor
public class SelfTestService {
private final DeviceStateService deviceStateService;
@Getter
private final SelfTestState selfTestState = new SelfTestState();
/**
* 是否存在需要移除的托盘
*/
public List<GetRequireOutTrayVO> getRequireOutTray() {
List<GetRequireOutTrayVO> getRequireOutTrayList = new ArrayList<>();
List<HeatModuleState> heatModuleStateList = deviceStateService.getDeviceState().getHeatModule();
for (HeatModuleState heatModuleState : heatModuleStateList) {
//TODO 只获取存在托盘的
getRequireOutTrayList.add(new GetRequireOutTrayVO(heatModuleState.getModuleCode(),heatModuleState.isTrayStatus()));
}
return getRequireOutTrayList;
}
}

3
src/main/java/com/iflytop/sgs/app/ws/server/WebSocketSender.java

@ -28,6 +28,9 @@ public class WebSocketSender {
push(WebSocketMessageType.CMD_RESPONSE, data);
}
public void pushSelfMoveTest(Object data) {
push(WebSocketMessageType.SELF_MOVE_TEST, data);
}
public void pushNotification(Notification notification) {
push("notification", notification);

4
src/main/java/com/iflytop/sgs/common/constant/WebSocketMessageType.java

@ -10,6 +10,10 @@ public class WebSocketMessageType {
*/
public static final String ALARM = "alarm";
/**
* 自检移动电机测试
*/
public static final String SELF_MOVE_TEST = "self_move_test";
/**
* 指令反馈
*/
public static final String CMD_RESPONSE = "cmd_response";

Loading…
Cancel
Save