Browse Source

feat:增加循环次数

master
白凤吉 3 months ago
parent
commit
313c227416
  1. 32
      src/main/java/com/iflytop/gd/app/cmd/debug/HoldingJawCloseCommandHandler.java
  2. 9
      src/main/java/com/iflytop/gd/app/cmd/debug/HoldingJawOpenCommandHandler.java
  3. 2
      src/main/java/com/iflytop/gd/app/cmd/debug/PalletElevatorLiftDownCommandHandler.java
  4. 3
      src/main/java/com/iflytop/gd/app/model/dto/CmdDTO.java

32
src/main/java/com/iflytop/gd/app/cmd/debug/HoldingJawCloseCommandHandler.java

@ -22,14 +22,44 @@ import java.util.concurrent.CompletableFuture;
@CommandMapping("debug_holding_jaw_close")
public class HoldingJawCloseCommandHandler extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private boolean stop = false;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
this.stop = false;
return runAsync(() -> {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.clawMove(34.0);
Double velocity = cmdDTO.getDoubleParam("velocity");
Double distance = cmdDTO.getDoubleParam("distance");
Integer times = cmdDTO.getIntegerParam("times");
if (velocity != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.clawSet(velocity);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
if (times != null) {
for (int i = 0; i < times; i++) {
if (stop) {
return;
}
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.clawMove(-distance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
DeviceCommandBundle backDeviceCommand = DeviceCommandGenerator.clawMove(distance);
CommandFuture backDeviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), backDeviceCommand);
commandWait(backDeviceCommandFuture);
}
} else {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.clawMove(-distance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}
});
}
public synchronized void stop() {
this.stop = true;
}
}

9
src/main/java/com/iflytop/gd/app/cmd/debug/HoldingJawOpenCommandHandler.java

@ -29,7 +29,8 @@ public class HoldingJawOpenCommandHandler extends BaseCommandHandler {
this.stop = false;
return runAsync(() -> {
Double velocity = cmdDTO.getDoubleParam("velocity");
Double distance = cmdDTO.getDoubleParam("distance");
Double openDistance = cmdDTO.getDoubleParam("openDistance");
Double closeDistance = cmdDTO.getDoubleParam("closeDistance");
Integer times = cmdDTO.getIntegerParam("times");
if (velocity != null) {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.clawSet(velocity);
@ -41,16 +42,16 @@ public class HoldingJawOpenCommandHandler extends BaseCommandHandler {
if (stop) {
return;
}
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.clawMove(distance);
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.clawMove(openDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
DeviceCommandBundle backDeviceCommand = DeviceCommandGenerator.clawMove(-distance);
DeviceCommandBundle backDeviceCommand = DeviceCommandGenerator.clawMove(closeDistance);
CommandFuture backDeviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), backDeviceCommand);
commandWait(backDeviceCommandFuture);
}
} else {
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.clawMove(distance);
DeviceCommandBundle deviceCommand = DeviceCommandGenerator.clawMove(openDistance);
CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), deviceCommand);
commandWait(deviceCommandFuture);
}

2
src/main/java/com/iflytop/gd/app/cmd/debug/PalletElevatorLiftDownCommandHandler.java

@ -31,7 +31,7 @@ public class PalletElevatorLiftDownCommandHandler extends BaseCommandHandler {
this.stop = false;
return runAsync(() -> {
String index = cmdDTO.getStringParam("index");
Double distance = -cmdDTO.getDoubleParam("distance");
Double distance = cmdDTO.getDoubleParam("distance");
Double velocity = cmdDTO.getDoubleParam("velocity");
Integer times = cmdDTO.getIntegerParam("times");
DeviceCommandBundle deviceCommand;

3
src/main/java/com/iflytop/gd/app/model/dto/CmdDTO.java

@ -27,6 +27,7 @@ public class CmdDTO {
public Double getDoubleParam(String key) {
return Optional.ofNullable(params.get(key))
.map(Object::toString)
.filter(value -> !value.isEmpty())
.map(Double::parseDouble)
.orElse(null);
}
@ -38,6 +39,7 @@ public class CmdDTO {
public Integer getIntegerParam(String key) {
return Optional.ofNullable(params.get(key))
.map(Object::toString)
.filter(value -> !value.isEmpty())
.map(Integer::parseInt)
.orElse(null);
}
@ -45,6 +47,7 @@ public class CmdDTO {
public Boolean getBooleanParam(String key) {
return Optional.ofNullable(params.get(key))
.map(Object::toString)
.filter(value -> !value.isEmpty())
.map(Boolean::parseBoolean)
.orElse(null);
}

Loading…
Cancel
Save