49 changed files with 1525 additions and 2219 deletions
-
1src/main/java/com/iflytop/colortitration/common/enums/Action.java
-
85src/main/java/com/iflytop/colortitration/hardware/command/handlers/CeramicPumpHandler.java
-
64src/main/java/com/iflytop/colortitration/hardware/command/handlers/ClawHandler.java
-
0src/main/java/com/iflytop/colortitration/hardware/command/handlers/HeatRodHandler.java
-
55src/main/java/com/iflytop/colortitration/hardware/command/handlers/IOCtrlHandler.java
-
145src/main/java/com/iflytop/colortitration/hardware/command/handlers/MotorHandler.java
-
86src/main/java/com/iflytop/colortitration/hardware/command/handlers/TricolorLightHandler.java
-
225src/main/java/com/iflytop/colortitration/hardware/config/StepMotorConfig.java
-
84src/main/java/com/iflytop/colortitration/hardware/controller/AcidPumpController.java
-
91src/main/java/com/iflytop/colortitration/hardware/controller/DualRobotController.java
-
70src/main/java/com/iflytop/colortitration/hardware/controller/HeaterMotorController.java
-
2src/main/java/com/iflytop/colortitration/hardware/controller/IOController.java
-
267src/main/java/com/iflytop/colortitration/hardware/drivers/CeramicPumpDriver.java
-
53src/main/java/com/iflytop/colortitration/hardware/drivers/ColdTrapDriver.java
-
24src/main/java/com/iflytop/colortitration/hardware/drivers/DODriver/FanDriver.java
-
22src/main/java/com/iflytop/colortitration/hardware/drivers/DODriver/VentilatorDriver.java
-
22src/main/java/com/iflytop/colortitration/hardware/drivers/DODriver/WaterPumpDriver.java
-
23src/main/java/com/iflytop/colortitration/hardware/drivers/FillLightDriver.java
-
122src/main/java/com/iflytop/colortitration/hardware/drivers/HeaterRodDriver.java
-
2src/main/java/com/iflytop/colortitration/hardware/drivers/InputDetectDriver.java
-
28src/main/java/com/iflytop/colortitration/hardware/drivers/LeisaiServoDriver.java
-
64src/main/java/com/iflytop/colortitration/hardware/drivers/LiquidDistributionArmDriver.java
-
127src/main/java/com/iflytop/colortitration/hardware/drivers/MiniServoDriver.java
-
110src/main/java/com/iflytop/colortitration/hardware/drivers/MiniServoDriver/ClawDriver.java
-
180src/main/java/com/iflytop/colortitration/hardware/drivers/MiniServoDriver/DualRobotDriver.java
-
6src/main/java/com/iflytop/colortitration/hardware/drivers/ModuleEnableCtrlDriver.java
-
41src/main/java/com/iflytop/colortitration/hardware/drivers/MotorWrapperDriver.java
-
18src/main/java/com/iflytop/colortitration/hardware/drivers/OutputIOCtrlDriver.java
-
43src/main/java/com/iflytop/colortitration/hardware/drivers/StepMotorCtrlDriver.java
-
101src/main/java/com/iflytop/colortitration/hardware/drivers/StepMotorDriver/AcidPumpDriver.java
-
100src/main/java/com/iflytop/colortitration/hardware/drivers/StepMotorDriver/HBotDriver.java
-
79src/main/java/com/iflytop/colortitration/hardware/drivers/StepMotorDriver/HeaterMotorDriver.java
-
90src/main/java/com/iflytop/colortitration/hardware/drivers/StepMotorDriver/ShakeMotorDriver.java
-
98src/main/java/com/iflytop/colortitration/hardware/drivers/StepMotorDriver/TrayMotorDriver.java
-
2src/main/java/com/iflytop/colortitration/hardware/drivers/TricolorLightDriver.java
-
35src/main/java/com/iflytop/colortitration/hardware/type/CeramicPumpDriverSlaveId.java
-
15src/main/java/com/iflytop/colortitration/hardware/type/CmdId.java
-
24src/main/java/com/iflytop/colortitration/hardware/type/IO/OutputIOMId.java
-
92src/main/java/com/iflytop/colortitration/hardware/type/MId.java
-
4src/main/java/com/iflytop/colortitration/hardware/type/Servo/MiniServoMId.java
-
4src/main/java/com/iflytop/colortitration/hardware/type/StepMotor/MotorDirect.java
-
40src/main/java/com/iflytop/colortitration/hardware/type/StepMotor/StepMotorMId.java
-
122src/main/java/com/iflytop/colortitration/hardware/utils/ZJsonHelper.java
@ -0,0 +1,85 @@ |
|||
package com.iflytop.colortitration.hardware.command.handlers; |
|||
|
|||
import com.iflytop.colortitration.app.core.command.DeviceCommand; |
|||
import com.iflytop.colortitration.common.enums.Action; |
|||
import com.iflytop.colortitration.common.enums.Device; |
|||
import com.iflytop.colortitration.common.enums.MotorDirection; |
|||
import com.iflytop.colortitration.hardware.command.CommandHandler; |
|||
import com.iflytop.colortitration.hardware.drivers.CeramicPumpDriver; |
|||
import com.iflytop.colortitration.hardware.type.CeramicPumpDriverSlaveId; |
|||
import com.iflytop.colortitration.hardware.type.MId; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.MotorDirect; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
import java.util.Set; |
|||
import java.util.stream.Collectors; |
|||
|
|||
import static java.lang.Math.abs; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class CeramicPumpHandler extends CommandHandler { |
|||
private final CeramicPumpDriver driver_; |
|||
|
|||
private final Map<Device, CeramicPumpDriverSlaveId> stepMotorMIdMap_ = Map.ofEntries( |
|||
Map.entry(Device.CERAMIC_PUMP_1, CeramicPumpDriverSlaveId.CERAMIC_PUMP1_ID), |
|||
Map.entry(Device.CERAMIC_PUMP_2, CeramicPumpDriverSlaveId.CERAMIC_PUMP2_ID) |
|||
); |
|||
private final Map<Device, MId> supportCmdDeviceMIdMap = stepMotorMIdMap_.entrySet().stream(). |
|||
collect(Collectors.toMap(Map.Entry::getKey, entry -> MId.NotSet)); |
|||
|
|||
private final Set<Action> supportActions = Set.of( |
|||
Action.SET, Action.CLOSE_CLAMP, |
|||
Action.MOVE_BY, |
|||
Action.STOP); |
|||
|
|||
@Override |
|||
protected Map<Device, MId> getSupportCmdDeviceMIdMap() { |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<Action> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
public MotorDirect getMotorDirect(MotorDirection cmdDirection) |
|||
{ |
|||
return switch (cmdDirection) { |
|||
case FORWARD -> MotorDirect.FORWARD; |
|||
case BACKWARD -> MotorDirect.BACKWARD; |
|||
}; |
|||
} |
|||
|
|||
@Override |
|||
public void handleCommand(DeviceCommand command) throws Exception { |
|||
// 发送命令 |
|||
CeramicPumpDriverSlaveId slaveId = stepMotorMIdMap_.get(command.getDevice()); |
|||
|
|||
switch (command.getAction()) { |
|||
case MOVE_BY -> { |
|||
double distance = command.getParam().getPosition(); |
|||
log.info("Motor {} Move By Distance {}", slaveId, distance); |
|||
CeramicPumpDriver.Direction direction = distance < 0 ? |
|||
CeramicPumpDriver.Direction.BACKWARD : CeramicPumpDriver.Direction.FORWARD; |
|||
driver_.moveByBlock(slaveId, direction, abs((int)(distance))); |
|||
} |
|||
case STOP -> { |
|||
log.info("Motor {} Stop", slaveId); |
|||
driver_.stop(slaveId); |
|||
} |
|||
case SET -> { |
|||
Double speed = command.getParam().getSpeed(); |
|||
if (speed != null) { |
|||
double d_speed = speed; |
|||
log.info("Motor {} Set Speed {}", slaveId, speed); |
|||
driver_.setSpeed(slaveId, (int)d_speed); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
@ -1,64 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.command.handlers; |
|||
|
|||
|
|||
import com.iflytop.colortitration.app.core.command.DeviceCommand; |
|||
import com.iflytop.colortitration.common.enums.Action; |
|||
import com.iflytop.colortitration.common.enums.Device; |
|||
import com.iflytop.colortitration.hardware.command.CommandHandler; |
|||
import com.iflytop.colortitration.hardware.drivers.MiniServoDriver.ClawDriver; |
|||
import com.iflytop.colortitration.hardware.type.MId; |
|||
import com.iflytop.colortitration.hardware.type.Servo.MiniServoMId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
import java.util.Set; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class ClawHandler extends CommandHandler { |
|||
private final ClawDriver clawDriver_; |
|||
|
|||
private final Map<Device, MiniServoMId> servoMIdMap_ = Map.ofEntries( |
|||
Map.entry(Device.CLAW, MiniServoMId.CLAW_MID) |
|||
); |
|||
private final Map<Device, MId> supportCmdDeviceMIdMap = servoMIdMap_.entrySet().stream(). |
|||
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); |
|||
private final Set<Action> supportActions = Set.of(Action.SET, Action.ORIGIN, Action.MOVE, Action.STOP); |
|||
|
|||
@Override |
|||
protected Map<Device, MId> getSupportCmdDeviceMIdMap() |
|||
{ |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<Action> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
@Override |
|||
public void handleCommand(DeviceCommand command) throws Exception { |
|||
// 发送命令 |
|||
MiniServoMId servoMId = servoMIdMap_.get(command.getDevice()); |
|||
if (command.getAction() == Action.ORIGIN) { |
|||
clawDriver_.moveToHome(servoMId); |
|||
} |
|||
else if(command.getAction() == Action.STOP) { |
|||
clawDriver_.stop(servoMId); |
|||
} |
|||
else if(command.getAction() == Action.MOVE) { |
|||
double position = command.getParam().getPosition(); |
|||
clawDriver_.moveTo(servoMId, position); |
|||
} |
|||
else if(command.getAction() == Action.SET) { |
|||
Double speed = command.getParam().getSpeed(); |
|||
if(speed != null) { |
|||
clawDriver_.setSpeed(servoMId, speed); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,55 @@ |
|||
package com.iflytop.colortitration.hardware.command.handlers; |
|||
|
|||
import com.iflytop.colortitration.app.core.command.DeviceCommand; |
|||
import com.iflytop.colortitration.common.enums.Action; |
|||
import com.iflytop.colortitration.common.enums.Device; |
|||
import com.iflytop.colortitration.hardware.command.CommandHandler; |
|||
import com.iflytop.colortitration.hardware.drivers.OutputIOCtrlDriver; |
|||
import com.iflytop.colortitration.hardware.type.IO.OutputIOMId; |
|||
import com.iflytop.colortitration.hardware.type.MId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
import java.util.Set; |
|||
import java.util.stream.Collectors; |
|||
|
|||
// |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class IOCtrlHandler extends CommandHandler { |
|||
private final OutputIOCtrlDriver driver_; |
|||
private final Map<Device, OutputIOMId> supportCmdDeviceIOOutputMap = Map.ofEntries( |
|||
); |
|||
|
|||
private final Map<Device, MId> supportCmdDeviceMIdMap = supportCmdDeviceIOOutputMap.entrySet().stream() |
|||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); |
|||
|
|||
private final Set<Action> supportActions = Set.of(Action.OPEN, Action.CLOSE); |
|||
|
|||
@Override |
|||
protected Map<Device, MId> getSupportCmdDeviceMIdMap() |
|||
{ |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<Action> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
@Override |
|||
public void handleCommand(DeviceCommand command) throws Exception { |
|||
// 发送命令 |
|||
if (command.getAction() == Action.OPEN) { |
|||
log.info("open {}", command.getDevice()); |
|||
driver_.open(supportCmdDeviceIOOutputMap.get(command.getDevice())); |
|||
} else if (command.getAction() == Action.CLOSE) { |
|||
log.info("close {}", command.getDevice()); |
|||
driver_.close(supportCmdDeviceIOOutputMap.get(command.getDevice())); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,145 @@ |
|||
package com.iflytop.colortitration.hardware.command.handlers; |
|||
|
|||
|
|||
import com.iflytop.colortitration.app.core.command.DeviceCommand; |
|||
import com.iflytop.colortitration.common.enums.Action; |
|||
import com.iflytop.colortitration.common.enums.Device; |
|||
import com.iflytop.colortitration.common.enums.MotorDirection; |
|||
import com.iflytop.colortitration.hardware.command.CommandHandler; |
|||
import com.iflytop.colortitration.hardware.drivers.MotorWrapperDriver; |
|||
import com.iflytop.colortitration.hardware.type.MId; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.MotorDirect; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorMId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
import java.util.Set; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class MotorHandler extends CommandHandler { |
|||
private final MotorWrapperDriver driver_; |
|||
|
|||
private final Map<Device, StepMotorMId> stepMotorMIdMap_ = Map.ofEntries( |
|||
Map.entry(Device.ROBOTIC_ARM_BIG, StepMotorMId.DualRobot1M), |
|||
Map.entry(Device.ROBOTIC_ARM_SMALL, StepMotorMId.DualRobot2M), |
|||
Map.entry(Device.Z_MOTOR, StepMotorMId.RobotArmZM), |
|||
Map.entry(Device.BRUSHLESS_PUMP_1, StepMotorMId.BrushlessPump1M), |
|||
Map.entry(Device.BRUSHLESS_PUMP_2, StepMotorMId.BrushlessPump2M), |
|||
Map.entry(Device.BRUSHLESS_PUMP_3, StepMotorMId.BrushlessPump3M), |
|||
Map.entry(Device.BRUSHLESS_PUMP_4, StepMotorMId.BrushlessPump4M), |
|||
Map.entry(Device.BRUSHLESS_PUMP_5, StepMotorMId.BrushlessPump5M), |
|||
Map.entry(Device.BRUSHLESS_PUMP_6, StepMotorMId.BrushlessPump6M), |
|||
Map.entry(Device.BRUSHLESS_PUMP_7, StepMotorMId.BrushlessPump7M), |
|||
Map.entry(Device.BRUSHLESS_PUMP_8, StepMotorMId.BrushlessPump8M), |
|||
Map.entry(Device.BRUSHLESS_PUMP_9, StepMotorMId.BrushlessPump9M), |
|||
Map.entry(Device.BRUSHLESS_PUMP_10, StepMotorMId.BrushlessPump10M), |
|||
Map.entry(Device.STEP_PUMP_1, StepMotorMId.StepPump1M), |
|||
Map.entry(Device.STEP_PUMP_2, StepMotorMId.StepPump2M), |
|||
Map.entry(Device.STEP_PUMP_3, StepMotorMId.StepPump3M), |
|||
Map.entry(Device.STIR_MOTOR_1, StepMotorMId.TitratorStir1M), |
|||
Map.entry(Device.STIR_MOTOR_2, StepMotorMId.TitratorStir2M), |
|||
Map.entry(Device.TITRATION_MOTOR_1, StepMotorMId.Titrator1M), |
|||
Map.entry(Device.TITRATION_MOTOR_2, StepMotorMId.Titrator2M) |
|||
); |
|||
private final Map<Device, MId> supportCmdDeviceMIdMap = stepMotorMIdMap_.entrySet().stream(). |
|||
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); |
|||
|
|||
private final Set<Action> supportActions = Set.of( |
|||
Action.SET, |
|||
Action.ENABLE, |
|||
Action.DISABLE, |
|||
Action.OPEN_CLAMP, |
|||
Action.CLOSE_CLAMP, |
|||
Action.ORIGIN, |
|||
Action.MOVE, |
|||
Action.MOVE_BY, |
|||
Action.ROTATE, |
|||
Action.STOP, |
|||
Action.MOVE_END); |
|||
|
|||
@Override |
|||
protected Map<Device, MId> getSupportCmdDeviceMIdMap() { |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<Action> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
public MotorDirect getMotorDirect(MotorDirection cmdDirection) |
|||
{ |
|||
return switch (cmdDirection) { |
|||
case FORWARD -> MotorDirect.FORWARD; |
|||
case BACKWARD -> MotorDirect.BACKWARD; |
|||
}; |
|||
} |
|||
|
|||
@Override |
|||
public void handleCommand(DeviceCommand command) throws Exception { |
|||
// 发送命令 |
|||
StepMotorMId stepMotorMId = stepMotorMIdMap_.get(command.getDevice()); |
|||
|
|||
switch (command.getAction()) { |
|||
case ENABLE -> { |
|||
log.info("Motor {} Enable", stepMotorMId.mid.getDescription()); |
|||
driver_.motorEnable(stepMotorMId, true); |
|||
} |
|||
case DISABLE -> { |
|||
log.info("Motor {} Disable", stepMotorMId.mid.getDescription()); |
|||
driver_.motorEnable(stepMotorMId, false); |
|||
} |
|||
case OPEN_CLAMP -> { |
|||
log.info("Motor {} Open Clamp", stepMotorMId.mid.getDescription()); |
|||
driver_.openClamp(stepMotorMId); |
|||
} |
|||
case CLOSE_CLAMP -> { |
|||
log.info("Motor {} Close Clamp", stepMotorMId.mid.getDescription()); |
|||
driver_.closeClamp(stepMotorMId); |
|||
} |
|||
case ORIGIN -> { |
|||
log.info("Motor {} Move To Origin", stepMotorMId.mid.getDescription()); |
|||
driver_.moveToHome(stepMotorMId); |
|||
} |
|||
case MOVE -> { |
|||
double position = command.getParam().getPosition(); |
|||
log.info("Motor {} Move To Position {}", stepMotorMId.mid.getDescription(), position); |
|||
driver_.moveTo(stepMotorMId, position); |
|||
} |
|||
case MOVE_BY -> { |
|||
double distance = command.getParam().getPosition(); |
|||
log.info("Motor {} Move By Distance {}", stepMotorMId.mid.getDescription(), distance); |
|||
driver_.moveBy(stepMotorMId, distance); |
|||
} |
|||
case ROTATE -> { |
|||
MotorDirection cmdDirection = command.getParam().getDirection(); |
|||
MotorDirect direct = getMotorDirect(cmdDirection); |
|||
log.info("Motor {} Rotate {}", stepMotorMId.mid.getDescription(), direct.name()); |
|||
driver_.rotate(stepMotorMId, direct); |
|||
} |
|||
case STOP -> { |
|||
log.info("Motor {} Stop", stepMotorMId.mid.getDescription()); |
|||
driver_.stop(stepMotorMId); |
|||
} |
|||
case SET -> { |
|||
Double speed = command.getParam().getSpeed(); |
|||
if (speed != null) { |
|||
log.info("Motor {} Set Speed {}", stepMotorMId.mid.getDescription(), speed); |
|||
driver_.setSpeed(stepMotorMId, speed); |
|||
} |
|||
} |
|||
case MOVE_END -> { |
|||
driver_.moveToEnd(stepMotorMId); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,86 @@ |
|||
package com.iflytop.colortitration.hardware.command.handlers; |
|||
|
|||
|
|||
import com.iflytop.colortitration.app.core.command.DeviceCommand; |
|||
import com.iflytop.colortitration.common.enums.Action; |
|||
import com.iflytop.colortitration.common.enums.Device; |
|||
import com.iflytop.colortitration.common.enums.TricolorLightColor; |
|||
import com.iflytop.colortitration.hardware.command.CommandHandler; |
|||
import com.iflytop.colortitration.hardware.drivers.TricolorLightDriver; |
|||
import com.iflytop.colortitration.hardware.type.MId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.security.InvalidParameterException; |
|||
import java.util.Map; |
|||
import java.util.Set; |
|||
|
|||
import static java.awt.Color.blue; |
|||
|
|||
/** |
|||
* 三色灯 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class TricolorLightHandler extends CommandHandler { |
|||
private final TricolorLightDriver tricolorLightDriver; |
|||
|
|||
private final Map<Device, MId> supportCmdDeviceMIdMap = Map.ofEntries( |
|||
Map.entry(Device.TRICOLOR_LIGHT, MId.IO1_TriColorLight) |
|||
); |
|||
|
|||
private final Set<Action> supportActions = Set.of(Action.OPEN, Action.CLOSE); |
|||
|
|||
@Override |
|||
protected Map<Device, MId> getSupportCmdDeviceMIdMap() |
|||
{ |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<Action> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
@Override |
|||
protected void checkParams(DeviceCommand command) throws Exception { |
|||
// 检查参数 |
|||
if (command.getAction() == Action.OPEN) { |
|||
// 检查参数 |
|||
TricolorLightColor cmdColor = command.getParam().getColor(); |
|||
getCmdColor(cmdColor); |
|||
} |
|||
|
|||
} |
|||
|
|||
TricolorLightDriver.Color getCmdColor(TricolorLightColor cmdColor){ |
|||
switch (cmdColor){ |
|||
case RED: |
|||
return TricolorLightDriver.Color.RED; |
|||
case GREEN: |
|||
return TricolorLightDriver.Color.GREEN; |
|||
case BLUE: |
|||
return TricolorLightDriver.Color.BLUE; |
|||
default: |
|||
throw new InvalidParameterException("颜色参数错误"); |
|||
} |
|||
} |
|||
|
|||
MId getMId(Device cmdDevice){ |
|||
return supportCmdDeviceMIdMap.get(cmdDevice); |
|||
} |
|||
|
|||
@Override |
|||
public void handleCommand(DeviceCommand command) throws Exception { |
|||
// 发送命令 |
|||
if (command.getAction() == Action.OPEN) { |
|||
TricolorLightColor cmdColor = command.getParam().getColor(); |
|||
TricolorLightDriver.Color color = getCmdColor(cmdColor); |
|||
tricolorLightDriver.open(getMId(command.getDevice()), color); |
|||
} else if (command.getAction() == Action.CLOSE) { |
|||
tricolorLightDriver.close(getMId(command.getDevice())); |
|||
} |
|||
} |
|||
} |
@ -1,84 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.controller; |
|||
|
|||
import com.iflytop.colortitration.app.service.DeviceParamConfigService; |
|||
import com.iflytop.colortitration.hardware.drivers.StepMotorDriver.AcidPumpDriver; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorRegIndex; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@Tag(name = "加酸泵控制") |
|||
@RestController |
|||
@RequestMapping("/api/acid-pump") |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class AcidPumpController { |
|||
private final AcidPumpDriver driver; |
|||
private final DeviceParamConfigService deviceParamConfigService; |
|||
|
|||
@PostMapping("/set-speed") |
|||
public void setSpeed(@RequestParam StepMotorMId stepMotorMId, @RequestParam int speed) { |
|||
log.info("Setting acid pump speed to: {}", speed); |
|||
try { |
|||
driver.setSpeed(stepMotorMId, speed); |
|||
deviceParamConfigService.setModuleAndReg(stepMotorMId.mid.name(), StepMotorRegIndex.kreg_step_motor_default_velocity.regIndex.name(),speed); |
|||
} catch (Exception e) { |
|||
log.error("Failed to set speed for acid pump: {}", e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/motor-enable") |
|||
public void motorEnable(@RequestParam StepMotorMId stepMotorMId, @RequestParam boolean enable) { |
|||
log.info("Setting acid pump motor enable to: {}", enable); |
|||
try { |
|||
driver.motorEnable(stepMotorMId, enable); |
|||
} catch (Exception e) { |
|||
log.error("Failed to enable motor for acid pump: {}", e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/move-to-home") |
|||
public void moveToHome(@RequestParam StepMotorMId stepMotorMId) { |
|||
log.info("Moving acid pump to home position"); |
|||
try { |
|||
driver.moveToHome(stepMotorMId); |
|||
} catch (Exception e) { |
|||
log.error("Failed to move acid pump to home: {}", e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/move-to") |
|||
public void moveTo(@RequestParam StepMotorMId stepMotorMId, @RequestParam int position) { |
|||
log.info("Moving acid pump to position: {}", position); |
|||
try { |
|||
driver.moveTo(stepMotorMId, position); |
|||
} catch (Exception e) { |
|||
log.error("Failed to move acid pump to position: {}", e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/move-by") |
|||
public void moveBy(@RequestParam StepMotorMId stepMotorMId, @RequestParam int offset) { |
|||
log.info("Moving acid pump by offset: {}", offset); |
|||
try { |
|||
driver.moveBy(stepMotorMId, offset); |
|||
} catch (Exception e) { |
|||
log.error("Failed to move acid pump by offset: {}", e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/stop") |
|||
public void stop(@RequestParam StepMotorMId stepMotorMId) { |
|||
log.info("Stopping acid pump"); |
|||
try { |
|||
driver.stop(stepMotorMId); |
|||
} catch (Exception e) { |
|||
log.error("Failed to stop acid pump: {}", e.getMessage()); |
|||
} |
|||
} |
|||
} |
@ -1,91 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.controller; |
|||
|
|||
import com.iflytop.colortitration.hardware.drivers.MiniServoDriver.DualRobotDriver; |
|||
import com.iflytop.colortitration.hardware.drivers.MiniServoDriver.DualRobotDriver.Joint; |
|||
import com.iflytop.colortitration.hardware.type.Servo.MiniServoMId; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@Tag(name = "双轴机械臂控制") |
|||
@RestController |
|||
@RequestMapping("/api/dual-robot") |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class DualRobotController { |
|||
private final DualRobotDriver driver; |
|||
|
|||
@PostMapping("/move-joint-to") |
|||
public void moveJointTo(@RequestParam MiniServoMId sevoMid, @RequestParam double position) { |
|||
log.info("Moving joint {} to position {}", sevoMid, position); |
|||
try { |
|||
driver.moveJointTo(sevoMid, position); |
|||
} catch (Exception e) { |
|||
log.error("Failed to move joint {} to position {}: {}", sevoMid, position, e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/stop-servo") |
|||
public void stop(@RequestParam MiniServoMId sevoMid) { |
|||
log.info("Stopping servo {}", sevoMid); |
|||
try { |
|||
driver.stop(sevoMid); |
|||
} catch (Exception e) { |
|||
log.error("Failed to stop servo {}: {}", sevoMid, e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/set-speed") |
|||
public void setSpeed(@RequestParam Joint joint, @RequestParam double speed) { |
|||
log.info("Setting speed for joint {} to {}", joint, speed); |
|||
try { |
|||
driver.setSpeed(joint, speed); |
|||
} catch (Exception e) { |
|||
log.error("Failed to set speed for joint {}: {}", joint, e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/move-to-point") |
|||
public void moveToPoint(@RequestParam double pointX, @RequestParam double pointY) { |
|||
log.info("Moving to point ({}, {})", pointX, pointY); |
|||
try { |
|||
driver.moveToPoint(pointX, pointY); |
|||
} catch (Exception e) { |
|||
log.error("Failed to move to point ({}, {}): {}", pointX, pointY, e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/move-to-home") |
|||
public void moveToHome(@RequestParam Joint joint) { |
|||
log.info("Moving joint {} to home position", joint); |
|||
try { |
|||
driver.moveToHome(joint); |
|||
} catch (Exception e) { |
|||
log.error("Failed to move joint {} to home position: {}", joint, e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/move-joint-to-position") |
|||
public void moveJointTo(@RequestParam Joint joint, @RequestParam double position) { |
|||
log.info("Moving joint {} to position {}", joint, position); |
|||
try { |
|||
driver.moveJointTo(joint, position); |
|||
} catch (Exception e) { |
|||
log.error("Failed to move joint {} to position {}: {}", joint, position, e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/stop-joint") |
|||
public void stop(@RequestParam Joint joint) { |
|||
log.info("Stopping joint {}", joint); |
|||
try { |
|||
driver.stop(joint); |
|||
} catch (Exception e) { |
|||
log.error("Failed to stop joint {}: {}", joint, e.getMessage()); |
|||
} |
|||
} |
|||
} |
@ -1,70 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.controller; |
|||
|
|||
import com.iflytop.colortitration.hardware.drivers.StepMotorDriver.HeaterMotorDriver; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorMId; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@Tag(name = "加热电机控制") |
|||
@RestController |
|||
@RequestMapping("/api/heater-motor") |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class HeaterMotorController { |
|||
private final HeaterMotorDriver driver; |
|||
|
|||
@PostMapping("/motor-enable") |
|||
public void motorEnable(@RequestParam StepMotorMId stepMotorMId, @RequestParam boolean enable) { |
|||
log.info("Setting heater motor enable to: {}", enable); |
|||
try { |
|||
driver.motorEnable(stepMotorMId, enable); |
|||
} catch (Exception e) { |
|||
log.error("Failed to enable motor for heater motor: {}", e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/move-to-home") |
|||
public void moveToHome(@RequestParam StepMotorMId stepMotorMId) { |
|||
log.info("Moving heater motor to home position"); |
|||
try { |
|||
driver.moveToHome(stepMotorMId); |
|||
} catch (Exception e) { |
|||
log.error("Failed to move heater motor to home: {}", e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/move-to") |
|||
public void moveTo(@RequestParam StepMotorMId stepMotorMId, @RequestParam int position) { |
|||
log.info("Moving heater motor to position: {}", position); |
|||
try { |
|||
driver.moveTo(stepMotorMId, position); |
|||
} catch (Exception e) { |
|||
log.error("Failed to move heater motor to position: {}", e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/move-by") |
|||
public void moveBy(@RequestParam StepMotorMId stepMotorMId, @RequestParam int offset) { |
|||
log.info("Moving heater motor by offset: {}", offset); |
|||
try { |
|||
driver.moveBy(stepMotorMId, offset); |
|||
} catch (Exception e) { |
|||
log.error("Failed to move heater motor by offset: {}", e.getMessage()); |
|||
} |
|||
} |
|||
|
|||
@PostMapping("/stop") |
|||
public void stop(@RequestParam StepMotorMId stepMotorMId) { |
|||
log.info("Stopping heater motor"); |
|||
try { |
|||
driver.stop(stepMotorMId); |
|||
} catch (Exception e) { |
|||
log.error("Failed to stop heater motor: {}", e.getMessage()); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,267 @@ |
|||
package com.iflytop.colortitration.hardware.drivers; |
|||
|
|||
|
|||
import com.iflytop.colortitration.hardware.comm.modbus.ModbusMasterService; |
|||
import com.iflytop.colortitration.hardware.type.CeramicPumpDriverSlaveId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class CeramicPumpDriver { |
|||
|
|||
|
|||
public enum CeramicPumpBaud { |
|||
CeramicPumpBaud_9600(0x04), |
|||
CeramicPumpBaud_115200(0x08); |
|||
|
|||
int getId(){ |
|||
return id; |
|||
} |
|||
|
|||
private final int id; |
|||
|
|||
CeramicPumpBaud(int id) { |
|||
this.id = id; |
|||
} |
|||
}; |
|||
|
|||
public enum Direction { |
|||
FORWARD(0x0000), // 正转 |
|||
BACKWARD(0x0001); // 反转 |
|||
|
|||
private final int value; |
|||
|
|||
Direction(int value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public int getValue() { |
|||
return value; |
|||
} |
|||
} |
|||
|
|||
private final ModbusMasterService modbusMaster; |
|||
|
|||
private static final int DEFAULT_ADDRESS = 0x11; |
|||
private static final int ADDRESS_REGISTER = 0x000A; |
|||
private static final int BAUDRATE_REGISTER = 0x001C; |
|||
private static final int SPEED_REGISTER = 0x000C; |
|||
private static final int RESET_REGISTER = 0x0014; |
|||
private static final int MOVE_REGISTER = 0x0014; |
|||
private static final int STOP_RESUME_REGISTER = 0x0010; |
|||
private static final int DIRECTION_REGISTER = 0x000E; // 正反转控制寄存器 |
|||
private static final int POSITION_REGISTER = 0x0012; // 当前圈数查询寄存器 |
|||
|
|||
private final ConcurrentHashMap<CeramicPumpDriverSlaveId, Boolean> runFlags = new ConcurrentHashMap<>(); |
|||
|
|||
/** |
|||
* 设置注射泵地址 |
|||
*/ |
|||
public void setDeviceAddress(CeramicPumpDriverSlaveId pumpId, int newAddress) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
if (!modbusMaster.writeRegister(slaveId, ADDRESS_REGISTER, newAddress)) { |
|||
throw new Exception("Failed to set device address for pump, slaveId: " + slaveId); |
|||
} |
|||
log.info("Pump[{}] address set to {}", slaveId, newAddress); |
|||
} |
|||
|
|||
/** |
|||
* 设置波特率 |
|||
*/ |
|||
public void setBaudRate(CeramicPumpDriverSlaveId pumpId, CeramicPumpBaud baudRate) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
if (!modbusMaster.writeRegister(slaveId, BAUDRATE_REGISTER, baudRate.getId())) { |
|||
throw new Exception("Failed to set baud rate for pump, slaveId: " + slaveId); |
|||
} |
|||
log.info("Pump[{}] baud rate set to {}", slaveId, baudRate); |
|||
} |
|||
|
|||
/** |
|||
* 设置注射泵速度 |
|||
*/ |
|||
public void setSpeed(CeramicPumpDriverSlaveId pumpId, int speed) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
if (!modbusMaster.writeRegister(slaveId, SPEED_REGISTER, speed)) { |
|||
throw new Exception("Failed to set speed for pump, slaveId: " + slaveId); |
|||
} |
|||
log.info("Pump[{}] speed set to {} rpm", slaveId, speed); |
|||
} |
|||
|
|||
/** |
|||
* 获取注射泵速度 |
|||
*/ |
|||
public int getSpeed(CeramicPumpDriverSlaveId pumpId) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
short[] response = modbusMaster.readHoldingRegisters(slaveId, SPEED_REGISTER, 1); |
|||
if (response == null || response.length == 0) { |
|||
throw new Exception("Failed to read speed for pump, slaveId: " + slaveId); |
|||
} |
|||
return response[0]; |
|||
} |
|||
|
|||
/** |
|||
* 获取注射泵位置(圈数) |
|||
*/ |
|||
public int getTargetPosition(CeramicPumpDriverSlaveId pumpId) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
short[] response = modbusMaster.readHoldingRegisters(slaveId, MOVE_REGISTER, 1); |
|||
if (response == null || response.length == 0) { |
|||
throw new Exception("Failed to read position for pump, slaveId: " + slaveId); |
|||
} |
|||
return response[0]; |
|||
} |
|||
|
|||
/** |
|||
* 查询注射泵当前地址(ID) |
|||
*/ |
|||
public int getDeviceAddress(CeramicPumpDriverSlaveId pumpId) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
short[] response = modbusMaster.readHoldingRegisters(slaveId, ADDRESS_REGISTER, 1); |
|||
if (response == null || response.length == 0) { |
|||
throw new Exception("Failed to read device address for pump, slaveId: " + slaveId); |
|||
} |
|||
return response[0]; |
|||
} |
|||
|
|||
/** |
|||
* 复位 |
|||
*/ |
|||
public void reset(CeramicPumpDriverSlaveId pumpId) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
if (!modbusMaster.writeRegister(slaveId, RESET_REGISTER, 0)) { |
|||
throw new Exception("Failed to reset pump, slaveId: " + slaveId); |
|||
} |
|||
log.info("Pump[{}] reset", slaveId); |
|||
} |
|||
|
|||
/** |
|||
* 定量运动 |
|||
*/ |
|||
public void moveBy(CeramicPumpDriverSlaveId pumpId, int r) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
if (!modbusMaster.writeRegister(slaveId, MOVE_REGISTER, r)) { |
|||
throw new Exception("Failed to move pump, slaveId: " + slaveId + ", r: " + r); |
|||
} |
|||
log.info("Pump[{}] move {} turns", slaveId, r); |
|||
} |
|||
|
|||
/** |
|||
* 设置正反转方向 |
|||
* @param direction 正转(FORWARD)或反转(REVERSE) |
|||
*/ |
|||
public void setDirection(CeramicPumpDriverSlaveId pumpId, Direction direction) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
if (!modbusMaster.writeRegister(slaveId, DIRECTION_REGISTER, direction.getValue())) { |
|||
throw new Exception("Failed to set direction for pump, slaveId: " + slaveId); |
|||
} |
|||
log.info("Pump[{}] direction set to {}", slaveId, direction); |
|||
} |
|||
|
|||
|
|||
public int getCurrentPosition(CeramicPumpDriverSlaveId pumpId) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
short[] response = modbusMaster.readHoldingRegisters(slaveId, POSITION_REGISTER, 1); |
|||
if (response == null || response.length == 0) { |
|||
throw new Exception("Failed to read current position for pump, slaveId: " + slaveId); |
|||
} |
|||
return response[0]; |
|||
} |
|||
|
|||
// 停止运动 |
|||
public void stop(CeramicPumpDriverSlaveId pumpId) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
if (!modbusMaster.writeRegister(slaveId, STOP_RESUME_REGISTER, 0x0000)) { |
|||
throw new Exception("Failed to stop pump, slaveId: " + slaveId); |
|||
} |
|||
log.info("Pump[{}] stopped", slaveId); |
|||
} |
|||
|
|||
/** |
|||
* 继续运动 |
|||
*/ |
|||
public void resume(CeramicPumpDriverSlaveId pumpId) throws Exception { |
|||
int slaveId = pumpId.getSlaveId(); |
|||
if (!modbusMaster.writeRegister(slaveId, STOP_RESUME_REGISTER, 0x0001)) { |
|||
throw new Exception("Failed to resume pump, slaveId: " + slaveId); |
|||
} |
|||
log.info("Pump[{}] resumed", slaveId); |
|||
} |
|||
|
|||
public void moveByBlock(CeramicPumpDriverSlaveId pumpId, Direction direction, int r) |
|||
{ |
|||
final int targetPosition = r; // 目标位置(圈数) |
|||
int currentPosition = 0; // 当前位置(圈数) |
|||
int currentSpeed = 0; // 当前速度(转速) |
|||
|
|||
if (runFlags.getOrDefault(pumpId, false)) { |
|||
log.warn("Pump {} is already running, skipping moveByBlock", pumpId); |
|||
return; |
|||
} |
|||
|
|||
runFlags.put(pumpId, true); |
|||
|
|||
try { |
|||
// 初始化 |
|||
currentSpeed = getSpeed(pumpId); |
|||
|
|||
this.reset(pumpId); |
|||
this.setDirection(pumpId, direction); |
|||
|
|||
// 计算移动目标位置的时间 速度单位 rpm, 距离 r, |
|||
int expectedMs = (int) ((targetPosition - currentPosition) * 60.0 * 1000.0 / currentSpeed) ; |
|||
log.info("Pump {} moveByBlock, targetPosition: {}, currentPosition: {}, currentSpeed: {}, expectedMs: {}", |
|||
pumpId, targetPosition, currentPosition, currentSpeed, expectedMs); |
|||
this.moveBy(pumpId, targetPosition); |
|||
|
|||
int timoutMs = (int)(expectedMs * 1.5); // 设置超时时间为预期时间的两倍 |
|||
int pollCurrentPosMs = (int)(expectedMs * 0.9); // 轮询当前位置的时间为预期时间的90%后开始 |
|||
long startTime = System.currentTimeMillis(); |
|||
int elapsedTime = 0; // 已用时间 |
|||
while (elapsedTime < timoutMs) { |
|||
if (!runFlags.getOrDefault(pumpId, false)) { |
|||
log.info("Pump {} stopped before reaching target position", pumpId); |
|||
return; // 如果在等待过程中被停止,退出 |
|||
} |
|||
|
|||
elapsedTime = (int)(System.currentTimeMillis() - startTime); |
|||
|
|||
if (elapsedTime >= pollCurrentPosMs) { |
|||
currentPosition = getCurrentPosition(pumpId); |
|||
|
|||
if (currentPosition >= targetPosition) { |
|||
log.info("Pump {} reached target position: {}", pumpId, targetPosition); |
|||
break; |
|||
} |
|||
} |
|||
Thread.sleep(20); // 每100ms检查一次 |
|||
} |
|||
} |
|||
catch (Exception e) { |
|||
log.error("Error initializing pump position: {}", e.getMessage()); |
|||
throw new RuntimeException("Error initializing pump position", e); |
|||
} |
|||
finally { |
|||
runFlags.put(pumpId, false); |
|||
} |
|||
} |
|||
|
|||
public void stopBlock(CeramicPumpDriverSlaveId pumpId) { |
|||
if (!runFlags.getOrDefault(pumpId, false)) { |
|||
log.warn("Pump {} is not running, cannot stop", pumpId); |
|||
return; |
|||
} |
|||
runFlags.put(pumpId, false); |
|||
try { |
|||
this.stop(pumpId); |
|||
} catch (Exception e) { |
|||
log.error("Error stopping pump {}: {}", pumpId, e.getMessage()); |
|||
} finally { |
|||
runFlags.put(pumpId, false); |
|||
} |
|||
} |
|||
} |
@ -1,53 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers; |
|||
|
|||
import com.iflytop.colortitration.hardware.drivers.DODriver.OutputIOCtrlDriver; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import static com.iflytop.colortitration.hardware.type.IO.OutputIOMId.DO_COLD_TRAP_POWER; |
|||
|
|||
|
|||
/** |
|||
* 物理冷阱 |
|||
*/ |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class ColdTrapDriver { |
|||
private final OutputIOCtrlDriver outputIOCtrlDriver_; |
|||
|
|||
public void setTemperature(Double temperature) throws Exception { |
|||
|
|||
} |
|||
|
|||
public void openPower() throws Exception{ |
|||
outputIOCtrlDriver_.setIOState(DO_COLD_TRAP_POWER, true); |
|||
} |
|||
|
|||
public void closePower() throws Exception{ |
|||
outputIOCtrlDriver_.setIOState(DO_COLD_TRAP_POWER, false); |
|||
} |
|||
|
|||
public boolean openCircle() { |
|||
return false; |
|||
} |
|||
|
|||
public boolean closeCircle() { |
|||
return false; |
|||
} |
|||
|
|||
public boolean openHeart() { |
|||
return false; |
|||
} |
|||
|
|||
public boolean closeHeart() { |
|||
return false; |
|||
} |
|||
|
|||
public boolean openCool() { |
|||
return false; |
|||
} |
|||
|
|||
public boolean closeCool() { |
|||
return false; |
|||
} |
|||
} |
@ -1,24 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.DODriver; |
|||
|
|||
import com.iflytop.colortitration.hardware.type.IO.OutputIOMId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class FanDriver { |
|||
private final OutputIOCtrlDriver outputIOCtrlDriver_; |
|||
|
|||
public void open(OutputIOMId outputIOMId) throws Exception |
|||
{ |
|||
log.info("Opening FanD {}", outputIOMId.mid.getDescription()); |
|||
outputIOCtrlDriver_.setIOState(outputIOMId, true); |
|||
} |
|||
public void close(OutputIOMId outputIOMId) throws Exception |
|||
{ |
|||
log.info("Closing FanD {}", outputIOMId.mid.getDescription()); |
|||
outputIOCtrlDriver_.setIOState(outputIOMId, false); |
|||
} |
|||
} |
@ -1,22 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.DODriver; |
|||
|
|||
import com.iflytop.colortitration.hardware.type.IO.OutputIOMId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class VentilatorDriver { |
|||
private final OutputIOCtrlDriver outputIOCtrlDriver_; |
|||
|
|||
public void openPower(OutputIOMId outputIOMId) throws Exception |
|||
{ |
|||
outputIOCtrlDriver_.setIOState(outputIOMId, true); |
|||
} |
|||
public void closePower(OutputIOMId outputIOMId) throws Exception |
|||
{ |
|||
outputIOCtrlDriver_.setIOState(outputIOMId, false); |
|||
} |
|||
} |
@ -1,22 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.DODriver; |
|||
|
|||
import com.iflytop.colortitration.hardware.type.IO.OutputIOMId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class WaterPumpDriver { |
|||
private final OutputIOCtrlDriver outputIOCtrlDriver_; |
|||
|
|||
public void openPower(OutputIOMId outputIOMId) throws Exception |
|||
{ |
|||
outputIOCtrlDriver_.setIOState(outputIOMId, true); |
|||
} |
|||
public void closePower(OutputIOMId outputIOMId) throws Exception |
|||
{ |
|||
outputIOCtrlDriver_.setIOState(outputIOMId, false); |
|||
} |
|||
} |
@ -1,23 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers; |
|||
|
|||
import com.iflytop.colortitration.hardware.comm.can.A8kCanBusService; |
|||
import com.iflytop.colortitration.hardware.type.CmdId; |
|||
import com.iflytop.colortitration.hardware.type.MId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class FillLightDriver { |
|||
private final A8kCanBusService canBus; |
|||
|
|||
public void open(MId mId, Integer brightness) throws Exception { |
|||
// 模拟打开 |
|||
canBus.callcmd(mId, CmdId.pwm_light_on, brightness); |
|||
} |
|||
public void close(MId mId) throws Exception { |
|||
canBus.callcmd(mId, CmdId.pwm_light_off); |
|||
} |
|||
} |
@ -1,122 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers; |
|||
|
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.iflytop.colortitration.hardware.comm.can.A8kCanBusService; |
|||
import com.iflytop.colortitration.hardware.comm.modbus.ModbusMasterService; |
|||
import com.iflytop.colortitration.hardware.exception.HardwareException; |
|||
import com.iflytop.colortitration.hardware.type.A8kPacket; |
|||
import com.iflytop.colortitration.hardware.type.CmdId; |
|||
import com.iflytop.colortitration.hardware.type.driver.HeaterRodSlavedId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Map; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class HeaterRodDriver { |
|||
private final A8kCanBusService canBus; |
|||
private final ModbusMasterService modbusMaster; |
|||
|
|||
private static final int SV_ADDRESS = 0x2000; |
|||
private static final int PV_ADDRESS = 0x2010; |
|||
|
|||
private static final int CONTROL_REGISTER = 0x2106; |
|||
private static final int DP_ADDRESS = 0x2107; |
|||
private static final int DEVICE_ADDRESS_REGISTER = 0x2112; |
|||
|
|||
private final Map<Integer, Integer> dpCache = new ConcurrentHashMap<>(); |
|||
private static final int DEFAULT_DP = 1; |
|||
|
|||
public void setDeviceAddress(HeaterRodSlavedId heaterRodId, int newAddress) throws Exception { |
|||
int slaveId = heaterRodId.getSlaveId(); |
|||
|
|||
if (!modbusMaster.writeRegister(slaveId, DEVICE_ADDRESS_REGISTER, newAddress)) { |
|||
throw new Exception("Failed to set device address for heater rod with ID: " + heaterRodId.name()); |
|||
} |
|||
|
|||
log.info("Device address for heater rod with ID: {} set to: {}", heaterRodId.name(), newAddress); |
|||
} |
|||
|
|||
private int getDecimalPoint(int slaveId) throws Exception { |
|||
return dpCache.computeIfAbsent(slaveId, id -> { |
|||
try { |
|||
short[] response = modbusMaster.readHoldingRegisters(id, DP_ADDRESS, 1); |
|||
if (response != null && response.length > 0) { |
|||
return (int) response[0]; |
|||
} |
|||
} catch (Exception e) { |
|||
log.warn("Failed to read DP for slave ID: {}, using default DP: {}", id, DEFAULT_DP); |
|||
} |
|||
return DEFAULT_DP; |
|||
}); |
|||
} |
|||
|
|||
public void openPower(HeaterRodSlavedId heaterRodId) throws Exception |
|||
{ |
|||
int slaveId = heaterRodId.getSlaveId(); |
|||
if (!modbusMaster.writeRegister(slaveId, CONTROL_REGISTER, 1)) { // 1 = Start |
|||
throw new Exception("Failed to start heater rod with ID: " + heaterRodId.name()); |
|||
} |
|||
} |
|||
|
|||
public void closePower(HeaterRodSlavedId heaterRodId) throws Exception |
|||
{ |
|||
int slaveId = heaterRodId.getSlaveId(); |
|||
|
|||
if (!modbusMaster.writeRegister(slaveId, CONTROL_REGISTER, 2)) { // 2 = Stop |
|||
throw new Exception("Failed to stop heater rod with ID: " + heaterRodId.name()); |
|||
} |
|||
|
|||
log.info("{} stopped.", heaterRodId.name()); |
|||
} |
|||
|
|||
public void setTemperature(HeaterRodSlavedId heaterRodId, double temperature) throws Exception { |
|||
int slaveId = heaterRodId.getSlaveId(); |
|||
int decimalPoint = getDecimalPoint(slaveId); |
|||
int scaledTemperature = (int) (temperature * Math.pow(10, decimalPoint)); |
|||
|
|||
if (!modbusMaster.writeRegister(slaveId, SV_ADDRESS, scaledTemperature)) { |
|||
throw new Exception("Failed to set temperature for heater rod with ID: " + heaterRodId.name()); |
|||
} |
|||
|
|||
log.info("{} started with temperature: {}", heaterRodId.name(), temperature); |
|||
} |
|||
|
|||
public double getTemperature(HeaterRodSlavedId heaterRodId) throws Exception { |
|||
int slaveId = heaterRodId.getSlaveId(); |
|||
int decimalPoint = getDecimalPoint(slaveId); |
|||
|
|||
short[] response = modbusMaster.readHoldingRegisters(slaveId, PV_ADDRESS, 1); |
|||
if (response == null || response.length == 0) { |
|||
throw new Exception(StrUtil.format("Failed to read temperature {}", heaterRodId.name())); |
|||
} |
|||
double temperature = response[0] / Math.pow(10, decimalPoint); |
|||
log.info("{} GET temperature {}", heaterRodId.name(), temperature); |
|||
return temperature; |
|||
} |
|||
|
|||
/** |
|||
* 获取电流 |
|||
* @return |
|||
*/ |
|||
public Integer getCurrent(HeaterRodSlavedId heaterRodId) throws HardwareException |
|||
{ |
|||
A8kPacket packet = canBus.callcmd(heaterRodId.getMid(), CmdId.adc_read_adc, heaterRodId.getAdcCurrentIndex()); |
|||
Integer current = packet.getContentI32(0); |
|||
return current; |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== application ==== ==== ==== ==== ==== ==== |
|||
public void open(HeaterRodSlavedId heaterRodId, double temperature) throws Exception { |
|||
this.openPower(heaterRodId); |
|||
this.setTemperature(heaterRodId, temperature); |
|||
} |
|||
|
|||
public void close(HeaterRodSlavedId heaterRodId) throws Exception { |
|||
this.closePower(heaterRodId); |
|||
} |
|||
} |
@ -1,4 +1,4 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.DIDriver; |
|||
package com.iflytop.colortitration.hardware.drivers; |
|||
|
|||
import com.iflytop.colortitration.hardware.comm.can.A8kCanBusService; |
|||
import com.iflytop.colortitration.hardware.exception.HardwareException; |
@ -1,110 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.MiniServoDriver; |
|||
|
|||
import com.iflytop.colortitration.hardware.exception.HardwareException; |
|||
import com.iflytop.colortitration.hardware.type.Servo.MiniServoMId; |
|||
import com.iflytop.colortitration.hardware.utils.Math.ServoPositionConverter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.security.InvalidParameterException; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class ClawDriver { |
|||
private static final double MIN_DISTANCE = 34.0; |
|||
private static final double MAX_DISTANCE = 54.0; |
|||
|
|||
private static double MIN_SERVO_POSITION = 2048; |
|||
private static double MAX_SERVO_POSITION = 3000; |
|||
|
|||
private final MiniServoDriver miniServoDriver; |
|||
|
|||
private double speed_ = 10.0; // mm/s |
|||
|
|||
// ==== ==== ==== ==== ==== ==== convert ==== ==== ==== ==== ==== ==== |
|||
/** |
|||
* 将距离转换为舵机位置 |
|||
* @param distance 距离值,范围在 MIN_DISTANCE 到 MAX_DISTANCE 之间 |
|||
* @return 对应的舵机位置,范围在 MIN_SERVO_POSITION 到 MAX_SERVO_POSITION 之间 |
|||
*/ |
|||
public static double distanceToServoPosition(double distance) { |
|||
if (distance < MIN_DISTANCE) { |
|||
distance = MIN_DISTANCE; |
|||
} else if (distance > MAX_DISTANCE) { |
|||
distance = MAX_DISTANCE; |
|||
} |
|||
return MIN_SERVO_POSITION + (distance - MIN_DISTANCE) * (MAX_SERVO_POSITION - MIN_SERVO_POSITION) / (MAX_DISTANCE - MIN_DISTANCE); |
|||
} |
|||
|
|||
/** |
|||
* 将舵机位置转换为距离 |
|||
* @param servoPosition 舵机位置值,范围在 MIN_SERVO_POSITION 到 MAX_SERVO_POSITION 之间 |
|||
* @return 对应的距离,范围在 MIN_DISTANCE 到 MAX_DISTANCE 之间 |
|||
*/ |
|||
public static double servoPositionToDistance(double servoPosition) { |
|||
if (servoPosition < MIN_SERVO_POSITION) { |
|||
servoPosition = MIN_SERVO_POSITION; |
|||
} else if (servoPosition > MAX_SERVO_POSITION) { |
|||
servoPosition = MAX_SERVO_POSITION; |
|||
} |
|||
return MIN_DISTANCE + (servoPosition - MIN_SERVO_POSITION) * (MAX_DISTANCE - MIN_DISTANCE) / (MAX_SERVO_POSITION - MIN_SERVO_POSITION); |
|||
} |
|||
|
|||
|
|||
private int toServoPosition(double position) { |
|||
int servoPosition = 0; |
|||
servoPosition = (int)distanceToServoPosition(position); |
|||
servoPosition = (int) ServoPositionConverter.convert4096To3600(servoPosition); |
|||
return servoPosition; |
|||
} |
|||
|
|||
private int toServoSpeed(double speed) { |
|||
int servoSpeed = 0; |
|||
servoSpeed = (int)speed; |
|||
return servoSpeed; |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Get ==== ==== ==== ==== ==== ==== |
|||
private double getSpeed(MiniServoMId servoMid) |
|||
{ |
|||
// TODO: 从数据库中获取门的速度 |
|||
return speed_; |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Set ==== ==== ==== ==== ==== ==== |
|||
public void setSpeed(MiniServoMId servoMid, double speed) { |
|||
log.info("[ {} ] Setting speed to {}", servoMid.mid.getDescription(), speed); |
|||
// 检查速度是否合法 |
|||
speed_ = speed; |
|||
// TODO: 写入数据库 |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Ctrl ==== ==== ==== ==== ==== ==== |
|||
public void moveToHome(MiniServoMId servoMid) throws HardwareException |
|||
{ |
|||
log.info("[ {} ] moveToHome", servoMid.mid.getDescription()); |
|||
|
|||
this.moveTo(servoMid, MIN_DISTANCE); |
|||
} |
|||
|
|||
public void moveTo(MiniServoMId servoMid, double position) throws HardwareException |
|||
{ |
|||
// 检查位置是否合法 |
|||
if (position < MIN_DISTANCE || position > MAX_DISTANCE) { |
|||
log.error("[ {} ] Position is out of range", servoMid.mid.getDescription()); |
|||
throw new InvalidParameterException("Position is out of range"); |
|||
} |
|||
miniServoDriver.miniServoEnable(servoMid, 1); |
|||
int servoPosition = toServoPosition(position); |
|||
log.info("[ {} ] moveTo {}, servo position {} ...", servoMid, position, servoPosition); |
|||
miniServoDriver.miniServoMoveToBlock(servoMid, servoPosition); |
|||
log.info("[ {} ] moveTo {}, servo position {} end", servoMid, position, servoPosition); |
|||
} |
|||
|
|||
public void stop(MiniServoMId servoMid) throws HardwareException { |
|||
log.info("[ {} ] stop", servoMid.mid.getDescription()); |
|||
miniServoDriver.miniServoStop(servoMid); |
|||
} |
|||
} |
@ -1,180 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.MiniServoDriver; |
|||
|
|||
import com.iflytop.colortitration.hardware.exception.HardwareException; |
|||
import com.iflytop.colortitration.hardware.type.Servo.MiniServoMId; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.awt.geom.Point2D; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class DualRobotDriver { |
|||
public enum Joint { |
|||
JOINT_1, |
|||
JOINT_2 |
|||
} |
|||
|
|||
// 舵机角度范围常量(度) |
|||
public static final double MIN_ANGLE_DEG = -180.0; |
|||
public static final double MAX_ANGLE_DEG = 180.0; |
|||
|
|||
// 舵机位置值范围常量 |
|||
public static final int MIN_SERVO_POSITION = 0; |
|||
public static final int MAX_SERVO_POSITION = 3600; |
|||
|
|||
private final MiniServoDriver miniServoDriver; |
|||
|
|||
private double speed_ = 10.0; // mm/s |
|||
|
|||
// ==== ==== ==== ==== ==== ==== convert ==== ==== ==== ==== ==== ==== |
|||
|
|||
/** |
|||
* 将舵机角度(-180 到 180 度)转换为位置值(0 - 4096) |
|||
* @param angle 舵机角度,范围在 -180 到 180 度之间 |
|||
* @return 对应的位置值,范围在 0 到 4096 之间 |
|||
* @throws IllegalArgumentException 如果输入角度超出范围 |
|||
*/ |
|||
public static int angleToServoPosition(double angle) { |
|||
if (angle < MIN_ANGLE_DEG || angle > MAX_ANGLE_DEG) { |
|||
throw new IllegalArgumentException("角度必须在 " + MIN_ANGLE_DEG + " 到 " + MAX_ANGLE_DEG + " 度之间"); |
|||
} |
|||
|
|||
// 线性映射公式:position = minPos + (angle - minAngle) * (maxPos - minPos) / (maxAngle - minAngle) |
|||
return (int) Math.round( |
|||
MIN_SERVO_POSITION + |
|||
(angle - MIN_ANGLE_DEG) * |
|||
(MAX_SERVO_POSITION - MIN_SERVO_POSITION) / |
|||
(MAX_ANGLE_DEG - MIN_ANGLE_DEG) |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 将位置值(0 - 4096)转换为舵机角度(-180 到 180 度) |
|||
* @param servoPosition 设置值,范围在 0 到 4096 之间 |
|||
* @return 对应的舵机角度,范围在 -180 到 180 度之间 |
|||
* @throws IllegalArgumentException 如果输入位置值超出范围 |
|||
*/ |
|||
public static double servoPositionToAngle(int servoPosition) { |
|||
if (servoPosition < MIN_SERVO_POSITION || servoPosition > MAX_SERVO_POSITION) { |
|||
throw new IllegalArgumentException("位置值必须在 " + MIN_SERVO_POSITION + " 到 " + MAX_SERVO_POSITION + " 之间"); |
|||
} |
|||
|
|||
// 线性映射公式:angle = minAngle + (position - minPos) * (maxAngle - minAngle) / (maxPos - minPos) |
|||
return MIN_ANGLE_DEG + |
|||
(servoPosition - MIN_SERVO_POSITION) * |
|||
(MAX_ANGLE_DEG - MIN_ANGLE_DEG) / |
|||
(MAX_SERVO_POSITION - MIN_SERVO_POSITION); |
|||
} |
|||
|
|||
|
|||
private int toServoPosition(double angle) { |
|||
int servoPosition = angleToServoPosition(angle); |
|||
return servoPosition; |
|||
} |
|||
|
|||
private double toAngle(Integer position) |
|||
{ |
|||
double angle = servoPositionToAngle(position); |
|||
return angle; |
|||
} |
|||
|
|||
private Point2D toServoPosition(Point2D point) { |
|||
Point2D servoPosition = new Point2D.Double(0, 0); |
|||
servoPosition.setLocation(point.getX(), point.getY()); |
|||
return servoPosition; |
|||
} |
|||
|
|||
private int toServoSpeed(double speed) { |
|||
int servoSpeed = 0; |
|||
servoSpeed = (int)speed; |
|||
return servoSpeed; |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Get ==== ==== ==== ==== ==== ==== |
|||
private double getSpeed(MiniServoMId servoMid) |
|||
{ |
|||
// TODO: 从数据库中获取门的速度 |
|||
return speed_; |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Set ==== ==== ==== ==== ==== ==== |
|||
public void setSpeed(MiniServoMId servoMid, double speed) { |
|||
// 检查速度是否合法 |
|||
speed_ = speed; |
|||
// TODO: 写入数据库 |
|||
} |
|||
|
|||
public MiniServoMId getMiniServoMId(Joint joint) { |
|||
switch (joint) { |
|||
case JOINT_1: |
|||
return MiniServoMId.DUAL_ROBOT_AXIS1_MID; |
|||
case JOINT_2: |
|||
return MiniServoMId.DUAL_ROBOT_AXIS2_MID; |
|||
default: |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Ctrl ==== ==== ==== ==== ==== ==== |
|||
public void servoEnable(MiniServoMId servoMId, boolean enable) throws HardwareException |
|||
{ |
|||
miniServoDriver.miniServoEnable(servoMId, enable ? 1 : 0); |
|||
} |
|||
|
|||
public void moveToHome(MiniServoMId servoMid) throws HardwareException |
|||
{ |
|||
log.info("Servo {} Move To Home", servoMid.mid.getDescription()); |
|||
this.servoEnable(servoMid, true); |
|||
} |
|||
|
|||
public void moveJointTo(MiniServoMId servoMid, double position) throws HardwareException |
|||
{ |
|||
// 检查位置是否合法 |
|||
Integer servoPosition = toServoPosition(position); |
|||
log.info("Servo {} Move To position {}, Servo Position {}", servoMid.mid.getDescription(), position, servoPosition); |
|||
this.servoEnable(servoMid, true); |
|||
miniServoDriver.miniServoMoveToBlock(servoMid, servoPosition); |
|||
} |
|||
|
|||
public void stop(MiniServoMId servoMid) throws HardwareException { |
|||
log.info("Servo {} Stop", servoMid.mid.getDescription()); |
|||
miniServoDriver.miniServoStop(servoMid); |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Application ==== ==== ==== ==== ==== ==== |
|||
|
|||
public void setSpeed(Joint joint, double speed) throws HardwareException { |
|||
MiniServoMId servoMId = getMiniServoMId(joint); |
|||
setSpeed(servoMId, speed); |
|||
log.info("Set speed for {} to {}", joint, speed); |
|||
} |
|||
|
|||
public void moveToPoint(double pointX, double pointY) throws HardwareException { |
|||
// Point2D point = getServoPosition(new Point2D.Double(pointX, pointY)); |
|||
// |
|||
// miniServoDriver.miniServoMoveToBlock(MiniServoMId.DUAL_ROBOT_AXIS1_MID, (int)point.getX()); |
|||
// miniServoDriver.miniServoMoveToBlock(MiniServoMId.DUAL_ROBOT_AXIS2_MID, (int)point.getY()); |
|||
} |
|||
|
|||
public void moveToHome(Joint joint) throws HardwareException { |
|||
MiniServoMId servoMId = getMiniServoMId(joint); |
|||
log.info("Servo {} Move To Home", servoMId.mid.getDescription()); |
|||
moveToHome(servoMId); |
|||
} |
|||
|
|||
public void moveJointTo(Joint joint, double position) throws HardwareException { |
|||
MiniServoMId servoMId = getMiniServoMId(joint); |
|||
log.info("Servo {} Move To position {}", servoMId.mid.getDescription(), position); |
|||
moveJointTo(servoMId, position); |
|||
} |
|||
|
|||
public void stop(Joint joint) throws HardwareException { |
|||
MiniServoMId servoMId = getMiniServoMId(joint); |
|||
log.info("Servo {} Stop", servoMId.mid.getDescription()); |
|||
stop(servoMId); |
|||
} |
|||
|
|||
} |
@ -1,101 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.StepMotorDriver; |
|||
|
|||
import com.iflytop.colortitration.hardware.config.StepMotorConfig; |
|||
import com.iflytop.colortitration.hardware.exception.HardwareException; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorDirect; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorRegIndex; |
|||
import com.iflytop.colortitration.hardware.utils.Math.StepMotorConverter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.security.InvalidParameterException; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class AcidPumpDriver { |
|||
private final StepMotorConfig config_; |
|||
private final StepMotorCtrlDriver stepMotorCtrlDriver_; |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Get ==== ==== ==== ==== ==== ==== |
|||
private double getSpeed(StepMotorMId stepMotorMId) |
|||
{ |
|||
// TODO: 从单片机中获取速度 |
|||
return 0.0; |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Set ==== ==== ==== ==== ==== ==== |
|||
public void setSpeed(StepMotorMId stepMotorMId, double speed) throws HardwareException { |
|||
// 检查速度是否合法 |
|||
// 设置速度到单片机 |
|||
int motorSpeed = StepMotorConverter.toMotorSpeed(Math.abs(speed), config_.getLead(stepMotorMId)); |
|||
log.info("Motor {} speed set to {}, motorSpeed {}", stepMotorMId.mid.getDescription(), speed, motorSpeed); |
|||
stepMotorCtrlDriver_.setReg(stepMotorMId, StepMotorRegIndex.kreg_step_motor_default_velocity, motorSpeed); |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Ctrl ==== ==== ==== ==== ==== ==== |
|||
public void motorEnable(StepMotorMId stepMotorMId, Boolean enable) throws Exception |
|||
{ |
|||
Integer i_enable = enable ? 1 : 0; |
|||
stepMotorCtrlDriver_.stepMotorEnable(stepMotorMId, i_enable); |
|||
} |
|||
|
|||
public void moveToHome(StepMotorMId stepMotorMId) throws Exception |
|||
{ |
|||
log.info("Motor {} Move To Home", stepMotorMId.mid.getDescription()); |
|||
motorEnable(stepMotorMId, true); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveToZeroBlock(stepMotorMId); |
|||
motorEnable(stepMotorMId, false); |
|||
} |
|||
|
|||
public void moveTo(StepMotorMId stepMotorMId, double position) throws Exception |
|||
{ |
|||
// 检查位置是否合法 |
|||
if (Math.abs(position) > Math.abs(config_.getMaxLimit(stepMotorMId))) { |
|||
log.error("Motor {} Move To position out of range, position {} , limit {}", stepMotorMId.mid.getDescription(), position , config_.getMaxLimit(stepMotorMId)); |
|||
throw new InvalidParameterException("position is out of range"); |
|||
} |
|||
|
|||
motorEnable(stepMotorMId, true); |
|||
int motorPosition = StepMotorConverter.toMotorPosition(position); |
|||
log.info("Motor {} Move To position {}, Motor Positon {}", stepMotorMId.mid.getDescription(), position, motorPosition); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveToBlock(stepMotorMId, motorPosition); |
|||
motorEnable(stepMotorMId, false); |
|||
} |
|||
|
|||
public void moveBy(StepMotorMId stepMotorMId, double distance) throws Exception |
|||
{ |
|||
// 检查位置是否合法 |
|||
|
|||
if (Math.abs(distance) > Math.abs(config_.getMaxLimit(stepMotorMId))) { |
|||
log.error("Motor {} Move By position out of range, position {} , limit {}", stepMotorMId.mid.getDescription(), distance , config_.getMaxLimit(stepMotorMId)); |
|||
throw new InvalidParameterException("Distance is out of range"); |
|||
} |
|||
|
|||
motorEnable(stepMotorMId, true); |
|||
int motorPosition = StepMotorConverter.toMotorPosition(distance); |
|||
log.info("Motor {} Move By position {}, Motor Positon {}", stepMotorMId.mid.getDescription(), distance, motorPosition); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveByBlock(stepMotorMId, motorPosition); |
|||
motorEnable(stepMotorMId, false); |
|||
} |
|||
|
|||
/** |
|||
* 正转加液 反转排液 |
|||
* @param stepMotorMId |
|||
* @param direct |
|||
* @throws Exception |
|||
*/ |
|||
public void rotate(StepMotorMId stepMotorMId, StepMotorDirect direct) throws Exception |
|||
{ |
|||
motorEnable(stepMotorMId, true); |
|||
stepMotorCtrlDriver_.stepMotorEasyRotate(stepMotorMId, direct.getValue()); |
|||
} |
|||
|
|||
public void stop(StepMotorMId stepMotorMId) throws Exception { |
|||
log.info("Motor {} Stop", stepMotorMId.mid.getDescription()); |
|||
stepMotorCtrlDriver_.stepMotorStop(stepMotorMId); |
|||
motorEnable(stepMotorMId, true); |
|||
} |
|||
} |
@ -1,100 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.StepMotorDriver; |
|||
|
|||
import com.iflytop.colortitration.hardware.config.StepMotorConfig; |
|||
import com.iflytop.colortitration.hardware.drivers.DODriver.OutputIOCtrlDriver; |
|||
import com.iflytop.colortitration.hardware.exception.HardwareException; |
|||
import com.iflytop.colortitration.hardware.type.IO.OutputIOMId; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorRegIndex; |
|||
import com.iflytop.colortitration.hardware.utils.Math.StepMotorConverter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.security.InvalidParameterException; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class HBotDriver { |
|||
private final StepMotorConfig config_; |
|||
private final OutputIOCtrlDriver doDriver_; |
|||
private final StepMotorCtrlDriver stepMotorCtrlDriver_; |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Get ==== ==== ==== ==== ==== ==== |
|||
private double getSpeed(StepMotorMId stepMotorMId) |
|||
{ |
|||
// TODO: 从单片机中获取速度 |
|||
return 0.0; |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Set ==== ==== ==== ==== ==== ==== |
|||
public void setSpeed(StepMotorMId stepMotorMId, double speed) throws HardwareException { |
|||
// 检查速度是否合法 |
|||
// 设置速度到单片机 |
|||
int motorSpeed = StepMotorConverter.toMotorSpeed(Math.abs(speed), config_.getLead(stepMotorMId)); |
|||
stepMotorCtrlDriver_.setReg(stepMotorMId, StepMotorRegIndex.kreg_step_motor_default_velocity, motorSpeed); |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Ctrl ==== ==== ==== ==== ==== ==== |
|||
public void motorEnable(StepMotorMId stepMotorMId, Boolean enable) throws Exception { |
|||
Integer i_enable = enable ? 1 : 0; |
|||
stepMotorCtrlDriver_.stepMotorEnable(stepMotorMId, i_enable); |
|||
} |
|||
|
|||
public void moveToHome(StepMotorMId stepMotorMId) throws Exception { |
|||
log.info("Motor {} Move To Home", stepMotorMId.mid.getDescription()); |
|||
motorEnable(stepMotorMId, true); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveToZeroBlock(stepMotorMId); |
|||
} |
|||
|
|||
public void moveTo(StepMotorMId stepMotorMId, double position) throws Exception { |
|||
// 检查位置是否合法 |
|||
if (Math.abs(position) > Math.abs(config_.getMaxLimit(stepMotorMId))) { |
|||
log.error("Motor {} Move To position out of range, position {}, limit {}", stepMotorMId.mid.getDescription(), position, config_.getMaxLimit(stepMotorMId)); |
|||
throw new InvalidParameterException("position is out of range"); |
|||
} |
|||
|
|||
motorEnable(stepMotorMId, true); |
|||
int motorPosition = StepMotorConverter.toMotorPosition(position); |
|||
log.info("Motor {} Move To position {}, Motor Position {}", stepMotorMId.mid.getDescription(), position, motorPosition); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveToBlock(stepMotorMId, motorPosition); |
|||
} |
|||
|
|||
public void moveBy(StepMotorMId stepMotorMId, double distance) throws Exception { |
|||
// 检查位置是否合法 |
|||
if (Math.abs(distance) > Math.abs(config_.getMaxLimit(stepMotorMId))) { |
|||
log.error("Motor {} Move By distance out of range, distance {}, limit {}", stepMotorMId.mid.getDescription(), distance, config_.getMaxLimit(stepMotorMId)); |
|||
throw new InvalidParameterException("Distance is out of range"); |
|||
} |
|||
|
|||
motorEnable(stepMotorMId, true); |
|||
int motorPosition = StepMotorConverter.toMotorPosition(distance); |
|||
log.info("Motor {} Move By distance {}, Motor Position {}", stepMotorMId.mid.getDescription(), distance, motorPosition); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveByBlock(stepMotorMId, motorPosition); |
|||
} |
|||
|
|||
public void stop(StepMotorMId stepMotorMId) throws Exception { |
|||
log.info("Motor {} Stop", stepMotorMId.mid.getDescription()); |
|||
stepMotorCtrlDriver_.stepMotorStop(stepMotorMId); |
|||
motorEnable(stepMotorMId, true); |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== IO Ctrl ==== ==== ==== ==== ==== |
|||
public void openClamp(OutputIOMId iomId) throws Exception |
|||
{ |
|||
if(iomId == null) { |
|||
return; |
|||
} |
|||
doDriver_.open(iomId); |
|||
} |
|||
|
|||
public void closeClamp(OutputIOMId iomId) throws Exception |
|||
{ |
|||
if(iomId == null) { |
|||
return; |
|||
} |
|||
doDriver_.close(iomId); |
|||
} |
|||
} |
|||
|
@ -1,79 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.StepMotorDriver; |
|||
|
|||
import com.iflytop.colortitration.hardware.config.StepMotorConfig; |
|||
import com.iflytop.colortitration.hardware.exception.HardwareException; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorRegIndex; |
|||
import com.iflytop.colortitration.hardware.utils.Math.StepMotorConverter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.security.InvalidParameterException; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class HeaterMotorDriver { |
|||
private final StepMotorConfig config_; |
|||
private final StepMotorCtrlDriver stepMotorCtrlDriver_; |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Get ==== ==== ==== ==== ==== ==== |
|||
private double getSpeed(StepMotorMId stepMotorMId) |
|||
{ |
|||
// TODO: 从单片机中获取速度 |
|||
return 0.0; |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Set ==== ==== ==== ==== ==== ==== |
|||
public void setSpeed(StepMotorMId stepMotorMId, double speed) throws HardwareException { |
|||
// 检查速度是否合法 |
|||
// 设置速度到单片机 |
|||
int motorSpeed = StepMotorConverter.toMotorSpeed(Math.abs(speed), config_.getLead(stepMotorMId)); |
|||
stepMotorCtrlDriver_.setReg(stepMotorMId, StepMotorRegIndex.kreg_step_motor_default_velocity, motorSpeed); |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Ctrl ==== ==== ==== ==== ==== ==== |
|||
public void motorEnable(StepMotorMId stepMotorMId, Boolean enable) throws Exception { |
|||
Integer i_enable = enable ? 1 : 0; |
|||
stepMotorCtrlDriver_.stepMotorEnable(stepMotorMId, i_enable); |
|||
} |
|||
|
|||
public void moveToHome(StepMotorMId stepMotorMId) throws Exception { |
|||
log.info("Motor {} Move To Home", stepMotorMId.mid.getDescription()); |
|||
motorEnable(stepMotorMId, true); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveToZeroBlock(stepMotorMId); |
|||
} |
|||
|
|||
public void moveTo(StepMotorMId stepMotorMId, double position) throws Exception { |
|||
// 检查位置是否合法 |
|||
if (Math.abs(position) > Math.abs(config_.getMaxLimit(stepMotorMId))) { |
|||
log.error("Motor {} Move To position out of range, position {}, limit {}", stepMotorMId.mid.getDescription(), position, config_.getMaxLimit(stepMotorMId)); |
|||
throw new InvalidParameterException("position is out of range"); |
|||
} |
|||
|
|||
motorEnable(stepMotorMId, true); |
|||
int motorPosition = StepMotorConverter.toMotorPosition(position); |
|||
log.info("Motor {} Move To position {}, Motor Position {}", stepMotorMId.mid.getDescription(), position, motorPosition); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveToBlock(stepMotorMId, motorPosition); |
|||
} |
|||
|
|||
public void moveBy(StepMotorMId stepMotorMId, double distance) throws Exception { |
|||
// 检查位置是否合法 |
|||
if (Math.abs(distance) > Math.abs(config_.getMaxLimit(stepMotorMId))) { |
|||
log.error("Motor {} Move By distance out of range, distance {}, limit {}", stepMotorMId.mid.getDescription(), distance, config_.getMaxLimit(stepMotorMId)); |
|||
throw new InvalidParameterException("Distance is out of range"); |
|||
} |
|||
|
|||
motorEnable(stepMotorMId, true); |
|||
int motorPosition = StepMotorConverter.toMotorPosition(distance); |
|||
log.info("Motor {} Move By distance {}, Motor Position {}", stepMotorMId.mid.getDescription(), distance, motorPosition); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveByBlock(stepMotorMId, motorPosition); |
|||
} |
|||
|
|||
public void stop(StepMotorMId stepMotorMId) throws Exception { |
|||
log.info("Motor {} Stop", stepMotorMId.mid.getDescription()); |
|||
stepMotorCtrlDriver_.stepMotorStop(stepMotorMId); |
|||
motorEnable(stepMotorMId, true); |
|||
} |
|||
} |
@ -1,90 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.StepMotorDriver; |
|||
|
|||
import com.iflytop.colortitration.hardware.config.StepMotorConfig; |
|||
import com.iflytop.colortitration.hardware.exception.HardwareException; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorDirect; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorRegIndex; |
|||
import com.iflytop.colortitration.hardware.utils.Math.StepMotorConverter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.security.InvalidParameterException; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class ShakeMotorDriver { |
|||
private final StepMotorConfig config_; |
|||
private final StepMotorCtrlDriver stepMotorCtrlDriver_; |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Get ==== ==== ==== ==== ==== ==== |
|||
private double getSpeed(StepMotorMId stepMotorMId) |
|||
{ |
|||
// TODO: 从单片机中获取速度 |
|||
return 0.0; |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Set ==== ==== ==== ==== ==== ==== |
|||
public void setSpeed(StepMotorMId stepMotorMId, double speed) throws HardwareException { |
|||
// 检查速度是否合法 |
|||
// 设置速度到单片机 |
|||
int motorSpeed = StepMotorConverter.toMotorSpeed(Math.abs(speed), config_.getLead(stepMotorMId)); |
|||
stepMotorCtrlDriver_.setReg(stepMotorMId, StepMotorRegIndex.kreg_step_motor_default_velocity, motorSpeed); |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Ctrl ==== ==== ==== ==== ==== ==== |
|||
public void motorEnable(StepMotorMId stepMotorMId, Boolean enable) throws Exception { |
|||
Integer i_enable = enable ? 1 : 0; |
|||
stepMotorCtrlDriver_.stepMotorEnable(stepMotorMId, i_enable); |
|||
} |
|||
|
|||
public void moveToHome(StepMotorMId stepMotorMId) throws Exception { |
|||
log.info("Motor {} Move To Home", stepMotorMId.mid.getDescription()); |
|||
motorEnable(stepMotorMId, true); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveToZeroBlock(stepMotorMId); |
|||
} |
|||
|
|||
public void moveTo(StepMotorMId stepMotorMId, double position) throws Exception { |
|||
// 检查位置是否合法 |
|||
if (Math.abs(position) > Math.abs(config_.getMaxLimit(stepMotorMId))) { |
|||
log.error("Motor {} Move To position out of range, position {}, limit {}", stepMotorMId.mid.getDescription(), position, config_.getMaxLimit(stepMotorMId)); |
|||
throw new InvalidParameterException("position is out of range"); |
|||
} |
|||
|
|||
motorEnable(stepMotorMId, true); |
|||
int motorPosition = StepMotorConverter.toMotorPosition(position); |
|||
log.info("Motor {} Move To position {}, Motor Position {}", stepMotorMId.mid.getDescription(), position, motorPosition); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveToBlock(stepMotorMId, motorPosition); |
|||
} |
|||
|
|||
public void moveBy(StepMotorMId stepMotorMId, double distance) throws Exception { |
|||
// 检查位置是否合法 |
|||
if (Math.abs(distance) > Math.abs(config_.getMaxLimit(stepMotorMId))) { |
|||
log.error("Motor {} Move By distance out of range, distance {}, limit {}", stepMotorMId.mid.getDescription(), distance, config_.getMaxLimit(stepMotorMId)); |
|||
throw new InvalidParameterException("Distance is out of range"); |
|||
} |
|||
|
|||
motorEnable(stepMotorMId, true); |
|||
int motorPosition = StepMotorConverter.toMotorPosition(distance); |
|||
log.info("Motor {} Move By distance {}, Motor Position {}", stepMotorMId.mid.getDescription(), distance, motorPosition); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveByBlock(stepMotorMId, motorPosition); |
|||
} |
|||
|
|||
public void stop(StepMotorMId stepMotorMId) throws Exception { |
|||
log.info("Motor {} Stop", stepMotorMId.mid.getDescription()); |
|||
stepMotorCtrlDriver_.stepMotorStop(stepMotorMId); |
|||
motorEnable(stepMotorMId, true); |
|||
} |
|||
|
|||
public void startShake(StepMotorMId stepMotorMId, StepMotorDirect direct) throws Exception { |
|||
motorEnable(stepMotorMId, true); |
|||
stepMotorCtrlDriver_.stepMotorEasyRotate(stepMotorMId, direct.getValue()); |
|||
} |
|||
|
|||
public void stopShake(StepMotorMId stepMotorMId) throws Exception { |
|||
this.stop(stepMotorMId); |
|||
this.moveToHome(stepMotorMId); |
|||
} |
|||
} |
@ -1,98 +0,0 @@ |
|||
package com.iflytop.colortitration.hardware.drivers.StepMotorDriver; |
|||
|
|||
import com.iflytop.colortitration.hardware.config.StepMotorConfig; |
|||
import com.iflytop.colortitration.hardware.drivers.DODriver.OutputIOCtrlDriver; |
|||
import com.iflytop.colortitration.hardware.exception.HardwareException; |
|||
import com.iflytop.colortitration.hardware.type.IO.OutputIOMId; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.colortitration.hardware.type.StepMotor.StepMotorRegIndex; |
|||
import com.iflytop.colortitration.hardware.utils.Math.StepMotorConverter; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.security.InvalidParameterException; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class TrayMotorDriver { |
|||
private final StepMotorConfig config_; |
|||
private final OutputIOCtrlDriver doDriver_; |
|||
private final StepMotorCtrlDriver stepMotorCtrlDriver_; |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Get ==== ==== ==== ==== ==== ==== |
|||
private double getSpeed(StepMotorMId stepMotorMId) |
|||
{ |
|||
// TODO: 从单片机中获取速度 |
|||
return 0.0; |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Set ==== ==== ==== ==== ==== ==== |
|||
public void setSpeed(StepMotorMId stepMotorMId, double speed) throws HardwareException { |
|||
// 检查速度是否合法 |
|||
// 设置速度到单片机 |
|||
int motorSpeed = StepMotorConverter.toMotorSpeed(Math.abs(speed), config_.getLead(stepMotorMId)); |
|||
stepMotorCtrlDriver_.setReg(stepMotorMId, StepMotorRegIndex.kreg_step_motor_default_velocity, motorSpeed); |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== Ctrl ==== ==== ==== ==== ==== ==== |
|||
public void motorEnable(StepMotorMId stepMotorMId, Boolean enable) throws Exception { |
|||
Integer i_enable = enable ? 1 : 0; |
|||
stepMotorCtrlDriver_.stepMotorEnable(stepMotorMId, i_enable); |
|||
} |
|||
|
|||
public void moveToHome(StepMotorMId stepMotorMId) throws Exception { |
|||
log.info("Motor {} Move To Home", stepMotorMId.mid.getDescription()); |
|||
motorEnable(stepMotorMId, true); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveToZeroBlock(stepMotorMId); |
|||
} |
|||
|
|||
public void moveTo(StepMotorMId stepMotorMId, double position) throws Exception { |
|||
// 检查位置是否合法 |
|||
if (Math.abs(position) > Math.abs(config_.getMaxLimit(stepMotorMId))) { |
|||
log.error("Motor {} Move To position out of range, position {}, limit {}", stepMotorMId.mid.getDescription(), position, config_.getMaxLimit(stepMotorMId)); |
|||
throw new InvalidParameterException("position is out of range"); |
|||
} |
|||
|
|||
motorEnable(stepMotorMId, true); |
|||
int motorPosition = StepMotorConverter.toMotorPosition(position); |
|||
log.info("Motor {} Move To position {}, Motor Position {}", stepMotorMId.mid.getDescription(), position, motorPosition); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveToBlock(stepMotorMId, motorPosition); |
|||
} |
|||
|
|||
public void moveBy(StepMotorMId stepMotorMId, double distance) throws Exception { |
|||
// 检查位置是否合法 |
|||
if (Math.abs(distance) > Math.abs(config_.getMaxLimit(stepMotorMId))) { |
|||
log.error("Motor {} Move By distance out of range, distance {}, limit {}", stepMotorMId.mid.getDescription(), distance, config_.getMaxLimit(stepMotorMId)); |
|||
throw new InvalidParameterException("Distance is out of range"); |
|||
} |
|||
|
|||
motorEnable(stepMotorMId, true); |
|||
int motorPosition = StepMotorConverter.toMotorPosition(distance); |
|||
log.info("Motor {} Move By distance {}, Motor Position {}", stepMotorMId.mid.getDescription(), distance, motorPosition); |
|||
stepMotorCtrlDriver_.stepMotorEasyMoveByBlock(stepMotorMId, motorPosition); |
|||
} |
|||
|
|||
public void stop(StepMotorMId stepMotorMId) throws Exception { |
|||
log.info("Motor {} Stop", stepMotorMId.mid.getDescription()); |
|||
stepMotorCtrlDriver_.stepMotorStop(stepMotorMId); |
|||
} |
|||
|
|||
// ==== ==== ==== ==== ==== ==== IO Ctrl ==== ==== ==== ==== ==== |
|||
public void openClamp(OutputIOMId iomId) throws Exception |
|||
{ |
|||
if(iomId == null) { |
|||
return; |
|||
} |
|||
doDriver_.open(iomId); |
|||
} |
|||
|
|||
public void closeClamp(OutputIOMId iomId) throws Exception |
|||
{ |
|||
if(iomId == null) { |
|||
return; |
|||
} |
|||
doDriver_.close(iomId); |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
package com.iflytop.colortitration.hardware.type; |
|||
|
|||
import com.iflytop.colortitration.common.enums.Device; |
|||
|
|||
public enum CeramicPumpDriverSlaveId { |
|||
|
|||
CERAMIC_PUMP1_ID(Device.CERAMIC_PUMP_1, 0x11), |
|||
CERAMIC_PUMP2_ID(Device.CERAMIC_PUMP_2, 0x12), |
|||
; |
|||
|
|||
private final Device cmdDevice; |
|||
private final Integer slaveId; |
|||
|
|||
CeramicPumpDriverSlaveId(Device cmdDevice, Integer slaveId) { |
|||
this.cmdDevice = cmdDevice; |
|||
this.slaveId = slaveId; |
|||
} |
|||
|
|||
public Device getCmdDevice() { |
|||
return cmdDevice; |
|||
} |
|||
|
|||
public Integer getSlaveId() { |
|||
return slaveId; |
|||
} |
|||
|
|||
static public CeramicPumpDriverSlaveId getByCmdDevice(Device cmdDevice) { |
|||
for (CeramicPumpDriverSlaveId value : CeramicPumpDriverSlaveId.values()) { |
|||
if (value.cmdDevice == cmdDevice) { |
|||
return value; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
} |
@ -1,13 +1,13 @@ |
|||
package com.iflytop.colortitration.hardware.type.StepMotor; |
|||
|
|||
public enum StepMotorDirect { |
|||
public enum MotorDirect { |
|||
FORWARD(1), // 正转 |
|||
BACKWARD(0), // 反转 |
|||
; |
|||
|
|||
private final int value; |
|||
|
|||
StepMotorDirect(int value) { |
|||
MotorDirect(int value) { |
|||
this.value = value; |
|||
} |
|||
|
@ -0,0 +1,122 @@ |
|||
package com.iflytop.colortitration.hardware.utils; |
|||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
|
|||
public class ZJsonHelper { |
|||
public static String objectToJson(Object obj) { |
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
try { |
|||
|
|||
return mapper.writeValueAsString(obj); |
|||
} catch (Exception e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
} |
|||
|
|||
public static String objToPrettyJson(Object obj) { |
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
try { |
|||
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj); |
|||
} catch (Exception e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
} |
|||
|
|||
public static ObjectNode createObjectNode() { |
|||
return new ObjectMapper().createObjectNode(); |
|||
} |
|||
|
|||
public static ObjectNode readTree(String node) { |
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
if(node == null) { |
|||
return null; |
|||
} |
|||
if(node.isEmpty()) { |
|||
return null; |
|||
} |
|||
try { |
|||
return (ObjectNode) mapper.readTree(node); |
|||
} catch (Exception e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
} |
|||
public static <T> T objectFromJson(String node, Class<T> tClass) { |
|||
return objectFromJson(readTree(node), tClass); |
|||
} |
|||
|
|||
|
|||
public static <T> T objectFromJson(ObjectNode node, Class<T> tClass) { |
|||
ObjectMapper mapper = new ObjectMapper(); |
|||
if (node == null) { |
|||
return null; |
|||
} |
|||
|
|||
|
|||
if (tClass.getTypeName().equals(Integer.class.getTypeName())) { |
|||
if (node.get("value") == null) |
|||
return null; |
|||
return (T) Integer.valueOf(node.get("value").asInt()); |
|||
} |
|||
if (tClass.getTypeName().equals(String.class.getTypeName())) { |
|||
if (node.get("value") == null) |
|||
return null; |
|||
return (T) node.get("value").asText(); |
|||
} |
|||
if (tClass.getTypeName().equals(Boolean.class.getTypeName())) { |
|||
if (node.get("value") == null) |
|||
return null; |
|||
return (T) Boolean.valueOf(node.get("value").asBoolean()); |
|||
} |
|||
if (tClass.getTypeName().equals(Double.class.getTypeName())) { |
|||
if (node.get("value") == null) |
|||
return null; |
|||
return (T) Double.valueOf(node.get("value").asDouble()); |
|||
} |
|||
if (tClass.getTypeName().equals(Float.class.getTypeName())) { |
|||
if (node.get("value") == null) |
|||
return null; |
|||
return (T) Float.valueOf(node.get("value").floatValue()); |
|||
} |
|||
|
|||
if (tClass.isEnum()) { |
|||
if (node.get("value") == null) |
|||
return null; |
|||
return (T) Enum.valueOf((Class<Enum>) tClass, node.get("value").asText()); |
|||
} |
|||
|
|||
|
|||
try { |
|||
return (T) mapper.treeToValue(node, tClass); |
|||
} catch (Exception e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
} |
|||
|
|||
public static ObjectNode createObjectNode(Object obj) { |
|||
ObjectMapper ObjectMapper = new ObjectMapper(); |
|||
if (obj == null) { |
|||
return null; |
|||
} |
|||
if (obj instanceof Integer) { |
|||
return ObjectMapper.createObjectNode().put("value", (Integer) obj); |
|||
} |
|||
if (obj instanceof String) { |
|||
return ObjectMapper.createObjectNode().put("value", (String) obj); |
|||
} |
|||
if (obj instanceof Boolean) { |
|||
return ObjectMapper.createObjectNode().put("value", (Boolean) obj); |
|||
} |
|||
if (obj instanceof Double) { |
|||
return ObjectMapper.createObjectNode().put("value", (Double) obj); |
|||
} |
|||
if (obj instanceof Float) { |
|||
return ObjectMapper.createObjectNode().put("value", (Float) obj); |
|||
} |
|||
if (obj instanceof Enum) { |
|||
return ObjectMapper.createObjectNode().put("value", obj.toString()); |
|||
} |
|||
return ObjectMapper.valueToTree(obj); |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue