14 changed files with 418 additions and 463 deletions
-
95src/main/java/com/iflytop/sgs/hardware/command/handlers/AcidPumpHandler.java
-
4src/main/java/com/iflytop/sgs/hardware/command/handlers/ChimeBuzzerHandler.java
-
72src/main/java/com/iflytop/sgs/hardware/command/handlers/DoorHandler.java
-
73src/main/java/com/iflytop/sgs/hardware/command/handlers/HeaterMotorHandler.java
-
2src/main/java/com/iflytop/sgs/hardware/command/handlers/IOCtrlHandler.java
-
5src/main/java/com/iflytop/sgs/hardware/command/handlers/LiquidPumpHandler.java
-
5src/main/java/com/iflytop/sgs/hardware/command/handlers/LiquidValveHandler.java
-
123src/main/java/com/iflytop/sgs/hardware/command/handlers/MotorHandler.java
-
124src/main/java/com/iflytop/sgs/hardware/command/handlers/ServoHandler.java
-
68src/main/java/com/iflytop/sgs/hardware/command/handlers/ShakeMotorHandler.java
-
33src/main/java/com/iflytop/sgs/hardware/drivers/StepMotorDriver/MotorWrapperDriver.java
-
19src/main/java/com/iflytop/sgs/hardware/type/StepMotor/DeviceStepMotorId.java
@ -1,95 +0,0 @@ |
|||
package com.iflytop.sgs.hardware.command.handlers; |
|||
|
|||
import com.iflytop.sgs.common.cmd.DeviceCommand; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdAction; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdDevice; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdDirection; |
|||
import com.iflytop.sgs.hardware.command.CommandHandler; |
|||
import com.iflytop.sgs.hardware.drivers.StepMotorDriver.AcidPumpDriver; |
|||
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorDirect; |
|||
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.sgs.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; |
|||
|
|||
import static com.iflytop.sgs.common.enums.cmd.CmdDirection.backward; |
|||
import static com.iflytop.sgs.common.enums.cmd.CmdDirection.forward; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class AcidPumpHandler extends CommandHandler { |
|||
private final AcidPumpDriver driver_; |
|||
|
|||
private final Map<CmdDevice, StepMotorMId> stepMotorMIdMap_ = Map.ofEntries( |
|||
// Map.entry(CmdDevice.acid_pump_1, StepMotorMId.ACID_PUMP_1_MOTOR_MID), |
|||
// Map.entry(CmdDevice.acid_pump_2, StepMotorMId.ACID_PUMP_2_MOTOR_MID), |
|||
// Map.entry(CmdDevice.acid_pump_3, StepMotorMId.ACID_PUMP_3_MOTOR_MID), |
|||
// Map.entry(CmdDevice.acid_pump_4, StepMotorMId.ACID_PUMP_4_MOTOR_MID), |
|||
// Map.entry(CmdDevice.acid_pump_5, StepMotorMId.ACID_PUMP_5_MOTOR_MID), |
|||
// Map.entry(CmdDevice.acid_pump_6, StepMotorMId.ACID_PUMP_6_MOTOR_MID), |
|||
// Map.entry(CmdDevice.acid_pump_7, StepMotorMId.ACID_PUMP_7_MOTOR_MID), |
|||
// Map.entry(CmdDevice.acid_pump_8, StepMotorMId.ACID_PUMP_8_MOTOR_MID) |
|||
); |
|||
private final Map<CmdDevice, MId> supportCmdDeviceMIdMap = stepMotorMIdMap_.entrySet().stream(). |
|||
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); |
|||
private final Set<CmdAction> supportActions = Set.of(CmdAction.set, CmdAction.move_by, CmdAction.stop, CmdAction.rotate); |
|||
|
|||
@Override |
|||
protected Map<CmdDevice, MId> getSupportCmdDeviceMIdMap() |
|||
{ |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<CmdAction> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
public StepMotorDirect getMotorDirect(CmdDirection cmdDirection) |
|||
{ |
|||
return switch (cmdDirection) { |
|||
case forward -> StepMotorDirect.FORWARD; |
|||
case backward -> StepMotorDirect.BACKWARD; |
|||
}; |
|||
} |
|||
|
|||
@Override |
|||
public void handleCommand(DeviceCommand command) throws Exception { |
|||
// 发送命令 |
|||
StepMotorMId stepMotorMId = stepMotorMIdMap_.get(command.getDevice()); |
|||
if (command.getAction() == CmdAction.origin) { |
|||
driver_.moveToHome(stepMotorMId); |
|||
} |
|||
else if(command.getAction() == CmdAction.stop) { |
|||
driver_.stop(stepMotorMId); |
|||
} |
|||
else if(command.getAction() == CmdAction.move) { |
|||
double position = command.getParam().getPosition(); |
|||
driver_.moveTo(stepMotorMId, position); |
|||
} |
|||
else if(command.getAction() == CmdAction.move_by) { |
|||
|
|||
double distance = command.getParam().getPosition(); |
|||
|
|||
driver_.moveBy(stepMotorMId, distance); |
|||
} |
|||
else if(command.getAction() == CmdAction.rotate) { |
|||
CmdDirection cmdDirection = command.getParam().getDirection(); |
|||
|
|||
StepMotorDirect direct = getMotorDirect(cmdDirection); |
|||
driver_.rotate(stepMotorMId, direct); |
|||
} |
|||
else if(command.getAction() == CmdAction.set) { |
|||
Double speed = command.getParam().getSpeed(); |
|||
if(speed != null) { |
|||
driver_.setSpeed(stepMotorMId, speed); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,4 @@ |
|||
package com.iflytop.sgs.hardware.command.handlers; |
|||
|
|||
public class ChimeBuzzerHandler { |
|||
} |
@ -1,72 +0,0 @@ |
|||
package com.iflytop.sgs.hardware.command.handlers; |
|||
|
|||
import com.iflytop.sgs.common.cmd.DeviceCommand; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdAction; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdDevice; |
|||
import com.iflytop.sgs.hardware.command.CommandHandler; |
|||
import com.iflytop.sgs.hardware.drivers.StepMotorDriver.DoorDriver; |
|||
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.sgs.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 DoorHandler extends CommandHandler { |
|||
private final DoorDriver driver_; |
|||
|
|||
private final Map<CmdDevice, StepMotorMId> stepMotorMIdMap_ = Map.ofEntries( |
|||
// Map.entry(CmdDevice.door_motor, StepMotorMId.DOOR_MOTOR_MID) |
|||
); |
|||
private final Map<CmdDevice, MId> supportCmdDeviceMIdMap = stepMotorMIdMap_.entrySet().stream(). |
|||
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); |
|||
private final Set<CmdAction> supportActions = Set.of(CmdAction.set, CmdAction.origin, CmdAction.move, CmdAction.move_by, CmdAction.stop); |
|||
|
|||
@Override |
|||
protected Map<CmdDevice, MId> getSupportCmdDeviceMIdMap() |
|||
{ |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<CmdAction> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
@Override |
|||
public void handleCommand(DeviceCommand command) throws Exception { |
|||
// 发送命令 |
|||
StepMotorMId stepMotorMId = stepMotorMIdMap_.get(command.getDevice()); |
|||
if (command.getAction() == CmdAction.origin) { |
|||
driver_.moveToHome(stepMotorMId); |
|||
} |
|||
else if(command.getAction() == CmdAction.stop) { |
|||
driver_.stop(stepMotorMId); |
|||
} |
|||
else if(command.getAction() == CmdAction.move) { |
|||
double position = command.getParam().getPosition(); |
|||
driver_.moveTo(stepMotorMId, position); |
|||
} |
|||
else if(command.getAction() == CmdAction.move_by) { |
|||
double distance = command.getParam().getPosition(); |
|||
|
|||
driver_.moveBy(stepMotorMId, distance); |
|||
} |
|||
else if(command.getAction() == CmdAction.set) { |
|||
Double speed = command.getParam().getSpeed(); |
|||
if(speed != null) { |
|||
driver_.setSpeed(stepMotorMId, speed); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
@ -1,73 +0,0 @@ |
|||
package com.iflytop.sgs.hardware.command.handlers; |
|||
|
|||
import com.iflytop.sgs.common.cmd.DeviceCommand; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdAction; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdDevice; |
|||
import com.iflytop.sgs.hardware.command.CommandHandler; |
|||
import com.iflytop.sgs.hardware.drivers.StepMotorDriver.HeaterMotorDriver; |
|||
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.sgs.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 HeaterMotorHandler extends CommandHandler { |
|||
private final HeaterMotorDriver driver_; |
|||
|
|||
private final Map<CmdDevice, StepMotorMId> stepMotorMIdMap_ = Map.ofEntries( |
|||
// Map.entry(CmdDevice.heater_motor_1, StepMotorMId.HEATER_4_MOTOR_MID),//前后端顺序定义不一致,这里做了映射关系 |
|||
// Map.entry(CmdDevice.heater_motor_2, StepMotorMId.HEATER_5_MOTOR_MID), |
|||
// Map.entry(CmdDevice.heater_motor_3, StepMotorMId.HEATER_6_MOTOR_MID), |
|||
// Map.entry(CmdDevice.heater_motor_4, StepMotorMId.HEATER_1_MOTOR_MID), |
|||
// Map.entry(CmdDevice.heater_motor_5, StepMotorMId.HEATER_2_MOTOR_MID), |
|||
// Map.entry(CmdDevice.heater_motor_6, StepMotorMId.HEATER_3_MOTOR_MID) |
|||
); |
|||
private final Map<CmdDevice, MId> supportCmdDeviceMIdMap = stepMotorMIdMap_.entrySet().stream(). |
|||
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); |
|||
private final Set<CmdAction> supportActions = Set.of(CmdAction.set, CmdAction.origin, CmdAction.move, CmdAction.move_by, CmdAction.stop); |
|||
|
|||
@Override |
|||
protected Map<CmdDevice, MId> getSupportCmdDeviceMIdMap() |
|||
{ |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<CmdAction> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
@Override |
|||
public void handleCommand(DeviceCommand command) throws Exception { |
|||
// 发送命令 |
|||
StepMotorMId stepMotorMId = stepMotorMIdMap_.get(command.getDevice()); |
|||
if (command.getAction() == CmdAction.origin) { |
|||
driver_.moveToHome(stepMotorMId); |
|||
} |
|||
else if(command.getAction() == CmdAction.stop) { |
|||
driver_.stop(stepMotorMId); |
|||
} |
|||
else if(command.getAction() == CmdAction.move) { |
|||
double position = command.getParam().getPosition(); |
|||
driver_.moveTo(stepMotorMId, position); |
|||
} |
|||
else if(command.getAction() == CmdAction.move_by) { |
|||
double distance = command.getParam().getPosition(); |
|||
|
|||
driver_.moveBy(stepMotorMId, distance); |
|||
} |
|||
else if(command.getAction() == CmdAction.set) { |
|||
Double speed = command.getParam().getSpeed(); |
|||
if(speed != null) { |
|||
driver_.setSpeed(stepMotorMId, speed); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,5 @@ |
|||
package com.iflytop.sgs.hardware.command.handlers; |
|||
|
|||
// TODO: Implement the LiquidPumpHandler class to handle liquid pump operations. |
|||
public class LiquidPumpHandler { |
|||
} |
@ -0,0 +1,5 @@ |
|||
package com.iflytop.sgs.hardware.command.handlers; |
|||
|
|||
|
|||
public class LiquidValveHandler { |
|||
} |
@ -0,0 +1,123 @@ |
|||
package com.iflytop.sgs.hardware.command.handlers; |
|||
|
|||
import com.iflytop.sgs.common.cmd.DeviceCommand; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdAction; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdDevice; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdDirection; |
|||
import com.iflytop.sgs.hardware.command.CommandHandler; |
|||
import com.iflytop.sgs.hardware.drivers.StepMotorDriver.MotorWrapperDriver; |
|||
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorDirect; |
|||
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.sgs.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 MotorHandler extends CommandHandler { |
|||
private final MotorWrapperDriver driver_; |
|||
|
|||
private final Map<CmdDevice, StepMotorMId> stepMotorMIdMap_ = Map.ofEntries( |
|||
Map.entry(CmdDevice.door_motor, StepMotorMId.DoorM), |
|||
Map.entry(CmdDevice.z_motor, StepMotorMId.ZM), |
|||
Map.entry(CmdDevice.liquid_motor, StepMotorMId.LiquidM) // TODO: 蠕动泵后期可能会调整方案 |
|||
); |
|||
private final Map<CmdDevice, MId> supportCmdDeviceMIdMap = stepMotorMIdMap_.entrySet().stream(). |
|||
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); |
|||
|
|||
private final Set<CmdAction> supportActions = Set.of( |
|||
CmdAction.set, |
|||
CmdAction.enable, |
|||
CmdAction.disable, |
|||
CmdAction.open_clamp, |
|||
CmdAction.close_clamp, |
|||
CmdAction.origin, |
|||
CmdAction.move, |
|||
CmdAction.move_by, |
|||
CmdAction.rotate, |
|||
CmdAction.stop); |
|||
|
|||
@Override |
|||
protected Map<CmdDevice, MId> getSupportCmdDeviceMIdMap() { |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<CmdAction> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
public StepMotorDirect getMotorDirect(CmdDirection cmdDirection) |
|||
{ |
|||
return switch (cmdDirection) { |
|||
case forward -> StepMotorDirect.FORWARD; |
|||
case backward -> StepMotorDirect.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 -> { |
|||
CmdDirection cmdDirection = command.getParam().getDirection(); |
|||
StepMotorDirect 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); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,124 @@ |
|||
package com.iflytop.sgs.hardware.command.handlers; |
|||
|
|||
import com.iflytop.sgs.common.cmd.DeviceCommand; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdAction; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdDevice; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdDirection; |
|||
import com.iflytop.sgs.hardware.command.CommandHandler; |
|||
import com.iflytop.sgs.hardware.drivers.StepMotorDriver.MotorWrapperDriver; |
|||
import com.iflytop.sgs.hardware.type.MId; |
|||
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorDirect; |
|||
import com.iflytop.sgs.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 ServoHandler extends CommandHandler { |
|||
private final MotorWrapperDriver driver_; |
|||
|
|||
private final Map<CmdDevice, StepMotorMId> stepMotorMIdMap_ = Map.ofEntries( |
|||
Map.entry(CmdDevice.door_motor, StepMotorMId.DoorM), |
|||
Map.entry(CmdDevice.z_motor, StepMotorMId.ZM), |
|||
Map.entry(CmdDevice.liquid_motor, StepMotorMId.LiquidM) // TODO: 蠕动泵后期可能会调整方案 |
|||
); |
|||
private final Map<CmdDevice, MId> supportCmdDeviceMIdMap = stepMotorMIdMap_.entrySet().stream(). |
|||
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); |
|||
|
|||
private final Set<CmdAction> supportActions = Set.of( |
|||
CmdAction.set, |
|||
CmdAction.enable, |
|||
CmdAction.disable, |
|||
CmdAction.open_clamp, |
|||
CmdAction.close_clamp, |
|||
CmdAction.origin, |
|||
CmdAction.move, |
|||
CmdAction.move_by, |
|||
CmdAction.rotate, |
|||
CmdAction.stop); |
|||
|
|||
@Override |
|||
protected Map<CmdDevice, MId> getSupportCmdDeviceMIdMap() { |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<CmdAction> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
public StepMotorDirect getMotorDirect(CmdDirection cmdDirection) |
|||
{ |
|||
return switch (cmdDirection) { |
|||
case forward -> StepMotorDirect.FORWARD; |
|||
case backward -> StepMotorDirect.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 -> { |
|||
CmdDirection cmdDirection = command.getParam().getDirection(); |
|||
StepMotorDirect 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); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
@ -1,68 +0,0 @@ |
|||
package com.iflytop.sgs.hardware.command.handlers; |
|||
|
|||
|
|||
import com.iflytop.sgs.common.cmd.DeviceCommand; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdAction; |
|||
import com.iflytop.sgs.common.enums.cmd.CmdDevice; |
|||
import com.iflytop.sgs.hardware.command.CommandHandler; |
|||
import com.iflytop.sgs.hardware.drivers.StepMotorDriver.ShakeMotorDriver; |
|||
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorDirect; |
|||
import com.iflytop.sgs.hardware.type.StepMotor.StepMotorMId; |
|||
import com.iflytop.sgs.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 ShakeMotorHandler extends CommandHandler { |
|||
private final ShakeMotorDriver driver_; |
|||
|
|||
private final Map<CmdDevice, StepMotorMId> stepMotorMIdMap_ = Map.ofEntries( |
|||
); |
|||
private final Map<CmdDevice, MId> supportCmdDeviceMIdMap = stepMotorMIdMap_.entrySet().stream(). |
|||
collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); |
|||
|
|||
private final Set<CmdAction> supportActions = Set.of(CmdAction.start, CmdAction.stop, CmdAction.set, CmdAction.origin); |
|||
|
|||
|
|||
@Override |
|||
protected Map<CmdDevice, MId> getSupportCmdDeviceMIdMap() |
|||
{ |
|||
return supportCmdDeviceMIdMap; |
|||
} |
|||
|
|||
@Override |
|||
protected Set<CmdAction> getSupportActions() { |
|||
return supportActions; |
|||
} |
|||
|
|||
@Override |
|||
public void handleCommand(DeviceCommand command) throws Exception { |
|||
// 发送命令 |
|||
StepMotorMId stepMotorMId = stepMotorMIdMap_.get(command.getDevice()); |
|||
|
|||
if(command.getAction() == CmdAction.stop) { |
|||
driver_.stopShake(stepMotorMId); |
|||
} |
|||
else if(command.getAction() == CmdAction.set) { |
|||
Double speed = command.getParam().getSpeed(); |
|||
if(speed != null) { |
|||
driver_.setSpeed(stepMotorMId, speed); |
|||
} |
|||
} |
|||
else if (command.getAction() == CmdAction.start) { |
|||
StepMotorDirect direct = StepMotorDirect.FORWARD; |
|||
driver_.startShake(stepMotorMId, direct); |
|||
} |
|||
else if(command.getAction() == CmdAction.origin){ |
|||
driver_.moveToHome(stepMotorMId); |
|||
} |
|||
} |
|||
} |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue