Commit 8405085f authored by wanghao's avatar wanghao

1 机械臂回零位置非零点导致指令提前完成的问题

- 问题现象:回零位置为(-1,0,0,0)等非零点时,系统误认为fullyIdle立即执行completeCommand,导致界面上的上料指令消失并错误执行下一条指令。
- 解决方案:在handleCompleteState中增加10秒持续时间校验,仅当从注册开始执行指令5秒后才允许指令完成操作
parent be3a7c5e
...@@ -23,8 +23,6 @@ import java.nio.charset.StandardCharsets; ...@@ -23,8 +23,6 @@ import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
...@@ -62,7 +60,9 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP ...@@ -62,7 +60,9 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
private final AtomicReference<CommandState> commandState = new AtomicReference<>(CommandState.IDLE); private final AtomicReference<CommandState> commandState = new AtomicReference<>(CommandState.IDLE);
// 当前执行的指令ID // 当前执行的指令ID
private volatile Long currentCommandId = null; private volatile Long currentCommandId = null;// 记录最近一次收到 fullyIdle 状态的时间(毫秒)
private volatile long lastFullyIdleTime = 0L;
private enum CommandState { private enum CommandState {
IDLE, // 空闲 IDLE, // 空闲
...@@ -229,6 +229,13 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP ...@@ -229,6 +229,13 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
} }
private void handleCompleteState() { private void handleCompleteState() {
// 检查时间条件:必须连续 fullyIdle 超过10秒
long now = System.currentTimeMillis();
if (now - lastFullyIdleTime < 5000) {
log.info("机械臂 fullyIdle 状态持续时间不足10秒,暂不完成指令。已持续 {} 毫秒", now - lastFullyIdleTime);
return;
}
// 只在完全空闲时处理 // 只在完全空闲时处理
Long commandIdToComplete = currentCommandId; Long commandIdToComplete = currentCommandId;
...@@ -271,6 +278,7 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP ...@@ -271,6 +278,7 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
public void registerCommandExecution(Long commandId) { public void registerCommandExecution(Long commandId) {
if (commandState.compareAndSet(CommandState.IDLE, CommandState.EXECUTING)) { if (commandState.compareAndSet(CommandState.IDLE, CommandState.EXECUTING)) {
currentCommandId = commandId; currentCommandId = commandId;
lastFullyIdleTime = System.currentTimeMillis();
log.info("注册指令跟踪: {}", commandId); log.info("注册指令跟踪: {}", commandId);
} else { } else {
throw new IllegalStateException("机械臂当前状态不能执行新指令"); throw new IllegalStateException("机械臂当前状态不能执行新指令");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment