fix(arm): preserve coordinate application proof during task pause
This commit is contained in:
parent
4e8f6e4dda
commit
0b8d283b24
@ -36,15 +36,21 @@ public class ArmTeachingService {
|
||||
});
|
||||
}
|
||||
public JSONObject execute(ArmTeachingOperation op,ArmTeachingRequest p) {
|
||||
if(recoveryOperation(op))try(var scope=com.cmvr.common.robot.RecoveryRpcScope.enter()){return executeScoped(op,p);}
|
||||
return executeScoped(op,p);
|
||||
if(recoveryOperation(op))try(var scope=com.cmvr.common.robot.RecoveryRpcScope.enter()){return executeScoped(op,p,false);}
|
||||
return executeScoped(op,p,false);
|
||||
}
|
||||
JSONObject executePauseStopMotion(ArmTeachingRequest p) {
|
||||
try(var scope=com.cmvr.common.robot.RecoveryRpcScope.enter()) {
|
||||
return executeScoped(ArmTeachingOperation.STOP_MOTION,p,true);
|
||||
}
|
||||
}
|
||||
private boolean recoveryOperation(ArmTeachingOperation op) {
|
||||
return op!=null&&(op.readOnly||java.util.Set.of(ArmTeachingOperation.STOP_MOTION,ArmTeachingOperation.STOP_TRAJECTORY_RECORDING,ArmTeachingOperation.EXIT_TEACHING_MODE,ArmTeachingOperation.COMPLETE_TEACHING).contains(op));
|
||||
}
|
||||
private JSONObject executeScoped(ArmTeachingOperation op,ArmTeachingRequest p) {
|
||||
private JSONObject executeScoped(ArmTeachingOperation op,ArmTeachingRequest p,boolean preserveCoordinateProof) {
|
||||
ArmTeachingParameters.validate(op,p);validateTarget(op,p);
|
||||
if(java.util.Set.of(ArmTeachingOperation.APPLY_USER_COORDINATE_SYSTEM,ArmTeachingOperation.UPDATE_USER_COORDINATE_SYSTEM,ArmTeachingOperation.DELETE_USER_COORDINATE_SYSTEM,ArmTeachingOperation.STOP_MOTION).contains(op))invalidateCoordinateProof(p.getRobotId(),p.getDeviceId());
|
||||
if(java.util.Set.of(ArmTeachingOperation.APPLY_USER_COORDINATE_SYSTEM,ArmTeachingOperation.UPDATE_USER_COORDINATE_SYSTEM,ArmTeachingOperation.DELETE_USER_COORDINATE_SYSTEM).contains(op)
|
||||
||(op==ArmTeachingOperation.STOP_MOTION&&!preserveCoordinateProof))invalidateCoordinateProof(p.getRobotId(),p.getDeviceId());
|
||||
var header=EdgeCommonUtil.buildRequest(p.getDeviceId());
|
||||
var stub=clients.getGrpcClient(p.getRobotId(),ArmServiceGrpc.ArmServiceBlockingStub.class)
|
||||
.withDeadlineAfter(ArmTeachingParameters.timeout(op,p.getTimeoutMs()),TimeUnit.MILLISECONDS);
|
||||
|
||||
@ -16,6 +16,12 @@ public class ArmTeachingStopExtension implements RobotStopExtension {
|
||||
return devices.selectByRobotId(robotId,2,false).stream().anyMatch(d->"1".equals(d.getEnabled()));
|
||||
}
|
||||
@Override public boolean stop(String robotId) {
|
||||
return stop(robotId,false);
|
||||
}
|
||||
@Override public boolean stopForPause(String robotId) {
|
||||
return stop(robotId,true);
|
||||
}
|
||||
private boolean stop(String robotId,boolean preserveCoordinateProof) {
|
||||
var enabled=devices.selectByRobotId(robotId,null,false).stream().filter(d->"1".equals(d.getEnabled())).toList();
|
||||
boolean allHandled=!enabled.isEmpty();
|
||||
for(var device:enabled) {
|
||||
@ -27,7 +33,8 @@ public class ArmTeachingStopExtension implements RobotStopExtension {
|
||||
if(unavailable.getMessage().contains("gRPC UNIMPLEMENTED")){allHandled=false;continue;} // Legacy arm: retain the original SystemService stop path.
|
||||
throw unavailable;
|
||||
}
|
||||
teaching.execute(ArmTeachingOperation.STOP_MOTION,request);
|
||||
if(preserveCoordinateProof)teaching.executePauseStopMotion(request);
|
||||
else teaching.execute(ArmTeachingOperation.STOP_MOTION,request);
|
||||
if(listing.getBooleanValue("recording"))teaching.execute(ArmTeachingOperation.STOP_TRAJECTORY_RECORDING,request);
|
||||
var state=teaching.execute(ArmTeachingOperation.GET_ROBOT_STATE,request).getJSONObject("state");
|
||||
if(state!=null&&"ARM_CONTROL_MODE_FREEDRIVE".equals(state.getString("controlMode")))teaching.execute(ArmTeachingOperation.EXIT_TEACHING_MODE,request);
|
||||
|
||||
@ -39,4 +39,7 @@ public interface EdgeSystemService {
|
||||
|
||||
|
||||
public String stopAll(String robotId);
|
||||
|
||||
/** Stop devices while pausing a flow, preserving only state explicitly safe to resume. */
|
||||
default String stopAllForPause(String robotId) { return stopAll(robotId); }
|
||||
}
|
||||
|
||||
@ -5,4 +5,6 @@ public interface RobotStopExtension {
|
||||
boolean handles(String robotId);
|
||||
/** Returns true only when this extension stopped all enabled devices on this robot. */
|
||||
boolean stop(String robotId);
|
||||
/** Stop for task pause; implementations may preserve state needed to resume safely. */
|
||||
default boolean stopForPause(String robotId) { return stop(robotId); }
|
||||
}
|
||||
|
||||
@ -245,11 +245,16 @@ public class EdgeSystemServiceImpl implements EdgeSystemService {
|
||||
|
||||
@Override
|
||||
public String stopAll(String robotId) {
|
||||
try(var scope=com.cmvr.common.robot.RecoveryRpcScope.enter()){return stopAllScoped(robotId);}
|
||||
try(var scope=com.cmvr.common.robot.RecoveryRpcScope.enter()){return stopAllScoped(robotId,false);}
|
||||
}
|
||||
private String stopAllScoped(String robotId) {
|
||||
@Override
|
||||
public String stopAllForPause(String robotId) {
|
||||
try(var scope=com.cmvr.common.robot.RecoveryRpcScope.enter()){return stopAllScoped(robotId,true);}
|
||||
}
|
||||
private String stopAllScoped(String robotId, boolean taskPause) {
|
||||
boolean exclusive = false;
|
||||
for (var extension : stopExtensions) if (extension.handles(robotId)) exclusive |= extension.stop(robotId);
|
||||
for (var extension : stopExtensions) if (extension.handles(robotId))
|
||||
exclusive |= taskPause ? extension.stopForPause(robotId) : extension.stop(robotId);
|
||||
if (exclusive) return "ACKNOWLEDGED";
|
||||
SystemServiceGrpc.SystemServiceBlockingStub stub = grpcServiceManager.getGrpcClient(
|
||||
robotId, SystemServiceGrpc.SystemServiceBlockingStub.class).withDeadlineAfter(120, TimeUnit.SECONDS);
|
||||
|
||||
@ -215,7 +215,7 @@ public class FlowControlService {
|
||||
catch (RuntimeException error) { log.warn("保存设备暂停状态失败,恢复将要求人工处理: instId={}, error={}", instId, error.getMessage()); }
|
||||
}
|
||||
// StopAll 是阻塞式调用。只有设备侧停止完成,暂停接口才返回,避免恢复请求和旧动作并发。
|
||||
boolean robotsStopped = stopAllRobotsAndWait(ctx);
|
||||
boolean robotsStopped = stopAllRobotsAndWait(ctx,true);
|
||||
boolean nodesFinished = waitForInterruptedNodes(instId, interruptedNodes);
|
||||
ctx.setPauseSettled(robotsStopped && nodesFinished);
|
||||
if (!ctx.isPauseSettled()) {
|
||||
@ -243,7 +243,7 @@ public class FlowControlService {
|
||||
}
|
||||
if (!ctx.isPauseSettled()) {
|
||||
List<TaskNodeExecuteContext> interruptedNodes = taskThreadRegistry.getPendingNodes(instId);
|
||||
boolean robotsStopped = stopAllRobotsAndWait(ctx);
|
||||
boolean robotsStopped = stopAllRobotsAndWait(ctx,true);
|
||||
boolean nodesFinished = waitForInterruptedNodes(instId, interruptedNodes);
|
||||
ctx.setPauseSettled(robotsStopped && nodesFinished);
|
||||
if (!ctx.isPauseSettled()) {
|
||||
@ -363,6 +363,10 @@ public class FlowControlService {
|
||||
}
|
||||
|
||||
private boolean stopAllRobotsAndWait(TaskContext context) {
|
||||
return stopAllRobotsAndWait(context,false);
|
||||
}
|
||||
|
||||
private boolean stopAllRobotsAndWait(TaskContext context, boolean taskPause) {
|
||||
List<String> robotIds = context.getRobotIds() == null || context.getRobotIds().isEmpty()
|
||||
? Collections.singletonList(context.getRobotId())
|
||||
: context.getRobotIds();
|
||||
@ -373,7 +377,8 @@ public class FlowControlService {
|
||||
.collect(Collectors.toList())) {
|
||||
abortLocalMediaRecordings(robotId);
|
||||
try {
|
||||
edgeSystemService.stopAll(robotId);
|
||||
if(taskPause)edgeSystemService.stopAllForPause(robotId);
|
||||
else edgeSystemService.stopAll(robotId);
|
||||
} catch (RuntimeException exception) {
|
||||
success = false;
|
||||
log.warn("停止机器人设备未确认,保留停止待确认状态: robotId={}, error={}",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user