forked from unitreerobotics/unitree_sim_isaaclab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsim_main.py
More file actions
679 lines (594 loc) · 30.8 KB
/
sim_main.py
File metadata and controls
679 lines (594 loc) · 30.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
# Copyright (c) 2025, Unitree Robotics Co., Ltd. All Rights Reserved.
# License: Apache License, Version 2.0
#!/usr/bin/env python3
# main.py
import os
project_root = os.path.dirname(os.path.abspath(__file__))
os.environ["PROJECT_ROOT"] = project_root
import argparse
import contextlib
import time
import sys
import signal
import torch
import gymnasium as gym
from pathlib import Path
# Isaac Lab AppLauncher
from isaaclab.app import AppLauncher
from teleimager.image_server import run_isaacsim_server
from dds.dds_create import create_dds_objects,create_dds_objects_replay
# add command line arguments
parser = argparse.ArgumentParser(description="Unitree Simulation")
parser.add_argument("--task", type=str, default="Isaac-PickPlace-G129-Head-Waist-Fix", help="task name")
parser.add_argument("--action_source", type=str, default="dds",
choices=["dds", "file", "trajectory", "policy", "replay","dds_wholebody"],
help="Action source")
parser.add_argument("--robot_type", type=str, default="g129", help="robot type")
parser.add_argument("--enable_dex1_dds", action="store_true", help="enable gripper DDS")
parser.add_argument("--enable_dex3_dds", action="store_true", help="enable dexterous hand DDS")
parser.add_argument("--enable_inspire_dds", action="store_true", help="enable inspire hand DDS")
parser.add_argument("--stats_interval", type=float, default=10.0, help="statistics print interval (seconds)")
parser.add_argument("--file_path", type=str, default="/home/unitree/Code/xr_teleoperate/teleop/utils/data", help="file path (when action_source=file)")
parser.add_argument("--generate_data_dir", type=str, default="./data", help="save data dir")
parser.add_argument("--generate_data", action="store_true", default=False, help="generate data")
parser.add_argument("--rerun_log", action="store_true", default=False, help="rerun log")
parser.add_argument("--replay_data", action="store_true", default=False, help="replay data")
parser.add_argument("--modify_light", action="store_true", default=False, help="modify light")
parser.add_argument("--modify_camera", action="store_true", default=False, help="modify camera")
# performance analysis parameters
parser.add_argument("--step_hz", type=int, default=100, help="control frequency")
parser.add_argument("--enable_profiling", action="store_true", default=True, help="enable performance analysis")
parser.add_argument("--profile_interval", type=int, default=500, help="performance analysis report interval (steps)")
parser.add_argument("--model_path", type=str, default="assets/model/policy.onnx", help="model path")
parser.add_argument("--reward_interval", type=int, default=10, help="step interval for reward calculation")
parser.add_argument("--enable_wholebody_dds", action="store_true", default=False, help="enable wh dds")
parser.add_argument("--physics_dt", type=float, default=None, help="physics time step, e.g., 0.005")
parser.add_argument("--render_interval", type=int, default=None, help="render interval steps (>=1)")
parser.add_argument("--camera_write_interval", type=int, default=None, help="camera write interval steps (>=1)")
parser.add_argument(
"--no_render",
action="store_true",
default=False,
help="disable rendering updates entirely (overrides render interval)",
)
parser.add_argument("--solver_iterations", type=int, default=None, help="physx solver iteration count (e.g., 4)")
parser.add_argument("--gravity_z", type=float, default=None, help="override gravity z (e.g., -9.8)")
parser.add_argument("--skip_cvtcolor", action="store_true", default=False, help="skip cv2.cvtColor if upstream already BGR")
parser.add_argument("--camera_jpeg", action="store_true", default=True, help="enable JPEG compression for camera frames")
parser.add_argument("--camera_jpeg_quality", type=int, default=85, help="JPEG quality (1-100)")
parser.add_argument("--physx_substeps", type=int, default=None, help="physx substeps per step")
parser.add_argument("--camera_include", type=str, default="front_camera,left_wrist_camera,right_wrist_camera", help="comma-separated camera names to enable")
parser.add_argument("--camera_exclude", type=str, default="world_camera", help="comma-separated camera names to disable")
parser.add_argument("--env_reward_interval", type=int, default=5, help="environment reward compute interval (steps)")
parser.add_argument("--seed", type=int, default=42, help="environment seed")
# add AppLauncher parameters
AppLauncher.add_app_launcher_args(parser)
args_cli = parser.parse_args()
if args_cli.enable_dex3_dds and args_cli.enable_dex1_dds and args_cli.enable_inspire_dds:
print("Error: enable_dex3_dds and enable_dex1_dds and enable_inspire_dds cannot be enabled at the same time")
print("Please select one of the options")
sys.exit(1)
import pinocchio
app_launcher = AppLauncher(args_cli)
simulation_app = app_launcher.app
from layeredcontrol.robot_control_system import (
RobotController,
ControlConfig,
)
from dds.reset_pose_dds import *
import tasks
from isaaclab_tasks.utils.parse_cfg import parse_env_cfg
from tools.augmentation_utils import (
update_light,
batch_augment_cameras_by_name,
)
from tools.data_json_load import sim_state_to_json
from dds.sim_state_dds import *
from action_provider.create_action_provider import create_action_provider
from tools.get_stiffness import get_robot_stiffness_from_env
from tools.get_reward import get_step_reward_value,get_current_rewards
def setup_signal_handlers(controller,dds_manager=None,image_server=None):
"""set signal handlers"""
def signal_handler(signum, frame):
print(f"\nreceived signal {signum}, stopping controller...")
try:
controller.stop()
except Exception as e:
print(f"Failed to stop controller: {e}")
try:
if dds_manager is not None:
dds_manager.stop_all_communication()
except Exception as e:
print(f"Failed to stop DDS: {e}")
try:
if image_server is not None:
image_server.stop()
except Exception as e:
print(f"Failed to stop image server: {e}")
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
def main():
"""main function"""
# import cProfile
# import pstats
# import io
# profiler = cProfile.Profile()
# profiler.enable()
import os
import atexit
try:
os.setpgrp()
current_pgid = os.getpgrp()
print(f"Setting process group: {current_pgid}")
def cleanup_process_group():
try:
print(f"Cleaning up process group: {current_pgid}")
import signal
os.killpg(current_pgid, signal.SIGTERM)
except Exception as e:
print(f"Failed to clean up process group: {e}")
atexit.register(cleanup_process_group)
except Exception as e:
print(f"Failed to set process group: {e}")
print("=" * 60)
print("robot control system started")
print(f"Task: {args_cli.task}")
print(f"Action source: {args_cli.action_source}")
print("=" * 60)
# parse environment configuration
try:
env_cfg = parse_env_cfg(args_cli.task, device=args_cli.device, num_envs=1)
env_cfg.env_name = args_cli.task
except Exception as e:
print(f"Failed to parse environment configuration: {e}")
return
# create environment
print("\ncreate environment...")
try:
env_cfg.seed = args_cli.seed
env = gym.make(args_cli.task, cfg=env_cfg).unwrapped
env.seed(args_cli.seed)
try:
sensors_dict = getattr(env.scene, "sensors", {})
if sensors_dict:
print("Sensors in the environment:")
for name, sensor in sensors_dict.items():
print(name, sensor)
print("="*60)
except Exception as e:
print(f"[sim] failed to list sensors: {e}")
print(f"\ncreate environment success ...")
try:
env._reward_interval = max(1, int(args_cli.env_reward_interval))
env._reward_counter = 0
env._reward_last = None
print(f"[env] reward compute interval set to {env._reward_interval} steps")
except Exception as e:
print(f"[env] failed to set reward interval: {e}")
if args_cli.physics_dt is not None:
try:
env.sim.set_substep_time(args_cli.physics_dt)
print(f"[sim] physics dt set to {args_cli.physics_dt}")
except Exception:
try:
env.sim.dt = args_cli.physics_dt
print(f"[sim] physics dt assigned to env.sim.dt={args_cli.physics_dt}")
except Exception as e:
print(f"[sim] failed to set physics dt: {e}")
headless_mode = bool(getattr(args_cli, "headless", False))
render_interval = None
if args_cli.render_interval is not None:
try:
render_interval = max(1, int(args_cli.render_interval))
except Exception as e:
print(f"[sim] invalid render_interval value {args_cli.render_interval}: {e}")
try:
if args_cli.no_render:
env.sim.render_interval = 1_000_000
env.sim.render_mode = "offscreen"
print("[sim] rendering disabled via --no_render")
elif headless_mode:
env.sim.render_mode = "offscreen"
env.sim.render_interval = render_interval or 1
print(f"[sim] headless offscreen rendering every {env.sim.render_interval} steps")
elif render_interval is not None:
env.sim.render_interval = render_interval
print(f"[sim] render_interval set to {env.sim.render_interval}")
except Exception as e:
print(f"[sim] failed to configure rendering: {e}")
if args_cli.camera_write_interval is not None:
try:
import tasks.common_observations.camera_state as cam_state
cam_state._camera_cache['write_interval_steps'] = max(1, int(args_cli.camera_write_interval))
print(f"[camera] write interval steps set to {cam_state._camera_cache['write_interval_steps']}")
except Exception as e:
print(f"[camera] failed to set write interval: {e}")
try:
if args_cli.solver_iterations is not None:
env.sim.physx.solver_iteration_count = int(args_cli.solver_iterations)
print(f"[sim] solver_iteration_count={env.sim.physx.solver_iteration_count}")
if args_cli.physx_substeps is not None:
try:
env.sim.physx.substeps = int(args_cli.physx_substeps)
except Exception:
try:
env.sim.set_substeps(int(args_cli.physx_substeps))
except Exception:
pass
print(f"[sim] physx_substeps set to {args_cli.physx_substeps}")
if args_cli.gravity_z is not None:
g = float(args_cli.gravity_z)
env.sim.physx.gravity = (0.0, 0.0, g)
print(f"[sim] gravity set to {env.sim.physx.gravity}")
except Exception as e:
print(f"[sim] failed to set physx params: {e}")
if args_cli.skip_cvtcolor:
os.environ["CAMERA_SKIP_CVTCOLOR"] = "1"
try:
import tasks.common_observations.camera_state as cam_state
enable_jpeg = bool(args_cli.camera_jpeg) or (os.getenv("CAMERA_JPEG") == "1")
jpeg_quality = int(args_cli.camera_jpeg_quality if args_cli.camera_jpeg else os.getenv("CAMERA_JPEG_QUALITY", args_cli.camera_jpeg_quality))
cam_state.set_writer_options(enable_jpeg=enable_jpeg, jpeg_quality=jpeg_quality, skip_cvtcolor=args_cli.skip_cvtcolor)
include = [n.strip() for n in (args_cli.camera_include or "").split(',') if n.strip()]
exclude = [n.strip() for n in (args_cli.camera_exclude or "").split(',') if n.strip()]
try:
cam_state.set_camera_allowlist(include)
except Exception:
pass
try:
sensors_dict = getattr(env.scene, "sensors", {})
for name, sensor in sensors_dict.items():
lname = name.lower()
if "camera" not in lname:
continue
if exclude and name in exclude:
for attr_name, value in [("enabled", False), ("is_enabled", False)]:
if hasattr(sensor, attr_name):
try:
setattr(sensor, attr_name, value)
except Exception:
pass
for meth in ("set_active", "disable", "pause"):
if hasattr(sensor, meth):
try:
getattr(sensor, meth)(False)
except Exception:
pass
for attr_name in ("update_period", "_update_period"):
if hasattr(sensor, attr_name):
try:
setattr(sensor, attr_name, 1e6)
except Exception:
pass
elif include and name not in include:
for attr_name in ("update_period", "_update_period"):
if hasattr(sensor, attr_name):
try:
setattr(sensor, attr_name, 1e6)
except Exception:
pass
except Exception as e:
print(f"[camera] failed to tune sensors: {e}")
except Exception as e:
print(f"[camera] failed to apply writer options: {e}")
except Exception as e:
print(f"\nFailed to create environment: {e}")
return
# get robot stiffness and damping parameters from runtime environment
print("\n" + "="*60)
print("🔍 Getting robot stiffness and damping parameters from runtime environment")
print("="*60)
try:
stiffness_data = get_robot_stiffness_from_env(env)
if stiffness_data:
print("✅ Successfully got robot parameters!")
else:
print("⚠️ Failed to get robot parameters, will try again after environment reset")
except Exception as e:
print(f"⚠️ Error getting robot parameters: {e}")
print("="*60)
if not getattr(args_cli, "headless", False) and not args_cli.no_render:
print("\n")
print("*** Please left-click on the Sim window to activate rendering. ***")
print("\n")
else:
print("\n")
print("*** Running without GUI; rendering handled offscreen. ***")
print("\n")
# reset environment
if args_cli.modify_light:
update_light(
prim_path="/World/light",
color=(0.75, 0.75, 0.75),
intensity=500.0,
# position=(1.0, 2.0, 3.0),
radius=0.1,
enabled=True,
cast_shadows=True
)
if args_cli.modify_camera:
batch_augment_cameras_by_name(
names=["front_cam"],
focal_length=3.0,
horizontal_aperture=22.0,
vertical_aperture=16.0,
exposure=0.8,
focus_distance=1.2
)
env.sim.reset()
env.reset()
# create simplified control configuration
try:
control_config = ControlConfig(
step_hz=args_cli.step_hz,
replay_mode=args_cli.replay_data
)
except Exception as e:
print(f"Failed to create control configuration: {e}")
return
# create controller
if not args_cli.replay_data:
print("========= create image server =========")
try:
image_server = run_isaacsim_server()
except Exception as e:
print(f"Failed to create image server: {e}")
return
print("========= create image server success =========")
print("========= create dds =========")
try:
reset_pose_dds,sim_state_dds,dds_manager = create_dds_objects(args_cli,env)
except Exception as e:
print(f"Failed to create dds: {e}")
return
print("========= create dds success =========")
else:
print("========= create dds =========")
try:
create_dds_objects_replay(args_cli,env)
except Exception as e:
print(f"Failed to create dds: {e}")
return
print("========= create dds success =========")
from tools.data_json_load import get_data_json_list
print("========= get data json list =========")
data_idx=0
data_json_list = get_data_json_list(args_cli.file_path)
if args_cli.action_source != "replay":
args_cli.action_source = "replay"
print("========= get data json list success =========")
# create action provider
print(f"\ncreate action provider: {args_cli.action_source}...")
try:
print(f"args_cli.task: {args_cli.task}")
if not args_cli.replay_data and ("Wholebody" in args_cli.task or args_cli.enable_wholebody_dds):
args_cli.action_source = "dds_wholebody"
args_cli.enable_wholebody_dds = True
control_config.use_rl_action_mode = True
action_provider = create_action_provider(env,args_cli)
if action_provider is None:
print("action provider creation failed, exiting")
return
except Exception as e:
print(f"Failed to create action provider: {e}")
return
# set action provider
print("========= create controller =========")
controller = RobotController(env, control_config)
controller.set_action_provider(action_provider)
print("========= create controller success =========")
# configure performance analysis
if args_cli.enable_profiling:
controller.set_profiling(True, args_cli.profile_interval)
print(f"performance analysis enabled, report every {args_cli.profile_interval} steps")
else:
controller.set_profiling(False)
print("performance analysis disabled")
# set signal handlers
if not args_cli.replay_data:
setup_signal_handlers(controller,dds_manager,image_server)
else:
setup_signal_handlers(controller)
print("Note: The DDS in Sim transmits messages on channel 1. Please ensure that other DDS instances use the same channel for message exchange by setting: ChannelFactoryInitialize(1).")
try:
# start controller - start asynchronous components
print("========= start controller =========")
controller.start()
print("========= start controller success =========")
# main loop - execute in main thread to support rendering
last_stats_time = time.time()
loop_start_time = time.time()
loop_count = 0
last_loop_time = time.time()
recent_loop_times = [] # for calculating moving average frequency
reward_interval = max(1, args_cli.reward_interval)
# use torch.inference_mode() and exception suppression
with contextlib.suppress(KeyboardInterrupt), torch.inference_mode():
while simulation_app.is_running() and controller.is_running:
current_time = time.time()
loop_count += 1
if not args_cli.replay_data:
try:
env_state = env.scene.get_state()
env_state_json = sim_state_to_json(env_state)
sim_state = {"init_state":env_state_json,"task_name":args_cli.task}
except Exception as e:
print(f"Failed to get env state: {e}")
raise e
try:
# sim_state = json.dumps(sim_state)
sim_state_dds.write_sim_state_data(sim_state)
except Exception as e:
print(f"Failed to write sim state: {e}")
raise e
try:
reset_pose_cmd = reset_pose_dds.get_reset_pose_command()
except Exception as e:
print(f"Failed to get reset pose command: {e}")
raise e
# Compute current reward values manually if needed for debugging
try:
if (loop_count % reward_interval) == 0:
pass
# current_reward = get_step_reward_value(env)
except Exception as e:
print(f"奖励计算失败: {e}")
pass
if reset_pose_cmd is not None:
try:
reset_category = reset_pose_cmd.get("reset_category")
if (args_cli.enable_wholebody_dds and (reset_category == '1' or reset_category == '2')) or (not args_cli.enable_wholebody_dds and reset_category == '1'):
print("reset object")
env_cfg.event_manager.trigger("reset_object_self", env)
reset_pose_dds.write_reset_pose_command(-1)
elif reset_category == '2' and not args_cli.enable_wholebody_dds:
print("reset all")
env_cfg.event_manager.trigger("reset_all_self", env)
reset_pose_dds.write_reset_pose_command(-1)
except Exception as e:
print(f"Failed to write reset pose command: {e}")
raise e
else:
if action_provider.get_start_loop() and data_idx<len(data_json_list):
print(f"data_idx: {data_idx}")
try:
sim_state,task_name = action_provider.load_data(data_json_list[data_idx])
if task_name!=args_cli.task:
raise ValueError(f" The {task_name} in the dataset is different from the {args_cli.task} being executed .")
except Exception as e:
print(f"Failed to load data: {e}")
raise e
try:
env.reset_to(sim_state, torch.tensor([0], device=env.device), is_relative=True)
env.sim.reset()
time.sleep(1)
action_provider.start_replay()
data_idx+=1
except Exception as e:
print(f"Failed to start replay: {e}")
raise e
# print(f"env_state: {env_state}")
# calculate instantaneous loop time
loop_dt = current_time - last_loop_time
last_loop_time = current_time
recent_loop_times.append(loop_dt)
# keep recent 100 loop times
if len(recent_loop_times) > 100:
recent_loop_times.pop(0)
# execute control step (in main thread, support rendering)
controller.step()
# print statistics and loop frequency periodically
if current_time - last_stats_time >= args_cli.stats_interval:
# calculate while loop execution frequency
elapsed_time = current_time - loop_start_time
loop_frequency = loop_count / elapsed_time if elapsed_time > 0 else 0
# calculate moving average frequency (based on recent loop times)
if recent_loop_times:
avg_loop_time = sum(recent_loop_times) / len(recent_loop_times)
moving_avg_frequency = 1.0 / avg_loop_time if avg_loop_time > 0 else 0
min_loop_time = min(recent_loop_times)
max_loop_time = max(recent_loop_times)
max_freq = 1.0 / min_loop_time if min_loop_time > 0 else 0
min_freq = 1.0 / max_loop_time if max_loop_time > 0 else 0
else:
moving_avg_frequency = 0
min_freq = max_freq = 0
print(f"\n=== While loop execution frequency statistics ===")
print(f"loop execution count: {loop_count}")
print(f"running time: {elapsed_time:.2f} seconds")
print(f"overall average frequency: {loop_frequency:.2f} Hz")
print(f"moving average frequency: {moving_avg_frequency:.2f} Hz (last {len(recent_loop_times)} times)")
print(f"frequency range: {min_freq:.2f} - {max_freq:.2f} Hz")
print(f"average loop time: {(elapsed_time/loop_count*1000):.2f} ms")
if recent_loop_times:
print(f"recent loop time: {(avg_loop_time*1000):.2f} ms")
print(f"=============================")
# print_stats(controller)
last_stats_time = current_time
# check environment state
if env.sim.is_stopped():
print("\nenvironment stopped")
break
# rate_limiter.sleep(env)
except KeyboardInterrupt:
print("\nuser interrupted program")
except Exception as e:
print(f"\nprogram exception: {e}")
finally:
# clean up resources
print("\nclean up resources...")
controller.cleanup()
image_server.stop()
env.close()
print("cleanup completed")
# profiler.disable()
# s = io.StringIO()
# ps = pstats.Stats(profiler, stream=s).strip_dirs().sort_stats("time")
# ps.print_stats(30)
# print(s.getvalue())
if __name__ == "__main__":
try:
main()
finally:
print("Performing final cleanup...")
# Get current process information
import os
import subprocess
import signal
import time
current_pid = os.getpid()
print(f"Current main process PID: {current_pid}")
try:
# Find all related Python processes
result = subprocess.run(['pgrep', '-f', 'sim_main.py'],
capture_output=True, text=True)
if result.returncode == 0:
pids = result.stdout.strip().split('\n')
print(f"Found related processes: {pids}")
for pid in pids:
if pid and pid != str(current_pid):
try:
print(f"Terminating child process: {pid}")
os.kill(int(pid), signal.SIGTERM)
except ProcessLookupError:
print(f"Process {pid} does not exist")
except Exception as e:
print(f"Failed to terminate process {pid}: {e}")
# Wait for processes to exit
time.sleep(2)
# Check if there are any remaining processes, force kill them
result2 = subprocess.run(['pgrep', '-f', 'sim_main.py'],
capture_output=True, text=True)
if result2.returncode == 0:
remaining_pids = result2.stdout.strip().split('\n')
for pid in remaining_pids:
if pid and pid != str(current_pid):
try:
print(f"Force killing process: {pid}")
os.kill(int(pid), signal.SIGKILL)
except Exception as e:
print(f"Failed to force kill process {pid}: {e}")
except Exception as e:
print(f"Error during process cleanup: {e}")
try:
simulation_app.close()
except Exception as e:
print(f"Failed to close simulation application: {e}")
print("Program exit completed")
# Force exit
os._exit(0)
# python sim_main.py --device cpu --enable_cameras --task Isaac-PickPlace-Cylinder-G129-Dex1-Joint --enable_dex1_dds --robot_type g129
# python sim_main.py --device cpu --enable_cameras --task Isaac-PickPlace-Cylinder-G129-Dex3-Joint --enable_dex3_dds --robot_type g129
# python sim_main.py --device cpu --enable_cameras --task Isaac-PickPlace-Cylinder-G129-Inspire-Joint --enable_inspire_dds --robot_type g129
# python sim_main.py --device cpu --enable_cameras --task Isaac-PickPlace-RedBlock-G129-Dex1-Joint --enable_dex1_dds --robot_type g129
# python sim_main.py --device cpu --enable_cameras --task Isaac-PickPlace-RedBlock-G129-Dex3-Joint --enable_dex3_dds --robot_type g129
# python sim_main.py --device cpu --enable_cameras --task Isaac-PickPlace-RedBlock-G129-Inspire-Joint --enable_inspire_dds --robot_type g129
# python sim_main.py --device cpu --enable_cameras --task Isaac-Stack-RgyBlock-G129-Dex1-Joint --enable_dex1_dds --robot_type g129
# python sim_main.py --device cpu --enable_cameras --task Isaac-Stack-RgyBlock-G129-Dex3-Joint --enable_dex3_dds --robot_type g129
# python sim_main.py --device cpu --enable_cameras --task Isaac-Stack-RgyBlock-G129-Inspire-Joint --enable_inspire_dds --robot_type g129
# python sim_main.py --device cpu --enable_cameras --task Isaac-Move-Cylinder-G129-Dex1-Wholebody --robot_type g129 --enable_dex1_dds
# python sim_main.py --device cpu --enable_cameras --task Isaac-Move-Cylinder-G129-Dex3-Wholebody --robot_type g129 --enable_dex3_dds
# python sim_main.py --device cpu --enable_cameras --task Isaac-Move-Cylinder-G129-Inspire-Wholebody --robot_type g129 --enable_inspire_dds
# python sim_main.py --device cpu --enable_cameras --task Isaac-PickPlace-Cylinder-H12-27dof-Inspire-Joint --enable_inspire_dds --robot_type h1_2
# python sim_main.py --device cpu --enable_cameras --task Isaac-PickPlace-RedBlock-H12-27dof-Inspire-Joint --enable_inspire_dds --robot_type h1_2
# python sim_main.py --device cpu --enable_cameras --task Isaac-Stack-RgyBlock-H12-27dof-Inspire-Joint --enable_inspire_dds --robot_type h1_2