From bdb5fb2418eb135626e9dd0ded3cbfa1e7956806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=B8=D0=BB=20=D0=93=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0=D1=80=D1=8C?= Date: Thu, 21 May 2026 07:56:11 +0300 Subject: [PATCH] fix: update robot IP address in configuration and improve process termination handling in run script --- cobot-setting.yaml | 2 +- cobot/commands/run.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cobot-setting.yaml b/cobot-setting.yaml index 92c57ac..8133957 100644 --- a/cobot-setting.yaml +++ b/cobot-setting.yaml @@ -1,6 +1,6 @@ robot: name: "iiwa7" - ip: "192.170.10.10" + ip: "192.170.10.2" port: 30200 command_mode: "position" # torque, position fri_cycle_ms: 10 # период FRI-цикла: 5 мс (200 Гц) или 10 мс (100 Гц) diff --git a/cobot/commands/run.py b/cobot/commands/run.py index 0afe5c4..b1fa232 100644 --- a/cobot/commands/run.py +++ b/cobot/commands/run.py @@ -4,6 +4,7 @@ import argparse import os import signal import shutil +import socket import subprocess from pathlib import Path from typing import Callable, List, Optional @@ -195,9 +196,18 @@ def _task_run_local(screen: RunScreen, mode: str) -> None: start_new_session=True, ) screen.set_proc(proc) - # Kill the entire process group so all child processes (nodes) are terminated together. - # Убиваем всю группу процессов, чтобы все дочерние процессы (узлы) завершились вместе. - screen.set_kill_fn(lambda: os.killpg(os.getpgid(proc.pid), signal.SIGTERM)) + # Kill the entire session so all ROS2 nodes are terminated together. + # ros2 launch puts each node in its own process group (setpgrp), so killpg on the + # bash pgid only reaches bash/launch itself. All nodes share the session started + # with start_new_session=True, so pkill -s reaches every one of them. + # Убиваем всю сессию, чтобы все ROS2-узлы завершились вместе. + # ros2 launch помещает каждый узел в отдельную группу процессов (setpgrp), поэтому + # killpg по pgid bash достигает только bash/launch. Все узлы разделяют сессию, + # созданную через start_new_session=True, поэтому pkill -s достигает каждого из них. + sid = os.getsid(proc.pid) + screen.set_kill_fn(lambda: subprocess.run( + ["pkill", "-TERM", "-s", str(sid)], capture_output=True + )) for line in proc.stdout: s = line.rstrip() @@ -230,6 +240,7 @@ def _task_run_docker(screen: RunScreen, image: str, mode: str, gpu: str) -> None "docker", "run", "--rm", "--name", container, "--network", "host", + "--hostname", socket.gethostname(), "-e", "USER=root", ]