diff --git a/src/main/java/com/iflytop/colortitration/hardware/controller/ServoController.java b/src/main/java/com/iflytop/colortitration/hardware/controller/ServoController.java deleted file mode 100644 index e918392..0000000 --- a/src/main/java/com/iflytop/colortitration/hardware/controller/ServoController.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.iflytop.colortitration.hardware.controller; - -import com.iflytop.colortitration.app.service.DeviceParamConfigService; -import com.iflytop.colortitration.common.result.Result; -import com.iflytop.colortitration.hardware.exception.HardwareException; -import com.iflytop.colortitration.hardware.service.ServoService; -import com.iflytop.colortitration.hardware.type.Servo.MiniServoId; -import com.iflytop.colortitration.hardware.type.Servo.MiniServoRegIndex; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Tag(name = "伺服电机控制") -@RestController -@RequestMapping("/api/servo") -@RequiredArgsConstructor -@Slf4j -public class ServoController { - private final ServoService servoService; - private final DeviceParamConfigService deviceParamConfigService; - - // 获取设备列表 - @PostMapping("/get-device-list") - @Operation(summary = "获取设备列表") - public Map getDeviceList() { - Map map = new HashMap<>(); - for(MiniServoId id : MiniServoId.values()) { - map.put(id.name(), id.getDescription()); - } - return map; - } - - // 获取寄存器列表 - @PostMapping("/get-reg-list") - @Operation(summary = "获取寄存器列表") - public List getRegList() { - List list = new ArrayList<>(); - for(MiniServoRegIndex reg : MiniServoRegIndex.values()) { - list.add(reg.name()); - } - return list; - } - - // 基础操作 - @PostMapping("/enable") - @Operation(summary = "电源开启") - public Result enable(@RequestParam MiniServoId deviceId) throws HardwareException { - servoService.enable(deviceId, true); - return Result.success(); - } - - @PostMapping("/disable") - @Operation(summary = "电源关闭") - public Result disable(@RequestParam MiniServoId deviceId) throws HardwareException { - servoService.enable(deviceId, false); - return Result.success(); - } - - @PostMapping("/stop") - @Operation(summary = "停止") - public Result stop(@RequestParam MiniServoId deviceId) throws HardwareException { - servoService.stop(deviceId); - return Result.success(); - } - - @PostMapping("/move-to") - @Operation(summary = "移动(绝对)") - public Result moveTo(@RequestParam MiniServoId deviceId, @RequestParam Integer pos) throws HardwareException { - servoService.moveTo(deviceId, pos); - return Result.success(); - } - - @PostMapping("/rotate-forward") - @Operation(summary = "正转") - public Result rotateForward(@RequestParam MiniServoId deviceId) throws HardwareException { - servoService.rotate(deviceId, 1); - return Result.success(); - } - - @PostMapping("/rotate-backward") - @Operation(summary = "反转") - public Result rotateBackward(@RequestParam MiniServoId deviceId) throws HardwareException { - servoService.rotate(deviceId, 0); - return Result.success(); - } - @PostMapping("/rotate-with-torque") - @Operation(summary = "旋转(力矩)") - public Result rotateWithTorque(@RequestParam MiniServoId deviceId, @RequestParam Integer pos) throws HardwareException { - servoService.rotateWithTorque(deviceId, pos); - return Result.success(); - } - - @PostMapping("/move-to-zero") - @Operation(summary = "回Home") - public Result moveToZero(@RequestParam MiniServoId deviceId) throws HardwareException { - servoService.moveToZero(deviceId); - return Result.success(); - } - - // 寄存器操作 - @PostMapping("/limit-velocity") - @Operation(summary = "设置限速") - public Result setLimitVelocity( - @RequestParam MiniServoId deviceId, - @RequestParam Integer val) throws HardwareException { - servoService.setLimitVelocity(deviceId, val); - deviceParamConfigService.setModuleAndReg(deviceId.getServoMId().mid.name(), MiniServoRegIndex.kreg_mini_servo_limit_velocity.regIndex.name(),val); - return Result.success(); - } - - @PostMapping("/limit-torque") - @Operation(summary = "设置限力矩") - public Result setLimitTorque( - @RequestParam MiniServoId deviceId, - @RequestParam Integer val) throws HardwareException { - servoService.setLimitTorque(deviceId, val); - deviceParamConfigService.setModuleAndReg(deviceId.getServoMId().mid.name(), MiniServoRegIndex.kreg_mini_servo_limit_torque.regIndex.name(),val); - return Result.success(); - } - - @PostMapping("/protective-torque") - @Operation(summary = "设置保护力矩") - public Result setProtectiveTorque( - @RequestParam MiniServoId deviceId, - @RequestParam Integer val) throws HardwareException { - servoService.setProtectiveTorque(deviceId, val); - deviceParamConfigService.setModuleAndReg(deviceId.getServoMId().mid.name(), MiniServoRegIndex.kreg_mini_servo_protective_torque.regIndex.name(),val); - return Result.success(); - } - - @PostMapping("/reg") - @Operation(summary = "设置寄存器") - public Result setReg( - @RequestParam MiniServoId deviceId, - @RequestParam MiniServoRegIndex reg, - @RequestParam Integer val) throws HardwareException { - servoService.setReg(deviceId, reg, val); - deviceParamConfigService.setModuleAndReg(deviceId.getServoMId().mid.name(), reg.regIndex.name(),val); - return Result.success(); - } - - // 状态查询 - @GetMapping("/position") - @Operation(summary = "读取位置") - public Integer readPos(@RequestParam MiniServoId deviceId) throws HardwareException { - return servoService.readPos(deviceId); - } - - @GetMapping("/regs") - @Operation(summary = "获取所有寄存器") - public Map getAllReg(@RequestParam MiniServoId deviceId) { - return servoService.getAllReg(deviceId); - } -} diff --git a/src/main/java/com/iflytop/colortitration/hardware/service/GDDeviceStatusService.java b/src/main/java/com/iflytop/colortitration/hardware/service/GDDeviceStatusService.java index 0d65419..2d7c5a5 100644 --- a/src/main/java/com/iflytop/colortitration/hardware/service/GDDeviceStatusService.java +++ b/src/main/java/com/iflytop/colortitration/hardware/service/GDDeviceStatusService.java @@ -1,13 +1,10 @@ package com.iflytop.colortitration.hardware.service; -import com.iflytop.colortitration.hardware.drivers.DIDriver.InputDetectDriver; -import com.iflytop.colortitration.hardware.drivers.HeaterRodDriver; -import com.iflytop.colortitration.hardware.drivers.LeisaiServoDriver; -import com.iflytop.colortitration.hardware.drivers.MiniServoDriver.MiniServoDriver; -import com.iflytop.colortitration.hardware.drivers.StepMotorDriver.StepMotorCtrlDriver; +import com.iflytop.colortitration.hardware.drivers.InputDetectDriver; +import com.iflytop.colortitration.hardware.drivers.MiniServoDriver; +import com.iflytop.colortitration.hardware.drivers.StepMotorCtrlDriver; import com.iflytop.colortitration.hardware.exception.HardwareException; import com.iflytop.colortitration.hardware.type.IO.InputIOMId; -import com.iflytop.colortitration.hardware.type.Servo.LeisaiServoMId; import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorMId; import com.iflytop.colortitration.hardware.type.driver.HeaterRodSlavedId; import com.iflytop.colortitration.hardware.utils.Math.StepMotorConverter; @@ -20,13 +17,13 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class GDDeviceStatusService { private final InputDetectDriver inputDetectDriver; - private final HeaterRodDriver heaterRodDriver; + //private final HeaterRodDriver heaterRodDriver; private final StepMotorCtrlDriver stepMotorCtrlDriver; private final MiniServoDriver miniServoDriver; - private final LeisaiServoDriver leisaiServoDriver; /** * 获取步进电机的原点状态 + * * @param stepMotorMId * @return true 在原点 false 不在原点 */ @@ -35,18 +32,8 @@ public class GDDeviceStatusService { } /** - * 获取XY 伺服的原点状态 - * @param mid - * @return - * @throws HardwareException - */ - public Boolean getXYServoIsOrigin(LeisaiServoMId mid) throws HardwareException - { - return leisaiServoDriver.readIoState(mid, 0); - } - - /** * 获取 拍子 试管架拍子 急停 到位信号 + * * @param inputIOMId * @return * @throws HardwareException @@ -57,16 +44,19 @@ public class GDDeviceStatusService { /** * 获取加热棒温度 + * * @param heaterRodSlavedId * @return * @throws Exception */ public Double getHeaterRodTemperature(HeaterRodSlavedId heaterRodSlavedId) throws Exception { - return heaterRodDriver.getTemperature(heaterRodSlavedId); + return null; + //return heaterRodDriver.getTemperature(heaterRodSlavedId); } /** * 获取电机位置 + * * @param stepMotorMId * @return * @throws HardwareException @@ -77,15 +67,5 @@ public class GDDeviceStatusService { return realPosition; } - /** - * 获取伺服类电机位置 - * @param mid - * @return - * @throws HardwareException - */ - public Double getXYServoPosition(LeisaiServoMId mid) throws HardwareException { - int servoPosition = leisaiServoDriver.readPosition(mid); - return StepMotorConverter.toUserPosition(servoPosition); - } } diff --git a/src/main/java/com/iflytop/colortitration/hardware/service/ServoService.java b/src/main/java/com/iflytop/colortitration/hardware/service/ServoService.java deleted file mode 100644 index 3ff5815..0000000 --- a/src/main/java/com/iflytop/colortitration/hardware/service/ServoService.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.iflytop.colortitration.hardware.service; - -import com.iflytop.colortitration.hardware.drivers.MiniServoDriver.MiniServoDriver; -import com.iflytop.colortitration.hardware.exception.HardwareException; -import com.iflytop.colortitration.hardware.type.Servo.MiniServoId; -import com.iflytop.colortitration.hardware.type.Servo.MiniServoMId; -import com.iflytop.colortitration.hardware.type.Servo.MiniServoRegIndex; -import com.iflytop.colortitration.hardware.type.error.A8kEcode; -import com.iflytop.colortitration.hardware.type.error.AppError; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -import java.util.HashMap; -import java.util.Map; - -@Service -@RequiredArgsConstructor -public class ServoService { - private final MiniServoDriver miniServoDriver; - - private void throwDeviceNull(MiniServoId id) throws HardwareException - { - throw new HardwareException(new AppError(A8kEcode.PE_PARAM_OUT_OF_RANGE, "StepMotorMId is null for id: " + id)); - } - - public void enable(MiniServoId id, Boolean enable) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - miniServoDriver.miniServoEnable(servoMId, enable ? 1 : 0); - } - - public void stop(MiniServoId id) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - miniServoDriver.moduleStop(servoMId); - } - - public void moveTo(MiniServoId id, Integer pos) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - miniServoDriver.miniServoMoveToBlock(servoMId, pos); - } - - public void rotate(MiniServoId id, Integer direction) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - miniServoDriver.miniServoRotate(servoMId, direction); - } - - public void rotateWithTorque(MiniServoId id, Integer pos) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - miniServoDriver.miniServoRotateWithTorque(servoMId, pos); - } - - public void setReg(MiniServoId id, MiniServoRegIndex reg, Integer val) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - miniServoDriver.setReg(servoMId, reg, val); - } - - public Map getAllReg(MiniServoId id) { - Map map = new HashMap<>(); - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - return map; - } - - for (MiniServoRegIndex reg : MiniServoRegIndex.values()) { - try { - map.put(reg.name(), miniServoDriver.getReg(servoMId, reg)); - } catch (HardwareException e) { - } - } - return map; - } - - public void setLimitVelocity(MiniServoId id, Integer val) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - miniServoDriver.setReg(servoMId, MiniServoRegIndex.kreg_mini_servo_limit_velocity, val); - } - - public void setLimitTorque(MiniServoId id, Integer val) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - miniServoDriver.setReg(servoMId, MiniServoRegIndex.kreg_mini_servo_limit_torque, val); - } - - public void setProtectiveTorque(MiniServoId id, Integer val) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - miniServoDriver.setReg(servoMId, MiniServoRegIndex.kreg_mini_servo_protective_torque, val); - } - - public Integer readPos(MiniServoId id) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - return miniServoDriver.miniServoReadPos(servoMId); - } - - public void moveToZero(MiniServoId id) throws HardwareException { - MiniServoMId servoMId = id.getServoMId(); - if (servoMId == null) { - throwDeviceNull(id); - } - miniServoDriver.miniServoMoveToZeroBlock(servoMId); - } -} diff --git a/src/main/java/com/iflytop/colortitration/hardware/service/StepMotorService.java b/src/main/java/com/iflytop/colortitration/hardware/service/StepMotorService.java index c5cf170..ee4ec24 100644 --- a/src/main/java/com/iflytop/colortitration/hardware/service/StepMotorService.java +++ b/src/main/java/com/iflytop/colortitration/hardware/service/StepMotorService.java @@ -1,6 +1,6 @@ package com.iflytop.colortitration.hardware.service; -import com.iflytop.colortitration.hardware.drivers.StepMotorDriver.StepMotorCtrlDriver; +import com.iflytop.colortitration.hardware.drivers.StepMotorCtrlDriver; import com.iflytop.colortitration.hardware.exception.HardwareException; import com.iflytop.colortitration.hardware.type.StepMotor.DeviceStepMotorId; import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorMId; @@ -22,8 +22,7 @@ public class StepMotorService { StepMotorSpeedLevel speedLevel_ = StepMotorSpeedLevel.DEFAULT; - private void throwDeviceNull(DeviceStepMotorId id) throws HardwareException - { + private void throwDeviceNull(DeviceStepMotorId id) throws HardwareException { throw new HardwareException(new AppError(A8kEcode.PE_PARAM_OUT_OF_RANGE, "StepMotorMId is null for id: " + id)); } @@ -249,7 +248,8 @@ public class StepMotorService { if (stepId == null) { throwDeviceNull(id); } - return stepMotorCtrlDriver_.getAllReg(stepId); + //return stepMotorCtrlDriver_.getAllReg(stepId); todo + return null; } public Boolean readIoState(DeviceStepMotorId id, Integer ioindex) throws HardwareException { diff --git a/src/main/java/com/iflytop/colortitration/hardware/type/StepMotor/DeviceStepMotorId.java b/src/main/java/com/iflytop/colortitration/hardware/type/StepMotor/DeviceStepMotorId.java index fe4b66d..0fdf626 100644 --- a/src/main/java/com/iflytop/colortitration/hardware/type/StepMotor/DeviceStepMotorId.java +++ b/src/main/java/com/iflytop/colortitration/hardware/type/StepMotor/DeviceStepMotorId.java @@ -2,26 +2,6 @@ package com.iflytop.colortitration.hardware.type.StepMotor; public enum DeviceStepMotorId { - door(StepMotorMId.DOOR_MOTOR_MID, "门"), - shake_motor(StepMotorMId.SHAKE_MOTOR_MID, "摇匀电机"), - tray_motor(StepMotorMId.TRAY_MOTOR_MID, "托盘电机"), - gantry_x(StepMotorMId.HBOT_X_MOTOR_MID, "龙门架X轴"), - gantry_y(StepMotorMId.HBOT_Y_MOTOR_MID, "龙门架Y轴"), - gantry_z(StepMotorMId.HBOT_Z_MOTOR_MID, "龙门架Z轴"), - heater_motor_1(StepMotorMId.HEATER_1_MOTOR_MID, "加热位顶升电机1"), - heater_motor_2(StepMotorMId.HEATER_2_MOTOR_MID, "加热位顶升电机2"), - heater_motor_3(StepMotorMId.HEATER_3_MOTOR_MID, "加热位顶升电机3"), - heater_motor_4(StepMotorMId.HEATER_4_MOTOR_MID, "加热位顶升电机4"), - heater_motor_5(StepMotorMId.HEATER_5_MOTOR_MID, "加热位顶升电机5"), - heater_motor_6(StepMotorMId.HEATER_6_MOTOR_MID, "加热位顶升电机6"), - acid_pump_1(StepMotorMId.ACID_PUMP_1_MOTOR_MID, "加酸泵电机1"), - acid_pump_2(StepMotorMId.ACID_PUMP_2_MOTOR_MID, "加酸泵电机2"), - acid_pump_3(StepMotorMId.ACID_PUMP_3_MOTOR_MID, "加酸泵电机3"), - acid_pump_4(StepMotorMId.ACID_PUMP_4_MOTOR_MID, "加酸泵电机4"), - acid_pump_5(StepMotorMId.ACID_PUMP_5_MOTOR_MID, "加酸泵电机5"), - acid_pump_6(StepMotorMId.ACID_PUMP_6_MOTOR_MID, "加酸泵电机6"), - acid_pump_7(StepMotorMId.ACID_PUMP_7_MOTOR_MID, "加酸泵电机7"), - acid_pump_8(StepMotorMId.ACID_PUMP_8_MOTOR_MID, "加酸泵电机8"), ; private StepMotorMId stepMotorMId;