6 changed files with 174 additions and 7 deletions
-
38src/main/java/com/iflytop/colortitration/app/command/selftest/GantryXYOriginCommand.java
-
2src/main/java/com/iflytop/colortitration/app/command/selftest/GantryZOriginCommand.java
-
92src/main/java/com/iflytop/colortitration/app/command/selftest/MoveTestCommand.java
-
41src/main/java/com/iflytop/colortitration/app/command/selftest/TitrationMotorOriginCommand.java
-
3src/main/java/com/iflytop/colortitration/app/command/selftest/package-info.java
-
5src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketSender.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<Void> 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); |
|||
}); |
|||
} |
|||
} |
|||
|
@ -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<Void> 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); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
|
@ -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<Void> 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); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
|
@ -1,3 +0,0 @@ |
|||
package com.iflytop.colortitration.app.command.selftest; |
|||
|
|||
//自检相关指令 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue