From 6af094fb982f5716943cf1ced10ebdb876c26151 Mon Sep 17 00:00:00 2001 From: HSZ_HeSongZhen <210202959@qq.com> Date: Wed, 28 May 2025 10:23:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hardware/command/handlers/CameraHandler.java | 50 ------------ .../command/handlers/DualRobotHandler.java | 90 ---------------------- .../command/handlers/TricolorLightHandler.java | 2 +- 3 files changed, 1 insertion(+), 141 deletions(-) delete mode 100644 src/main/java/com/iflytop/sgs/hardware/command/handlers/CameraHandler.java delete mode 100644 src/main/java/com/iflytop/sgs/hardware/command/handlers/DualRobotHandler.java diff --git a/src/main/java/com/iflytop/sgs/hardware/command/handlers/CameraHandler.java b/src/main/java/com/iflytop/sgs/hardware/command/handlers/CameraHandler.java deleted file mode 100644 index afda886..0000000 --- a/src/main/java/com/iflytop/sgs/hardware/command/handlers/CameraHandler.java +++ /dev/null @@ -1,50 +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.CameraDriver; -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; - -@Slf4j -@Component -@RequiredArgsConstructor -public class CameraHandler extends CommandHandler { - private final CameraDriver cameraDriver_; - - private final Map supportCmdDeviceMIdMap = Map.ofEntries( - Map.entry(CmdDevice.photo, MId.NotSet) - ); - - private final Set supportActions = Set.of(CmdAction.open, CmdAction.close); - - @Override - protected Map getSupportCmdDeviceMIdMap() - { - return supportCmdDeviceMIdMap; - } - - @Override - protected Set getSupportActions() { - return supportActions; - } - - MId getMId(CmdDevice cmdDevice){ - return supportCmdDeviceMIdMap.get(cmdDevice); - } - - @Override - public void handleCommand(DeviceCommand command) throws Exception { - // 发送命令 - if (command.getAction() == CmdAction.take_photo) { - cameraDriver_.takePhoto(); - } - } -} diff --git a/src/main/java/com/iflytop/sgs/hardware/command/handlers/DualRobotHandler.java b/src/main/java/com/iflytop/sgs/hardware/command/handlers/DualRobotHandler.java deleted file mode 100644 index 723fe5d..0000000 --- a/src/main/java/com/iflytop/sgs/hardware/command/handlers/DualRobotHandler.java +++ /dev/null @@ -1,90 +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.command.CmdAxis; -import com.iflytop.sgs.common.enums.cmd.CmdDevice; -import com.iflytop.sgs.hardware.command.CommandHandler; -import com.iflytop.sgs.hardware.drivers.MiniServoDriver.DualRobotDriver; -import com.iflytop.sgs.hardware.type.Servo.MiniServoMId; -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 DualRobotHandler extends CommandHandler { - private final DualRobotDriver dualRobotDriver_; - - private final Map servoMIdMap_ = Map.ofEntries( - Map.entry(CmdDevice.dual_robot, MiniServoMId.NotSet) - ); - private final Map supportCmdDeviceMIdMap = servoMIdMap_.entrySet().stream(). - collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().mid)); - private final Set supportActions = Set.of(CmdAction.set, CmdAction.origin, CmdAction.move, CmdAction.stop, CmdAction.move_joint); - - @Override - protected Map getSupportCmdDeviceMIdMap() - { - return supportCmdDeviceMIdMap; - } - - @Override - protected Set getSupportActions() { - return supportActions; - } - - private DualRobotDriver.Joint getJoint(CmdAxis axis) { - switch (axis) { - case CmdAxis.joint1 -> { - return DualRobotDriver.Joint.JOINT_1; - } - case CmdAxis.joint2 -> { - return DualRobotDriver.Joint.JOINT_2; - } - default -> { - return null; - } - } - } - - @Override - public void handleCommand(DeviceCommand command) throws Exception { - // 发送命令 - if (command.getAction() == CmdAction.origin) { - dualRobotDriver_.moveToHome(MiniServoMId.DUAL_ROBOT_AXIS1_MID); - } - else if(command.getAction() == CmdAction.stop) { - CmdAxis axis = command.getParam().getAxis(); - DualRobotDriver.Joint joint = getJoint(axis); - dualRobotDriver_.stop(joint); - } - else if(command.getAction() == CmdAction.move_joint) { - CmdAxis axis = command.getParam().getAxis(); - double position = command.getParam().getPosition(); - - DualRobotDriver.Joint joint = getJoint(axis); - dualRobotDriver_.moveJointTo(joint, position); - } - else if(command.getAction() == CmdAction.move) { - double pos_x = command.getParam().getPosition(); - double pos_y = command.getParam().getPosition(); - dualRobotDriver_.moveToPoint(pos_x, pos_y); - } - else if(command.getAction() == CmdAction.set) { - CmdAxis axis = command.getParam().getAxis(); - DualRobotDriver.Joint joint = getJoint(axis); - Double speed = command.getParam().getSpeed(); - if(speed != null) { - dualRobotDriver_.setSpeed(joint, speed); - } - } - } -} diff --git a/src/main/java/com/iflytop/sgs/hardware/command/handlers/TricolorLightHandler.java b/src/main/java/com/iflytop/sgs/hardware/command/handlers/TricolorLightHandler.java index 9b4a252..127b425 100644 --- a/src/main/java/com/iflytop/sgs/hardware/command/handlers/TricolorLightHandler.java +++ b/src/main/java/com/iflytop/sgs/hardware/command/handlers/TricolorLightHandler.java @@ -2,7 +2,7 @@ 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.command.CmdColor; +import com.iflytop.sgs.common.enums.cmd.CmdColor; import com.iflytop.sgs.common.enums.cmd.CmdDevice; import com.iflytop.sgs.hardware.command.CommandHandler; import com.iflytop.sgs.hardware.drivers.TricolorLightDriver;