Browse Source

fix:优化调整

master
白凤吉 3 weeks ago
parent
commit
5e0b3704fc
  1. 34
      src/main/java/com/qyft/ms/app/controller/TestController.java
  2. 5
      src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java

34
src/main/java/com/qyft/ms/app/controller/TestController.java

@ -1,8 +1,14 @@
package com.qyft.ms.app.controller;
import cn.hutool.json.JSONObject;
import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.app.model.bo.Point3D;
import com.qyft.ms.app.model.vo.SelfTestVO;
import com.qyft.ms.system.common.device.command.CommandFuture;
import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
import com.qyft.ms.system.common.result.Result;
import com.qyft.ms.system.model.bo.DeviceCommand;
import com.qyft.ms.system.service.device.DeviceCommandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
@ -11,6 +17,10 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
/**
* 测试用
*/
@ -21,6 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
public class TestController {
private final DeviceStatus deviceStatus;
private final DeviceCommandService deviceCommandService;
@Operation(summary = "启动虚拟模式")
@PostMapping("/virtual")
@ -36,4 +47,27 @@ public class TestController {
deviceStatus.setSelfTestCompleted(true);
return Result.success();
}
@Operation(summary = "获取当前xyz位置")
@PostMapping("/get-xyz")
public Result<Point3D> getXyz() throws Exception {
DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); // 生成获得电机XYZ相对原点坐标指令
CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommandNoFront(motorXyzPositionGetCommand);
commandWait(motorXyzPositionGetCommandFuture);
JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getResponseResult();
Double xAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("xAxisPosition");
Double yAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("yAxisPosition");
Double zAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("zAxisPosition");
Point3D point3D = new Point3D(xAxisPosition, yAxisPosition, zAxisPosition);
return Result.success(point3D);
}
protected void commandWait(CommandFuture... futures) throws Exception {
CompletableFuture<?>[] responseFutures = Arrays.stream(futures)
.map(CommandFuture::getResponseFuture)
.toArray(CompletableFuture[]::new);
CompletableFuture.allOf(responseFutures)
.get(120, TimeUnit.SECONDS);
}
}

5
src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java

@ -83,6 +83,7 @@ public class SprayTaskExecutor {
int sprayNum = 1; //当前玻片是第几次喷涂
for (SprayTimes sprayTimes : sprayTaskParam.getTimes()) {//每个拨片有多次喷涂循环每次喷涂
if (sprayNum < sprayTask.getSprayNum()) {
sprayNum++;
continue;
}
sprayTask.setSprayTimes(sprayTimes);
@ -91,7 +92,7 @@ public class SprayTaskExecutor {
List<SprayTaskStep> sprayTaskStepList = getSprayPath(sprayTaskParam.getIndex(), sprayTimes);//计算本次喷涂的路线
//先移动到玻片左上角位置
DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskParam.getIndex()][0], 20.0);
DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskParam.getIndex()][1], 20.0);
DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(slideArr[sprayTaskParam.getIndex()][1], 20.0);
CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand);
CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand);
@ -151,7 +152,7 @@ public class SprayTaskExecutor {
cacheXPoint = currentPoint.x;
}
if (cacheYPoint != currentPoint.y) {
DeviceCommand deviceCommand = DeviceCommandGenerator.motorXPositionSet(slide[1] + currentPoint.y, sprayTimes.getMovingSpeed());
DeviceCommand deviceCommand = DeviceCommandGenerator.motorYPositionSet(slide[1] + currentPoint.y, sprayTimes.getMovingSpeed());
CommandFuture commandFuture = deviceCommandService.sendCommandSprayTask(sprayTask.getCmdId(), sprayTask.getCmdCode(), deviceCommand);
commandFutureList.add(commandFuture);
cacheYPoint = currentPoint.y;

Loading…
Cancel
Save