diff --git a/src/main/java/com/iflytop/colortitration/app/command/selftest/GantryXYOriginCommand.java b/src/main/java/com/iflytop/colortitration/app/command/selftest/GantryXYOriginCommand.java new file mode 100644 index 0000000..31c7ccf --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/selftest/GantryXYOriginCommand.java @@ -0,0 +1,38 @@ +package com.iflytop.colortitration.app.command.selftest; + +import com.iflytop.colortitration.app.common.annotation.CommandMapping; +import com.iflytop.colortitration.app.common.utils.CommandUtil; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.core.command.CommandFuture; +import com.iflytop.colortitration.app.core.command.DeviceCommand; +import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.DeviceCommandService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 龙门架机械臂z轴回原点 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandMapping("check_gantry_xy_origin")//业务指令注解 +public class GantryXYOriginCommand extends BaseCommandHandler { + private final DeviceCommandService deviceCommandService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + return runAsync(() -> { + DeviceCommand roboticArmBigMotorCommand = DeviceCommandGenerator.roboticArmBigMotorOrigin(); + CommandFuture roboticArmBigMotorFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), roboticArmBigMotorCommand); + DeviceCommand roboticArmSmallMotorCommand = DeviceCommandGenerator.roboticArmSmallMotorOrigin(); + CommandFuture roboticArmSmallMotorFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), roboticArmSmallMotorCommand); + CommandUtil.wait(roboticArmBigMotorFuture, roboticArmSmallMotorFuture); + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/selftest/GantryZOriginCommand.java b/src/main/java/com/iflytop/colortitration/app/command/selftest/GantryZOriginCommand.java index a887a22..638e598 100644 --- a/src/main/java/com/iflytop/colortitration/app/command/selftest/GantryZOriginCommand.java +++ b/src/main/java/com/iflytop/colortitration/app/command/selftest/GantryZOriginCommand.java @@ -20,7 +20,7 @@ import java.util.concurrent.CompletableFuture; @Slf4j @Component @RequiredArgsConstructor -@CommandMapping("gantry_z_origin")//业务指令注解 +@CommandMapping("check_gantry_z_origin")//业务指令注解 public class GantryZOriginCommand extends BaseCommandHandler { private final DeviceCommandService deviceCommandService; diff --git a/src/main/java/com/iflytop/colortitration/app/command/selftest/MoveTestCommand.java b/src/main/java/com/iflytop/colortitration/app/command/selftest/MoveTestCommand.java new file mode 100644 index 0000000..3cc91d5 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/selftest/MoveTestCommand.java @@ -0,0 +1,92 @@ +package com.iflytop.colortitration.app.command.selftest; + +import cn.hutool.json.JSONObject; +import com.iflytop.colortitration.app.common.annotation.CommandMapping; +import com.iflytop.colortitration.app.common.utils.CommandUtil; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.core.command.CommandFuture; +import com.iflytop.colortitration.app.core.command.DeviceCommand; +import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.DeviceCommandService; +import com.iflytop.colortitration.app.websocket.server.WebSocketSender; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 自检移动测试 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandMapping("check_move_test")//业务指令注解 +public class MoveTestCommand extends BaseCommandHandler { + private final WebSocketSender webSocketSender; + private final DeviceCommandService deviceCommandService; + + public static JSONObject generateJson(String commandId, String command, String title, Object schedule, String type) { + JSONObject jsonObject = new JSONObject(); + jsonObject.set("commandId", commandId); + jsonObject.set("command", command); + jsonObject.set("title", title); + jsonObject.set("schedule", schedule); + jsonObject.set("type", type); + return jsonObject; + } + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + return runAsync(() -> { + try { + webSocketSender.pushSelfMoveTest(MoveTestCommand.generateJson(commandDTO.getCommandId(), commandDTO.getCommand(), "1、各项传感器正常", 20, "success")); + DeviceCommand motorZCommand = DeviceCommandGenerator.zMove(10.0); //移动到200mm处 + CommandFuture motorZCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), motorZCommand); + CommandUtil.wait(motorZCommandFuture); + + DeviceCommand motorZOriginCommand = DeviceCommandGenerator.zOrigin();//z轴回原点 + CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), motorZOriginCommand); + CommandUtil.wait(motorZOriginCommandFuture); + webSocketSender.pushSelfMoveTest(MoveTestCommand.generateJson(commandDTO.getCommandId(), commandDTO.getCommand(), "2、Z轴电机检测完毕", 40, "success")); + + + DeviceCommand roboticArmBigMotorCommand = DeviceCommandGenerator.roboticArmBigMotorMoveTo(10.0);//大臂轴移动100mm + CommandFuture roboticArmBigMotorFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), roboticArmBigMotorCommand); + CommandUtil.wait(roboticArmBigMotorFuture); + + DeviceCommand roboticArmBigMotorOriginCommand = DeviceCommandGenerator.roboticArmBigMotorOrigin();//大臂回原点 + CommandFuture roboticArmBigMotorOriginFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), roboticArmBigMotorOriginCommand); + CommandUtil.wait(roboticArmBigMotorOriginFuture); + + webSocketSender.pushSelfMoveTest(MoveTestCommand.generateJson(commandDTO.getCommandId(), commandDTO.getCommand(), "3、机械臂大臂电机检测完毕", 65, "success")); + + DeviceCommand roboticArmSmallMotorCommand = DeviceCommandGenerator.roboticArmSmallMotorMoveTo(10.0);//小臂轴移动10mm + CommandFuture roboticArmSmallMotorFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), roboticArmSmallMotorCommand); + CommandUtil.wait(roboticArmSmallMotorFuture); + + DeviceCommand roboticArmSmallMotorOriginCommand = DeviceCommandGenerator.roboticArmBigMotorOrigin();//大臂回原点 + CommandFuture roboticArmSmallMotorOriginFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), roboticArmSmallMotorOriginCommand); + CommandUtil.wait(roboticArmSmallMotorOriginFuture); + webSocketSender.pushSelfMoveTest(MoveTestCommand.generateJson(commandDTO.getCommandId(), commandDTO.getCommand(), "4、机械臂小臂电机检测完毕", 80, "success")); + + DeviceCommand titrationMotor1Command = DeviceCommandGenerator.titrationMotor1MoveTo(10.0); //移动到200mm处 + CommandFuture titrationMotor1CommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), titrationMotor1Command); + DeviceCommand titrationMotor2Command = DeviceCommandGenerator.titrationMotor1MoveTo(10.0); //移动到200mm处 + CommandFuture titrationMotor2CommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), titrationMotor2Command); + CommandUtil.wait(titrationMotor1CommandFuture, titrationMotor2CommandFuture); + + DeviceCommand titrationMotor1OriginCommand = DeviceCommandGenerator.zOrigin();//z轴回原点 + CommandFuture titrationMotor1OriginCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), titrationMotor1OriginCommand); + DeviceCommand titrationMotor2OriginCommand = DeviceCommandGenerator.zOrigin();//z轴回原点 + CommandFuture titrationMotor2OriginCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), titrationMotor2OriginCommand); + CommandUtil.wait(titrationMotor1OriginCommandFuture, titrationMotor2OriginCommandFuture); + webSocketSender.pushSelfMoveTest(MoveTestCommand.generateJson(commandDTO.getCommandId(), commandDTO.getCommand(), "5、滴定电机检测完毕", 100, "success")); + } finally { + // deviceStatus.setSelfTestCompleted(true); + } + }); + } +} + diff --git a/src/main/java/com/iflytop/colortitration/app/command/selftest/TitrationMotorOriginCommand.java b/src/main/java/com/iflytop/colortitration/app/command/selftest/TitrationMotorOriginCommand.java new file mode 100644 index 0000000..d3814e8 --- /dev/null +++ b/src/main/java/com/iflytop/colortitration/app/command/selftest/TitrationMotorOriginCommand.java @@ -0,0 +1,41 @@ +package com.iflytop.colortitration.app.command.selftest; + +import com.iflytop.colortitration.app.common.annotation.CommandMapping; +import com.iflytop.colortitration.app.common.utils.CommandUtil; +import com.iflytop.colortitration.app.core.command.BaseCommandHandler; +import com.iflytop.colortitration.app.core.command.CommandFuture; +import com.iflytop.colortitration.app.core.command.DeviceCommand; +import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; +import com.iflytop.colortitration.app.model.dto.CommandDTO; +import com.iflytop.colortitration.app.service.DeviceCommandService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +/** + * 滴定移动电机回原点 + */ +@Slf4j +@Component +@RequiredArgsConstructor +@CommandMapping("check_titration_motor_origin") +public class TitrationMotorOriginCommand extends BaseCommandHandler { + private final DeviceCommandService deviceCommandService; + + @Override + public CompletableFuture handle(CommandDTO commandDTO) { + return runAsync(() -> { + DeviceCommand device1Command = DeviceCommandGenerator.titrationMotor1Origin(); + CommandFuture command1Future = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), device1Command); + CommandUtil.wait(command1Future); + + DeviceCommand device2Command = DeviceCommandGenerator.titrationMotor2Origin(); + CommandFuture command2Future = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), device2Command); + CommandUtil.wait(command2Future); + }); + } +} + + diff --git a/src/main/java/com/iflytop/colortitration/app/command/selftest/package-info.java b/src/main/java/com/iflytop/colortitration/app/command/selftest/package-info.java deleted file mode 100644 index 7cb379b..0000000 --- a/src/main/java/com/iflytop/colortitration/app/command/selftest/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.iflytop.colortitration.app.command.selftest; - -//自检相关指令 \ No newline at end of file diff --git a/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketSender.java b/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketSender.java index d1e869b..cf02051 100644 --- a/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketSender.java +++ b/src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketSender.java @@ -4,7 +4,6 @@ import cn.hutool.json.JSONUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import javax.management.Notification; import java.time.Instant; @Slf4j @@ -40,8 +39,8 @@ public class WebSocketSender { push(WebSocketMessageType.HEAT_COUNTDOWN, data); } - public void pushNotification(Notification notification) { + /* public void pushNotification(Notification notification) { push("notification", notification); - } + }*/ }