diff --git a/src/main/java/com/iflytop/sgs/app/cmd/control/SolutionAddCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/control/LiquidAddCommand.java similarity index 88% rename from src/main/java/com/iflytop/sgs/app/cmd/control/SolutionAddCommand.java rename to src/main/java/com/iflytop/sgs/app/cmd/control/LiquidAddCommand.java index a7e682a..3d06747 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/control/SolutionAddCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/control/LiquidAddCommand.java @@ -17,8 +17,8 @@ import java.util.concurrent.CompletableFuture; @Slf4j @Component @RequiredArgsConstructor -@CommandMapping("solution_add")//业务指令注解 -public class SolutionAddCommand extends BaseCommandHandler { +@CommandMapping("liquid_add")//业务指令注解 +public class LiquidAddCommand extends BaseCommandHandler { private final SolutionModuleService solutionModuleService; private final DeviceStateService deviceStateService; diff --git a/src/main/java/com/iflytop/sgs/app/cmd/control/SolutionReduceCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/control/LiquidReduceCommand.java similarity index 88% rename from src/main/java/com/iflytop/sgs/app/cmd/control/SolutionReduceCommand.java rename to src/main/java/com/iflytop/sgs/app/cmd/control/LiquidReduceCommand.java index f13a3e6..54c346a 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/control/SolutionReduceCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/control/LiquidReduceCommand.java @@ -17,8 +17,8 @@ import java.util.concurrent.CompletableFuture; @Slf4j @Component @RequiredArgsConstructor -@CommandMapping("solution_reduce")//业务指令注解 -public class SolutionReduceCommand extends BaseCommandHandler { +@CommandMapping("liquid_reduce")//业务指令注解 +public class LiquidReduceCommand extends BaseCommandHandler { private final SolutionModuleService solutionModuleService; private final DeviceStateService deviceStateService; diff --git a/src/main/java/com/iflytop/sgs/app/cmd/control/MoveToHeatAreaCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/control/MoveToHeatAreaCommand.java index 6cd0981..460f23f 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/control/MoveToHeatAreaCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/control/MoveToHeatAreaCommand.java @@ -1,10 +1,7 @@ package com.iflytop.sgs.app.cmd.control; -import cn.hutool.core.lang.Assert; import com.iflytop.sgs.app.core.BaseCommandHandler; import com.iflytop.sgs.app.model.bo.Point3D; -import com.iflytop.sgs.app.model.bo.status.device.HeatModuleState; -import com.iflytop.sgs.app.model.bo.status.device.SolutionModuleState; import com.iflytop.sgs.app.model.dto.CmdDTO; import com.iflytop.sgs.app.service.api.DevicePositionService; import com.iflytop.sgs.app.service.device.DeviceStateService; @@ -14,8 +11,6 @@ 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 com.iflytop.sgs.common.exception.AppException; -import com.iflytop.sgs.common.result.ResultCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -23,7 +18,7 @@ import org.springframework.stereotype.Component; import java.util.concurrent.CompletableFuture; /** - * 移至加热 todo wmy 需要改 + * 将上料区托盘或者机械臂上的托盘移至目标加热模块 */ @Slf4j @Component @@ -39,49 +34,31 @@ public class MoveToHeatAreaCommand extends BaseCommandHandler { @Override public CompletableFuture handle(CmdDTO cmdDTO) throws Exception { - if (deviceStateService.getCommandMutexState().get().isMoveToHeatAreaCommandExecuting()) { - throw new AppException(ResultCode.COMMAND_ALREADY_EXECUTING); + if (!deviceStateService.getDeviceState().getTransferModule().isTrayStatus()) { //判断机械臂上是否有托盘 + //TODO 判断目标加热模块传感器是否有托盘,如果有托盘的话提示错误 } - if (deviceStateService.getCommandMutexState().get().isMoveToSolutionAreaCommandExecuting()) { - throw new AppException(ResultCode.CMD_BUSY); - } - try { - deviceStateService.getCommandMutexState().get().setMoveToHeatAreaCommandExecuting(true); - } catch (Exception e) { - deviceStateService.getCommandMutexState().get().setMoveToHeatAreaCommandExecuting(false); - throw e; - } - String heatId = cmdDTO.getStringParam("heatId"); - HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId); - HeatModuleState heatModuleState=deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleId); - SolutionModuleState solutionModuleState=deviceStateService.getDeviceState().getSolutionModule(); - //判断泵现在处于关闭状态 - Assert.isTrue(solutionModuleState.isPumping(),"蠕动泵正在运行,无法转移"); - //转运模块Z轴拿取托盘时起下降的高度位置 - Point3D transferModuleZPickTrayDownPositon = devicePositionService.getPosition(DevicePositionCode.transferModuleZPickTrayDownPositon).getPoint3D(); - //转运模块Z轴移动托盘时起托盘的高度位置 - Point3D transferModuleZTrayUpMovePositon = devicePositionService.getPosition(DevicePositionCode.transferModuleZTrayUpMovePositon).getPoint3D(); - //转运模块X轴拿取托盘进出卡槽移动距离 - double transferModuleXPickTrayMoveDistance=devicePositionService.getPosition(DevicePositionCode.transferModuleXPickTrayMoveDistance).getDistance(); - //获取指定加热模块上方点位 - Point3D heatAreaTrayPoint3D = heatModuleService.getHeatModuleTrayClawPoint3D(heatModuleId); + + String targetHeatModuleCodeStr = cmdDTO.getStringParam("heatModuleCode"); + HeatModuleCode targetHeatModuleCode = HeatModuleCode.valueOf(targetHeatModuleCodeStr);//目标加热模块 + + 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(() -> { - try { - //升高加液电机高度 回0点 - solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0); - //移动机械臂到加热区上方 此时机械臂夹着托盘 - transferModuleService.transferMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayPoint3D); - //下降z轴 - transferModuleService.transferZMove(transferModuleZPickTrayDownPositon.getZ()); - //移动x轴向右脱离托盘 - transferModuleService.transferXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), -transferModuleXPickTrayMoveDistance); - //z轴返回0点 - solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(),0); - //设置加热区有托盘 - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleId).setTrayStatus(true); - } finally { - deviceStateService.getCommandMutexState().get().setMoveToHeatAreaCommandExecuting(false); + if (!deviceStateService.getDeviceState().getTransferModule().isTrayStatus()) { //判断机械臂上是否有托盘 + //机械臂上无托盘,取上料区托盘 + transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), feedAreaTrayPoint3D.getX() + transferModuleXPickTrayMoveDistance);//将X轴移动至上料区托盘夹取点 + 进出卡槽移动距离 + transferModuleService.transferZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), transferModuleZPickTrayDownPositon);//Z轴下降至夹取点,使托盘落入石墨加热盘 + transferModuleService.transferXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), -transferModuleXPickTrayMoveDistance);//X轴进入卡槽 + transferModuleService.transferZMoveZero(cmdDTO.getCommandId(), cmdDTO.getCommand());//Z轴抬升至最高 } + transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), targetHeatModuleTrayClawPoint3D.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().getHeatModuleByCode(targetHeatModuleCode).setTrayStatus(true);//设置目标加热区有托盘 }); } } diff --git a/src/main/java/com/iflytop/sgs/app/cmd/control/MoveToLiquidAreaCommand.java b/src/main/java/com/iflytop/sgs/app/cmd/control/MoveToLiquidAreaCommand.java index 8b2527b..8091ef6 100644 --- a/src/main/java/com/iflytop/sgs/app/cmd/control/MoveToLiquidAreaCommand.java +++ b/src/main/java/com/iflytop/sgs/app/cmd/control/MoveToLiquidAreaCommand.java @@ -2,8 +2,6 @@ package com.iflytop.sgs.app.cmd.control; import com.iflytop.sgs.app.core.BaseCommandHandler; import com.iflytop.sgs.app.model.bo.Point3D; -import com.iflytop.sgs.app.model.bo.status.device.HeatModuleState; -import com.iflytop.sgs.app.model.bo.status.device.SolutionModuleState; import com.iflytop.sgs.app.model.dto.CmdDTO; import com.iflytop.sgs.app.service.api.DevicePositionService; import com.iflytop.sgs.app.service.device.DeviceStateService; @@ -13,8 +11,6 @@ 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 com.iflytop.sgs.common.exception.AppException; -import com.iflytop.sgs.common.result.ResultCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -30,7 +26,6 @@ import java.util.concurrent.CompletableFuture; @CommandMapping("move_to_liquid_area")//业务指令注解 public class MoveToLiquidAreaCommand extends BaseCommandHandler { private final HeatModuleService heatModuleService; - private final SolutionModuleService solutionModuleService; private final TransferModuleService transferModuleService; private final DevicePositionService devicePositionService; @@ -38,45 +33,42 @@ public class MoveToLiquidAreaCommand extends BaseCommandHandler { @Override public CompletableFuture handle(CmdDTO cmdDTO) throws Exception { - if (deviceStateService.getCommandMutexState().get().isMoveToSolutionAreaCommandExecuting()) { - throw new AppException(ResultCode.COMMAND_ALREADY_EXECUTING); + String targetHeatModuleCodeStr = cmdDTO.getStringParam("heatModuleCode"); + HeatModuleCode targetHeatModuleCode;//目标加热模块 + if (targetHeatModuleCodeStr != null) {//目标加热模块非必填,如果没有传递目标加热模块则尝试获取上料区是否有托盘 + targetHeatModuleCode = HeatModuleCode.valueOf(targetHeatModuleCodeStr); + }else{ + targetHeatModuleCode = null; + //TODO 尝试获取上料区是否有托盘,如果没有托盘则提示错误 } - if (deviceStateService.getCommandMutexState().get().isMoveToHeatAreaCommandExecuting()) { - throw new AppException(ResultCode.CMD_BUSY); - } - String heatId = cmdDTO.getStringParam("heatId"); - HeatModuleCode heatModuleId = HeatModuleCode.valueOf(heatId); - HeatModuleState heatModuleState=deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleId); - SolutionModuleState solutionModuleState=deviceStateService.getDeviceState().getSolutionModule(); - //转运模块Z轴拿取托盘时起下降的高度位置 - Point3D transferModuleZPickTrayDownPositon = devicePositionService.getPosition(DevicePositionCode.transferModuleZPickTrayDownPositon).getPoint3D(); - //转运模块Z轴移动托盘时起托盘的高度位置 - Point3D transferModuleZTrayUpMovePositon = devicePositionService.getPosition(DevicePositionCode.transferModuleZTrayUpMovePositon).getPoint3D(); - //转运模块X轴拿取托盘进出卡槽移动距离 - double transferModuleXPickTrayMoveDistance=devicePositionService.getPosition(DevicePositionCode.transferModuleXPickTrayMoveDistance).getDistance(); - //获取指定加热模块上方点位 - Point3D heatAreaTrayPoint3D = heatModuleService.getHeatModuleTrayClawPoint3D(heatModuleId); - //获取加液区上方点位 - Point3D liquidAreaTrayPoint = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D(); + + 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();//获取上料区托盘夹爪位置点 + Point3D liquidAreaTrayPoint3D = devicePositionService.getPosition(DevicePositionCode.liquidAreaTrayPoint).getPoint3D();//获取加液时托盘位置点 + return runAsync(() -> { - try { - //升高加液电机高度 回0点 - solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), 0); - //移动机械臂到加热区上方 此时机械臂夹着托盘 - transferModuleService.transferMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatAreaTrayPoint3D); - //下降z轴 - transferModuleService.transferZMove(cmdDTO.getCommandId(), cmdDTO.getCommand(),transferModuleZPickTrayDownPositon.getZ()); - //移动x轴向左托起托盘 - transferModuleService.transferXMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), transferModuleXPickTrayMoveDistance); - //z轴返回0点 - solutionModuleService.solutionMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(),0); - //移动到建邺区 - transferModuleService.transferMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint); - //设置加液区有托盘 todo - //deviceStateService.getDeviceState().getSolutionModule().setTrayStatus(1); - } finally { - deviceStateService.getCommandMutexState().get().setMoveToHeatAreaCommandExecuting(false); + if(targetHeatModuleCode == null){ + //获取上料区托盘 + transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), feedAreaTrayPoint3D.getX() + transferModuleXPickTrayMoveDistance);//将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(false);//设定上料区托盘状态 + deviceStateService.getDeviceState().getTrayByHeatModuleCode(targetHeatModuleCode).setInFeedArea(false);//设定托盘不在上料区中 + }else{ + //获取目标加热模块托盘 + 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轴进入卡槽 + transferModuleService.transferZMoveZero(cmdDTO.getCommandId(), cmdDTO.getCommand());//Z轴抬升至最高 + deviceStateService.getDeviceState().getHeatModuleByCode(targetHeatModuleCode).setTrayStatus(false);//设定目标加热模块托盘状态 + deviceStateService.getDeviceState().getTrayByHeatModuleCode(targetHeatModuleCode).setInHeatModule(false);//设定托盘不在加热模块中 } + transferModuleService.transferXMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), liquidAreaTrayPoint3D.getX());//将X轴移动至加液时托盘位置点 + deviceStateService.getDeviceState().getTrayByHeatModuleCode(targetHeatModuleCode).setInSolutionPositon(true);//设定托盘在加液位中 + }); } } diff --git a/src/main/java/com/iflytop/sgs/app/model/bo/status/device/DeviceState.java b/src/main/java/com/iflytop/sgs/app/model/bo/status/device/DeviceState.java index e560bd0..7a773dc 100644 --- a/src/main/java/com/iflytop/sgs/app/model/bo/status/device/DeviceState.java +++ b/src/main/java/com/iflytop/sgs/app/model/bo/status/device/DeviceState.java @@ -59,4 +59,16 @@ public class DeviceState { return null; } + /** + * 根据指定加热模块获取所属托盘 + */ + public synchronized TrayState getTrayIn(HeatModuleCode heatModuleCode) { + for (TrayState t : trays) { + if (heatModuleCode.equals(t.getHeatModuleCode())) { + return t; + } + } + return null; + } + } diff --git a/src/main/java/com/iflytop/sgs/app/service/device/module/HeatModuleService.java b/src/main/java/com/iflytop/sgs/app/service/device/module/HeatModuleService.java index 55eeae4..38d5d01 100644 --- a/src/main/java/com/iflytop/sgs/app/service/device/module/HeatModuleService.java +++ b/src/main/java/com/iflytop/sgs/app/service/device/module/HeatModuleService.java @@ -70,6 +70,9 @@ public class HeatModuleService { * 获取指定加热区托盘夹爪点位 */ public Point3D getHeatModuleTrayClawPoint3D(HeatModuleCode heatModuleId) { + if(heatModuleId == null){ + return null; + } DevicePosition devicePosition = switch (heatModuleId) { case heat_module_01 -> devicePositionService.getPosition(DevicePositionCode.heatArea1TrayClawPoint); case heat_module_02 -> devicePositionService.getPosition(DevicePositionCode.heatArea2TrayClawPoint);