灵敏挡与稳定挡代码分离:灵敏挡使用 6393be9 原版 release_watch(release_watch_sensitive.py),较稳定/十分稳定使用 release_watch.py,按挡位分发;速度按挡位设置(灵敏 55%,较稳定/十分稳定 30%);切换挡位后界面速度/最大力滑块同步。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cheng
2026-09-28 16:47:21 +08:00
parent 8be8a80cff
commit d948883e93
7 changed files with 787 additions and 47 deletions
+34
View File
@@ -98,6 +98,7 @@ else:
from ..app import build_controller
from ..common.paths import PACKAGE_DIR, REPO_ROOT
from ..config.behavior_profiles import grip_behavior_profile, normalize_grip_behavior_mode
from ..sensors.camera_discovery import (
default_sensor_camera_sources,
list_camera_ids,
@@ -3114,6 +3115,7 @@ class VisualSettingsDialog(QDialog):
updated.get("slave_id", 1),
)
applied_live = self.viewer.apply_runtime_config(updated)
self.viewer._sync_mode_controls()
if applied_live:
tip = "配置已写入,并已对当前运行中的控制即时生效。"
else:
@@ -3729,6 +3731,36 @@ class GripperDemo02Viewer(QMainWindow):
position_max = position_min + 1
return open_pos, close_pos, position_min, position_max
def _sync_mode_controls(self, mode=None):
"""Speed / max-force sliders follow the active grip behavior mode."""
controller = getattr(self, "controller", None)
source = getattr(controller, "config", None)
if source is None:
try:
with open(self._control_config_path(), "r", encoding="utf-8") as f:
source = json.load(f)
except Exception:
source = {}
if mode is None:
mode = (source.get("grip_behavior_mode") if isinstance(source, dict)
else getattr(source, "grip_behavior_mode", None))
mode = normalize_grip_behavior_mode(mode)
if not source or (isinstance(source, dict)
and source.get("grip_behavior_mode") not in (None, mode)):
source = grip_behavior_profile(mode)
get = source.get if isinstance(source, dict) else (lambda k, d=None: getattr(source, k, d))
values = {"speed_control": get("speed"), "force_control": get("close_force")}
# Only on change, so a manual slider drag is not snapped back each tick.
key = (mode, tuple(values.values()))
if key == self._mode_controls_key:
return
self._mode_controls_key = key
for control_name, value in values.items():
control = getattr(self, control_name, None)
if control is not None and value is not None:
# Signals stay blocked so this does not echo into the live config.
control.set_value(value, force=True)
def _load_manual_control_config(self):
speed = 25
force = 10
@@ -3771,6 +3803,7 @@ class GripperDemo02Viewer(QMainWindow):
self.action_label.setObjectName("StatusSub")
status_layout.addWidget(self.status_chip)
status_layout.addWidget(self.action_label)
self._mode_controls_key = None
self.start_button = TopIconButton("start", "启动控制程序")
self.start_button.clicked.connect(self.start_control)
self.stop_button = TopIconButton("stop", "停止控制程序")
@@ -4465,6 +4498,7 @@ class GripperDemo02Viewer(QMainWindow):
self.action_label.setText(
shorten_status_text(f"action={label_with_cn(action, ACTION_TEXT)}", 28)
)
self._sync_mode_controls(status.get("grip_behavior_mode"))
self.manual_hold_button.setText(
"释放" if bool(status.get("manual_hold_active")) else "保持"
)