Browse Source

修复bug

master
HSZ_HeSongZhen 2 months ago
parent
commit
6af094fb98
  1. 50
      src/main/java/com/iflytop/sgs/hardware/command/handlers/CameraHandler.java
  2. 90
      src/main/java/com/iflytop/sgs/hardware/command/handlers/DualRobotHandler.java
  3. 2
      src/main/java/com/iflytop/sgs/hardware/command/handlers/TricolorLightHandler.java

50
src/main/java/com/iflytop/sgs/hardware/command/handlers/CameraHandler.java

@ -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<CmdDevice, MId> supportCmdDeviceMIdMap = Map.ofEntries(
Map.entry(CmdDevice.photo, MId.NotSet)
);
private final Set<CmdAction> supportActions = Set.of(CmdAction.open, CmdAction.close);
@Override
protected Map<CmdDevice, MId> getSupportCmdDeviceMIdMap()
{
return supportCmdDeviceMIdMap;
}
@Override
protected Set<CmdAction> 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();
}
}
}

90
src/main/java/com/iflytop/sgs/hardware/command/handlers/DualRobotHandler.java

@ -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<CmdDevice, MiniServoMId> servoMIdMap_ = Map.ofEntries(
Map.entry(CmdDevice.dual_robot, MiniServoMId.NotSet)
);
private final Map<CmdDevice, MId> supportCmdDeviceMIdMap = servoMIdMap_.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.stop, CmdAction.move_joint);
@Override
protected Map<CmdDevice, MId> getSupportCmdDeviceMIdMap()
{
return supportCmdDeviceMIdMap;
}
@Override
protected Set<CmdAction> 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);
}
}
}
}

2
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;

Loading…
Cancel
Save