Browse Source

增加自检指令

master
王梦远 1 week ago
parent
commit
10590e4696
  1. 38
      src/main/java/com/iflytop/colortitration/app/command/selftest/GantryXYOriginCommand.java
  2. 2
      src/main/java/com/iflytop/colortitration/app/command/selftest/GantryZOriginCommand.java
  3. 92
      src/main/java/com/iflytop/colortitration/app/command/selftest/MoveTestCommand.java
  4. 41
      src/main/java/com/iflytop/colortitration/app/command/selftest/TitrationMotorOriginCommand.java
  5. 3
      src/main/java/com/iflytop/colortitration/app/command/selftest/package-info.java
  6. 5
      src/main/java/com/iflytop/colortitration/app/websocket/server/WebSocketSender.java

38
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<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);
});
}
}

2
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;

92
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<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);
}
});
}
}

41
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<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);
});
}
}

3
src/main/java/com/iflytop/colortitration/app/command/selftest/package-info.java

@ -1,3 +0,0 @@
package com.iflytop.colortitration.app.command.selftest;
//自检相关指令

5
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);
}
}*/
}
Loading…
Cancel
Save