{"id":116991,"date":"2026-10-22T10:07:26","date_gmt":"2026-10-22T02:07:26","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/116991.html"},"modified":"2026-10-22T10:07:26","modified_gmt":"2026-10-22T02:07:26","slug":"%e3%80%90%e5%85%b7%e8%ba%ab%e7%ac%94%e8%ae%b0%e3%80%91%e3%80%90piperpi0-5%e3%80%91%e4%b8%80%e3%80%81%e5%9f%ba%e4%ba%8e%e9%94%ae%e7%9b%98%e5%ae%9e%e7%8e%b0%e6%95%b0%e6%8d%ae%e9%87%87%e9%9b%86","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/116991.html","title":{"rendered":"\u3010\u5177\u8eab\u7b14\u8bb0\u3011\u3010Piper+PI0.5\u3011\u4e00\u3001\u57fa\u4e8e\u952e\u76d8\u5b9e\u73b0\u6570\u636e\u91c7\u96c6"},"content":{"rendered":"<h3>\u6982\u8ff0\u4e0eQA<\/h3>\n<p>\u672c\u7cfb\u5217\u4e3a\u6211\u5728vla\u4e0a\u7684\u7b2c\u4e8c\u4e2a\u5b9e\u8df5&#xff1a;\u57fa\u4e8epiper\u673a\u68b0\u81c2\u5b8c\u6210\u6570\u636e\u91c7\u96c6&#8211;\u683c\u5f0f\u8f6c\u6362&#8211;pi05\u5fae\u8c03&#8211;\u8bc4\u4f30&#8211;panda\u652f\u7ebf\u5bf9\u6bd4\u3002\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u5982\u4f55\u5b9e\u73b0\u57fa\u4e8e\u952e\u76d8\u9065\u64cd\u4f5c\u91c7\u96c6\u6570\u636e\u3002<\/p>\n<hr \/>\n<h3>1. \u5148\u9a8c\u8bc1\u81ea\u5df1\u7684\u8bbe\u5907\u80fd\u4e0d\u80fd\u652f\u6301\u952e\u76d8\u9065\u64cd<\/h3>\n<p>\u5176\u5b9e\u5728\u8fdb\u884c\u8fd9\u9879\u5b9e\u8df5\u6211\u4e00\u76f4\u5728\u62c5\u5fc3\u81ea\u5df1\u7684\u96c6\u663eubuntu\u7535\u8111\u65e0\u6cd5\u652f\u6301\u9065\u91c7&#xff0c;\u5fc5\u987b\u8981\u53bbautodl\u4e0a\u79df\u5361\u7136\u540e\u505a\u753b\u9762\u6e32\u67d3\u548c\u8f6c\u53d1\u624d\u80fd\u5b9e\u73b0\u3002\u8fdb\u4e00\u6b65\u4e86\u89e3\u540e\u624d\u77e5\u9053\u8fd9\u9879\u4e3b\u8981\u9700\u6c42\u7684\u662fCPU&#xff0c;\u663e\u5361\u53ea\u8981\u80fd\u5e26\u52a8mujoco\u5c31\u884c\u3002<\/p>\n<p>\u4e8e\u662f\u6211\u901a\u8fc7\u4e0b\u9762\u7684\u4ee3\u7801\u521d\u6b65\u5c1d\u8bd5\u4e86\u9065\u64cd\u4f5c&#xff0c;\u5e76\u6d4b\u8bd5\u4e86\u81ea\u5df1\u7535\u8111\u4e0a\u80fd\u505a\u5230\u7684fps&#xff1a;<\/p>\n<p>import argparse<br \/>\nimport time<br \/>\nfrom pathlib import Path<br \/>\n# \u7528\u4e8e\u7b97\u5747\u503c<br \/>\nfrom statistics import mean<\/p>\n<p>import numpy as np<br \/>\n# \u7528libero\u642d\u5efa\u4efb\u52a1\u5957\u4ef6\u73af\u5883<br \/>\nfrom libero.libero import benchmark, get_libero_path<br \/>\nfrom libero.libero.envs.env_wrapper import ControlEnv<br \/>\n# \u7528robosuite\u5b9a\u4e49\u952e\u76d8\u8f93\u5165\u8bbe\u5907\u548c\u52a8\u4f5c\u6620\u5c04<br \/>\nfrom robosuite.devices import Keyboard<br \/>\nfrom robosuite.utils.input_utils import input2action<\/p>\n<p># \u5b9e\u73b0 python script.py &#8211;two-cameras&#xff0c;store_true\u8868\u793a\u547d\u4ee4\u884c\u53ea\u8981\u5199\u4e86\u8fd9\u4e2a\u53c2\u6570&#xff0c;\u5176\u503c\u5c31\u662ftrue&#xff0c;\u4e0d\u5199\u5c31\u662ffalse<br \/>\nparser &#061; argparse.ArgumentParser()<br \/>\nparser.add_argument(&#034;&#8211;two-cameras&#034;, action&#061;&#034;store_true&#034;)<br \/>\nargs &#061; parser.parse_args()<\/p>\n<p>mode &#061; &#034;viewr &#043; \u4e24\u8def\u76f8\u673a&#034; if args.two_cameras else &#034;\u4ec5 viewer&#034;<\/p>\n<p>suite &#061; benchmark.get_benchmark_dict()[&#034;libero_spatial&#034;]()<br \/>\ntask &#061; suite.get_task(0)<br \/>\n# \u7528Path\u62fc\u76ee\u5f55<br \/>\nbddl_path &#061; (<br \/>\n    Path(get_libero_path(&#034;bddl_files&#034;)) # \u7b2c 1 \u90e8\u5206&#xff1a;\u6839\u76ee\u5f55<br \/>\n    \/ task.problem_folder               # \u7b2c 2 \u90e8\u5206&#xff1a;\u4efb\u52a1\u5b50\u76ee\u5f55<br \/>\n    \/ task.bddl_file                    # \u7b2c 3 \u90e8\u5206&#xff1a;BDDL \u6587\u4ef6\u540d<br \/>\n)<\/p>\n<p>print(f&#034;\u4efb\u52a1: {task.language}&#034;)<br \/>\nprint(f&#034;\u6d4b\u8bd5\u6a21\u5f0f: {mode}&#034;)<\/p>\n<p>env &#061; ControlEnv(<br \/>\n    bddl_file_name&#061;str(bddl_path),<br \/>\n    robots&#061;[&#034;Panda&#034;],<br \/>\n    controller&#061;&#034;OSC_POSE&#034;,<br \/>\n    control_freq&#061;20,<br \/>\n    # \u6253\u5f00\u4e3b\u7a97\u53e3<br \/>\n    has_renderer&#061;True,<br \/>\n    has_offscreen_renderer&#061;True,<br \/>\n    render_camera&#061;&#034;agentview&#034;,<br \/>\n    # \u662f\u5426\u5728\u89c2\u6d4bobs\u91cc\u8fd4\u56de\u56fe\u50cf&#xff0c;True\u7684\u8bddobs\u5c31\u6709agentview_image\u3001robot0_eye_in_hand_image\u56fe\u50cf<br \/>\n    use_camera_obs&#061;args.two_cameras,<br \/>\n    camera_names&#061;[&#034;agentview&#034;, &#034;robot0_eye_in_hand&#034;],<br \/>\n    camera_widths&#061;256,<br \/>\n    camera_heights&#061;256,<br \/>\n    ignore_done&#061;True,<br \/>\n)<br \/>\ndevice &#061; None<\/p>\n<p>try:<br \/>\n    env.seed(1000)<br \/>\n    observation &#061; env.reset()<\/p>\n<p>    if args.two_cameras:<br \/>\n        for key in [&#034;agentview_image&#034;, &#034;robot0_eye_in_hand_image&#034;]:<br \/>\n            print(key, observation[key].shape)<br \/>\n            assert observation[key].shape &#061;&#061; (256, 256, 3)<\/p>\n<p>    # \u65e0\u79fb\u52a8&#xff0c;\u4fdd\u6301\u5939\u722a\u6253\u5f00<br \/>\n    idle_action &#061; np.array([0, 0, 0, 0, 0, 0, -1], dtype&#061;float)<br \/>\n    # \u9884\u70ed<br \/>\n    for _ in range(20):<br \/>\n        env.step(idle_action)<br \/>\n        # \u628a\u5f53\u524d\u753b\u9762\u753b\u5230\u7a97\u53e3<br \/>\n        env.env.render()<br \/>\n    print(&#034;\u5f00\u59cb\u6d4bfps, \u4e0d\u9700\u6309\u952e&#034;)<br \/>\n    fps_records &#061; []<\/p>\n<p>    # \u6bcf\u6b21\u6d4b 100 \u4e2a\u63a7\u5236\u6b65&#xff0c;\u5305\u62ec\u7269\u7406\u4eff\u771f\u3001\u89c2\u6d4b\u751f\u6210\u548c\u7a97\u53e3\u663e\u793a<br \/>\n    # \u6b64\u5904\u4e0d sleep&#xff0c;\u6d4b\u7684\u662f\u5904\u7406\u80fd\u529b&#xff0c;\u4e0d\u662f\u4eba\u4e3a\u9650\u5236\u7684 20 FPS<br \/>\n    for trial in range(3):<br \/>\n        start &#061; time.perf_counter()<\/p>\n<p>        for _ in range(100):<br \/>\n            env.step(idle_action)<br \/>\n            env.env.render()<\/p>\n<p>        elapsed &#061; time.perf_counter() &#8211; start<br \/>\n        fps &#061; 100 \/ elapsed<br \/>\n        fps_records.append(fps)<\/p>\n<p>        print(<br \/>\n            f&#034;\u7b2c {trial &#043; 1} \u6b21: &#034;<br \/>\n            f&#034;100 \u6b65\u8017\u65f6&#061;{elapsed} \u79d2&#xff0c;FPS&#061;{fps}&#034;<br \/>\n        )<\/p>\n<p>    print(&#034;\u6a21\u5f0f:&#034;, mode)<br \/>\n    print(&#034;\u4e09\u6b21 FPS:&#034;, fps_records)<br \/>\n    print(&#034;\u5e73\u5747 FPS:&#034;, mean(fps_records))<\/p>\n<p>    # \u6d4b\u5b8c\u91cd\u65b0\u521d\u59cb\u5316&#xff0c;\u907f\u514d\u6d4b\u8bd5\u8fc7\u7a0b\u6539\u53d8\u573a\u666f\u72b6\u6001<br \/>\n    env.reset()<br \/>\n    env.env.render()<\/p>\n<p>    device &#061; Keyboard(<br \/>\n        # \u4f4d\u7f6e\u7075\u654f\u5ea6\u548c\u59ff\u6001\u7075\u654f\u5ea6<br \/>\n        pos_sensitivity&#061;0.1,<br \/>\n        rot_sensitivity&#061;0.2<br \/>\n    )<br \/>\n    device.start_control()<\/p>\n<p>    print(&#034;\\\\n\u5f00\u59cb\u952e\u76d8\u64cd\u4f5c:&#034;)<br \/>\n    # \u8fd9\u4e2a\u5bf9\u5e94\u5173\u7cfb\u662frobosuite Keyboard\u63d0\u524d\u5b9a\u4e49\u597d\u7684<br \/>\n    print(&#034;W\/A\/S\/D \u6c34\u5e73\u79fb\u52a8:R\/F \u5347\u964d&#xff1b;\u7a7a\u683c\u5f00\u5408\u5939\u722a\u3002&#034;)<br \/>\n    print(&#034;\u672c\u811a\u672c\u6309 Q \u7ed3\u675f&#xff0c;\u4e5f\u53ef\u4ee5\u5728\u7ec8\u7aef\u6309 Ctrl&#043;C\u3002&#034;)<\/p>\n<p>    while True:<br \/>\n        start &#061; time.perf_counter()<\/p>\n<p>        action, grasp &#061; input2action(<br \/>\n            device&#061;device,<br \/>\n            robot&#061;env.robots[0],<br \/>\n            active_arm&#061;&#034;right&#034;,<br \/>\n        )<\/p>\n<p>        if action is None:<br \/>\n            break<\/p>\n<p>        assert action.shape &#061;&#061; (7, )<br \/>\n        env.step(action)<br \/>\n        env.env.render()<\/p>\n<p>        remaining &#061; 1 \/ 20 &#8211; (time.perf_counter() &#8211; start)<br \/>\n        if remaining &gt; 0:<br \/>\n            time.sleep(remaining)<\/p>\n<p>except KeyboardInterrupt:<br \/>\n    print(&#034;\\\\n\u6d4b\u8bd5\u7ed3\u675f\u3002&#034;)  <\/p>\n<p>finally:<br \/>\n    if device is not None:<br \/>\n        device.listener.stop()<br \/>\n    env.close()<\/p>\n<p>\u6211\u89c9\u5f97\u8fd9\u91cc\u7684\u6838\u5fc3\u6709\u4e24\u70b9&#xff1a;<\/p>\n<p>1. \u642d\u573a\u666f&#xff0c;\u8ddf\u4e4b\u524dmujoco\u5728libero\u4e0a\u7684\u5b9e\u8df5\u4e00\u6837&#xff0c;\u5148\u627e\u5230\u9700\u6c42\u7684\u4efb\u52a1&#xff0c;\u5f97\u5230\u5176bddl\u8def\u5f84&#xff0c;\u901a\u8fc7libero\u642d\u5efa\u4eff\u771f\u573a\u666f<\/p>\n<p>2. \u4f7f\u7528 robosuite \u63d0\u4f9b\u7684\u952e\u76d8\u8f93\u5165\u5de5\u5177\u548c\u673a\u68b0\u81c2\u63a7\u5236\u5668&#xff0c;\u628a\u6309\u952e\u8f6c\u6362\u6210\u52a8\u4f5c&#xff0c;\u901a\u8fc7 env.step(action) \u9a71\u52a8\u673a\u68b0\u81c2\u3002robosuite \u5c01\u88c5\u4e86\u673a\u5668\u4eba\u3001\u4f20\u611f\u5668\u3001\u63a7\u5236\u5668\u7b49\u63a5\u53e3&#xff0c;\u65b9\u4fbf\u7528\u6237\u64cd\u4f5c MuJoCo \u4e2d\u7684\u673a\u5668\u4eba\u3002<\/p>\n<p>\u6b64\u5916&#xff0c;has_renderer\u8868\u793a\u8981\u5f00\u4e3b\u7a97\u53e3&#xff0c;has_offscreen_renderer\u7528\u4e8e\u83b7\u53d6\u56fe\u50cf&#xff0c;\u4e4b\u524dautodl\u4e0a\u8fdb\u884cmujoco\u5b9e\u8df5\u7528\u7684OffScreenRenderEnv\u5b9e\u8d28\u5c31\u662f\u7ee7\u627f\u4e8eControlEnv&#xff0c;\u4e14\u5176\u9ed8\u8ba4has_offscreen_renderer\u4e3atrue\u3002<\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>(libero) dukiya&#064;dukiya-XiaoXinPro-14-APH8:~\/libero-learning\/week4$ python -u A1_libero_keyboard_fps.py<br \/>\n[robosuite WARNING] No private macro file found! (__init__.py:7)<br \/>\n[robosuite WARNING] It is recommended to use a private macro file (__init__.py:8)<br \/>\n[robosuite WARNING] To setup, run: python \/home\/dukiya\/venvs\/libero\/lib\/python3.10\/site-packages\/robosuite\/scripts\/setup_macros.py (__init__.py:9)<br \/>\nUnable to load module hid, required to interface with SpaceMouse.<\/p>\n<p>           Only macOS is officially supported. Install the additional<\/p>\n<p>           requirements with &#096;pip install -r requirements-extra.txt&#096;<br \/>\n[info] using task orders [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]<br \/>\n\u4efb\u52a1: pick up the black bowl between the plate and the ramekin and place it on the plate<br \/>\n\u6d4b\u8bd5\u6a21\u5f0f: \u4ec5 viewer<br \/>\nLocal assets not found. Downloading from HuggingFace Hub&#8230;<br \/>\nAssets already downloaded at \/home\/dukiya\/.cache\/libero\/assets<br \/>\nqt.qpa.plugin: Could not find the Qt platform plugin &#034;wayland&#034; in &#034;\/home\/dukiya\/venvs\/libero\/lib\/python3.10\/site-packages\/cv2\/qt\/plugins&#034;<br \/>\n\u5f00\u59cb\u6d4bfps, \u4e0d\u9700\u6309\u952e<br \/>\n\u7b2c 1 \u6b21: 100 \u6b65\u8017\u65f6&#061;3.7127978919888847 \u79d2&#xff0c;FPS&#061;26.933865755464446<br \/>\n\u7b2c 2 \u6b21: 100 \u6b65\u8017\u65f6&#061;3.1702399159548804 \u79d2&#xff0c;FPS&#061;31.543354020851723<br \/>\n\u7b2c 3 \u6b21: 100 \u6b65\u8017\u65f6&#061;3.4133581139612943 \u79d2&#xff0c;FPS&#061;29.296662307708257<br \/>\n\u6a21\u5f0f: \u4ec5 viewer<br \/>\n\u4e09\u6b21 FPS: [26.933865755464446, 31.543354020851723, 29.296662307708257]<br \/>\n\u5e73\u5747 FPS: 29.257960694674807<\/p>\n<p>Keys            Command<br \/>\nq               reset simulation<br \/>\nspacebar        toggle gripper (open\/close)<br \/>\nw-a-s-d         move arm horizontally in x-y plane<br \/>\nr-f             move arm vertically<br \/>\nz-x             rotate arm about x-axis<br \/>\nt-g             rotate arm about y-axis<br \/>\nc-v             rotate arm about z-axis<br \/>\nESC             quit<\/p>\n<p>\u5f00\u59cb\u952e\u76d8\u64cd\u4f5c:<br \/>\nW\/A\/S\/D \u6c34\u5e73\u79fb\u52a8:R\/F \u5347\u964d&#xff1b;\u7a7a\u683c\u5f00\u5408\u5939\u722a\u3002<br \/>\n\u672c\u811a\u672c\u6309 Q \u7ed3\u675f&#xff0c;\u4e5f\u53ef\u4ee5\u5728\u7ec8\u7aef\u6309 Ctrl&#043;C\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"800\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020718-6ad96fd61cf4a.png\" width=\"1280\" \/><\/p>\n<p>\u7ed3\u679c\u8868\u660e\u6211\u7684\u96c6\u6210\u663e\u5361\u9065\u64cd\u4f5c\u5b8c\u5168\u6ca1\u95ee\u9898&#xff0c;\u5e73\u5747\u5e27\u7387\u80fd\u8fbe\u523030\u5de6\u53f3\u3002<\/p>\n<hr \/>\n<h3>2. \u5728mujoco\u4e2d\u5f15\u5165piper<\/h3>\n<p>\u8fd9\u4e00\u6b65\u662f\u5728\u4e86\u89e3piper\u662f\u4ec0\u4e48&#xff0c;\u957f\u4ec0\u4e48\u6837\u3002<\/p>\n<h4>2.1. piper\u662f\u4ec0\u4e48<\/h4>\n<p>Piper \u662f\u677e\u7075\u673a\u5668\u4eba&#xff08;AgileX&#xff09;\u63a8\u51fa\u7684\u4e00\u6b3e\u516d\u81ea\u7531\u5ea6\u673a\u68b0\u81c2&#xff0c;\u53ef\u4ee5\u63a7\u5236\u672b\u7aef\u5939\u722a\u5728\u7a7a\u95f4\u4e2d\u7684\u4f4d\u7f6e\u548c\u671d\u5411&#xff0c;\u5b8c\u6210\u6293\u53d6\u3001\u642c\u8fd0\u3001\u653e\u7f6e\u7b49\u64cd\u4f5c\u3002<\/p>\n<p>\u8fdb\u4e00\u6b65\u8bf4&#xff0c;piper\u662f\u56fd\u4ea7\u7684\u673a\u68b0\u81c2&#xff0c;pi05\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u5e76\u6ca1\u6709\u5728\u5b83\u7684\u6570\u636e\u96c6\u4e0a\u8bad\u7ec3\u8fc7&#xff0c;\u7528piper\u505a\u6b64\u5b9e\u8df5&#xff0c;\u4e00\u65b9\u9762\u662f\u66f4\u597d\u7684\u9002\u914d\u56fd\u5185\u591a\u6570\u4f01\u4e1a\u7684\u60c5\u51b5&#xff0c;\u4e00\u65b9\u9762\u80fd\u66f4\u597d\u7684\u4f53\u9a8cpi05\u5728\u672a\u89c1\u8fc7\u7684\u673a\u68b0\u81c2\u6a21\u578b\u4e0a\u7684\u9002\u914d\u60c5\u51b5\u3002<\/p>\n<h4>2.2. \u4e0b\u8f7dpiper\u6a21\u578b\u5e76\u5f15\u5165mujoco<\/h4>\n<p>\u901a\u8fc7\u4e0b\u9762\u7684\u6307\u4ee4\u4e0b\u8f7dpiper\u6a21\u578b&#xff1a;<\/p>\n<p>source \/home\/dukiya\/venvs\/libero\/bin\/activate<br \/>\nunset PYTHONPATH<br \/>\nunset PYTHONHOME<br \/>\nunset MUJOCO_GL<br \/>\nunset PYOPENGL_PLATFORM<\/p>\n<p>mkdir -p \/home\/dukiya\/libero-learning\/week4\/assets<br \/>\ncd \/home\/dukiya\/libero-learning\/week4\/assets<\/p>\n<p># \u53ea\u53d6 Piper \u5b50\u76ee\u5f55&#xff0c;\u907f\u514d\u4e0b\u8f7d\u6a21\u578b\u5e93\u4e2d\u7684\u5168\u90e8\u673a\u5668\u4eba<br \/>\ngit clone &#8211;depth 1 &#8211;filter&#061;blob:none &#8211;sparse \\\\<br \/>\n  https:\/\/github.com\/google-deepmind\/mujoco_menagerie.git<\/p>\n<p>git -C mujoco_menagerie sparse-checkout set agilex_piper<\/p>\n<p># \u4fdd\u7559\u8fd9\u884c\u8f93\u51fa&#xff0c;\u4f5c\u4e3a\u5b9e\u9645\u4e0b\u8f7d\u7248\u672c\u7684\u8bb0\u5f55<br \/>\ngit -C mujoco_menagerie rev-parse HEAD<\/p>\n<p>\u7528\u4e4b\u524dmujoco\u5f15\u5165\u81ea\u5df1\u5199\u7684mjcf\u7684\u65b9\u6cd5&#xff0c;\u628a\u8def\u5f84\u627e\u5bf9&#xff0c;\u5c31\u80fd\u5728mujoco\u4e2d\u770b\u5230piper\u7684\u4eff\u771f&#xff1a;<\/p>\n<p>from pathlib import Path<br \/>\nimport mujoco<br \/>\nimport mujoco.viewer<\/p>\n<p># scene.xml \u662f\u573a\u666f\u5165\u53e3&#xff0c;\u5185\u90e8\u5305\u542b\u673a\u5668\u4eba piper.xml<br \/>\nmodel_path &#061; (<br \/>\n    Path(__file__).resolve().parent<br \/>\n    \/ &#034;assets&#034;<br \/>\n    \/ &#034;mujoco_menagerie&#034;<br \/>\n    \/ &#034;agilex_piper&#034;<br \/>\n    \/ &#034;scene.xml&#034;<br \/>\n)<\/p>\n<p>model &#061; mujoco.MjModel.from_xml_path(str(model_path))<br \/>\ndata &#061; mujoco.MjData(model)<\/p>\n<p># \u6309\u540d\u5b57\u627eid,\u4e2d\u95f4\u7684\u53c2\u6570\u8868\u660e\u67e5\u8be2\u5bf9\u8c61\u7684\u7c7b\u578b<br \/>\nhome_id &#061; mujoco.mj_name2id(<br \/>\n    model, mujoco.mjtObj.mjOBJ_KEY, &#034;home&#034;<br \/>\n)<br \/>\nassert home_id &gt;&#061; 0, &#034;\u6a21\u578b\u4e2d\u6ca1\u6709\u627e\u5230 home \u59ff\u6001&#034;<\/p>\n<p>mujoco.mj_resetDataKeyframe(model, data, home_id)<br \/>\nmujoco.mj_forward(model, data)<\/p>\n<p>print(&#034;&#061;&#061;&#061; Piper \u6a21\u578b\u4fe1\u606f &#061;&#061;&#061;&#034;)<br \/>\nprint(&#034;\u6a21\u578b\u8def\u5f84:&#034;, model_path)<br \/>\nprint(&#034;MuJoCo \u7248\u672c:&#034;, mujoco.__version__)<br \/>\nprint(&#034;\u5173\u8282\u6570 njnt:&#034;, model.njnt)<br \/>\nprint(&#034;\u4f4d\u7f6e\u72b6\u6001\u957f\u5ea6 nq:&#034;, model.nq)<br \/>\nprint(&#034;\u901f\u5ea6\u72b6\u6001\u957f\u5ea6 nv:&#034;, model.nv)<br \/>\nprint(&#034;\u6267\u884c\u5668\u6570 nu:&#034;, model.nu)<br \/>\nprint(&#034;\u7269\u7406\u6b65\u957f dt:&#034;, model.opt.timestep)<\/p>\n<p>print(&#034;\\\\n&#061;&#061;&#061; \u5173\u8282\u540d\u79f0\u4e0e\u9650\u4f4d &#061;&#061;&#061;&#034;)<br \/>\nfor index in range(model.njnt):<br \/>\n    name &#061; mujoco.mj_id2name(<br \/>\n        model, mujoco.mjtObj.mjOBJ_JOINT, index<br \/>\n    )<br \/>\n    joint_type &#061; model.jnt_type[index]<\/p>\n<p>    if joint_type &#061;&#061; mujoco.mjtJoint.mjJNT_HINGE:<br \/>\n        description &#061; &#034;\u8f6c\u52a8\u5173\u8282&#xff0c;\u5355\u4f4d rad&#034;<br \/>\n    elif joint_type &#061;&#061; mujoco.mjtJoint.mjJNT_SLIDE:<br \/>\n        description &#061; &#034;\u6ed1\u52a8\u5173\u8282&#xff0c;\u5355\u4f4d m&#034;<br \/>\n    else:<br \/>\n        description &#061; f&#034;\u5176\u4ed6\u5173\u8282\u7c7b\u578b {joint_type}&#034;<\/p>\n<p>    print(name, description, &#034;\u9650\u4f4d&#034;, model.jnt_range[index])<\/p>\n<p>print(&#034;\\\\n&#061;&#061;&#061; \u6267\u884c\u5668\u4e0e\u521d\u59cb\u63a7\u5236\u503c &#061;&#061;&#061;&#034;)<br \/>\nfor index in range(model.nu):<br \/>\n    name &#061; mujoco.mj_id2name(<br \/>\n        model, mujoco.mjtObj.mjOBJ_ACTUATOR, index<br \/>\n    )<br \/>\n    print(name, &#034;\u521d\u59cb ctrl: &#034;, data.ctrl[index])<\/p>\n<p># \u6838\u5bf9\u5f53\u524d\u9009\u7528\u7684\u6a21\u578b\u7ed3\u6784<br \/>\nassert (model.njnt, model.nq, model.nu) &#061;&#061; (8, 8, 7)<\/p>\n<p># MuJoCo \u539f\u751f\u67e5\u770b\u5668\u8d1f\u8d23\u63a8\u8fdb\u7269\u7406\u4eff\u771f<br \/>\nmujoco.viewer.launch(model, data)<\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>(libero) dukiya&#064;dukiya-XiaoXinPro-14-APH8:~\/libero-learning\/week4$ python -u A2_piper_model.py<br \/>\n&#061;&#061;&#061; Piper \u6a21\u578b\u4fe1\u606f &#061;&#061;&#061;<br \/>\n\u6a21\u578b\u8def\u5f84: \/home\/dukiya\/libero-learning\/week4\/assets\/mujoco_menagerie\/agilex_piper\/scene.xml<br \/>\nMuJoCo \u7248\u672c: 3.3.7<br \/>\n\u5173\u8282\u6570 njnt: 8<br \/>\n\u4f4d\u7f6e\u72b6\u6001\u957f\u5ea6 nq: 8<br \/>\n\u901f\u5ea6\u72b6\u6001\u957f\u5ea6 nv: 8<br \/>\n\u6267\u884c\u5668\u6570 nu: 7<br \/>\n\u7269\u7406\u6b65\u957f dt: 0.002<\/p>\n<p>&#061;&#061;&#061; \u5173\u8282\u540d\u79f0\u4e0e\u9650\u4f4d &#061;&#061;&#061;<br \/>\njoint1 \u8f6c\u52a8\u5173\u8282&#xff0c;\u5355\u4f4d rad \u9650\u4f4d [-2.618  2.618]<br \/>\njoint2 \u8f6c\u52a8\u5173\u8282&#xff0c;\u5355\u4f4d rad \u9650\u4f4d [0.   3.14]<br \/>\njoint3 \u8f6c\u52a8\u5173\u8282&#xff0c;\u5355\u4f4d rad \u9650\u4f4d [-2.697  0.   ]<br \/>\njoint4 \u8f6c\u52a8\u5173\u8282&#xff0c;\u5355\u4f4d rad \u9650\u4f4d [-1.832  1.832]<br \/>\njoint5 \u8f6c\u52a8\u5173\u8282&#xff0c;\u5355\u4f4d rad \u9650\u4f4d [-1.22  1.22]<br \/>\njoint6 \u8f6c\u52a8\u5173\u8282&#xff0c;\u5355\u4f4d rad \u9650\u4f4d [-3.14  3.14]<br \/>\njoint7 \u6ed1\u52a8\u5173\u8282&#xff0c;\u5355\u4f4d m \u9650\u4f4d [0.    0.035]<br \/>\njoint8 \u6ed1\u52a8\u5173\u8282&#xff0c;\u5355\u4f4d m \u9650\u4f4d [-0.035  0.   ]<\/p>\n<p>&#061;&#061;&#061; \u6267\u884c\u5668\u4e0e\u521d\u59cb\u63a7\u5236\u503c &#061;&#061;&#061;<br \/>\njoint1 \u521d\u59cb ctrl:  0.0<br \/>\njoint2 \u521d\u59cb ctrl:  1.57<br \/>\njoint3 \u521d\u59cb ctrl:  -1.3485<br \/>\njoint4 \u521d\u59cb ctrl:  0.0<br \/>\njoint5 \u521d\u59cb ctrl:  0.0<br \/>\njoint6 \u521d\u59cb ctrl:  0.0<br \/>\ngripper \u521d\u59cb ctrl:  0.0<br \/>\n\/home\/dukiya\/venvs\/libero\/lib\/python3.10\/site-packages\/glfw\/__init__.py:917: GLFWError: (65548) b&#039;Wayland: The platform does not provide the window position&#039;<br \/>\n  warnings.warn(message, GLFWError)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"815\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020718-6ad96fd6d7d4d.png\" width=\"1280\" \/><\/p>\n<p>\u53ef\u4ee5\u770b\u5230&#xff0c;piper\u4e3a6\u4e2a\u5173\u8282\u52a01\u4e2a\u5939\u722a\u7ec4\u6210\u3002<\/p>\n<hr \/>\n<h3>3. \u5b9e\u73b0\u952e\u76d8\u9a71\u52a8piper<\/h3>\n<p>\u6211\u4eec\u540c\u6837\u662f\u8981\u57fa\u4e8erobosuite\u7684\u952e\u76d8\u63a5\u53e3\u505a\u8fd9\u4e2a\u9700\u6c42&#xff0c;\u7531\u4e8erobosuite\u5e76\u6ca1\u6709\u63d0\u524d\u9002\u914d\u597dpiper&#xff0c;\u56e0\u6b64\u6211\u4eec\u9700\u8981\u5199\u597d\u5bf9\u5e94\u7684\u9002\u914d\u63a5\u5165robosuite&#xff0c;\u5e76\u5b9e\u73b0\u5bf9\u5e94\u7684\u63a7\u5236\u903b\u8f91\u8ba9\u952e\u76d8\u63a7\u5236piper\u52a8\u8d77\u6765\u3002<\/p>\n<h4>3.1. \u8f93\u51fa\u80fd\u88abrobosuite\u65f6\u7528\u7684\u673a\u68b0\u81c2xml\u548c\u5939\u722axml<\/h4>\n<p>\u8fd9\u4e00\u6b65\u5176\u5b9e\u53ea\u662f\u505a\u4e00\u4e9b\u683c\u5f0f\u7684\u8f6c\u6362\u548c\u6807\u7b7e\u8865\u9f50\u3002\u539f\u59cb\u7684piper\u6a21\u578b\u80fd\u591f\u88abmujoco\u8bfb\u53d6&#xff0c;\u4f46\u8fd8\u4e0d\u6ee1\u8db3robosuite\u8bfb\u53d6&#xff0c;\u6211\u4eec\u53ea\u9700\u8981\u5efa\u7acb\u811a\u672c\u8fdb\u884c\u8f6c\u6362\u5c31\u884c&#xff1a;<\/p>\n<p>from copy import deepcopy<br \/>\nfrom pathlib import Path<br \/>\nimport xml.etree.ElementTree as ET<\/p>\n<p>from robosuite.models.base import MujocoXML<\/p>\n<p>project &#061; Path(__file__).resolve().parent<br \/>\nsource_dir &#061; project \/ &#034;assets\/mujoco_menagerie\/agilex_piper&#034;<br \/>\noutput_dir &#061; project \/ &#034;assets\/piper_robosuite&#034;<br \/>\noutput_dir.mkdir(parents&#061;True, exist_ok&#061;True)<\/p>\n<p>source &#061; ET.parse(source_dir \/ &#034;piper.xml&#034;).getroot()<\/p>\n<p># 1. \u5c55\u5f00\u5d4c\u5957 default \u548c childclass<br \/>\n# robosuite 1.4.0 \u7684\u8bfb\u53d6\u5668\u4e0d\u80fd\u76f4\u63a5\u5904\u7406\u539f\u6a21\u578b\u7684\u8fd9\u5957\u5d4c\u5957\u914d\u7f6e<br \/>\ndefaults &#061; {}<\/p>\n<p>def collect_defaults(node, inherited):<br \/>\n    settings &#061; deepcopy(inherited)<\/p>\n<p>    for child in node:<br \/>\n        if child.tag !&#061; &#034;default&#034;:<br \/>\n            settings.setdefault(child.tag, {}).update(child.attrib)<\/p>\n<p>    defaults[node.get(&#034;class&#034;, &#034;main&#034;)] &#061; settings<\/p>\n<p>    for child in node.findall(&#034;default&#034;):<br \/>\n        collect_defaults(child, settings)<\/p>\n<p>def expand_defaults(node, inherited_class&#061;&#034;main&#034;):<br \/>\n    class_name &#061; node.attrib.pop(&#034;class&#034;, inherited_class)<\/p>\n<p>    for key, value in defaults[class_name].get(node.tag, {}).items():<br \/>\n        node.attrib.setdefault(key, value)<\/p>\n<p>    child_class &#061; node.attrib.pop(&#034;childclass&#034;, inherited_class)<\/p>\n<p>    for child in node:<br \/>\n        expand_defaults(child, child_class)<\/p>\n<p>default_node &#061; source.find(&#034;default&#034;)<br \/>\nassert default_node is not None<\/p>\n<p>collect_defaults(default_node, {})<br \/>\nsource.remove(default_node)<br \/>\nexpand_defaults(source)<\/p>\n<p># 2. \u660e\u786e\u7f51\u683c\u540d\u79f0\u548c\u6587\u4ef6\u8def\u5f84<br \/>\n# \u539f\u6a21\u578b\u6709\u4e9b mesh \u6ca1\u5199 name&#xff0c;MuJoCo \u4f1a\u81ea\u52a8\u547d\u540d&#xff0c;<br \/>\n# \u4f46 robosuite \u6dfb\u52a0\u673a\u5668\u4eba\u524d\u7f00\u65f6\u9700\u8981\u660e\u786e\u7684\u540d\u79f0<br \/>\nsource.find(&#034;compiler&#034;).attrib.pop(&#034;meshdir&#034;, None)<\/p>\n<p>for mesh in source.findall(&#034;asset\/mesh&#034;):<br \/>\n    original_file &#061; mesh.get(&#034;file&#034;)<br \/>\n    mesh.attrib.setdefault(&#034;name&#034;, Path(original_file).stem)<br \/>\n    mesh.set(<br \/>\n        &#034;file&#034;,<br \/>\n        str((source_dir \/ &#034;assets&#034; \/ original_file).resolve()),<br \/>\n    )<\/p>\n<p># 3. \u8865\u51e0\u4f55\u4f53\u540d\u79f0&#xff0c;\u5e76\u6362\u6210 robosuite \u7684\u663e\u793a\u5206\u7ec4<br \/>\n# group&#061;0&#xff1a;\u78b0\u649e\u51e0\u4f55&#xff1b;group&#061;1&#xff1a;\u89c6\u89c9\u51e0\u4f55<br \/>\nfor body in source.iter(&#034;body&#034;):<br \/>\n    body.attrib.pop(&#034;gravcomp&#034;, None)<\/p>\n<p>    for index, geom in enumerate(body.findall(&#034;geom&#034;)):<br \/>\n        geom.attrib.setdefault(<br \/>\n            &#034;name&#034;, f&#034;{body.get(&#039;name&#039;)}_geom_{index}&#034;<br \/>\n        )<br \/>\n        is_visual &#061; (<br \/>\n            geom.get(&#034;contype&#034;, &#034;1&#034;) &#061;&#061; &#034;0&#034;<br \/>\n            and geom.get(&#034;conaffinity&#034;, &#034;1&#034;) &#061;&#061; &#034;0&#034;<br \/>\n        )<br \/>\n        geom.set(&#034;group&#034;, &#034;1&#034; if is_visual else &#034;0&#034;)<\/p>\n<p>arm &#061; deepcopy(source)<br \/>\ngripper &#061; deepcopy(source)<\/p>\n<p># 4. \u673a\u68b0\u81c2&#xff1a;\u79fb\u9664\u4e24\u6839\u624b\u6307&#xff0c;\u6dfb\u52a0\u5939\u722a\u5b89\u88c5\u4f4d\u7f6e<br \/>\nwrist &#061; arm.find(&#034;.\/\/body[&#064;name&#061;&#039;link6&#039;]&#034;)<br \/>\nassert wrist is not None<\/p>\n<p>for name in [&#034;link7&#034;, &#034;link8&#034;]:<br \/>\n    finger &#061; wrist.find(f&#034;body[&#064;name&#061;&#039;{name}&#039;]&#034;)<br \/>\n    assert finger is not None<br \/>\n    wrist.remove(finger)<\/p>\n<p>hand &#061; ET.SubElement(<br \/>\n    wrist, &#034;body&#034;, name&#061;&#034;right_hand&#034;, pos&#061;&#034;0 0 0&#034;<br \/>\n)<\/p>\n<p># \u8155\u90e8\u76f8\u673a\u5148\u7ed9\u4e00\u4e2a\u521d\u59cb\u914d\u7f6e&#xff0c;\u8fdb\u5165\u573a\u666f\u540e\u518d\u8c03\u6574\u53d6\u666f<br \/>\nET.SubElement(<br \/>\n    hand,<br \/>\n    &#034;camera&#034;,<br \/>\n    name&#061;&#034;eye_in_hand&#034;,<br \/>\n    pos&#061;&#034;0.04 0 0.025&#034;,<br \/>\n    quat&#061;&#034;0 1 0 0&#034;,<br \/>\n    fovy&#061;&#034;80&#034;,<br \/>\n)<\/p>\n<p># \u539f\u6765\u7684\u706f\u6307\u5411 link8&#xff1b;\u624b\u6307\u62c6\u8d70\u540e\u4e0d\u518d\u4fdd\u7559\u8be5\u706f<br \/>\nworld &#061; arm.find(&#034;worldbody&#034;)<br \/>\nfor light in list(world.findall(&#034;light&#034;)):<br \/>\n    world.remove(light)<\/p>\n<p>for tag in [&#034;equality&#034;, &#034;keyframe&#034;]:<br \/>\n    node &#061; arm.find(tag)<br \/>\n    if node is not None:<br \/>\n        arm.remove(node)<\/p>\n<p># \u516d\u4e2a\u673a\u68b0\u81c2\u6267\u884c\u5668\u6539\u4e3a\u529b\u77e9\u63a7\u5236<br \/>\nactuators &#061; arm.find(&#034;actuator&#034;)<br \/>\nactuators.clear()<\/p>\n<p>for index in range(1, 7):<br \/>\n    ET.SubElement(<br \/>\n        actuators,<br \/>\n        &#034;motor&#034;,<br \/>\n        name&#061;f&#034;joint{index}&#034;,<br \/>\n        joint&#061;f&#034;joint{index}&#034;,<br \/>\n        gear&#061;&#034;1&#034;,<br \/>\n        ctrllimited&#061;&#034;true&#034;,<br \/>\n        ctrlrange&#061;&#034;-100 100&#034;,<br \/>\n        forcelimited&#061;&#034;true&#034;,<br \/>\n        forcerange&#061;&#034;-100 100&#034;,<br \/>\n    )<\/p>\n<p># 5. \u5939\u722a&#xff1a;\u4fdd\u7559\u539f\u6765\u7684\u4e24\u6839\u624b\u6307\u4e0e\u8054\u52a8\u7ea6\u675f<br \/>\noriginal_wrist &#061; gripper.find(&#034;.\/\/body[&#064;name&#061;&#039;link6&#039;]&#034;)<br \/>\nfingers &#061; [<br \/>\n    deepcopy(original_wrist.find(f&#034;body[&#064;name&#061;&#039;{name}&#039;]&#034;))<br \/>\n    for name in [&#034;link7&#034;, &#034;link8&#034;]<br \/>\n]<\/p>\n<p>gripper_world &#061; gripper.find(&#034;worldbody&#034;)<br \/>\ngripper_world.clear()<br \/>\ngripper_body &#061; ET.SubElement(<br \/>\n    gripper_world, &#034;body&#034;, name&#061;&#034;right_gripper&#034;, pos&#061;&#034;0 0 0&#034;<br \/>\n)<\/p>\n<p>for finger, side in zip(fingers, [&#034;left&#034;, &#034;right&#034;]):<br \/>\n    boxes &#061; [<br \/>\n        geom for geom in finger.findall(&#034;geom&#034;)<br \/>\n        if geom.get(&#034;type&#034;) &#061;&#061; &#034;box&#034;<br \/>\n    ]<br \/>\n    assert len(boxes) &#061;&#061; 2<\/p>\n<p>    boxes[0].set(&#034;name&#034;, f&#034;{side}_finger_collision&#034;)<br \/>\n    boxes[1].set(&#034;name&#034;, f&#034;{side}_fingerpad_collision&#034;)<br \/>\n    gripper_body.append(finger)<\/p>\n<p>for tag in [&#034;contact&#034;, &#034;keyframe&#034;]:<br \/>\n    node &#061; gripper.find(tag)<br \/>\n    if node is not None:<br \/>\n        gripper.remove(node)<\/p>\n<p>gripper_actuators &#061; gripper.find(&#034;actuator&#034;)<br \/>\nposition_actuator &#061; deepcopy(<br \/>\n    gripper_actuators.find(&#034;position[&#064;name&#061;&#039;gripper&#039;]&#034;)<br \/>\n)<br \/>\nassert position_actuator is not None<\/p>\n<p>gripper_actuators.clear()<br \/>\nposition_actuator.attrib.pop(&#034;inheritrange&#034;, None)<br \/>\nposition_actuator.set(&#034;ctrllimited&#034;, &#034;true&#034;)<br \/>\nposition_actuator.set(&#034;ctrlrange&#034;, &#034;0 0.035&#034;)<br \/>\ngripper_actuators.append(position_actuator)<\/p>\n<p># 6. \u6dfb\u52a0 robosuite \u9700\u8981\u7684\u672b\u7aef\u6807\u8bb0\u548c\u529b\/\u529b\u77e9\u4f20\u611f\u5668<br \/>\n# 0.09003 &#061; \u624b\u6307\u5b89\u88c5\u4f4d\u7f6e 0.13503 &#8211; \u8fdc\u7aef\u5939\u6301\u5757\u504f\u79fb 0.045<br \/>\neef &#061; ET.SubElement(<br \/>\n    gripper_body, &#034;body&#034;, name&#061;&#034;eef&#034;, pos&#061;&#034;0 0 0.09003&#034;<br \/>\n)<\/p>\n<p>for name, position in [<br \/>\n    (&#034;grip_site&#034;, &#034;0 0 0&#034;),<br \/>\n    (&#034;ee&#034;, &#034;0 0 0&#034;),<br \/>\n    (&#034;ee_x&#034;, &#034;0.03 0 0&#034;),<br \/>\n    (&#034;ee_y&#034;, &#034;0 0.03 0&#034;),<br \/>\n    (&#034;ee_z&#034;, &#034;0 0 0.03&#034;),<br \/>\n]:<br \/>\n    ET.SubElement(<br \/>\n        eef, &#034;site&#034;, name&#061;name, pos&#061;position,<br \/>\n        type&#061;&#034;sphere&#034;, size&#061;&#034;0.004&#034;, group&#061;&#034;1&#034;,<br \/>\n    )<\/p>\n<p>ET.SubElement(<br \/>\n    eef, &#034;site&#034;, name&#061;&#034;grip_site_cylinder&#034;,<br \/>\n    type&#061;&#034;cylinder&#034;, size&#061;&#034;0.003 0.03&#034;, group&#061;&#034;1&#034;,<br \/>\n)<\/p>\n<p>ET.SubElement(<br \/>\n    gripper_body, &#034;site&#034;, name&#061;&#034;ft_frame&#034;,<br \/>\n    pos&#061;&#034;0 0 0&#034;, size&#061;&#034;0.004&#034;, group&#061;&#034;1&#034;,<br \/>\n)<\/p>\n<p>sensors &#061; gripper.find(&#034;sensor&#034;)<br \/>\nif sensors is None:<br \/>\n    sensors &#061; ET.SubElement(gripper, &#034;sensor&#034;)<\/p>\n<p>ET.SubElement(sensors, &#034;force&#034;, name&#061;&#034;force_ee&#034;, site&#061;&#034;ft_frame&#034;)<br \/>\nET.SubElement(sensors, &#034;torque&#034;, name&#061;&#034;torque_ee&#034;, site&#061;&#034;ft_frame&#034;)<\/p>\n<p># 7. \u5220\u9664\u5404\u90e8\u5206\u4e0d\u518d\u4f7f\u7528\u7684\u7f51\u683c\u3001\u6750\u8d28<br \/>\ndef trim_assets(root):<br \/>\n    meshes &#061; {<br \/>\n        geom.get(&#034;mesh&#034;) for geom in root.iter(&#034;geom&#034;)<br \/>\n        if geom.get(&#034;mesh&#034;) is not None<br \/>\n    }<br \/>\n    materials &#061; {<br \/>\n        geom.get(&#034;material&#034;) for geom in root.iter(&#034;geom&#034;)<br \/>\n        if geom.get(&#034;material&#034;) is not None<br \/>\n    }<\/p>\n<p>    assets &#061; root.find(&#034;asset&#034;)<br \/>\n    for item in list(assets):<br \/>\n        unused_mesh &#061; (<br \/>\n            item.tag &#061;&#061; &#034;mesh&#034; and item.get(&#034;name&#034;) not in meshes<br \/>\n        )<br \/>\n        unused_material &#061; (<br \/>\n            item.tag &#061;&#061; &#034;material&#034;<br \/>\n            and item.get(&#034;name&#034;) not in materials<br \/>\n        )<br \/>\n        if unused_mesh or unused_material:<br \/>\n            assets.remove(item)<\/p>\n<p>trim_assets(arm)<br \/>\ntrim_assets(gripper)<\/p>\n<p># \u5df2\u6709\u6587\u4ef6\u5982\u679c\u5185\u5bb9\u4e0d\u540c&#xff0c;\u5219\u505c\u6b62&#xff0c;\u907f\u514d\u8986\u76d6\u540e\u7eed\u624b\u52a8\u4fee\u6539<br \/>\ndef save_text(path, text):<br \/>\n    if path.exists():<br \/>\n        if path.read_text(encoding&#061;&#034;utf-8&#034;) !&#061; text:<br \/>\n            raise FileExistsError(<br \/>\n                f&#034;{path} \u5df2\u5b58\u5728\u4e14\u5185\u5bb9\u4e0d\u540c&#xff0c;\u8bf7\u5148\u5907\u4efd\u518d\u91cd\u65b0\u751f\u6210&#034;<br \/>\n            )<br \/>\n    else:<br \/>\n        path.write_text(text, encoding&#061;&#034;utf-8&#034;)<\/p>\n<p>for root, filename in [<br \/>\n    (arm, &#034;piper_arm.xml&#034;),<br \/>\n    (gripper, &#034;piper_gripper.xml&#034;),<br \/>\n]:<br \/>\n    ET.indent(root, space&#061;&#034;  &#034;)<br \/>\n    save_text(<br \/>\n        output_dir \/ filename,<br \/>\n        ET.tostring(root, encoding&#061;&#034;unicode&#034;),<br \/>\n    )<\/p>\n<p>save_text(<br \/>\n    output_dir \/ &#034;LICENSE&#034;,<br \/>\n    (source_dir \/ &#034;LICENSE&#034;).read_text(encoding&#061;&#034;utf-8&#034;),<br \/>\n)<\/p>\n<p># 8. \u7528 robosuite \u8bfb\u53d6&#xff0c;\u518d\u7531 MuJoCo \u7f16\u8bd1&#xff0c;\u68c0\u67e5\u62c6\u5206\u548c\u5408\u5e76\u7ed3\u6784<br \/>\narm_xml &#061; MujocoXML(str(output_dir \/ &#034;piper_arm.xml&#034;))<br \/>\ngripper_xml &#061; MujocoXML(str(output_dir \/ &#034;piper_gripper.xml&#034;))<\/p>\n<p>arm_model &#061; arm_xml.get_model()<br \/>\ngripper_model &#061; gripper_xml.get_model()<\/p>\n<p>print(&#034;\u673a\u68b0\u81c2 nq \/ nu:&#034;, arm_model.nq, arm_model.nu)<br \/>\nprint(&#034;\u5939\u722a nq \/ nu:&#034;, gripper_model.nq, gripper_model.nu)<\/p>\n<p>assert (arm_model.nq, arm_model.nu) &#061;&#061; (6, 6)<br \/>\nassert (gripper_model.nq, gripper_model.nu) &#061;&#061; (2, 1)<\/p>\n<p>arm_xml.merge(gripper_xml, merge_body&#061;&#034;right_hand&#034;)<br \/>\ncombined &#061; arm_xml.get_model()<\/p>\n<p>print(&#034;\u5408\u5e76\u540e nq \/ nu:&#034;, combined.nq, combined.nu)<br \/>\nassert (combined.nq, combined.nu) &#061;&#061; (8, 7)<\/p>\n<p>print(&#034;\u9002\u914d\u6587\u4ef6\u76ee\u5f55:&#034;, output_dir)<br \/>\nprint(&#034;A3_PIPER_XML_OK&#034;)<\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>(libero) dukiya&#064;dukiya-XiaoXinPro-14-APH8:~\/libero-learning\/week4$ \/home\/dukiya\/venvs\/libero\/bin\/python \/home\/dukiya\/libero-learning\/week4\/A3_1_prepare_piper.py<br \/>\n[robosuite WARNING] No private macro file found! (__init__.py:7)<br \/>\n[robosuite WARNING] It is recommended to use a private macro file (__init__.py:8)<br \/>\n[robosuite WARNING] To setup, run: python \/home\/dukiya\/venvs\/libero\/lib\/python3.10\/site-packages\/robosuite\/scripts\/setup_macros.py (__init__.py:9)<br \/>\n\u673a\u68b0\u81c2 nq \/ nu: 6 6<br \/>\n\u5939\u722a nq \/ nu: 2 1<br \/>\n\u5408\u5e76\u540e nq \/ nu: 8 7<br \/>\n\u9002\u914d\u6587\u4ef6\u76ee\u5f55: \/home\/dukiya\/libero-learning\/week4\/assets\/piper_robosuite<br \/>\nA3_PIPER_XML_OK<\/p>\n<p>\u6838\u5fc3\u6539\u53d8\u5982\u4e0b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"646\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020719-6ad96fd74b03b.png\" width=\"2364\" \/><\/p>\n<h4>3.2. \u6ce8\u518cpiper<\/h4>\n<p>\u5f97\u5230\u4e86\u80fd\u88abrobosuite\u8bc6\u522b\u7684xml&#xff0c;\u6211\u4eec\u4e0b\u4e00\u6b65\u5c31\u9700\u8981\u8fdb\u884c\u76f8\u5e94\u7684\u6ce8\u518c&#xff0c;\u8ba9\u6700\u540e\u4e66\u5199\u53c2\u6570robots&#061;[&#034;Piper&#034;]\u80fd\u6210\u529f\u88ab\u7cfb\u7edf\u8bc6\u522b\u3002<\/p>\n<p>\u6ce8\u518c\u7c7b&#xff1a;<\/p>\n<p>from pathlib import Path<br \/>\nimport numpy as np<br \/>\nfrom robosuite.models.robots.manipulators.manipulator_model import ManipulatorModel<br \/>\nfrom robosuite.models.grippers.gripper_model import GripperModel<br \/>\nfrom robosuite.models.grippers import GRIPPER_MAPPING<br \/>\nfrom robosuite.robots import ROBOT_CLASS_MAPPING, SingleArm<\/p>\n<p># \u5728robosuite\u4e2d\u6ce8\u518cpiper\u8fd9\u4e2a\u5168\u65b0\u7684\u673a\u68b0\u81c2<br \/>\nMODEL_DIR &#061; (<br \/>\n    Path(__file__).resolve().parent<br \/>\n    \/ &#034;assets&#034;<br \/>\n    \/ &#034;piper_robosuite&#034;<br \/>\n)<\/p>\n<p>class PiperGripper(GripperModel):<br \/>\n    def __init__(self, idn&#061;0):<br \/>\n        super().__init__(<br \/>\n            str(MODEL_DIR \/ &#034;piper_gripper.xml&#034;),<br \/>\n            idn&#061;idn,<br \/>\n        )<\/p>\n<p>    &#064;property<br \/>\n    # &#064;property\u53ef\u4ee5\u8ba9\u4e00\u4e2a\u65b9\u6cd5\u4f2a\u88c5\u6210\u5c5e\u6027\u6765\u4f7f\u7528&#xff0c;\u8bbf\u95ee\u65f6\u4e0d\u7528\u518d\u52a0\u62ec\u53f7<br \/>\n    def init_qpos(self):<br \/>\n        # \u4e24\u6839\u624b\u6307\u7684\u4f4d\u7f6e&#xff1a;\u521d\u59cb\u5b8c\u5168\u5f20\u5f00<br \/>\n        return np.array([0.035, -0.035])<\/p>\n<p>    def format_action(self, action):<br \/>\n        action &#061; np.asarray(action, dtype&#061;float)<br \/>\n        assert action.shape &#061;&#061; (1, )<br \/>\n        # robosuite\u4e0b&#xff0c;\u7ed9\u5939\u722a-1\u8868\u793a\u5f20\u5f00&#xff0c;&#043;1\u8868\u793a\u95ed\u5408<br \/>\n        # \u5bf9piper xml\u6765\u8bb2&#xff0c;\u63a7\u5236\u503c\u8d8a\u5927&#xff0c;\u5939\u722a\u5f20\u7684\u8d8a\u5f00<br \/>\n        # \u56e0\u6b64\u53cd\u8f6c\u7b26\u53f7, \u6846\u67b6\u968f\u540e\u4f1a\u6620\u5c04\u5230 [0, 0.035] \u7c73<br \/>\n        # clip\u7528\u4e8e\u6536\u7d27\u8303\u56f4&#xff0c;\u4e0d\u7ba1\u53d6\u503c\u4e3a\u591a\u5c11&#xff0c;\u6700\u7ec8\u7684\u8303\u56f4\u53ea\u80fd\u5728-1&#xff0c;&#043;1\u4e4b\u95f4<br \/>\n        self.current_action &#061; -np.clip(action, -1.0, 1.0)<br \/>\n        return self.current_action<\/p>\n<p>    &#064;property<br \/>\n    def _important_geoms(self):<br \/>\n        # \u6307\u5b9a\u54ea\u4e9b\u78b0\u649e\u4f53\u662f\u624b\u6307\u3001\u54ea\u4e9b\u662f\u5939\u6301\u9762<br \/>\n        return {<br \/>\n            &#034;left_finger&#034;:[<br \/>\n                &#034;left_finger_collision&#034;,<br \/>\n                &#034;left_fingerpad_collision&#034;,<br \/>\n            ],<br \/>\n            &#034;right_finger&#034;:[<br \/>\n                &#034;right_finger_collision&#034;,<br \/>\n                &#034;right_fingerpad_collision&#034;,<br \/>\n            ],<br \/>\n            &#034;left_fingerpad&#034;:[&#034;left_fingerpad_collision&#034;],<br \/>\n            &#034;right_fingerpad&#034;:[&#034;right_fingerpad_collision&#034;],<br \/>\n        }<\/p>\n<p>class Piper(ManipulatorModel):<br \/>\n    def __init__(self, idn&#061;0):<br \/>\n        super().__init__(<br \/>\n            str(MODEL_DIR \/ &#034;piper_arm.xml&#034;),<br \/>\n            idn&#061;idn,<br \/>\n        )<\/p>\n<p>        # \u8155\u90e8\u76f8\u673a&#xff1a;\u5411\u4fa7\u9762\u79fb\u5f00&#xff0c;\u5e76\u671d\u5411\u5939\u722a\u524d\u65b9<br \/>\n        camera_name &#061; self.correct_naming(&#034;eye_in_hand&#034;)<br \/>\n        camera &#061; self.worldbody.find(<br \/>\n            f&#034;.\/\/camera[&#064;name&#061;&#039;{camera_name}&#039;]&#034;<br \/>\n        )<br \/>\n        assert camera is not None<\/p>\n<p>        # \u8bbe\u7f6e\u624b\u8155\u76f8\u673a\u4f4d\u7f6e<br \/>\n        camera.set(&#034;pos&#034;, &#034;0.06 0 0.04&#034;)<br \/>\n        camera.set(&#034;quat&#034;, &#034;0 0.97324898946773 0 0.22975292054736&#034;)<\/p>\n<p>        # \u7ed9\u673a\u68b0\u81c2\u76846\u4e2a\u5173\u8282\u8bbe\u7f6e\u7edf\u4e000.1\u7684\u963b\u5c3c\u7cfb\u6570<br \/>\n        self.set_joint_attribute(<br \/>\n            attrib&#061;&#034;damping&#034;,<br \/>\n            values&#061;np.full(6, 0.1),<br \/>\n        )<\/p>\n<p>    &#064;property<br \/>\n    def default_mount(self):<br \/>\n        # \u76f4\u63a5\u56fa\u5b9a\u5728\u684c\u9762&#xff0c;\u4e0d\u4f7f\u7528 Panda \u7684\u652f\u6491\u67b6<br \/>\n        return None<\/p>\n<p>    &#064;property<br \/>\n    def default_gripper(self):<br \/>\n        return &#034;PiperGripper&#034;<\/p>\n<p>    &#064;property<br \/>\n    def default_controller_config(self):<br \/>\n        return &#034;osc_pose&#034;<\/p>\n<p>    &#064;property<br \/>\n    def init_qpos(self):<br \/>\n        # \u57fa\u4e8e\u539f\u6a21\u578b home \u59ff\u6001&#xff0c;\u7a0d\u5fae\u5f2f\u66f2\u7b2c\u4e94\u5173\u8282<br \/>\n        # \u907f\u514d\u521d\u59cb\u8155\u90e8\u5b8c\u5168\u4f38\u76f4&#xff1b;\u4e0d\u662f\u6700\u7ec8\u6293\u53d6\u59ff\u6001<br \/>\n        return np.array([0.0, 1.57, -1.3485, 0.0, 0.35, 0.0])<\/p>\n<p>    # \u4e0b\u9762\u56db\u4e2a\u5c5e\u6027\u8ba9robosuite\u77e5\u9053\u4e86\u673a\u68b0\u81c2\u7684\u5305\u56f4\u8303\u56f4<br \/>\n    &#064;property<br \/>\n    # \u51b3\u5b9a\u673a\u68b0\u81c2\u653e\u5728\u54ea<br \/>\n    def base_xpos_offset(self):<br \/>\n        return {<br \/>\n            # \u5f53\u524d\u9ed1\u7897\u573a\u666f\u684c\u9762\u9ad8 0.90 \u7c73<br \/>\n            # \u5e95\u5ea7\u653e\u5728\u684c\u9762\u7684\u8d1f x \u8fb9\u7f18\u9644\u8fd1&#xff0c;\u671d\u5411\u6b63 x<br \/>\n            &#034;table&#034;: lambda table_length: (<br \/>\n                -table_length \/ 2 &#043; 0.05,<br \/>\n                0.0,<br \/>\n                0.90,<br \/>\n            ),<br \/>\n        }<\/p>\n<p>    &#064;property<br \/>\n    # \u673a\u68b0\u81c2\u6700\u9ad8\u70b9\u5927\u7ea6\u5728\u5e95\u5ea7\u4e0a\u65b9 0.9 \u7c73\u5904<br \/>\n    def top_offset(self):<br \/>\n        return np.array([0.0, 0.0, 0.9])<\/p>\n<p>    &#064;property<br \/>\n    # \u673a\u68b0\u81c2\u6c34\u5e73\u65b9\u5411\u534a\u5f84<br \/>\n    def _horizontal_radius(self):<br \/>\n        return 0.9<\/p>\n<p>    &#064;property<br \/>\n    def horizontal_radius(self):<br \/>\n        # \u6ca1\u6709 mount \u65f6&#xff0c;\u907f\u514d\u7236\u7c7b\u8bbf\u95ee mount.horizontal_radius<br \/>\n        return self._horizontal_radius<\/p>\n<p>    &#064;property<br \/>\n    def arm_type(self):<br \/>\n        return &#034;single&#034;<\/p>\n<p>class MountedPiper(Piper):<br \/>\n    pass<\/p>\n<p># \u52a0\u5165robosuite\u5939\u722a\u6ce8\u518c\u8868<br \/>\nGRIPPER_MAPPING[&#034;PiperGripper&#034;] &#061; PiperGripper<br \/>\n# \u52a0\u5165\u673a\u68b0\u81c2\u6ce8\u518c\u8868&#xff0c;SingleArm\u4ee3\u8868\u8fd0\u884c\u65f6\u7c7b<br \/>\nROBOT_CLASS_MAPPING.update({<br \/>\n    &#034;Piper&#034;: SingleArm,<br \/>\n    &#034;MountedPiper&#034;: SingleArm,<br \/>\n})<\/p>\n<p>\u7ee7\u627frobotsuite\u7684\u76f8\u5173\u7c7b&#xff0c;\u628a\u4fe1\u606f\u6539\u6210piper\u5c31\u5b9e\u73b0\u4e86\u6ce8\u518c\u3002<\/p>\n<h4>3.3. \u63a5\u5165\u952e\u76d8\u63a7\u5236<\/h4>\n<p>\u7528\u5982\u4e0b\u4ee3\u7801\u5b9e\u73b0\u952e\u76d8\u63a7\u5236piper&#xff1a;<\/p>\n<p>import time<br \/>\nfrom pathlib import Path<br \/>\nimport cv2<br \/>\nfrom robosuite import macros<\/p>\n<p>import numpy as np<br \/>\nimport piper_robot<\/p>\n<p>from libero.libero import benchmark, get_libero_path<br \/>\nfrom libero.libero.envs.env_wrapper import ControlEnv<br \/>\n# \u7528robosuite\u5b9a\u4e49\u952e\u76d8\u8f93\u5165\u8bbe\u5907\u548c\u52a8\u4f5c\u6620\u5c04<br \/>\nfrom robosuite.devices import Keyboard<br \/>\nfrom robosuite.utils.input_utils import input2action<br \/>\nfrom robosuite.utils import transform_utils as T<\/p>\n<p># \u952e\u76d8\u589e\u91cf\u5230\u76ee\u6807\u4f4d\u59ff\u7684\u7f29\u653e&#xff1b;\u53ef\u4ee5\u5728\u624b\u611f\u6d4b\u8bd5\u540e\u8c03\u6574<br \/>\nPOSITION_GAIN &#061; 0.01<br \/>\nROTATION_GAIN &#061; 0.5<br \/>\n# \u9650\u5236\u76ee\u6807\u9886\u5148\u5b9e\u9645\u672b\u7aef\u7684\u8ddd\u79bb\u548c\u89d2\u5ea6&#xff0c;\u907f\u514d\u79ef\u7d2f\u4e0d\u53ef\u8fbe\u76ee\u6807<br \/>\nMAX_POSITION_LEAD &#061; 0.03<br \/>\nMAX_ROTATION_LEAD &#061; 0.2<\/p>\n<p>suite &#061; benchmark.get_benchmark_dict()[&#034;libero_spatial&#034;]()<br \/>\ntask &#061; suite.get_task(0)<\/p>\n<p>bddl_path &#061; (<br \/>\n    Path(get_libero_path(&#034;bddl_files&#034;)) # \u7b2c 1 \u90e8\u5206&#xff1a;\u6839\u76ee\u5f55<br \/>\n    \/ task.problem_folder               # \u7b2c 2 \u90e8\u5206&#xff1a;\u4efb\u52a1\u5b50\u76ee\u5f55<br \/>\n    \/ task.bddl_file                    # \u7b2c 3 \u90e8\u5206&#xff1a;BDDL \u6587\u4ef6\u540d<br \/>\n)<\/p>\n<p>print(f&#034;\u4efb\u52a1: {task.language}&#034;)<br \/>\n# \u673a\u68b0\u81c2\u7528piper<br \/>\nenv &#061; ControlEnv(<br \/>\n    bddl_file_name&#061;str(bddl_path),<br \/>\n    robots&#061;[&#034;Piper&#034;],<br \/>\n    controller&#061;&#034;OSC_POSE&#034;,<br \/>\n    initialization_noise&#061;None,<br \/>\n    control_freq&#061;20,<br \/>\n    # \u6253\u5f00\u4e3b\u7a97\u53e3<br \/>\n    has_renderer&#061;True,<br \/>\n    has_offscreen_renderer&#061;True,<br \/>\n    render_camera&#061;&#034;agentview&#034;,<br \/>\n    # \u662f\u5426\u5728\u89c2\u6d4bobs\u91cc\u8fd4\u56de\u56fe\u50cf&#xff0c;True\u7684\u8bddobs\u5c31\u6709agentview_image\u3001robot0_eye_in_hand_image\u56fe\u50cf<br \/>\n    use_camera_obs&#061;True,<br \/>\n    camera_names&#061;[&#034;agentview&#034;, &#034;robot0_eye_in_hand&#034;],<br \/>\n    camera_widths&#061;256,<br \/>\n    camera_heights&#061;256,<br \/>\n    camera_depths&#061;False,<br \/>\n    ignore_done&#061;True,<br \/>\n)<\/p>\n<p>device &#061; None<\/p>\n<p>try:<br \/>\n    env.seed(1000)<br \/>\n    observation &#061; env.reset()<\/p>\n<p>    robot &#061; env.robots[0]<br \/>\n    controller &#061; robot.controller<br \/>\n    controller.update(force&#061;True)<br \/>\n    target_pos &#061; controller.ee_pos.copy()<br \/>\n    target_ori &#061; controller.ee_ori_mat.copy()<br \/>\n    # \u6309\u952e\u66f4\u65b0\u76ee\u6807&#xff1b;\u677e\u5f00\u540e\u7ee7\u7eed\u5b88\u4f4f\u540c\u4e00\u4e2a\u76ee\u6807&#xff0c;\u4e0d\u8ffd\u968f\u5b9e\u9645\u4f4d\u7f6e\u6f02\u79fb<br \/>\n    controller.uncoupling &#061; False<br \/>\n    controller.use_delta &#061; False<br \/>\n    print(&#034;\\\\n&#061;&#061;&#061; Piper \u63a5\u5165\u4fe1\u606f &#061;&#061;&#061;&#034;)<br \/>\n    print(&#034;\u673a\u5668\u4eba\u6a21\u578b:&#034;, type(robot.robot_model).__name__)<br \/>\n    print(&#034;\u673a\u68b0\u81c2\u5173\u8282\u6570:&#034;, robot.robot_model.dof)<br \/>\n    print(&#034;\u5939\u722a:&#034;, type(robot.gripper).__name__)<br \/>\n    print(&#034;\u52a8\u4f5c\u7ef4\u5ea6:&#034;, robot.action_dim)<br \/>\n    print(&#034;\u521d\u59cb\u5173\u8282\u89d2:&#034;, observation[&#034;robot0_joint_pos&#034;])<br \/>\n    print(&#034;\u672b\u7aef\u4f4d\u7f6e:&#034;, observation[&#034;robot0_eef_pos&#034;])<br \/>\n    print(&#034;\u5939\u722a\u4f4d\u7f6e:&#034;, observation[&#034;robot0_gripper_qpos&#034;])<\/p>\n<p>    assert robot.robot_model.dof &#061;&#061; 6<br \/>\n    assert robot.action_dim &#061;&#061; 7<\/p>\n<p>    print(&#034;\\\\n&#061;&#061;&#061; \u63a7\u5236\u5668 &#061;&#061;&#061;&#034;)<br \/>\n    print(&#034;\u7c7b\u578b:&#034;, controller.name)<br \/>\n    print(&#034;\u76f8\u5bf9\u63a7\u5236:&#034;, controller.use_delta)<br \/>\n    print(&#034;\u4f4d\u7f6e\/\u671d\u5411\u5206\u5f00\u8ba1\u7b97:&#034;, controller.uncoupling)<br \/>\n    print(&#034;kp:&#034;, controller.kp)<br \/>\n    print(&#034;kd(\u963b\u5c3c\u589e\u76ca):&#034;, controller.kd)<br \/>\n    print(&#034;damping_ratio(\u7531 kp\u3001kd \u8fd8\u539f):&#034;,<br \/>\n      controller.kd \/ (2 * np.sqrt(controller.kp)))<br \/>\n    print(&#034;\u76f8\u5bf9\u63a7\u5236\u7684\u9ed8\u8ba4\u7f29\u653e\u4e0a\u9650&#xff08;\u5f53\u524d\u7edd\u5bf9\u6a21\u5f0f\u4e0d\u4f7f\u7528&#xff09;:&#034;, controller.output_max)<br \/>\n    print(&#034;\u952e\u76d8\u4f4d\u7f6e\/\u65cb\u8f6c\u589e\u76ca:&#034;, POSITION_GAIN, ROTATION_GAIN)<br \/>\n    print(&#034;\u76ee\u6807\u9886\u5148\u4e0a\u9650 \/ m\u3001rad:&#034;, MAX_POSITION_LEAD, MAX_ROTATION_LEAD)<br \/>\n    print(&#034;\u63a7\u5236\u9891\u7387:&#034;, env.env.control_freq)<br \/>\n    print(&#034;\u7269\u7406\u6b65\u957f:&#034;, env.sim.model.opt.timestep)<\/p>\n<p>    root_body &#061; robot.robot_model.root_body<br \/>\n    print(&#034;\\\\n&#061;&#061;&#061; \u5e95\u5ea7 &#061;&#061;&#061;&#034;)<br \/>\n    print(&#034;\u4e16\u754c\u4f4d\u7f6e:&#034;, env.sim.data.get_body_xpos(root_body))<br \/>\n    print(&#034;\u4e16\u754c\u56db\u5143\u6570 wxyz:&#034;, env.sim.data.get_body_xquat(root_body))<\/p>\n<p>    print(&#034;\\\\n&#061;&#061;&#061; \u76f8\u673a &#061;&#061;&#061;&#034;)<br \/>\n    for name in [&#034;agentview&#034;, &#034;robot0_eye_in_hand&#034;]:<br \/>\n        camera_id &#061; env.sim.model.camera_name2id(name)<br \/>\n        key &#061; f&#034;{name}_image&#034;<\/p>\n<p>        print(name)<br \/>\n        print(&#034;  \u56fe\u50cf\u5f62\u72b6:&#034;, observation[key].shape)<br \/>\n        print(&#034;  \u5c40\u90e8\u4f4d\u7f6e:&#034;, env.sim.model.cam_pos[camera_id])<br \/>\n        print(&#034;  \u5c40\u90e8\u56db\u5143\u6570:&#034;, env.sim.model.cam_quat[camera_id])<br \/>\n        print(&#034;  fovy:&#034;, env.sim.model.cam_fovy[camera_id])<\/p>\n<p>        assert observation[key].shape &#061;&#061; (256, 256, 3)<\/p>\n<p>    # \u5148\u4fdd\u6301\u4f4d\u7f6e\u5e76\u5f20\u5f00\u5939\u722a&#xff0c;\u89c2\u5bdf\u662f\u5426\u7a33\u5b9a<br \/>\n    # \u7edd\u5bf9\u6a21\u5f0f\u4e0d\u80fd\u7528\u5168\u96f6\u4f4d\u59ff&#xff1a;\u4fdd\u6301\u521d\u59cb\u5316\u65f6\u7684\u4f4d\u7f6e\u548c\u671d\u5411<br \/>\n    idle_action &#061; np.concatenate([<br \/>\n        target_pos,<br \/>\n        T.quat2axisangle(T.mat2quat(target_ori)),<br \/>\n        [-1.0],<br \/>\n    ])<br \/>\n    initial_eef &#061; observation[&#034;robot0_eef_pos&#034;].copy()<\/p>\n<p>    for _ in range(20):<br \/>\n        observation, _, _, _ &#061; env.step(idle_action)<br \/>\n        env.env.render()<br \/>\n        assert np.isfinite(env.sim.data.qpos).all()<\/p>\n<p>    print(&#034;\\\\n\u4fdd\u6301 20 \u6b65\u540e\u7684\u672b\u7aef\u4f4d\u79fb:&#034;)<br \/>\n    print(observation[&#034;robot0_eef_pos&#034;] &#8211; initial_eef)<br \/>\n    print(&#034;A3_PIPER_ENV_READY&#034;)<\/p>\n<p>    device &#061; Keyboard(<br \/>\n        pos_sensitivity&#061;0.1,<br \/>\n        rot_sensitivity&#061;0.2,<br \/>\n    )<br \/>\n    device.start_control()<\/p>\n<p>    print(&#034;\\\\n\u5f00\u59cb\u952e\u76d8\u6d4b\u8bd5:&#034;)<br \/>\n    print(&#034;W\/A\/S\/D \u5e73\u79fb&#xff1b;R\/F \u5347\u964d&#xff1b;\u7a7a\u683c\u5f00\u5408\u5939\u722a\u3002&#034;)<br \/>\n    print(&#034;Z\/X\u3001T\/G\u3001C\/V \u65cb\u8f6c&#xff1b;Q \u7ed3\u675f\u3002&#034;)<br \/>\n    print(&#034;\u63a7\u5236\u65b9\u5f0f&#xff1a;\u6309\u952e\u66f4\u65b0\u56fa\u5b9a\u76ee\u6807&#xff0c;\u677e\u5f00\u540e\u4fdd\u6301\u76ee\u6807\u3002&#034;)<br \/>\n    print(&#034;\u82e5\u660e\u663e\u6296\u52a8\u3001\u5931\u63a7\u6216\u7a7f\u684c&#xff0c;\u7acb\u5373 Ctrl&#043;C&#xff0c;\u5e76\u4fdd\u7559\u8f93\u51fa\u3002&#034;)<\/p>\n<p>    joint_names &#061; robot.robot_model.joints<br \/>\n    joint_ids &#061; [<br \/>\n        env.sim.model.joint_name2id(name)<br \/>\n        for name in joint_names<br \/>\n    ]<\/p>\n<p>    print(&#034;\u5173\u8282\u987a\u5e8f:&#034;, joint_names)<br \/>\n    print(&#034;\u5173\u8282\u9650\u4f4d \/ rad:\\\\n&#034;, env.sim.model.jnt_range[joint_ids])<br \/>\n    last_log &#061; time.perf_counter()<\/p>\n<p>    while True:<br \/>\n        start &#061; time.perf_counter()<\/p>\n<p>        action, grasp &#061; input2action(<br \/>\n            device&#061;device,<br \/>\n            robot&#061;robot,<br \/>\n            active_arm&#061;&#034;right&#034;,<br \/>\n        )<\/p>\n<p>        if action is None:<br \/>\n            break<\/p>\n<p>        assert action.shape &#061;&#061; (7,)<br \/>\n        assert np.isfinite(action).all()<br \/>\n        controller.update(force&#061;True)<\/p>\n<p>        candidate_pos &#061; target_pos &#043; action[:3] * POSITION_GAIN<br \/>\n        if np.linalg.norm(candidate_pos &#8211; controller.ee_pos) &lt;&#061; MAX_POSITION_LEAD:<br \/>\n            target_pos &#061; candidate_pos<\/p>\n<p>        delta_rotation &#061; T.quat2mat(<br \/>\n            T.axisangle2quat(action[3:6] * ROTATION_GAIN)<br \/>\n        )<br \/>\n        # \u540c\u6837&#xff0c;\u8f6c\u592a\u731b\u4e86\u5c31\u820d\u5f03&#xff0c;\u8fd9\u91cc\u6700\u597d\u63a2\u7a76\u6e05\u695a\u7ebf\u6027\u4ee3\u6570\u5173\u7cfb<br \/>\n        # \u4e3a\u5565\u4e0d\u76f4\u63a5\u7528delta_rotation\u7b97rotation_gap&#xff1f;\u56e0\u4e3a\u5faa\u73af\u8dd1\u8d77\u6765\u4e4b\u540etarget_ori\u8ddfcontroller.ee_ori_mat\u4e0d\u4e00\u5b9a\u76f8\u7b49<br \/>\n        # \u4e0a\u9762\u662f\u539f\u6ce8\u91ca&#xff1b;\u73b0\u5728\u8d85\u9650\u53ea\u622a\u65ad\u591a\u4f59\u89d2\u5ea6&#xff0c;\u4e0d\u518d\u6574\u6b65\u820d\u5f03<br \/>\n        candidate_ori &#061; delta_rotation &#064; target_ori<br \/>\n        rotation_gap &#061; T.quat2axisangle(<br \/>\n            T.mat2quat(candidate_ori &#064; controller.ee_ori_mat.T)<br \/>\n        )<br \/>\n        if np.linalg.norm(rotation_gap) &lt;&#061; MAX_ROTATION_LEAD:<br \/>\n            target_ori &#061; candidate_ori<\/p>\n<p>        # action \u662f\u952e\u76d8\u589e\u91cf&#xff1b;command \u662f\u53d1\u7ed9 OSC \u7684\u7edd\u5bf9\u76ee\u6807\u4f4d\u59ff<br \/>\n        command &#061; np.concatenate([<br \/>\n            target_pos,<br \/>\n            T.quat2axisangle(T.mat2quat(target_ori)),<br \/>\n            action[6:7],<br \/>\n        ])<br \/>\n        observation, _, _, _ &#061; env.step(command)<br \/>\n        env.env.render()<\/p>\n<p>        for key in [&#034;agentview_image&#034;, &#034;robot0_eye_in_hand_image&#034;]:<br \/>\n            frame &#061; observation[key]<br \/>\n            assert frame.shape &#061;&#061; (256, 256, 3)<\/p>\n<p>            # \u4ec5\u8f6c\u6362\u663e\u793a\u65b9\u5411\u548c\u989c\u8272&#xff0c;\u4e0d\u4fee\u6539\u539f\u59cb\u89c2\u6d4b<br \/>\n            if macros.IMAGE_CONVENTION &#061;&#061; &#034;opengl&#034;:<br \/>\n                frame &#061; frame[::-1]<\/p>\n<p>            # \u53ea\u5bf9\u5939\u722a\u76f8\u673a\u989d\u5916\u9006\u65f6\u9488\u65cb\u8f6c 90 \u5ea6<br \/>\n            if key &#061;&#061; &#034;robot0_eye_in_hand_image&#034;:<br \/>\n                frame &#061; np.rot90(frame, k&#061;1, axes&#061;(0, 1))<br \/>\n                frame &#061; np.ascontiguousarray(frame)<\/p>\n<p>            cv2.imshow(<br \/>\n                key,<br \/>\n                cv2.cvtColor(frame, cv2.COLOR_RGB2BGR),<br \/>\n            )<\/p>\n<p>        cv2.waitKey(1)<br \/>\n        # \u6bcf\u79d2\u6253\u5370\u4e00\u6b21&#xff0c;\u907f\u514d\u5237\u5c4f\u5f71\u54cd\u64cd\u4f5c<br \/>\n        if time.perf_counter() &#8211; last_log &gt;&#061; 1.0:<br \/>\n            angles &#061; np.array([<br \/>\n                env.sim.data.get_joint_qpos(name)<br \/>\n                for name in joint_names<br \/>\n            ])<\/p>\n<p>            print(&#034;\u5b9e\u9645\u5173\u8282\u89d2 \/ rad:&#034;, angles)<br \/>\n            print(&#034;\u952e\u76d8\u52a8\u4f5c:&#034;, action)<br \/>\n            print(&#034;\u5b9e\u9645\u672b\u7aef\u4f4d\u7f6e \/ m:&#034;, observation[&#034;robot0_eef_pos&#034;])<br \/>\n            print(&#034;\u76ee\u6807\u672b\u7aef\u4f4d\u7f6e \/ m:&#034;, target_pos)<br \/>\n            last_log &#061; time.perf_counter()<\/p>\n<p>        assert np.isfinite(env.sim.data.qpos).all()<\/p>\n<p>        remaining &#061; 1 \/ 20 &#8211; (time.perf_counter() &#8211; start)<br \/>\n        if remaining &gt; 0:<br \/>\n            time.sleep(remaining)<\/p>\n<p>    print(&#034;A3_PIPER_KEYBOARD_TEST_ENDED&#034;)<\/p>\n<p>except KeyboardInterrupt:<br \/>\n    print(&#034;\\\\n\u7528\u6237\u505c\u6b62\u6d4b\u8bd5\u3002&#034;)<\/p>\n<p>finally:<br \/>\n    if device is not None:<br \/>\n        device.listener.stop()<br \/>\n    env.close()<br \/>\n    cv2.destroyAllWindows()<\/p>\n<p>\u53ef\u4ee5\u770b\u5230ControlEnv\u5b9e\u4f8b\u5316\u65f6\u5df2\u80fd\u6210\u529f\u7528robots&#061;[&#034;Piper&#034;]\u505a\u53c2\u6570&#xff0c;\u8fd9\u4e00\u6b65\u4e4b\u540e\u4f1a\u7ee7\u7eed\u5f80\u4e0b\u4f20\u5230robosuite&#xff0c;\u5e76\u88ab\u6210\u529f\u8bc6\u522b\u3002<\/p>\n<p>LIBERO&#xff1a;ControlEnv(robots&#061;[&#034;Piper&#034;])<br \/>\n                \u2193 \u4f20\u9012\u673a\u5668\u4eba\u540d\u79f0<br \/>\nrobosuite&#xff1a;\u67e5\u627e\u5e76\u521b\u5efa Piper&#xff0c;\u88c5\u4e0a PiperGripper \u548c\u63a7\u5236\u5668<br \/>\n                \u2193 \u52a0\u8f7d\u3001\u7ec4\u88c5 XML<br \/>\nMuJoCo&#xff1a;\u8ba1\u7b97\u673a\u5668\u4eba\u8fd0\u52a8\u548c\u63a5\u89e6<\/p>\n<p>\u4e0b\u9762\u5206\u6790\u6700\u4e3a\u91cd\u8981\u7684\u63a7\u5236\u903b\u8f91\u90e8\u5206&#xff1a;<\/p>\n<p>        candidate_pos &#061; target_pos &#043; action[:3] * POSITION_GAIN<br \/>\n        if np.linalg.norm(candidate_pos &#8211; controller.ee_pos) &lt;&#061; MAX_POSITION_LEAD:<br \/>\n            target_pos &#061; candidate_pos<\/p>\n<p>        delta_rotation &#061; T.quat2mat(<br \/>\n            T.axisangle2quat(action[3:6] * ROTATION_GAIN)<br \/>\n        )<br \/>\n        # \u540c\u6837&#xff0c;\u8f6c\u592a\u731b\u4e86\u5c31\u820d\u5f03&#xff0c;\u8fd9\u91cc\u6700\u597d\u63a2\u7a76\u6e05\u695a\u7ebf\u6027\u4ee3\u6570\u5173\u7cfb<br \/>\n        # \u4e3a\u5565\u4e0d\u76f4\u63a5\u7528delta_rotation\u7b97rotation_gap&#xff1f;\u56e0\u4e3a\u5faa\u73af\u8dd1\u8d77\u6765\u4e4b\u540etarget_ori\u8ddfcontroller.ee_ori_mat\u4e0d\u4e00\u5b9a\u76f8\u7b49<br \/>\n        candidate_ori &#061; delta_rotation &#064; target_ori<br \/>\n        rotation_gap &#061; T.quat2axisangle(<br \/>\n            T.mat2quat(candidate_ori &#064; controller.ee_ori_mat.T)<br \/>\n        )<br \/>\n        if np.linalg.norm(rotation_gap) &lt;&#061; MAX_ROTATION_LEAD:<br \/>\n            target_ori &#061; candidate_ori<\/p>\n<p>        # action \u662f\u952e\u76d8\u589e\u91cf&#xff1b;command \u662f\u53d1\u7ed9 OSC \u7684\u7edd\u5bf9\u76ee\u6807\u4f4d\u59ff<br \/>\n        command &#061; np.concatenate([<br \/>\n            target_pos,<br \/>\n            T.quat2axisangle(T.mat2quat(target_ori)),<br \/>\n            action[6:7],<br \/>\n        ])<\/p>\n<p>action\u65f6\u662f\u952e\u76d8\u8bfb\u5230\u7684&#xff0c;\u8868\u793a\u6bcf\u6b21\u6309\u4e0b\u952e\u76d8\u540e\u76847\u7ef4\u53d8\u5316\u91cf&#xff0c;\u8fd9\u4e2a\u53d8\u5316\u91cf\u52a0\u4e0a\u4e0a\u4e00\u6b65\u7684\u671f\u671b\u76ee\u6807\u5c31\u7b49\u4e8e\u5f53\u524d\u8fd9\u4e00\u6b65\u7684\u671f\u671b\u76ee\u6807\u3002<\/p>\n<p>\u6ce8\u610f&#xff0c;\u4e3a\u4ec0\u4e48\u662f\u52a0\u4e0a\u4e00\u6b65\u7684\u671f\u671b\u76ee\u6807\u800c\u4e0d\u662f\u5f53\u524d\u7684\u771f\u5b9e\u72b6\u6001&#xff1f;\u56e0\u4e3a\u9700\u8981\u7ea0\u504f\u3002\u8bd5\u60f3&#xff0c;\u5047\u5982\u4f60\u957f\u6309\u952e\u76d8\u60f3\u8ba9\u673a\u68b0\u81c2\u5de6\u79fb\u5230A&#xff0c;\u4f46\u6b64\u65f6\u673a\u68b0\u81c2\u8d70\u504f\u5230\u4e86B&#xff0c;\u7531\u4e8e\u662f\u957f\u6309\u952e\u76d8&#xff0c;\u671f\u95f4\u7684action\u90fd\u662f0&#xff0c;\u5982\u679c\u662f\u57fa\u4e8e\u4e0a\u4e00\u6b65\u7684\u671f\u671b\u76ee\u6807&#xff0c;\u4e5f\u5c31\u662fA&#xff0c;\u90a3\u4e48\u673a\u68b0\u81c2\u6b64\u65f6\u5728B\u77e5\u9053\u8fd8\u9700\u8981\u7ee7\u7eed\u5f80A\u8d70&#xff0c;\u5b9e\u73b0\u7ea0\u504f&#xff1b;\u5982\u679c\u662f\u57fa\u4e8e\u5f53\u524d\u72b6\u6001&#xff0c;\u589e\u91cf\u4e3a0&#xff0c;\u90a3\u4e48\u673a\u68b0\u81c2\u6b64\u65f6\u7684\u76ee\u6807\u70b9\u4e5f\u5c31\u662fB\u70b9\u672c\u8eab&#xff0c;\u673a\u68b0\u81c2\u4e0d\u518d\u79fb\u52a8&#xff0c;\u65e0\u6cd5\u5230\u8fbe\u76ee\u6807\u70b9A\u3002<\/p>\n<p>\u65cb\u8f6c\u91cf\u4e5f\u662f\u540c\u6837\u7684\u7ea0\u504f\u601d\u60f3&#xff0c;\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f\u77e9\u9635\u65cb\u8f6c\u7684\u76f8\u5173\u77e5\u8bc6&#xff1a;<\/p>\n<p>1. \u65cb\u8f6c\u77e9\u9635\u5de6\u4e58\u5f53\u524d\u72b6\u6001\u77e9\u9635&#xff0c;\u4fbf\u80fd\u5f97\u5230\u65cb\u8f6c\u4e4b\u540e\u7684\u59ff\u6001\u77e9\u9635<\/p>\n<p>2. \u65cb\u8f6c\u77e9\u9635\u7684\u9006\u77e9\u9635\u7b49\u4e8e\u5176\u8f6c\u7f6e<\/p>\n<p>\n\u6700\u7ec8\u5b9e\u73b0\u4e86\u952e\u76d8\u63a7\u5236\u673a\u68b0\u81c2\u8fd0\u52a8&#xff0c;\u5e76\u5b8c\u6210\u4e86\u7269\u4f53\u5939\u53d6&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"800\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020719-6ad96fd7edeb7.png\" width=\"1280\" \/><\/p>\n<hr \/>\n<h3>4. \u6570\u636e\u91c7\u96c6\u4e0e\u683c\u5f0f\u8f6c\u6362<\/h3>\n<h4 style=\"background-color:transparent\">4.1. \u91c7\u96c6\u811a\u672c<\/h4>\n<p>import argparse<br \/>\nimport hashlib<br \/>\nimport json<br \/>\nimport time<br \/>\nfrom datetime import datetime<br \/>\nfrom pathlib import Path<br \/>\nfrom zoneinfo import ZoneInfo<\/p>\n<p>import cv2<br \/>\nimport h5py<br \/>\nimport numpy as np<\/p>\n<p>from A4_2_piper_env import PACK, load_piper_env<br \/>\nfrom piper_xml import PHYSICS_XML_VERSION, fix_piper_xml<\/p>\n<p>from robosuite import macros<br \/>\nfrom robosuite.devices import Keyboard<br \/>\nfrom robosuite.utils import transform_utils as T<br \/>\nfrom robosuite.utils.input_utils import input2action<br \/>\nfrom libero.libero import benchmark<\/p>\n<p>parser &#061; argparse.ArgumentParser(description&#061;&#034;Piper \u8bad\u7ec3\u5f00\u5c40\u952e\u76d8\u91c7\u96c6&#xff0c;\u4e00\u6b21\u4e00\u6761&#034;)<br \/>\nparser.add_argument(&#034;&#8211;init-index&#034;, type&#061;int, required&#061;True, choices&#061;range(30))<br \/>\nargs &#061; parser.parse_args()<\/p>\n<p>CONTROL_FREQ &#061; 20<br \/>\nMAX_STEPS &#061; 1000<br \/>\nWRIST_FOV &#061; 90.0<\/p>\n<p># \u4fdd\u7559\u4e0a\u5468\u9a8c\u8bc1\u8fc7\u7684\u63a7\u5236\u53c2\u6570<br \/>\nPOSITION_GAIN &#061; 0.01<br \/>\nROTATION_GAIN &#061; 0.5<br \/>\nMAX_POSITION_LEAD &#061; 0.03<br \/>\nMAX_ROTATION_LEAD &#061; 0.2<\/p>\n<p># \u201c\u8fd1\u9759\u6b62\u201d\u7684\u5224\u636e&#xff1a;\u4e00\u4e2a\u63a7\u5236\u6b65\u5185\u7684\u5b9e\u9645\u5173\u8282\u53d8\u5316<br \/>\nARM_STILL_THRESHOLD &#061; 0.001       # rad<br \/>\nGRIPPER_STILL_THRESHOLD &#061; 0.0001  # m<\/p>\n<p>OUTPUT_DIR &#061; (<br \/>\n    Path(__file__).resolve().parent<br \/>\n    \/ &#034;datasets\/b1_piper_black_bowl_v2&#034;<br \/>\n)<br \/>\nINIT_SOURCE &#061; f&#034;{PACK.name}\/train.pruned_init&#034;<br \/>\nINIT_SHA256 &#061; hashlib.sha256((PACK \/ &#034;train.pruned_init&#034;).read_bytes()).hexdigest()<br \/>\nINIT_MODEL_SHA256 &#061; hashlib.sha256((PACK \/ &#034;model.xml&#034;).read_bytes()).hexdigest()<br \/>\nMANIFEST &#061; json.loads((PACK \/ &#034;manifest.json&#034;).read_text(encoding&#061;&#034;utf-8&#034;))<br \/>\nassert len(MANIFEST[&#034;splits&#034;][&#034;train&#034;]) &#061;&#061; 30<br \/>\nRUN_ID &#061; datetime.now(<br \/>\n    ZoneInfo(&#034;Asia\/Shanghai&#034;)<br \/>\n).strftime(&#034;%Y%m%d_%H%M%S_%f&#034;)<\/p>\n<p>def display_image(frame, wrist&#061;False):<br \/>\n    &#034;&#034;&#034;\u53ea\u6539\u53d8\u663e\u793a\u65b9\u5411&#xff0c;\u4e0d\u4fee\u6539\u539f\u59cb\u89c2\u6d4b\u3002&#034;&#034;&#034;<br \/>\n    if macros.IMAGE_CONVENTION &#061;&#061; &#034;opengl&#034;:<br \/>\n        frame &#061; frame[::-1]<br \/>\n    if wrist:<br \/>\n        frame &#061; np.rot90(frame, k&#061;1)<br \/>\n    return cv2.cvtColor(<br \/>\n        np.ascontiguousarray(frame),<br \/>\n        cv2.COLOR_RGB2BGR,<br \/>\n    )<\/p>\n<p>class CollectKeyboard(Keyboard):<br \/>\n    def __init__(self, **kwargs):<br \/>\n        self.retry_count &#061; 0<br \/>\n        self.recording &#061; False<br \/>\n        super().__init__(**kwargs)<\/p>\n<p>    def on_release(self, key):<br \/>\n        # \u677e\u5f00 N \u65f6\u8ba1\u4e00\u6b21&#xff0c;\u907f\u514d\u957f\u6309\u91cd\u590d\u8ba1\u6570<br \/>\n        if getattr(key, &#034;char&#034;, None) &#061;&#061; &#034;n&#034;:<br \/>\n            if self.recording:<br \/>\n                self.retry_count &#043;&#061; 1<br \/>\n                print(&#034;\u624b\u52a8\u6807\u8bb0\u91cd\u8bd5\u6b21\u6570:&#034;, self.retry_count)<br \/>\n            return<br \/>\n        super().on_release(key)<\/p>\n<p>def show_progress():<br \/>\n    &#034;&#034;&#034;\u4ee5\u5b9e\u9645\u6210\u529f\u6587\u4ef6\u4e3a\u51c6&#xff1b;\u540c\u4e00\u65f6\u95f4\u53ea\u8fd0\u884c\u4e00\u4e2a\u91c7\u96c6\u8fdb\u7a0b\u3002&#034;&#034;&#034;<br \/>\n    counts &#061; [0] * 30<br \/>\n    for path in sorted(OUTPUT_DIR.glob(&#034;demo_*.hdf5&#034;)):<br \/>\n        with h5py.File(path, &#034;r&#034;) as file:<br \/>\n            info &#061; json.loads(file[&#034;data&#034;].attrs[&#034;env_info&#034;])<br \/>\n            demo &#061; file[&#034;data\/demo_0&#034;]<br \/>\n            assert info[&#034;init_source&#034;] &#061;&#061; INIT_SOURCE, path<br \/>\n            assert info[&#034;init_sha256&#034;] &#061;&#061; INIT_SHA256, path<br \/>\n            assert info[&#034;init_model_sha256&#034;] &#061;&#061; INIT_MODEL_SHA256, path<br \/>\n            index &#061; info[&#034;init_index&#034;]<br \/>\n            assert 0 &lt;&#061; index &lt; 30, path<br \/>\n            assert bool(demo.attrs[&#034;success&#034;]), path<br \/>\n            assert 0 &lt; len(demo[&#034;actions&#034;]) &lt;&#061; MAX_STEPS, path<br \/>\n            assert demo[&#034;actions&#034;].shape &#061;&#061; (len(demo[&#034;states&#034;]), 7), path<br \/>\n            counts[index] &#043;&#061; 1<br \/>\n    print(&#034;\u5404\u8bad\u7ec3\u5f00\u5c40\u6210\u529f\u6761\u6570&#xff08;\u7f16\u53f7 0&#xff5e;29&#xff09;:&#034;, counts)<br \/>\n    print(&#034;\u7d2f\u8ba1\u6210\u529f\u6761\u6570:&#034;, sum(counts), &#034;\/ 60&#034;)<br \/>\n    print(&#034;\u5f53\u524d\u5f00\u5c40:&#034;, args.init_index, &#034;\u5df2\u6210\u529f:&#034;, counts[args.init_index], &#034;\/ 2&#034;)<br \/>\n    return counts<\/p>\n<p>counts &#061; show_progress()<br \/>\nif counts[args.init_index] &gt;&#061; 2:<br \/>\n    parser.exit(message&#061;&#034;\u5f53\u524d\u5f00\u5c40\u5df2\u6709\u4e24\u6761\u6210\u529f\u6f14\u793a&#xff0c;\u8bf7\u9009\u62e9\u5176\u4ed6\u7f16\u53f7\u3002\\\\n&#034;)<\/p>\n<p>def save_result(<br \/>\n    states, actions, stationary_flags,<br \/>\n    initial_state, model_xml, env_info, attempt,<br \/>\n):<br \/>\n    &#034;&#034;&#034;\u6210\u529f\u4e14\u672a\u8d85\u957f\u624d\u4fdd\u5b58 HDF5&#xff1b;\u6240\u6709\u5df2\u5f55\u5236\u5c1d\u8bd5\u90fd\u4fdd\u7559\u65e5\u5fd7\u3002&#034;&#034;&#034;<br \/>\n    OUTPUT_DIR.mkdir(parents&#061;True, exist_ok&#061;True)<br \/>\n    path &#061; None<\/p>\n<p>    assert len(states) &#061;&#061; len(actions) &#061;&#061; len(stationary_flags)<\/p>\n<p>    if attempt[&#034;success&#034;]:<br \/>\n        assert 0 &lt; len(actions) &lt;&#061; MAX_STEPS<\/p>\n<p>        state_array &#061; np.asarray(states, dtype&#061;np.float64)<br \/>\n        action_array &#061; np.asarray(actions, dtype&#061;np.float64)<\/p>\n<p>        assert action_array.shape &#061;&#061; (len(state_array), 7)<br \/>\n        assert np.isfinite(state_array).all()<br \/>\n        assert np.isfinite(action_array).all()<\/p>\n<p>        path &#061; OUTPUT_DIR \/ f&#034;demo_train_{args.init_index:02d}_{RUN_ID}.hdf5&#034;<br \/>\n        pending_path &#061; path.with_suffix(&#034;.hdf5.partial&#034;)<\/p>\n<p>        # \u5199\u5165\u4e2d\u65ad\u7684\u6587\u4ef6\u4e0d\u8ba1\u5165\u6210\u529f\u6761\u6570&#xff0c;\u539f\u6587\u4ef6\u59cb\u7ec8\u4e0d\u8986\u76d6\u3002<br \/>\n        with h5py.File(pending_path, &#034;x&#034;) as file:<br \/>\n            data &#061; file.create_group(&#034;data&#034;)<br \/>\n            data.attrs[&#034;env&#034;] &#061; env_info[&#034;environment&#034;]<br \/>\n            data.attrs[&#034;env_info&#034;] &#061; json.dumps(<br \/>\n                env_info, ensure_ascii&#061;False<br \/>\n            )<\/p>\n<p>            demo &#061; data.create_group(&#034;demo_0&#034;)<br \/>\n            demo.create_dataset(&#034;states&#034;, data&#061;state_array)<br \/>\n            demo.create_dataset(&#034;actions&#034;, data&#061;action_array)<br \/>\n            demo.create_dataset(<br \/>\n                &#034;settled_initial_state&#034;, data&#061;initial_state<br \/>\n            )<br \/>\n            # \u8bca\u65ad\u5b57\u6bb5&#xff0c;\u4e0d\u4f5c\u4e3a\u6a21\u578b\u8f93\u5165<br \/>\n            demo.create_dataset(<br \/>\n                &#034;stationary_flags&#034;,<br \/>\n                data&#061;np.asarray(stationary_flags, dtype&#061;bool),<br \/>\n            )<\/p>\n<p>            demo.attrs[&#034;model_file&#034;] &#061; model_xml<br \/>\n            demo.attrs[&#034;success&#034;] &#061; True<br \/>\n            demo.attrs[&#034;split&#034;] &#061; &#034;train&#034;<br \/>\n            demo.attrs[&#034;init_index&#034;] &#061; args.init_index<br \/>\n            demo.attrs[&#034;num_samples&#034;] &#061; len(actions)<br \/>\n            demo.attrs[&#034;recording_seconds&#034;] &#061; attempt[<br \/>\n                &#034;recording_seconds&#034;<br \/>\n            ]<br \/>\n            demo.attrs[&#034;collection_fps&#034;] &#061; attempt[&#034;collection_fps&#034;]<br \/>\n            demo.attrs[&#034;stationary_ratio&#034;] &#061; attempt[<br \/>\n                &#034;stationary_ratio&#034;<br \/>\n            ]<br \/>\n            demo.attrs[&#034;retry_count_manual&#034;] &#061; attempt[<br \/>\n                &#034;retry_count_manual&#034;<br \/>\n            ]<br \/>\n            demo.attrs[&#034;gripper_switch_count&#034;] &#061; attempt[<br \/>\n                &#034;gripper_switch_count&#034;<br \/>\n            ]<\/p>\n<p>        with h5py.File(pending_path, &#034;r&#034;) as file:<br \/>\n            demo &#061; file[&#034;data\/demo_0&#034;]<br \/>\n            assert demo[&#034;states&#034;].shape &#061;&#061; state_array.shape<br \/>\n            assert demo[&#034;actions&#034;].shape &#061;&#061; action_array.shape<br \/>\n            assert bool(demo.attrs[&#034;success&#034;])<br \/>\n            assert int(demo.attrs[&#034;init_index&#034;]) &#061;&#061; args.init_index<br \/>\n            print(&#034;states shape:&#034;, demo[&#034;states&#034;].shape)<br \/>\n            print(&#034;actions shape:&#034;, demo[&#034;actions&#034;].shape)<\/p>\n<p>        pending_path.rename(path)<br \/>\n        print(&#034;HDF5:&#034;, path)<br \/>\n        print(&#034;\u6587\u4ef6\u5927\u5c0f \/ bytes:&#034;, path.stat().st_size)<br \/>\n        print(&#034;B1_HDF5_READBACK_OK&#034;)<br \/>\n    else:<br \/>\n        print(&#034;\u672c\u6b21\u4e0d\u4fdd\u5b58\u4e3a\u6210\u529f\u793a\u8303&#xff0c;\u53ea\u8bb0\u5f55\u5c1d\u8bd5\u7ed3\u679c\u3002&#034;)<\/p>\n<p>    attempt[&#034;hdf5_path&#034;] &#061; str(path) if path else None<br \/>\n    attempt[&#034;env_info&#034;] &#061; env_info<\/p>\n<p>    # ponytail: \u5355\u4e2a\u91c7\u96c6\u8fdb\u7a0b\u4f7f\u7528&#xff1b;\u5e76\u884c\u91c7\u96c6\u65f6\u9700\u72ec\u7acb\u65e5\u5fd7<br \/>\n    with (OUTPUT_DIR \/ &#034;attempts.jsonl&#034;).open(<br \/>\n        &#034;a&#034;, encoding&#061;&#034;utf-8&#034;<br \/>\n    ) as file:<br \/>\n        file.write(json.dumps(attempt, ensure_ascii&#061;False) &#043; &#034;\\\\n&#034;)<\/p>\n<p>    print(&#034;\\\\n&#061;&#061;&#061; B1 \u91c7\u96c6\u7ed3\u679c &#061;&#061;&#061;&#034;)<br \/>\n    print(&#034;\u8bad\u7ec3\u5f00\u5c40\u7f16\u53f7:&#034;, args.init_index)<br \/>\n    for key in [<br \/>\n        &#034;success&#034;, &#034;steps&#034;, &#034;recording_seconds&#034;,<br \/>\n        &#034;collection_fps&#034;, &#034;stationary_ratio&#034;,<br \/>\n        &#034;gripper_switch_count&#034;, &#034;retry_count_manual&#034;,<br \/>\n        &#034;stop_reason&#034;,<br \/>\n    ]:<br \/>\n        print(f&#034;{key}: {attempt[key]}&#034;)<br \/>\n    print(&#034;\u672c\u6b21\u5c1d\u8bd5\u65e5\u5fd7:&#034;, OUTPUT_DIR \/ &#034;attempts.jsonl&#034;)<br \/>\n    show_progress()<\/p>\n<p>env &#061; None<br \/>\ndevice &#061; None<br \/>\nstates &#061; []<br \/>\nactions &#061; []<br \/>\nstationary_flags &#061; []<\/p>\n<p>record_start &#061; None<br \/>\nsuccess &#061; False<br \/>\nsuccess_count &#061; 0<br \/>\ngripper_switch_count &#061; 0<br \/>\nprevious_gripper_command &#061; -1.0<br \/>\nstop_reason &#061; &#034;\u7528\u6237\u6309 Q \u7ed3\u675f&#034;<br \/>\ninitial_state &#061; None<br \/>\nmodel_xml &#061; None<br \/>\nenv_info &#061; None<\/p>\n<p>try:<br \/>\n    env, observation, init_info &#061; load_piper_env(<br \/>\n        split&#061;&#034;train&#034;, init_index&#061;args.init_index, viewer&#061;True,<br \/>\n    )<br \/>\n    suite &#061; benchmark.get_benchmark_dict()[init_info[&#034;suite&#034;]]()<br \/>\n    task &#061; suite.get_task(0)<\/p>\n<p>    robot &#061; env.robots[0]<br \/>\n    controller &#061; robot.controller<br \/>\n    controller.update(force&#061;True)<br \/>\n    controller.uncoupling &#061; False<br \/>\n    controller.use_delta &#061; False<\/p>\n<p>    target_pos &#061; controller.ee_pos.copy()<br \/>\n    target_ori &#061; controller.ee_ori_mat.copy()<\/p>\n<p>    # A4 \u7684\u5f00\u5c40\u5df2\u7a33\u5b9a&#xff0c;\u4e0d\u989d\u5916\u9884\u70ed\u63a8\u8fdb&#xff1b;\u9996\u6b21\u52a8\u4f5c\u524d\u4ecd\u6309\u539f\u903b\u8f91\u4fdd\u6301\u59ff\u6001\u3002<br \/>\n    initial_state &#061; env.get_sim_state().copy()<br \/>\n    np.testing.assert_allclose(<br \/>\n        observation[&#034;akita_black_bowl_1_pos&#034;],<br \/>\n        init_info[&#034;expected_position&#034;], rtol&#061;0, atol&#061;1e-7,<br \/>\n    )<br \/>\n    initial_objects &#061; {<br \/>\n        key: np.asarray(value).tolist()<br \/>\n        for key, value in observation.items()<br \/>\n        if not key.startswith(&#034;robot0_&#034;)<br \/>\n        and key.endswith((&#034;_pos&#034;, &#034;_quat&#034;))<br \/>\n    }<\/p>\n<p>    camera_id &#061; env.sim.model.camera_name2id(<br \/>\n        &#034;robot0_eye_in_hand&#034;<br \/>\n    )<br \/>\n    assert np.isclose(env.sim.model.cam_fovy[camera_id], WRIST_FOV)<br \/>\n    camera_config &#061; {<br \/>\n        &#034;pos&#034;: env.sim.model.cam_pos[camera_id].tolist(),<br \/>\n        &#034;quat&#034;: env.sim.model.cam_quat[camera_id].tolist(),<br \/>\n        &#034;fovy&#034;: float(env.sim.model.cam_fovy[camera_id]),<br \/>\n    }<br \/>\n    # \u4e0e A4 \u6062\u590d\u5f00\u5c40\u65f6\u4f7f\u7528\u540c\u4e00\u4efd XML&#xff1b;\u76f8\u673a\u5df2\u56fa\u5b9a 90\u00b0&#xff0c;\u4e0d\u518d\u91cd\u590d\u8c03\u53c2\u622a\u56fe\u3002<br \/>\n    model_xml &#061; fix_piper_xml((PACK \/ &#034;model.xml&#034;).read_text(encoding&#061;&#034;utf-8&#034;))<\/p>\n<p>    env_info &#061; {<br \/>\n        &#034;environment&#034;: type(env.env).__name__,<br \/>\n        &#034;physics_xml_version&#034;: PHYSICS_XML_VERSION,<br \/>\n        &#034;suite&#034;: init_info[&#034;suite&#034;],<br \/>\n        &#034;task_id&#034;: 0,<br \/>\n        &#034;task&#034;: task.language,<br \/>\n        &#034;bddl_file&#034;: task.bddl_file,<br \/>\n        &#034;robots&#034;: [&#034;Piper&#034;],<br \/>\n        &#034;robot_model&#034;: type(robot.robot_model).__name__,<br \/>\n        &#034;seed&#034;: MANIFEST[&#034;seed&#034;],<br \/>\n        &#034;split&#034;: &#034;train&#034;,<br \/>\n        &#034;init_source&#034;: INIT_SOURCE,<br \/>\n        &#034;init_sha256&#034;: INIT_SHA256,<br \/>\n        &#034;init_model_sha256&#034;: INIT_MODEL_SHA256,<br \/>\n        &#034;init_index&#034;: init_info[&#034;init_index&#034;],<br \/>\n        &#034;expected_initial_bowl_position&#034;: init_info[&#034;expected_position&#034;],<br \/>\n        &#034;initial_objects&#034;: initial_objects,<br \/>\n        &#034;control_freq&#034;: CONTROL_FREQ,<br \/>\n        &#034;physics_dt&#034;: float(env.sim.model.opt.timestep),<br \/>\n        &#034;controller&#034;: {<br \/>\n            &#034;type&#034;: controller.name,<br \/>\n            &#034;control_delta&#034;: False,<br \/>\n            &#034;uncouple_pos_ori&#034;: False,<br \/>\n            &#034;kp&#034;: controller.kp.tolist(),<br \/>\n            &#034;kd&#034;: controller.kd.tolist(),<br \/>\n            &#034;input_min&#034;: controller.input_min.tolist(),<br \/>\n            &#034;input_max&#034;: controller.input_max.tolist(),<br \/>\n            &#034;output_min&#034;: controller.output_min.tolist(),<br \/>\n            &#034;output_max&#034;: controller.output_max.tolist(),<br \/>\n        },<br \/>\n        &#034;action_representation&#034;: (<br \/>\n            &#034;world_xyz_m &#043; world_axis_angle_rad &#043; gripper&#034;<br \/>\n        ),<br \/>\n        &#034;wrist_camera&#034;: camera_config,<br \/>\n        &#034;wrist_display_rotation_deg&#034;: 90,<br \/>\n        &#034;stationary_definition&#034;: {<br \/>\n            &#034;max_arm_joint_change_rad&#034;: ARM_STILL_THRESHOLD,<br \/>\n            &#034;max_gripper_joint_change_m&#034;: GRIPPER_STILL_THRESHOLD,<br \/>\n        },<br \/>\n    }<\/p>\n<p>    device &#061; CollectKeyboard(<br \/>\n        pos_sensitivity&#061;0.1,<br \/>\n        rot_sensitivity&#061;0.2,<br \/>\n    )<br \/>\n    device.start_control()<\/p>\n<p>    print(&#034;\\\\n&#061;&#061;&#061; B1 Piper \u8bad\u7ec3\u6570\u636e\u91c7\u96c6 &#061;&#061;&#061;&#034;)<br \/>\n    print(&#034;\u4efb\u52a1:&#034;, task.language)<br \/>\n    print(&#034;\u8bad\u7ec3\u5f00\u5c40\u7f16\u53f7:&#034;, args.init_index)<br \/>\n    print(&#034;\u76ee\u6807\u7897\u521d\u59cb\u4f4d\u7f6e:&#034;, init_info[&#034;expected_position&#034;])<br \/>\n    print(&#034;\u7269\u7406\u6a21\u578b\u7248\u672c:&#034;, init_info[&#034;physics_xml_version&#034;])<br \/>\n    print(&#034;\u76ee\u6807\u7897\u8d28\u91cf \/ kg:&#034;, init_info[&#034;target_bowl_mass_kg&#034;])<br \/>\n    print(&#034;\u8155\u90e8\u76f8\u673a:&#034;, camera_config)<br \/>\n    print(&#034;\u8f93\u51fa\u76ee\u5f55:&#034;, OUTPUT_DIR)<br \/>\n    print(&#034;\u9996\u6b21\u8fd0\u52a8\u6216\u95ed\u5408\u5939\u722a\u5f00\u59cb\u5f55\u5236\u3002&#034;)<br \/>\n    print(&#034;\u79fb\u52a8\u3001\u65cb\u8f6c\u548c\u5939\u722a\u6309\u952e\u6cbf\u7528\u4e0a\u5468\u3002&#034;)<br \/>\n    print(&#034;N&#xff1a;\u5931\u8d25\u540e\u91cd\u65b0\u5c1d\u8bd5\u65f6&#xff0c;\u624b\u52a8\u6807\u8bb0\u4e00\u6b21\u91cd\u8bd5\u3002&#034;)<br \/>\n    print(&#034;Q&#xff1a;\u653e\u5f03&#xff1b;\u660e\u663e\u5931\u63a7\u65f6 Ctrl&#043;C\u3002&#034;)<br \/>\n    print(&#034;\u8fbe\u5230 1000 \u6b65\u4ecd\u672a\u6210\u529f\u5219\u7ec8\u6b62\u3002&#034;)<\/p>\n<p>    last_log &#061; time.perf_counter()<\/p>\n<p>    while True:<br \/>\n        loop_start &#061; time.perf_counter()<br \/>\n        action, _ &#061; input2action(<br \/>\n            device&#061;device,<br \/>\n            robot&#061;robot,<br \/>\n            active_arm&#061;&#034;right&#034;,<br \/>\n        )<br \/>\n        if action is None:<br \/>\n            break<\/p>\n<p>        assert action.shape &#061;&#061; (7,)<br \/>\n        assert np.isfinite(action).all()<br \/>\n        controller.update(force&#061;True)<\/p>\n<p>        candidate_pos &#061; target_pos &#043; action[:3] * POSITION_GAIN<br \/>\n        if np.linalg.norm(<br \/>\n            candidate_pos &#8211; controller.ee_pos<br \/>\n        ) &lt;&#061; MAX_POSITION_LEAD:<br \/>\n            target_pos &#061; candidate_pos<\/p>\n<p>        delta_rotation &#061; T.quat2mat(<br \/>\n            T.axisangle2quat(action[3:6] * ROTATION_GAIN)<br \/>\n        )<br \/>\n        candidate_ori &#061; delta_rotation &#064; target_ori<br \/>\n        rotation_gap &#061; T.quat2axisangle(<br \/>\n            T.mat2quat(candidate_ori &#064; controller.ee_ori_mat.T)<br \/>\n        )<br \/>\n        if np.linalg.norm(rotation_gap) &lt;&#061; MAX_ROTATION_LEAD:<br \/>\n            target_ori &#061; candidate_ori<\/p>\n<p>        command &#061; np.concatenate([<br \/>\n            target_pos,<br \/>\n            T.quat2axisangle(T.mat2quat(target_ori)),<br \/>\n            action[6:7],<br \/>\n        ])<br \/>\n        assert np.isfinite(command).all()<\/p>\n<p>        if record_start is None and (<br \/>\n            np.any(action[:6] !&#061; 0) or action[6] &gt; 0<br \/>\n        ):<br \/>\n            record_start &#061; time.perf_counter()<br \/>\n            device.recording &#061; True<br \/>\n            print(&#034;RECORDING_STARTED&#034;)<\/p>\n<p>        if record_start is not None:<br \/>\n            state_before &#061; env.get_sim_state().copy()<br \/>\n            arm_before &#061; observation[&#034;robot0_joint_pos&#034;].copy()<br \/>\n            gripper_before &#061; observation[<br \/>\n                &#034;robot0_gripper_qpos&#034;<br \/>\n            ].copy()<\/p>\n<p>        observation, _, _, _ &#061; env.step(command)<\/p>\n<p>        if record_start is not None:<br \/>\n            states.append(state_before)<br \/>\n            actions.append(command.copy())<\/p>\n<p>            arm_change &#061; np.max(np.abs(<br \/>\n                observation[&#034;robot0_joint_pos&#034;] &#8211; arm_before<br \/>\n            ))<br \/>\n            gripper_change &#061; np.max(np.abs(<br \/>\n                observation[&#034;robot0_gripper_qpos&#034;]<br \/>\n                &#8211; gripper_before<br \/>\n            ))<br \/>\n            stationary_flags.append(bool(<br \/>\n                arm_change &lt;&#061; ARM_STILL_THRESHOLD<br \/>\n                and gripper_change &lt;&#061; GRIPPER_STILL_THRESHOLD<br \/>\n            ))<\/p>\n<p>            if command[6] !&#061; previous_gripper_command:<br \/>\n                gripper_switch_count &#043;&#061; 1<br \/>\n            previous_gripper_command &#061; float(command[6])<\/p>\n<p>        assert np.isfinite(env.sim.data.qpos).all()<br \/>\n        env.env.render()<\/p>\n<p>        for key in [<br \/>\n            &#034;agentview_image&#034;,<br \/>\n            &#034;robot0_eye_in_hand_image&#034;,<br \/>\n        ]:<br \/>\n            assert observation[key].shape &#061;&#061; (256, 256, 3)<br \/>\n            cv2.imshow(<br \/>\n                key,<br \/>\n                display_image(<br \/>\n                    observation[key],<br \/>\n                    wrist&#061;(key &#061;&#061; &#034;robot0_eye_in_hand_image&#034;),<br \/>\n                ),<br \/>\n            )<br \/>\n        cv2.waitKey(1)<\/p>\n<p>        if record_start is not None:<br \/>\n            success_count &#061; (<br \/>\n                success_count &#043; 1<br \/>\n                if env.check_success() and command[6] &lt; 0<br \/>\n                else 0<br \/>\n            )<br \/>\n            if success_count &gt;&#061; 10:<br \/>\n                success &#061; True<br \/>\n                stop_reason &#061; &#034;\u8fde\u7eed\u6210\u529f\u5e76\u6301\u7eed\u53d1\u9001\u677e\u722a\u6307\u4ee4&#034;<br \/>\n                print(&#034;TASK_SUCCESS&#034;)<br \/>\n                break<\/p>\n<p>            if len(actions) &gt;&#061; MAX_STEPS:<br \/>\n                stop_reason &#061; &#034;\u8fbe\u5230 1000 \u6b65&#xff0c;\u4ecd\u672a\u6ee1\u8db3\u6210\u529f\u6761\u4ef6&#034;<br \/>\n                break<\/p>\n<p>        if time.perf_counter() &#8211; last_log &gt;&#061; 1:<br \/>\n            print(<br \/>\n                &#034;\u6b65\u6570:&#034;, len(actions),<br \/>\n                &#034;\u5939\u722a\u5207\u6362:&#034;, gripper_switch_count,<br \/>\n                &#034;\u624b\u52a8\u91cd\u8bd5:&#034;, device.retry_count,<br \/>\n                &#034;\u8fde\u7eed\u6210\u529f:&#034;, success_count,<br \/>\n            )<br \/>\n            last_log &#061; time.perf_counter()<\/p>\n<p>        remaining &#061; (<br \/>\n            1 \/ CONTROL_FREQ<br \/>\n            &#8211; (time.perf_counter() &#8211; loop_start)<br \/>\n        )<br \/>\n        if remaining &gt; 0:<br \/>\n            time.sleep(remaining)<\/p>\n<p>except KeyboardInterrupt:<br \/>\n    success &#061; False<br \/>\n    stop_reason &#061; &#034;\u7528\u6237\u901a\u8fc7 Ctrl&#043;C \u7ed3\u675f&#034;<\/p>\n<p>except Exception as error:<br \/>\n    success &#061; False<br \/>\n    stop_reason &#061; f&#034;{type(error).__name__}: {error}&#034;<br \/>\n    raise<\/p>\n<p>finally:<br \/>\n    record_end &#061; time.perf_counter()<\/p>\n<p>    try:<br \/>\n        if record_start is None:<br \/>\n            print(&#034;\u6ca1\u6709\u5f00\u59cb\u5f55\u5236&#xff0c;\u4e0d\u8ba1\u5165\u91c7\u96c6\u5c1d\u8bd5\u3002&#034;)<br \/>\n        else:<br \/>\n            elapsed &#061; record_end &#8211; record_start<br \/>\n            attempt &#061; {<br \/>\n                &#034;timestamp&#034;: RUN_ID,<br \/>\n                &#034;split&#034;: &#034;train&#034;,<br \/>\n                &#034;init_index&#034;: args.init_index,<br \/>\n                &#034;success&#034;: success,<br \/>\n                &#034;steps&#034;: len(actions),<br \/>\n                &#034;recording_seconds&#034;: elapsed,<br \/>\n                &#034;collection_fps&#034;: (<br \/>\n                    len(actions) \/ elapsed if elapsed &gt; 0 else 0.0<br \/>\n                ),<br \/>\n                &#034;stationary_ratio&#034;: (<br \/>\n                    float(np.mean(stationary_flags))<br \/>\n                    if stationary_flags else None<br \/>\n                ),<br \/>\n                &#034;gripper_switch_count&#034;: gripper_switch_count,<br \/>\n                &#034;retry_count_manual&#034;: (<br \/>\n                    device.retry_count if device else None<br \/>\n                ),<br \/>\n                &#034;stop_reason&#034;: stop_reason,<br \/>\n            }<br \/>\n            save_result(<br \/>\n                states, actions, stationary_flags,<br \/>\n                initial_state, model_xml, env_info, attempt,<br \/>\n            )<br \/>\n    finally:<br \/>\n        try:<br \/>\n            if device is not None:<br \/>\n                device.listener.stop()<br \/>\n        finally:<br \/>\n            try:<br \/>\n                if env is not None:<br \/>\n                    env.close()<br \/>\n            finally:<br \/>\n                cv2.destroyAllWindows()<\/p>\n<p>\u672c\u6b21\u5b9a\u4e49\u4e8630\u79cd\u521d\u59cb\u72b6\u6001&#xff0c;\u4e5f\u5c31\u662f30\u79cd\u7897\u7684\u521d\u59cb\u4f4d\u7f6e&#xff0c;\u5404\u81ea\u91c7\u4e24\u6761\u6570\u636e&#xff0c;\u4e00\u517160\u6761\u3002<\/p>\n<h4>4.2. \u7edd\u5bf9\u76ee\u6807\u4e0e\u76f8\u5bf9\u8f93\u5165\u4e4b\u524d\u7684\u6570\u91cf\u5173\u7cfb<\/h4>\n<p>\u8fd9\u4e00\u6b65\u6d89\u53ca\u5230\u6570\u636e\u7684\u8f6c\u6362\u3002\u6211\u4eec\u5728\u91c7\u96c6\u6570\u636e\u65f6&#xff0c;\u5f97\u5230\u7684\u662f\u7edd\u5bf9\u4f4d\u59ff&#xff0c;\u6bd4\u5982\u7b2c0\u79d2\u672b\u7aef\u57280.2\u7c73&#xff0c;\u7b2c1\u79d2\u57280.21\u79d2&#xff0c;\u8fd91\u79d2\u95f4\u7684\u53d8\u5316\u91cf\u4e3a0.01\u7c73&#xff0c;\u6a21\u578b\u9700\u8981\u76847\u7ef4action\u4e2d\u6bcf\u4e00\u4f4d\u90fd\u662f\u76f8\u5bf9\u589e\u91cf&#xff0c;\u90a3\u4e5f\u5c31\u662f\u8bf4\u6b64\u65f6\u586b\u5165action\u7684\u6570\u503c\u5c31\u662f0.1\u5417&#xff1f;\u5b9e\u9645\u5e76\u4e0d\u662f&#xff0c;\u5b9e\u9645\u586b\u5165\u7684\u6570\u503c\u8ddf\u8fd9\u91cc\u76840.1\u5b58\u5728\u500d\u6570\u5173\u7cfb&#xff0c;\u5177\u4f53\u6570\u636e\u7531\u4e0b\u9762\u7684\u4ee3\u7801\u5f97\u77e5&#xff1a;<\/p>\n<p>import sys<br \/>\nfrom pathlib import Path<br \/>\nimport inspect<br \/>\nimport numpy as np<\/p>\n<p>week4_dir &#061; Path(&#034;\/home\/dukiya\/libero-learning\/week4&#034;)<br \/>\nassert (week4_dir \/ &#034;piper_robot.py&#034;).is_file()<br \/>\n# \u628a week4 \u76ee\u5f55\u52a0\u8fdb sys.path&#xff0c;\u8ba9 Python \u80fd\u627e\u5230 piper_robot.py\u3002<br \/>\nsys.path.insert(0, str(week4_dir))<\/p>\n<p>import piper_robot<br \/>\nfrom libero.libero import benchmark, get_libero_path<br \/>\nfrom libero.libero.envs.env_wrapper import ControlEnv<br \/>\n# \u59ff\u6001\u8f6c\u6362\u5de5\u5177<br \/>\nfrom robosuite.utils import transform_utils as T<\/p>\n<p>suite &#061; benchmark.get_benchmark_dict()[&#034;libero_spatial&#034;]()<br \/>\ntask &#061; suite.get_task(0)<\/p>\n<p>bddl_path &#061; (<br \/>\n    Path(get_libero_path(&#034;bddl_files&#034;))<br \/>\n    \/ task.problem_folder<br \/>\n    \/ task.bddl_file<br \/>\n)<\/p>\n<p>env &#061; ControlEnv(<br \/>\n    bddl_file_name&#061;str(bddl_path),<br \/>\n    robots&#061;[&#034;Piper&#034;],<br \/>\n    controller&#061;&#034;OSC_POSE&#034;,<br \/>\n    initialization_noise&#061;None,<br \/>\n    control_freq&#061;20,<br \/>\n    # \u4e0d\u5f00\u7a97\u53e3<br \/>\n    has_renderer&#061;False,<br \/>\n    has_offscreen_renderer&#061;False,<br \/>\n    # \u89c2\u6d4b\u6570\u636e\u4e0d\u8fd4\u56de\u56fe\u50cf<br \/>\n    use_camera_obs&#061;False,<br \/>\n)<\/p>\n<p>try:<br \/>\n    env.seed(1000)<br \/>\n    env.reset()<\/p>\n<p>    # \u62ff\u5230\u63a7\u5236\u5668&#xff0c;\u4f4d\u7f6e\u548c\u59ff\u6001\u8054\u5408\u8ba1\u7b97<br \/>\n    controller &#061; env.robots[0].controller<br \/>\n    controller.uncoupling &#061; False<br \/>\n    controller.update(force&#061;True)<\/p>\n<p>    current_pos &#061; controller.ee_pos.copy()<br \/>\n    current_ori &#061; controller.ee_ori_mat.copy()<br \/>\n    # \u4eff\u771f\u5668\u5185\u7684\u6570\u636e<br \/>\n    original_qpos &#061; env.sim.data.qpos.copy()<br \/>\n    original_time &#061; env.sim.data.time<\/p>\n<p>    # \u770b\u4e00\u4e0b\u7f29\u653e\u7cfb\u6570\u662f\u591a\u5c11<br \/>\n    # \u7269\u7406\u4f4d\u79fb &#061; output_min &#043; (action &#8211; input_min) \/ (input_max &#8211; input_min) \u00d7 (output_max &#8211; output_min)<br \/>\n    print(&#034;&#061;&#061;&#061; \u63a7\u5236\u5668\u914d\u7f6e &#061;&#061;&#061;&#034;)<br \/>\n    print(&#034;\u6e90\u7801\u6587\u4ef6:&#034;, inspect.getfile(type(controller)))<br \/>\n    print(&#034;input_min:&#034;, controller.input_min)<br \/>\n    print(&#034;input_max:&#034;, controller.input_max)<br \/>\n    print(&#034;output_min:&#034;, controller.output_min)<br \/>\n    print(&#034;output_max:&#034;, controller.output_max)<br \/>\n    print(&#034;impedance_mode:&#034;, controller.impedance_mode)<\/p>\n<p>    assert controller.control_dim &#061;&#061; 6<br \/>\n    assert controller.impedance_mode &#061;&#061; &#034;fixed&#034;<\/p>\n<p>    target_pos &#061; current_pos &#043; np.array([0.01, -0.005, 0.003])<\/p>\n<p>    # \u8f74\u89d2 \u2192 \u56db\u5143\u6570 \u2192 \u65cb\u8f6c\u77e9\u9635&#xff0c;\u5de6\u4e58\u5f53\u524d\u59ff\u6001<br \/>\n    rotation_change &#061; np.array([0.02, -0.03, 0.04])<br \/>\n    target_ori &#061; (<br \/>\n        T.quat2mat(T.axisangle2quat(rotation_change))<br \/>\n        &#064; current_ori<br \/>\n    )<\/p>\n<p>    # \u7edd\u5bf9action\u503c&#xff1a;\u4f4d\u7f6e&#043;\u59ff\u6001\u8f74\u89d2&#043;\u5939\u722a\u662f\u5426\u5f00\u5408<br \/>\n    absolute_action &#061; np.concatenate([<br \/>\n        target_pos,<br \/>\n        T.quat2axisangle(T.mat2quat(target_ori)),<br \/>\n        [-1.0],<br \/>\n    ])<\/p>\n<p>    # False:\u8f93\u5165\u7684\u662f\u7edd\u5bf9\u76ee\u6807&#xff1b;True:\u8f93\u5165\u7684\u662f\u76f8\u5bf9\u589e\u91cf<br \/>\n    controller.use_delta &#061; False<br \/>\n    # \u91cd\u65b0\u8bbe\u5b9a\u76ee\u6807\u70b9&#xff0c;\u53ea\u53d6\u524d6\u7ef4&#xff0c;\u56e0\u4e3a\u5939\u722a\u662f\u5355\u72ec\u5904\u7406\u7684<br \/>\n    controller.reset_goal()<br \/>\n    controller.set_goal(absolute_action[:6])<\/p>\n<p>    absolute_goal_pos &#061; controller.goal_pos.copy()<br \/>\n    absolute_goal_ori &#061; controller.goal_ori.copy()<\/p>\n<p>    # \u5f00\u59cb\u8ba1\u7b97\u76f8\u5bf9\u6539\u53d8\u91cf<br \/>\n    position_delta &#061; target_pos &#8211; current_pos<br \/>\n    # \u8ba1\u7b97\u4ece\u5f53\u524d\u59ff\u6001\u5230\u76ee\u6807\u59ff\u6001\u7684\u76f8\u5bf9\u65cb\u8f6c&#xff0c;\u5148\u7b97\u65cb\u8f6c\u77e9\u9635&#xff0c;\u518d\u8f6c\u89d2<br \/>\n    # target_ori&#xff0c; current_ori\u90fd\u662f\u77e9\u9635&#xff0c;\u65cb\u8f6c\u77e9\u9635\u7684\u8f6c\u7f6e\u7b49\u4e8e\u5176\u9006<br \/>\n    relative_rotation &#061; target_ori &#064; current_ori.T<br \/>\n    rotation_delta &#061; T.quat2axisangle(<br \/>\n        T.mat2quat(relative_rotation)<br \/>\n    )<\/p>\n<p>    physical_delta &#061; np.concatenate([<br \/>\n        position_delta,<br \/>\n        rotation_delta,<br \/>\n    ])<\/p>\n<p>    # \u53cd\u7b97\u63a7\u5236\u5668\u7f29\u653e\u524d\u7684\u8f93\u5165&#xff0c;\u4e0d\u628a\u201c\u7c73\u201d\u76f4\u63a5\u5f53\u52a8\u4f5c\u8f93\u5165<br \/>\n    input_mid &#061; (<br \/>\n        controller.input_max &#043; controller.input_min<br \/>\n    ) \/ 2<\/p>\n<p>    output_mid &#061; (<br \/>\n        controller.output_max &#043; controller.output_min<br \/>\n    ) \/ 2<\/p>\n<p>    scale &#061; (<br \/>\n        (controller.output_max &#8211; controller.output_min)<br \/>\n        \/ (controller.input_max &#8211; controller.input_min)<br \/>\n    )<br \/>\n    assert np.all(scale &gt; 0)<\/p>\n<p>    relative_arm_action &#061; (<br \/>\n        (physical_delta &#8211; output_mid) \/ scale &#043; input_mid<br \/>\n    )<\/p>\n<p>    # \u672c\u5b9e\u9a8c\u9009\u62e9\u7684\u5c0f\u76ee\u6807\u5e94\u5728\u8f93\u5165\u8303\u56f4\u5185&#xff0c;\u4e0d\u80fd\u9760\u88c1\u526a\u63a9\u76d6\u9519\u8bef<br \/>\n    assert np.all(<br \/>\n        relative_arm_action &gt;&#061; controller.input_min &#8211; 1e-8<br \/>\n    )<br \/>\n    assert np.all(<br \/>\n        relative_arm_action &lt;&#061; controller.input_max &#043; 1e-8<br \/>\n    )<\/p>\n<p>    # \u673a\u68b0\u81c2&#043;\u5939\u722a<br \/>\n    relative_action &#061; np.concatenate([<br \/>\n        relative_arm_action,<br \/>\n        [-1.0],<br \/>\n    ])<\/p>\n<p>    controller.use_delta &#061; True<br \/>\n    controller.reset_goal()<br \/>\n    controller.set_goal(relative_action[:6])<\/p>\n<p>    # \u8ba1\u7b97\u76f8\u5bf9\u52a8\u4f5c\u548c\u7edd\u5bf9\u52a8\u4f5c\u4e4b\u95f4\u7684\u8bef\u5dee<br \/>\n    position_error &#061; np.linalg.norm(<br \/>\n        controller.goal_pos &#8211; absolute_goal_pos<br \/>\n    )<br \/>\n    rotation_matrix_error &#061; np.linalg.norm(<br \/>\n        controller.goal_ori &#8211; absolute_goal_ori<br \/>\n    )<\/p>\n<p>    print(&#034;\\\\n&#061;&#061;&#061; \u540c\u4e00\u76ee\u6807\u7684\u4e24\u79cd\u8f93\u5165 &#061;&#061;&#061;&#034;)<br \/>\n    print(&#034;\u7edd\u5bf9\u52a8\u4f5c:&#034;, absolute_action)<br \/>\n    print(&#034;\u5b9e\u9645\u4f4d\u59ff\u589e\u91cf:&#034;, physical_delta)<br \/>\n    print(&#034;relative \u52a8\u4f5c:&#034;, relative_action)<\/p>\n<p>    print(&#034;\\\\n&#061;&#061;&#061; \u63a7\u5236\u5668\u751f\u6210\u7684\u76ee\u6807\u662f\u5426\u4e00\u81f4 &#061;&#061;&#061;&#034;)<br \/>\n    print(&#034;\u4f4d\u7f6e\u8bef\u5dee \/ m:&#034;, position_error)<br \/>\n    print(&#034;\u65cb\u8f6c\u77e9\u9635\u5dee\u7684\u8303\u6570:&#034;, rotation_matrix_error)<\/p>\n<p>    assert absolute_action.shape &#061;&#061; relative_action.shape &#061;&#061; (7,)<br \/>\n    assert np.isfinite(relative_action).all()<br \/>\n    assert position_error &lt; 1e-6<br \/>\n    assert rotation_matrix_error &lt; 1e-6<\/p>\n<p>    # \u786e\u8ba4\u6ca1\u6709\u63a8\u8fdb\u7269\u7406\u65f6\u95f4&#xff0c;\u4e5f\u6ca1\u6709\u6539\u53d8\u5173\u8282\u4f4d\u7f6e<br \/>\n    assert env.sim.data.time &#061;&#061; original_time<br \/>\n    assert np.array_equal(env.sim.data.qpos, original_qpos)<\/p>\n<p>    print(&#034;\\\\n&#061;&#061;&#061; \u672c\u673a set_goal \u6e90\u7801 &#061;&#061;&#061;&#034;)<br \/>\n    print(inspect.getsource(type(controller).set_goal))<br \/>\n    print(&#034;A1_ACTION_MAPPING_OK&#034;)<\/p>\n<p>finally:<br \/>\n    env.close()<\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>(libero) dukiya&#064;dukiya-XiaoXinPro-14-APH8:~\/libero-learning$ \/home\/dukiya\/venvs\/libero\/bin\/python \/home\/dukiya\/libero-learning\/week5\/A1_3_check_action_mapping.py<br \/>\n[robosuite WARNING] No private macro file found! (__init__.py:7)<br \/>\n[robosuite WARNING] It is recommended to use a private macro file (__init__.py:8)<br \/>\n[robosuite WARNING] To setup, run: python \/home\/dukiya\/venvs\/libero\/lib\/python3.10\/site-packages\/robosuite\/scripts\/setup_macros.py (__init__.py:9)<br \/>\n[info] using task orders [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]<br \/>\nLocal assets not found. Downloading from HuggingFace Hub&#8230;<br \/>\nAssets already downloaded at \/home\/dukiya\/.cache\/libero\/assets<br \/>\n&#061;&#061;&#061; \u63a7\u5236\u5668\u914d\u7f6e &#061;&#061;&#061;<br \/>\n\u6e90\u7801\u6587\u4ef6: \/home\/dukiya\/venvs\/libero\/lib\/python3.10\/site-packages\/robosuite\/controllers\/osc.py<br \/>\ninput_min: [-1. -1. -1. -1. -1. -1.]<br \/>\ninput_max: [1. 1. 1. 1. 1. 1.]<br \/>\noutput_min: [-0.05 -0.05 -0.05 -0.5  -0.5  -0.5 ]<br \/>\noutput_max: [0.05 0.05 0.05 0.5  0.5  0.5 ]<br \/>\nimpedance_mode: fixed<\/p>\n<p>&#061;&#061;&#061; \u540c\u4e00\u76ee\u6807\u7684\u4e24\u79cd\u8f93\u5165 &#061;&#061;&#061;<br \/>\n\u7edd\u5bf9\u52a8\u4f5c: [ 1.54273714e-04 -3.58575396e-03  1.21355331e&#043;00 -2.85290014e-02<br \/>\n  2.02465343e&#043;00  4.51160483e-02 -1.00000000e&#043;00]<br \/>\n\u5b9e\u9645\u4f4d\u59ff\u589e\u91cf: [ 0.01       -0.005       0.003       0.01999984 -0.02999977  0.03999976]<br \/>\nrelative \u52a8\u4f5c: [ 0.2        -0.1         0.06        0.03999967 -0.05999953  0.07999952<br \/>\n -1.        ]<\/p>\n<p>&#061;&#061;&#061; \u63a7\u5236\u5668\u751f\u6210\u7684\u76ee\u6807\u662f\u5426\u4e00\u81f4 &#061;&#061;&#061;<br \/>\n\u4f4d\u7f6e\u8bef\u5dee \/ m: 0.0<br \/>\n\u65cb\u8f6c\u77e9\u9635\u5dee\u7684\u8303\u6570: 6.252380293787821e-07<\/p>\n<p>&#061;&#061;&#061; \u672c\u673a set_goal \u6e90\u7801 &#061;&#061;&#061;<br \/>\n    def set_goal(self, action, set_pos&#061;None, set_ori&#061;None):<br \/>\n        &#034;&#034;&#034;<br \/>\n        Sets goal based on input &#064;action. If self.impedance_mode is not &#034;fixed&#034;, then the input will be parsed into the<br \/>\n        delta values to update the goal position \/ pose and the kp and\/or damping_ratio values to be immediately updated<br \/>\n        internally before executing the proceeding control loop.<\/p>\n<p>        Note that &#064;action expected to be in the following format, based on impedance mode!<\/p>\n<p>            :Mode &#096;&#039;fixed&#039;&#096;: [joint pos command]<br \/>\n            :Mode &#096;&#039;variable&#039;&#096;: [damping_ratio values, kp values, joint pos command]<br \/>\n            :Mode &#096;&#039;variable_kp&#039;&#096;: [kp values, joint pos command]<\/p>\n<p>        Args:<br \/>\n            action (Iterable): Desired relative joint position goal state<br \/>\n            set_pos (Iterable): If set, overrides &#064;action and sets the desired absolute eef position goal state<br \/>\n            set_ori (Iterable): IF set, overrides &#064;action and sets the desired absolute eef orientation goal state<br \/>\n        &#034;&#034;&#034;<br \/>\n        # Update state<br \/>\n        self.update()<\/p>\n<p>        # Parse action based on the impedance mode, and update kp \/ kd as necessary<br \/>\n        if self.impedance_mode &#061;&#061; &#034;variable&#034;:<br \/>\n            damping_ratio, kp, delta &#061; action[:6], action[6:12], action[12:]<br \/>\n            self.kp &#061; np.clip(kp, self.kp_min, self.kp_max)<br \/>\n            self.kd &#061; 2 * np.sqrt(self.kp) * np.clip(damping_ratio, self.damping_ratio_min, self.damping_ratio_max)<br \/>\n        elif self.impedance_mode &#061;&#061; &#034;variable_kp&#034;:<br \/>\n            kp, delta &#061; action[:6], action[6:]<br \/>\n            self.kp &#061; np.clip(kp, self.kp_min, self.kp_max)<br \/>\n            self.kd &#061; 2 * np.sqrt(self.kp)  # critically damped<br \/>\n        else:  # This is case &#034;fixed&#034;<br \/>\n            delta &#061; action<\/p>\n<p>        # If we&#039;re using deltas, interpret actions as such<br \/>\n        if self.use_delta:<br \/>\n            if delta is not None:<br \/>\n                scaled_delta &#061; self.scale_action(delta)<br \/>\n                if not self.use_ori and set_ori is None:<br \/>\n                    # Set default control for ori since user isn&#039;t actively controlling ori<br \/>\n                    set_ori &#061; np.array([[0.0, 1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, -1.0]])<br \/>\n            else:<br \/>\n                scaled_delta &#061; []<br \/>\n        # Else, interpret actions as absolute values<br \/>\n        else:<br \/>\n            if set_pos is None:<br \/>\n                set_pos &#061; delta[:3]<br \/>\n            # Set default control for ori if we&#039;re only using position control<br \/>\n            if set_ori is None:<br \/>\n                set_ori &#061; (<br \/>\n                    T.quat2mat(T.axisangle2quat(delta[3:6]))<br \/>\n                    if self.use_ori<br \/>\n                    else np.array([[0.0, 1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, -1.0]])<br \/>\n                )<br \/>\n            # No scaling of values since these are absolute values<br \/>\n            scaled_delta &#061; delta<\/p>\n<p>        # We only want to update goal orientation if there is a valid delta ori value OR if we&#039;re using absolute ori<br \/>\n        # use math.isclose instead of numpy because numpy is slow<br \/>\n        bools &#061; [0.0 if math.isclose(elem, 0.0) else 1.0 for elem in scaled_delta[3:]]<br \/>\n        if sum(bools) &gt; 0.0 or set_ori is not None:<br \/>\n            self.goal_ori &#061; set_goal_orientation(<br \/>\n                scaled_delta[3:], self.ee_ori_mat, orientation_limit&#061;self.orientation_limits, set_ori&#061;set_ori<br \/>\n            )<br \/>\n        self.goal_pos &#061; set_goal_position(<br \/>\n            scaled_delta[:3], self.ee_pos, position_limit&#061;self.position_limits, set_pos&#061;set_pos<br \/>\n        )<\/p>\n<p>        if self.interpolator_pos is not None:<br \/>\n            self.interpolator_pos.set_goal(self.goal_pos)<\/p>\n<p>        if self.interpolator_ori is not None:<br \/>\n            self.ori_ref &#061; np.array(self.ee_ori_mat)  # reference is the current orientation at start<br \/>\n            self.interpolator_ori.set_goal(<br \/>\n                orientation_error(self.goal_ori, self.ori_ref)<br \/>\n            )  # goal is the total orientation error<br \/>\n            self.relative_ori &#061; np.zeros(3)  # relative orientation always starts at 0<\/p>\n<p>A1_ACTION_MAPPING_OK<\/p>\n<p>\u91cd\u70b9\u5728\u8fd9\u91cc&#xff1a;<\/p>\n<p>\u5b9e\u9645\u4f4d\u59ff\u589e\u91cf: [ 0.01       -0.005       0.003       0.01999984 -0.02999977  0.03999976]<br \/>\nrelative \u52a8\u4f5c: [ 0.2        -0.1         0.06        0.03999967 -0.05999953  0.07999952<br \/>\n -1.        ]<\/p>\n<p>\u53ef\u4ee5\u53d1\u73b0&#xff0c;\u5b9e\u9645\u7684\u589e\u91cf\u4e3a0.01&#xff0c;\u4f46\u586b\u5165action\u7684\u76f8\u5bf9\u91cf\u4e3a0.2\u3002\u7b80\u5355\u6765\u8bf4&#xff0c;\u5c31\u662f\u6211\u4eec\u5728\u8f6c\u6362\u6570\u636e\u65f6&#xff0c;\u9700\u8981\u628a\u539f\u59cb\u6570\u636e\u6bcf\u4e00\u5e27\u7684\u53d8\u5316\u91cf\u6c42\u51fa\u6765&#xff0c;\u7136\u540e\u4e58\u4e0a20&#xff0c;\u624d\u80fd\u53d8\u6210\u6a21\u578b\u9700\u8981\u7684\u6570\u636e\u3002<\/p>\n<h4>4.3. \u6570\u636e\u8f6c\u6362<\/h4>\n<p>\u57fa\u4e8e4.2&#xff0c;\u6211\u4eec\u8981\u5c06\u81ea\u5df1\u91c7\u7684\u539f\u59cbhdf5\u8f6c\u6362\u6210\u6a21\u578b\u6240\u9700\u8981\u8868\u5f81\u65b9\u5f0f\u7684hdf5&#xff0c;\u518d\u8f6c\u6210\u8bad\u7ec3\u6240\u9700\u8981\u7684lerobot\u683c\u5f0f\u3002<\/p>\n<h5>4.3.1. \u539f\u59cbhdf5\u8f6c\u4e2d\u95f4hdf5<\/h5>\n<p>import sys<br \/>\nimport json<br \/>\nimport time<br \/>\nfrom pathlib import Path<\/p>\n<p>import cv2<br \/>\nimport h5py<br \/>\nimport numpy as np<br \/>\nfrom piper_xml import PHYSICS_XML_VERSION, fix_piper_xml<\/p>\n<p># \u590d\u7528\u5df2\u7ecf\u9002\u914d\u597d\u7684 Piper<br \/>\nsys.path.insert(0, &#034;\/home\/dukiya\/libero-learning\/week4&#034;)<br \/>\nimport piper_robot<\/p>\n<p>from robosuite import macros<br \/>\nfrom robosuite.utils import transform_utils as T<br \/>\nfrom libero.libero.envs.env_wrapper import ControlEnv<\/p>\n<p>SOURCE &#061; Path(<br \/>\n    &#034;\/home\/dukiya\/libero-learning\/week5\/datasets\/&#034;<br \/>\n    &#034;a2_piper_black_bowl\/&#034;<br \/>\n    &#034;demo_20261015_234043_644558.hdf5&#034;<br \/>\n)<\/p>\n<p># \u6bcf\u6b21\u4f7f\u7528\u65b0\u76ee\u5f55&#xff0c;\u907f\u514d\u8986\u76d6\u4e4b\u524d\u7684\u7ed3\u679c<br \/>\nOUTPUT &#061; (<br \/>\n    Path(__file__).resolve().parent<br \/>\n    \/ &#034;datasets\/a3_replay&#034;<br \/>\n    \/ f&#034;{SOURCE.stem}_{time.time_ns()}&#034;<br \/>\n)<\/p>\n<p>CAMERAS &#061; {<br \/>\n    &#034;agentview_image&#034;: &#034;observation.images.image&#034;,<br \/>\n    &#034;robot0_eye_in_hand_image&#034;: &#034;observation.images.image2&#034;,<br \/>\n}<\/p>\n<p>def absolute_to_relative(action, controller):<br \/>\n    &#034;&#034;&#034;\u628a\u4e16\u754c\u5750\u6807\u4e0b\u7684\u7edd\u5bf9\u76ee\u6807&#xff0c;\u8f6c\u6362\u4e3a\u63a7\u5236\u5668\u7f29\u653e\u524d\u7684\u76f8\u5bf9\u52a8\u4f5c\u3002&#034;&#034;&#034;<br \/>\n    target_rotation &#061; T.quat2mat(<br \/>\n        T.axisangle2quat(action[3:6])<br \/>\n    )<\/p>\n<p>    position_delta &#061; action[:3] &#8211; controller.ee_pos<\/p>\n<p>    # \u76f8\u5bf9\u65cb\u8f6c\u5fc5\u987b\u7528\u77e9\u9635\u8ba1\u7b97&#xff0c;\u4e0d\u80fd\u76f4\u63a5\u76f8\u51cf\u4e24\u4e2a\u8f74\u89d2<br \/>\n    rotation_delta &#061; (<br \/>\n        target_rotation &#064; controller.ee_ori_mat.T<br \/>\n    )<br \/>\n    quat_delta &#061; T.mat2quat(rotation_delta).astype(np.float64)<\/p>\n<p>    # \u5bf9\u589e\u91cf\u9009\u62e9\u8f83\u77ed\u7684\u65cb\u8f6c&#xff1b;\u4e0d\u6539\u53d8 observation.state \u7684\u56db\u5143\u6570\u7ea6\u5b9a<br \/>\n    if quat_delta[3] &lt; 0:<br \/>\n        quat_delta &#061; -quat_delta<\/p>\n<p>    # mat2quat \u4f7f\u7528 float32&#xff1b;\u6781\u5c0f\u65cb\u8f6c\u7684 w \u53ef\u80fd\u820d\u5165\u4e3a 1\u3002<br \/>\n    # \u7528 atan2 \u4fdd\u7559\u5411\u91cf\u90e8\u5206\u643a\u5e26\u7684\u5c0f\u65cb\u8f6c&#xff0c;\u907f\u514d acos(w) \u5c06\u5176\u5f52\u96f6\u3002<br \/>\n    vector &#061; quat_delta[:3]<br \/>\n    vector_norm &#061; np.linalg.norm(vector)<br \/>\n    if vector_norm &gt; 1e-12:<br \/>\n        angle &#061; 2.0 * np.arctan2(vector_norm, quat_delta[3])<br \/>\n        rotation_vector &#061; vector \/ vector_norm * angle<br \/>\n    else:<br \/>\n        rotation_vector &#061; 2.0 * vector<\/p>\n<p>    physical_delta &#061; np.concatenate([<br \/>\n        position_delta,<br \/>\n        rotation_vector,<br \/>\n    ])<\/p>\n<p>    input_mid &#061; (<br \/>\n        controller.input_max &#043; controller.input_min<br \/>\n    ) \/ 2<\/p>\n<p>    output_mid &#061; (<br \/>\n        controller.output_max &#043; controller.output_min<br \/>\n    ) \/ 2<\/p>\n<p>    scale &#061; (<br \/>\n        (controller.output_max &#8211; controller.output_min)<br \/>\n        \/ (controller.input_max &#8211; controller.input_min)<br \/>\n    )<br \/>\n    assert np.all(scale &gt; 0)<\/p>\n<p>    relative_arm &#061; (<br \/>\n        (physical_delta &#8211; output_mid) \/ scale &#043; input_mid<br \/>\n    )<\/p>\n<p>    # \u4e0d\u9759\u9ed8\u88c1\u526a&#xff0c;\u5426\u5219\u53ef\u80fd\u63a9\u76d6\u8f6c\u6362\u9519\u8bef<br \/>\n    if (<br \/>\n        np.any(relative_arm &lt; controller.input_min &#8211; 1e-6)<br \/>\n        or np.any(relative_arm &gt; controller.input_max &#043; 1e-6)<br \/>\n    ):<br \/>\n        raise ValueError(<br \/>\n            f&#034;\u76f8\u5bf9\u52a8\u4f5c\u8d85\u8fc7\u63a7\u5236\u5668\u8f93\u5165\u8303\u56f4: {relative_arm}&#034;<br \/>\n        )<\/p>\n<p>    return np.concatenate([<br \/>\n        relative_arm,<br \/>\n        action[6:7],  # \u4fdd\u7559\u5939\u722a\u5f00\u5408\u6307\u4ee4<br \/>\n    ])<\/p>\n<p>start &#061; time.perf_counter()<\/p>\n<p># \u53ea\u8bfb\u539f\u59cb\u6f14\u793a&#xff0c;\u4e0d\u4fee\u6539\u91c7\u96c6\u6570\u636e<br \/>\nwith h5py.File(SOURCE, &#034;r&#034;) as file:<br \/>\n    demo &#061; file[&#034;data\/demo_0&#034;]<\/p>\n<p>    assert bool(demo.attrs[&#034;success&#034;])<br \/>\n    states &#061; demo[&#034;states&#034;][:]<br \/>\n    absolute_actions &#061; demo[&#034;actions&#034;][:]<br \/>\n    model_xml &#061; demo.attrs[&#034;model_file&#034;]<br \/>\n    env_info &#061; json.loads(file[&#034;data&#034;].attrs[&#034;env_info&#034;])<\/p>\n<p># \u517c\u5bb9\u65e7 HDF5 \u4e2d\u7f3a\u5931 compiler \u5c5e\u6027\u7684 XML&#xff1b;\u539f\u59cb\u6570\u636e\u53ea\u8bfb&#xff0c;\u4e0d\u6539\u5199\u3002<br \/>\nmodel_xml &#061; fix_piper_xml(model_xml)<br \/>\nenv_info[&#034;physics_xml_version&#034;] &#061; PHYSICS_XML_VERSION<\/p>\n<p>count &#061; len(states)<br \/>\nfps &#061; int(env_info[&#034;control_freq&#034;])<\/p>\n<p>assert count &gt; 0<br \/>\nassert absolute_actions.shape &#061;&#061; (count, 7)<br \/>\nassert np.isfinite(states).all()<br \/>\nassert np.isfinite(absolute_actions).all()<br \/>\nassert np.all(np.abs(absolute_actions[:, 6]) &lt;&#061; 1)<br \/>\nassert env_info[&#034;action_representation&#034;] &#061;&#061; (<br \/>\n    &#034;world_xyz_m &#043; world_axis_angle_rad &#043; gripper&#034;<br \/>\n)<\/p>\n<p># \u5b8c\u6574\u4eff\u771f\u72b6\u6001\u7684\u7b2c 0 \u7ef4\u662f\u65f6\u95f4<br \/>\nassert np.allclose(<br \/>\n    np.diff(states[:, 0]),<br \/>\n    1 \/ fps,<br \/>\n    atol&#061;1e-6,<br \/>\n    rtol&#061;0,<br \/>\n)<\/p>\n<p># \u56fa\u5b9a\u539f\u59cb\u89c2\u6d4b\u7ea6\u5b9a&#xff0c;\u907f\u514d\u6362\u673a\u5668\u540e\u56fe\u50cf\u88ab\u91cd\u590d\u7ffb\u8f6c<br \/>\nassert macros.IMAGE_CONVENTION &#061;&#061; &#034;opengl&#034;, (<br \/>\n    &#034;\u5f53\u524d\u56fe\u50cf\u7ea6\u5b9a\u4e0d\u662f opengl&#xff0c;\u8bf7\u5148\u6838\u5bf9\u56fe\u50cf\u5904\u7406\u65b9\u5f0f&#034;<br \/>\n)<\/p>\n<p># \u4e0d\u8986\u76d6\u65e7\u8f6c\u6362\u7ed3\u679c<br \/>\nOUTPUT.mkdir(parents&#061;True, exist_ok&#061;False)<\/p>\n<p>env &#061; None<br \/>\nwriter &#061; None<\/p>\n<p>try:<br \/>\n    env &#061; ControlEnv(<br \/>\n        bddl_file_name&#061;env_info[&#034;bddl_file&#034;],<br \/>\n        robots&#061;env_info[&#034;robots&#034;],<br \/>\n        controller&#061;&#034;OSC_POSE&#034;,<br \/>\n        initialization_noise&#061;None,<br \/>\n        control_freq&#061;fps,<br \/>\n        has_renderer&#061;False,<br \/>\n        has_offscreen_renderer&#061;True,<br \/>\n        use_camera_obs&#061;True,<br \/>\n        camera_names&#061;[&#034;agentview&#034;, &#034;robot0_eye_in_hand&#034;],<br \/>\n        camera_widths&#061;256,<br \/>\n        camera_heights&#061;256,<br \/>\n        camera_depths&#061;False,<br \/>\n        ignore_done&#061;True,<br \/>\n    )<\/p>\n<p>    env.seed(env_info[&#034;seed&#034;])<br \/>\n    env.reset()<\/p>\n<p>    # \u5fc5\u987b\u6062\u590d\u91c7\u96c6\u65f6\u4fdd\u5b58\u7684\u6a21\u578b&#xff0c;\u5305\u62ec\u6700\u7ec8\u7684 90\u00b0 \u76f8\u673a\u8bbe\u7f6e<br \/>\n    env.reset_from_xml_string(model_xml)<\/p>\n<p>    controller &#061; env.robots[0].controller<br \/>\n    controller.uncoupling &#061; False<\/p>\n<p>    assert controller.impedance_mode &#061;&#061; &#034;fixed&#034;<br \/>\n    assert states.shape[1] &#061;&#061; env.get_sim_state().size<\/p>\n<p>    for name in [<br \/>\n        &#034;input_min&#034;, &#034;input_max&#034;,<br \/>\n        &#034;output_min&#034;, &#034;output_max&#034;,<br \/>\n    ]:<br \/>\n        assert np.allclose(<br \/>\n            getattr(controller, name),<br \/>\n            env_info[&#034;controller&#034;][name],<br \/>\n        ), f&#034;\u63a7\u5236\u5668\u53c2\u6570\u53d8\u5316: {name}&#034;<\/p>\n<p>    camera_id &#061; env.sim.model.camera_name2id(<br \/>\n        &#034;robot0_eye_in_hand&#034;<br \/>\n    )<br \/>\n    assert np.isclose(<br \/>\n        env.sim.model.cam_fovy[camera_id], 90.0<br \/>\n    )<\/p>\n<p>    writer &#061; cv2.VideoWriter(<br \/>\n        str(OUTPUT \/ &#034;preview.mp4&#034;),<br \/>\n        cv2.VideoWriter_fourcc(*&#034;mp4v&#034;),<br \/>\n        fps,<br \/>\n        (512, 256),<br \/>\n    )<br \/>\n    assert writer.isOpened(), &#034;\u65e0\u6cd5\u521b\u5efa\u9884\u89c8\u89c6\u9891&#034;<\/p>\n<p>    max_position_error &#061; 0.0<br \/>\n    max_rotation_error &#061; 0.0<br \/>\n    check_frames &#061; {0, count \/\/ 2, count &#8211; 1}<\/p>\n<p>    with h5py.File(OUTPUT \/ &#034;episode.hdf5&#034;, &#034;x&#034;) as file:<br \/>\n        file.attrs[&#034;complete&#034;] &#061; False<br \/>\n        file.attrs[&#034;source&#034;] &#061; str(SOURCE)<br \/>\n        file.attrs[&#034;task&#034;] &#061; env_info[&#034;task&#034;]<br \/>\n        file.attrs[&#034;fps&#034;] &#061; fps<br \/>\n        file.attrs[&#034;env_info&#034;] &#061; json.dumps(<br \/>\n            env_info, ensure_ascii&#061;False<br \/>\n        )<br \/>\n        file.attrs[&#034;action_representation&#034;] &#061; (<br \/>\n            &#034;relative controller input &#043; gripper&#034;<br \/>\n        )<br \/>\n        file.attrs[&#034;image_transform&#034;] &#061; (<br \/>\n            &#034;raw observation flipped in height and width&#034;<br \/>\n        )<\/p>\n<p>        state_data &#061; file.create_dataset(<br \/>\n            &#034;observation.state&#034;,<br \/>\n            shape&#061;(count, 8),<br \/>\n            dtype&#061;&#034;float32&#034;,<br \/>\n        )<br \/>\n        action_data &#061; file.create_dataset(<br \/>\n            &#034;action&#034;,<br \/>\n            shape&#061;(count, 7),<br \/>\n            dtype&#061;&#034;float32&#034;,<br \/>\n        )<br \/>\n        file.create_dataset(<br \/>\n            &#034;source_frame_index&#034;,<br \/>\n            data&#061;np.arange(count),<br \/>\n        )<\/p>\n<p>        image_data &#061; {<br \/>\n            key: file.create_dataset(<br \/>\n                key,<br \/>\n                shape&#061;(count, 256, 256, 3),<br \/>\n                dtype&#061;&#034;uint8&#034;,<br \/>\n                chunks&#061;(1, 256, 256, 3),<br \/>\n                compression&#061;&#034;lzf&#034;,<br \/>\n            )<br \/>\n            for key in CAMERAS.values()<br \/>\n        }<\/p>\n<p>        for index, (sim_state, absolute_action) in enumerate(<br \/>\n            zip(states, absolute_actions)<br \/>\n        ):<br \/>\n            # \u6062\u590d\u52a8\u4f5c\u6267\u884c\u524d\u7684\u540c\u4e00\u5e27\u72b6\u6001&#xff1b;\u4e0d\u4f1a\u63a8\u8fdb\u7269\u7406\u65f6\u95f4<br \/>\n            observation &#061; env.regenerate_obs_from_state(<br \/>\n                sim_state<br \/>\n            )<br \/>\n            controller.update(force&#061;True)<\/p>\n<p>            assert np.isclose(<br \/>\n                env.sim.data.time, sim_state[0]<br \/>\n            )<\/p>\n<p>            # 8 \u7ef4 state&#xff1a;\u672b\u7aef\u4f4d\u7f6e3 &#043; \u671d\u5411\u8f74\u89d23 &#043; \u4e24\u6307\u4f4d\u7f6e2<br \/>\n            state &#061; np.concatenate([<br \/>\n                observation[&#034;robot0_eef_pos&#034;],<br \/>\n                T.quat2axisangle(<br \/>\n                    observation[&#034;robot0_eef_quat&#034;].copy()<br \/>\n                ),<br \/>\n                observation[&#034;robot0_gripper_qpos&#034;],<br \/>\n            ]).astype(np.float32)<\/p>\n<p>            assert state.shape &#061;&#061; (8,)<br \/>\n            assert np.isfinite(state).all()<\/p>\n<p>            relative_action &#061; absolute_to_relative(<br \/>\n                absolute_action, controller<br \/>\n            ).astype(np.float32)<br \/>\n            assert np.isfinite(relative_action).all()<\/p>\n<p>            # \u68c0\u67e5\u4e24\u79cd\u52a8\u4f5c\u8f93\u5165\u662f\u5426\u6307\u5411\u540c\u4e00\u4e2a\u63a7\u5236\u76ee\u6807<br \/>\n            controller.use_delta &#061; False<br \/>\n            controller.reset_goal()<br \/>\n            controller.set_goal(absolute_action[:6])<br \/>\n            absolute_goal_pos &#061; controller.goal_pos.copy()<br \/>\n            absolute_goal_ori &#061; controller.goal_ori.copy()<\/p>\n<p>            controller.use_delta &#061; True<br \/>\n            controller.reset_goal()<br \/>\n            controller.set_goal(relative_action[:6])<\/p>\n<p>            position_error &#061; np.linalg.norm(<br \/>\n                controller.goal_pos &#8211; absolute_goal_pos<br \/>\n            )<br \/>\n            rotation_error &#061; np.linalg.norm(<br \/>\n                controller.goal_ori &#8211; absolute_goal_ori<br \/>\n            )<\/p>\n<p>            assert position_error &lt; 1e-5, (<br \/>\n                f&#034;\u5e27&#061;{index}, \u76ee\u6807\u4f4d\u7f6e\u8bef\u5dee&#061;{position_error}&#034;<br \/>\n            )<br \/>\n            assert rotation_error &lt; 1e-5, (<br \/>\n                f&#034;\u5e27&#061;{index}, \u76ee\u6807\u65cb\u8f6c\u77e9\u9635\u8bef\u5dee&#061;{rotation_error}, &#034;<br \/>\n                f&#034;\u76f8\u5bf9\u65cb\u8f6c\u8f93\u5165&#061;{relative_action[3:6]}&#034;<br \/>\n            )<\/p>\n<p>            max_position_error &#061; max(<br \/>\n                max_position_error, position_error<br \/>\n            )<br \/>\n            max_rotation_error &#061; max(<br \/>\n                max_rotation_error, rotation_error<br \/>\n            )<\/p>\n<p>            state_data[index] &#061; state<br \/>\n            action_data[index] &#061; relative_action.astype(<br \/>\n                np.float32<br \/>\n            )<\/p>\n<p>            frames &#061; []<br \/>\n            for raw_key, dataset_key in CAMERAS.items():<br \/>\n                raw &#061; observation[raw_key]<br \/>\n                assert raw.shape &#061;&#061; (256, 256, 3)<br \/>\n                assert raw.dtype &#061;&#061; np.uint8<\/p>\n<p>                # \u4e0e\u5728\u7ebf LIBERO \u89c2\u6d4b\u5904\u7406\u4fdd\u6301\u4e00\u81f4<br \/>\n                rgb &#061; np.ascontiguousarray(<br \/>\n                    raw[::-1, ::-1]<br \/>\n                )<br \/>\n                image_data[dataset_key][index] &#061; rgb<br \/>\n                frames.append(rgb)<\/p>\n<p>                if index in check_frames:<br \/>\n                    assert cv2.imwrite(<br \/>\n                        str(<br \/>\n                            OUTPUT<br \/>\n                            \/ f&#034;{index:06d}_{raw_key}.png&#034;<br \/>\n                        ),<br \/>\n                        cv2.cvtColor(<br \/>\n                            rgb, cv2.COLOR_RGB2BGR<br \/>\n                        ),<br \/>\n                    )<\/p>\n<p>            preview &#061; np.concatenate(frames, axis&#061;1)<br \/>\n            writer.write(<br \/>\n                cv2.cvtColor(<br \/>\n                    preview, cv2.COLOR_RGB2BGR<br \/>\n                )<br \/>\n            )<\/p>\n<p>            if (index &#043; 1) % 50 &#061;&#061; 0:<br \/>\n                print(f&#034;\u5df2\u6062\u590d: {index &#043; 1}\/{count}&#034;)<\/p>\n<p>        file.attrs[&#034;complete&#034;] &#061; True<\/p>\n<p>    writer.release()<br \/>\n    writer &#061; None<\/p>\n<p>    # \u4fdd\u5b58\u540e\u8bfb\u56de\u68c0\u67e5<br \/>\n    with h5py.File(OUTPUT \/ &#034;episode.hdf5&#034;, &#034;r&#034;) as file:<br \/>\n        assert bool(file.attrs[&#034;complete&#034;])<br \/>\n        assert file[&#034;observation.state&#034;].shape &#061;&#061; (count, 8)<br \/>\n        assert file[&#034;action&#034;].shape &#061;&#061; (count, 7)<\/p>\n<p>        for key in CAMERAS.values():<br \/>\n            assert file[key].shape &#061;&#061; (<br \/>\n                count, 256, 256, 3<br \/>\n            )<\/p>\n<p>    elapsed &#061; time.perf_counter() &#8211; start<\/p>\n<p>    print(&#034;\\\\n&#061;&#061;&#061; A3 \u7b2c\u4e00\u6bb5\u7ed3\u679c &#061;&#061;&#061;&#034;)<br \/>\n    print(&#034;\u539f\u59cb\u5e27\u6570:&#034;, count)<br \/>\n    print(&#034;observation.state:&#034;, (count, 8))<br \/>\n    print(&#034;action:&#034;, (count, 7))<br \/>\n    print(&#034;\u4e24\u8def\u56fe\u50cf\u5206\u522b\u4e3a:&#034;, (count, 256, 256, 3))<br \/>\n    print(&#034;\u6700\u5927\u76ee\u6807\u4f4d\u7f6e\u8bef\u5dee \/ m:&#034;, max_position_error)<br \/>\n    print(&#034;\u6700\u5927\u76ee\u6807\u65cb\u8f6c\u77e9\u9635\u8bef\u5dee:&#034;, max_rotation_error)<br \/>\n    print(&#034;\u6062\u590d\u4e0e\u5bfc\u51fa\u8017\u65f6 \/ s:&#034;, elapsed)<br \/>\n    print(&#034;\u8f93\u51fa\u76ee\u5f55:&#034;, OUTPUT)<br \/>\n    print(&#034;A3_REPLAY_EXPORT_OK&#034;)<\/p>\n<p>finally:<br \/>\n    if writer is not None:<br \/>\n        writer.release()<br \/>\n    if env is not None:<br \/>\n        env.close()<\/p>\n<p>\u8fd9\u4e00\u6b65\u505a\u4e86\u521a\u521a\u63d0\u5230\u7684\u6570\u503c\u500d\u6570\u8f6c\u6362&#xff0c;\u5f97\u5230\u4e86\u5e26\u6709\u56fe\u50cf\u4fe1\u606f\u3001state\u3001action\u7684hdf5.<\/p>\n<h5>4.3.2. \u4e2d\u95f4hdf5\u8f6cLeRobotDatasetv3\u683c\u5f0f<\/h5>\n<p>\u8fdb\u884c\u8bad\u7ec3\u7684\u6570\u636e\u8fd8\u8981\u8fdb\u4e00\u6b65\u5c01\u88c5\u4e00\u4e0b&#xff0c;\u6bd4\u5982\u9700\u8981\u9610\u8ff0\u6e05\u695a\u8fd9\u4e2a\u6570\u636e\u5bf9\u5e94\u54ea\u4e2a\u4efb\u52a1\u6587\u672c\u7b49\u7b49&#xff1a;<\/p>\n<p>import time<br \/>\nfrom pathlib import Path<\/p>\n<p>import h5py<br \/>\nimport numpy as np<\/p>\n<p>from lerobot.configs.video import RGBEncoderConfig<br \/>\nfrom lerobot.datasets.lerobot_dataset import LeRobotDataset<\/p>\n<p>SOURCE &#061; Path(<br \/>\n    &#034;\/root\/autodl-tmp\/workspace\/datasets\/week5\/&#034;<br \/>\n    &#034;a3_replay_90deg\/episode.hdf5&#034;<br \/>\n)<\/p>\n<p>ROOT &#061; Path(<br \/>\n    &#034;\/root\/autodl-tmp\/workspace\/datasets\/week5\/&#034;<br \/>\n    &#034;piper_black_bowl_a3_lerobot&#034;<br \/>\n)<\/p>\n<p># \u8fd9\u91cc\u53ea\u662f\u6570\u636e\u96c6\u6807\u8bc6&#xff0c;\u4e0d\u4f1a\u81ea\u52a8\u4e0a\u4f20 Hugging Face<br \/>\nREPO_ID &#061; &#034;dukiya\/piper_black_bowl_a3&#034;<\/p>\n<p>CAMERA_KEYS &#061; (<br \/>\n    &#034;observation.images.image&#034;,<br \/>\n    &#034;observation.images.image2&#034;,<br \/>\n)<\/p>\n<p>FEATURES &#061; {<br \/>\n    &#034;observation.state&#034;: {<br \/>\n        &#034;dtype&#034;: &#034;float32&#034;,<br \/>\n        &#034;shape&#034;: (8,),<br \/>\n        &#034;names&#034;: None,<br \/>\n    },<br \/>\n    &#034;action&#034;: {<br \/>\n        &#034;dtype&#034;: &#034;float32&#034;,<br \/>\n        &#034;shape&#034;: (7,),<br \/>\n        &#034;names&#034;: None,<br \/>\n    },<br \/>\n}<\/p>\n<p>for key in CAMERA_KEYS:<br \/>\n    FEATURES[key] &#061; {<br \/>\n        &#034;dtype&#034;: &#034;video&#034;,<br \/>\n        &#034;shape&#034;: (256, 256, 3),<br \/>\n        &#034;names&#034;: [&#034;height&#034;, &#034;width&#034;, &#034;channels&#034;],<br \/>\n    }<\/p>\n<p>start &#061; time.perf_counter()<\/p>\n<p>assert SOURCE.is_file(), SOURCE<br \/>\nassert not ROOT.exists(), (<br \/>\n    f&#034;\u8f93\u51fa\u76ee\u5f55\u5df2\u5b58\u5728&#xff0c;\u5148\u68c0\u67e5\u662f\u5426\u5df2\u6709\u8f6c\u6362\u7ed3\u679c&#xff1a;{ROOT}&#034;<br \/>\n)<\/p>\n<p>with h5py.File(SOURCE, &#034;r&#034;) as source:<br \/>\n    assert bool(source.attrs[&#034;complete&#034;])<\/p>\n<p>    fps &#061; int(source.attrs[&#034;fps&#034;])<br \/>\n    task &#061; str(source.attrs[&#034;task&#034;])<br \/>\n    count &#061; source[&#034;action&#034;].shape[0]<\/p>\n<p>    assert source[&#034;observation.state&#034;].shape &#061;&#061; (count, 8)<br \/>\n    assert source[&#034;action&#034;].shape &#061;&#061; (count, 7)<br \/>\n    assert source.attrs[&#034;action_representation&#034;] &#061;&#061; (<br \/>\n        &#034;relative controller input &#043; gripper&#034;<br \/>\n    )<\/p>\n<p>    for key in CAMERA_KEYS:<br \/>\n        assert source[key].shape &#061;&#061; (count, 256, 256, 3)<\/p>\n<p>    # \u4f7f\u7528 CPU \u7684 H.264 \u7f16\u7801&#xff0c;\u4e0d\u4f9d\u8d56 GPU\u3002<br \/>\n    encoder &#061; RGBEncoderConfig(<br \/>\n        vcodec&#061;&#034;h264&#034;,<br \/>\n        crf&#061;18,<br \/>\n        preset&#061;&#034;fast&#034;,<br \/>\n        video_backend&#061;&#034;pyav&#034;,<br \/>\n    )<\/p>\n<p>    dataset &#061; LeRobotDataset.create(<br \/>\n        repo_id&#061;REPO_ID,<br \/>\n        root&#061;ROOT,<br \/>\n        robot_type&#061;&#034;piper&#034;,<br \/>\n        fps&#061;fps,<br \/>\n        features&#061;FEATURES,<br \/>\n        use_videos&#061;True,<br \/>\n        video_backend&#061;&#034;pyav&#034;,<br \/>\n        rgb_encoder&#061;encoder,<br \/>\n        image_writer_processes&#061;0,<br \/>\n        image_writer_threads&#061;0,<br \/>\n        encoder_threads&#061;1,<br \/>\n    )<\/p>\n<p>    try:<br \/>\n        for index in range(count):<br \/>\n            frame &#061; {<br \/>\n                &#034;observation.state&#034;: source[<br \/>\n                    &#034;observation.state&#034;<br \/>\n                ][index],<br \/>\n                &#034;action&#034;: source[&#034;action&#034;][index],<br \/>\n                &#034;task&#034;: task,<br \/>\n            }<\/p>\n<p>            for key in CAMERA_KEYS:<br \/>\n                frame[key] &#061; source[key][index]<\/p>\n<p>            assert np.isfinite(<br \/>\n                frame[&#034;observation.state&#034;]<br \/>\n            ).all()<br \/>\n            assert np.isfinite(frame[&#034;action&#034;]).all()<\/p>\n<p>            dataset.add_frame(frame)<\/p>\n<p>            if (index &#043; 1) % 50 &#061;&#061; 0:<br \/>\n                print(f&#034;\u5df2\u5199\u5165: {index &#043; 1}\/{count}&#034;)<\/p>\n<p>        # \u4e24\u8def\u76f8\u673a\u4e32\u884c\u7f16\u7801&#xff0c;\u907f\u514d\u989d\u5916\u542f\u52a8\u7f16\u7801\u5b50\u8fdb\u7a0b<br \/>\n        dataset.save_episode(parallel_encoding&#061;False)<\/p>\n<p>    finally:<br \/>\n        # \u5fc5\u987b\u8c03\u7528&#xff0c;\u786e\u4fdd parquet \u7b49\u6587\u4ef6\u5b8c\u6574\u843d\u76d8<br \/>\n        dataset.finalize()<\/p>\n<p>conversion_seconds &#061; time.perf_counter() &#8211; start<\/p>\n<p># \u4ece\u6700\u7ec8\u6570\u636e\u96c6\u91cd\u65b0\u52a0\u8f7d&#xff0c;\u800c\u4e0d\u662f\u53ea\u68c0\u67e5\u4e2d\u95f4\u6587\u4ef6<br \/>\nchecked &#061; LeRobotDataset(<br \/>\n    repo_id&#061;REPO_ID,<br \/>\n    root&#061;ROOT,<br \/>\n    video_backend&#061;&#034;pyav&#034;,<br \/>\n)<\/p>\n<p>assert len(checked) &#061;&#061; count<br \/>\nassert checked.meta.total_episodes &#061;&#061; 1<br \/>\nassert checked.meta.info[&#034;codebase_version&#034;] &#061;&#061; &#034;v3.0&#034;<\/p>\n<p># \u62bd\u67e5\u9996\u3001\u4e2d\u3001\u672b\u5e27&#xff0c;\u68c0\u67e5\u4f4e\u7ef4\u6570\u636e\u4e0e\u539f\u6587\u4ef6\u4e00\u81f4&#xff0c;<br \/>\n# \u5e76\u786e\u8ba4\u4e24\u8def\u89c6\u9891\u53ef\u4ee5\u89e3\u7801\u6210\u6a21\u578b\u8bfb\u53d6\u7684\u56fe\u50cf\u5f20\u91cf\u3002<br \/>\nwith h5py.File(SOURCE, &#034;r&#034;) as source:<br \/>\n    for index in (0, count \/\/ 2, count &#8211; 1):<br \/>\n        sample &#061; checked[index]<\/p>\n<p>        for key in (&#034;observation.state&#034;, &#034;action&#034;):<br \/>\n            np.testing.assert_allclose(<br \/>\n                sample[key].numpy(),<br \/>\n                source[key][index],<br \/>\n                rtol&#061;0,<br \/>\n                atol&#061;1e-7,<br \/>\n            )<\/p>\n<p>        for key in CAMERA_KEYS:<br \/>\n            image &#061; sample[key].numpy()<br \/>\n            assert image.shape &#061;&#061; (3, 256, 256)<br \/>\n            assert np.isfinite(image).all()<br \/>\n            assert image.min() &gt;&#061; 0<br \/>\n            assert image.max() &lt;&#061; 1<\/p>\n<p>        print(&#034;\u8bfb\u56de\u68c0\u67e5\u901a\u8fc7&#xff0c;\u5e27:&#034;, index)<\/p>\n<p>print(&#034;\\\\n&#061;&#061;&#061; A3 LeRobot \u6570\u636e\u96c6\u7ed3\u679c &#061;&#061;&#061;&#034;)<br \/>\nprint(&#034;\u6570\u636e\u96c6\u683c\u5f0f:&#034;, checked.meta.info[&#034;codebase_version&#034;])<br \/>\nprint(&#034;episodes:&#034;, checked.meta.total_episodes)<br \/>\nprint(&#034;\u603b\u5e27\u6570:&#034;, len(checked))<br \/>\nprint(&#034;fps:&#034;, checked.meta.fps)<br \/>\nprint(&#034;\u4efb\u52a1:&#034;, task)<\/p>\n<p>for key in (<br \/>\n    &#034;observation.state&#034;,<br \/>\n    &#034;action&#034;,<br \/>\n    *CAMERA_KEYS,<br \/>\n):<br \/>\n    feature &#061; checked.meta.features[key]<br \/>\n    print(<br \/>\n        f&#034;{key}: dtype&#061;{feature[&#039;dtype&#039;]}, &#034;<br \/>\n        f&#034;shape&#061;{feature[&#039;shape&#039;]}&#034;<br \/>\n    )<\/p>\n<p>print(&#034;\u672c\u9636\u6bb5\u8f6c\u6362\u8017\u65f6 \/ s:&#034;, conversion_seconds)<br \/>\nprint(&#034;\u8f93\u51fa\u76ee\u5f55:&#034;, ROOT)<br \/>\nprint(&#034;A3_LEROBOT_WRITE_OK&#034;)<\/p>\n<p>\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u53ef\u89c6\u5316\u9a8c\u8bc1&#xff1a;<\/p>\n<p>source \/root\/miniconda3\/etc\/profile.d\/conda.sh<br \/>\nconda activate lerobot<\/p>\n<p>export HF_HOME&#061;\/root\/autodl-tmp\/huggingface<br \/>\nexport HF_HUB_OFFLINE&#061;1<br \/>\nexport OMP_NUM_THREADS&#061;1<br \/>\nexport MKL_NUM_THREADS&#061;1<br \/>\nexport OPENBLAS_NUM_THREADS&#061;1<\/p>\n<p>lerobot-dataset-viz \\\\<br \/>\n  &#8211;repo-id dukiya\/piper_black_bowl_a3 \\\\<br \/>\n  &#8211;root \/root\/autodl-tmp\/workspace\/datasets\/week5\/piper_black_bowl_a3_lerobot \\\\<br \/>\n  &#8211;episode-index 0 \\\\<br \/>\n  &#8211;batch-size 1 \\\\<br \/>\n  &#8211;num-workers 0 \\\\<br \/>\n  &#8211;display-compressed-images \\\\<br \/>\n  &#8211;save 1 \\\\<br \/>\n  &#8211;output-dir \/root\/autodl-tmp\/workspace\/my_test\/week5\/a3_viz<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1964\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020720-6ad96fd8c8aa1.png\" width=\"3024\" \/><\/p>\n<p>\u8bc1\u660e\u6570\u636e\u8f6c\u6362\u6210\u529f&#xff0c;\u80fd\u88ablerobot\u8bc6\u522b\u3002<\/p>\n<hr \/>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86\u952e\u76d8\u9065\u64cd\u4f5c\u91c7\u96c6piper\u9ed1\u7897\u4efb\u52a1\u6570\u636e\u96c6&#xff0c;\u8bbe\u8ba1\u9065\u64cd\u4f5c\u7684\u5b9e\u73b0\u548c\u6570\u636e\u8f6c\u6362\u3002<\/p>\n<p>\u6587\u7ae0\u4ec5\u505a\u5b66\u4e60\u5206\u4eab&#xff0c;\u5982\u6709\u8c2c\u8bef&#xff0c;\u6b22\u8fce\u6307\u6b63\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8ff0\u4e0eQA\u672c\u7cfb\u5217\u4e3a\u6211\u5728vla\u4e0a\u7684\u7b2c\u4e8c\u4e2a\u5b9e\u8df5&#xff1a;\u57fa\u4e8epiper\u673a\u68b0\u81c2\u5b8c\u6210\u6570\u636e\u91c7\u96c6&#8211;\u683c\u5f0f\u8f6c\u6362&#8211;pi05\u5fae\u8c03&#8211;\u8bc4\u4f30&#8211;panda\u652f\u7ebf\u5bf9\u6bd4\u3002\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u5982\u4f55\u5b9e\u73b0\u57fa\u4e8e\u952e\u76d8\u9065\u64cd\u4f5c\u91c7\u96c6\u6570\u636e\u30021. \u5148\u9a8c\u8bc1\u81ea\u5df1\u7684\u8bbe\u5907\u80fd\u4e0d\u80fd\u652f\u6301\u952e\u76d8\u9065\u64cd\u5176\u5b9e\u5728\u8fdb\u884c\u8fd9\u9879\u5b9e\u8df5\u6211\u4e00\u76f4\u5728\u62c5\u5fc3\u81ea\u5df1\u7684\u96c6\u663eubuntu\u7535\u8111\u65e0\u6cd5\u652f\u6301\u9065\u91c7&#xff0c;\u5fc5\u987b\u8981\u53bbautodl\u4e0a\u79df\u5361\u7136\u540e\u505a\u753b\u9762\u6e32\u67d3\u548c\u8f6c\u53d1\u624d\u80fd\u5b9e\u73b0\u3002\u8fdb\u4e00\u6b65\u4e86\u89e3\u540e\u624d\u77e5\u9053\u8fd9\u9879\u4e3b\u8981\u9700\u6c42\u7684\u662fCPU&#xff0c;\u663e\u5361\u53ea\u8981\u80fd\u5e26\u52a8mujoco\u5c31\u884c\u3002\u4e8e\u662f\u6211\u901a\u8fc7\u4e0b\u9762\u7684\u4ee3<\/p>\n","protected":false},"author":2,"featured_media":116986,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[12546,13266,305],"topic":[],"class_list":["post-116991","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-vla","tag-13266","tag-305"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u5177\u8eab\u7b14\u8bb0\u3011\u3010Piper+PI0.5\u3011\u4e00\u3001\u57fa\u4e8e\u952e\u76d8\u5b9e\u73b0\u6570\u636e\u91c7\u96c6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/116991.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u5177\u8eab\u7b14\u8bb0\u3011\u3010Piper+PI0.5\u3011\u4e00\u3001\u57fa\u4e8e\u952e\u76d8\u5b9e\u73b0\u6570\u636e\u91c7\u96c6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6982\u8ff0\u4e0eQA\u672c\u7cfb\u5217\u4e3a\u6211\u5728vla\u4e0a\u7684\u7b2c\u4e8c\u4e2a\u5b9e\u8df5&#xff1a;\u57fa\u4e8epiper\u673a\u68b0\u81c2\u5b8c\u6210\u6570\u636e\u91c7\u96c6--\u683c\u5f0f\u8f6c\u6362--pi05\u5fae\u8c03--\u8bc4\u4f30--panda\u652f\u7ebf\u5bf9\u6bd4\u3002\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u5982\u4f55\u5b9e\u73b0\u57fa\u4e8e\u952e\u76d8\u9065\u64cd\u4f5c\u91c7\u96c6\u6570\u636e\u30021. \u5148\u9a8c\u8bc1\u81ea\u5df1\u7684\u8bbe\u5907\u80fd\u4e0d\u80fd\u652f\u6301\u952e\u76d8\u9065\u64cd\u5176\u5b9e\u5728\u8fdb\u884c\u8fd9\u9879\u5b9e\u8df5\u6211\u4e00\u76f4\u5728\u62c5\u5fc3\u81ea\u5df1\u7684\u96c6\u663eubuntu\u7535\u8111\u65e0\u6cd5\u652f\u6301\u9065\u91c7&#xff0c;\u5fc5\u987b\u8981\u53bbautodl\u4e0a\u79df\u5361\u7136\u540e\u505a\u753b\u9762\u6e32\u67d3\u548c\u8f6c\u53d1\u624d\u80fd\u5b9e\u73b0\u3002\u8fdb\u4e00\u6b65\u4e86\u89e3\u540e\u624d\u77e5\u9053\u8fd9\u9879\u4e3b\u8981\u9700\u6c42\u7684\u662fCPU&#xff0c;\u663e\u5361\u53ea\u8981\u80fd\u5e26\u52a8mujoco\u5c31\u884c\u3002\u4e8e\u662f\u6211\u901a\u8fc7\u4e0b\u9762\u7684\u4ee3\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/116991.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-22T02:07:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020718-6ad96fd61cf4a.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"40 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/116991.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/116991.html\",\"name\":\"\u3010\u5177\u8eab\u7b14\u8bb0\u3011\u3010Piper+PI0.5\u3011\u4e00\u3001\u57fa\u4e8e\u952e\u76d8\u5b9e\u73b0\u6570\u636e\u91c7\u96c6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-22T02:07:26+00:00\",\"dateModified\":\"2026-10-22T02:07:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/116991.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/116991.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/116991.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u5177\u8eab\u7b14\u8bb0\u3011\u3010Piper+PI0.5\u3011\u4e00\u3001\u57fa\u4e8e\u952e\u76d8\u5b9e\u73b0\u6570\u636e\u91c7\u96c6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010\u5177\u8eab\u7b14\u8bb0\u3011\u3010Piper+PI0.5\u3011\u4e00\u3001\u57fa\u4e8e\u952e\u76d8\u5b9e\u73b0\u6570\u636e\u91c7\u96c6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/116991.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u5177\u8eab\u7b14\u8bb0\u3011\u3010Piper+PI0.5\u3011\u4e00\u3001\u57fa\u4e8e\u952e\u76d8\u5b9e\u73b0\u6570\u636e\u91c7\u96c6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6982\u8ff0\u4e0eQA\u672c\u7cfb\u5217\u4e3a\u6211\u5728vla\u4e0a\u7684\u7b2c\u4e8c\u4e2a\u5b9e\u8df5&#xff1a;\u57fa\u4e8epiper\u673a\u68b0\u81c2\u5b8c\u6210\u6570\u636e\u91c7\u96c6--\u683c\u5f0f\u8f6c\u6362--pi05\u5fae\u8c03--\u8bc4\u4f30--panda\u652f\u7ebf\u5bf9\u6bd4\u3002\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u5982\u4f55\u5b9e\u73b0\u57fa\u4e8e\u952e\u76d8\u9065\u64cd\u4f5c\u91c7\u96c6\u6570\u636e\u30021. \u5148\u9a8c\u8bc1\u81ea\u5df1\u7684\u8bbe\u5907\u80fd\u4e0d\u80fd\u652f\u6301\u952e\u76d8\u9065\u64cd\u5176\u5b9e\u5728\u8fdb\u884c\u8fd9\u9879\u5b9e\u8df5\u6211\u4e00\u76f4\u5728\u62c5\u5fc3\u81ea\u5df1\u7684\u96c6\u663eubuntu\u7535\u8111\u65e0\u6cd5\u652f\u6301\u9065\u91c7&#xff0c;\u5fc5\u987b\u8981\u53bbautodl\u4e0a\u79df\u5361\u7136\u540e\u505a\u753b\u9762\u6e32\u67d3\u548c\u8f6c\u53d1\u624d\u80fd\u5b9e\u73b0\u3002\u8fdb\u4e00\u6b65\u4e86\u89e3\u540e\u624d\u77e5\u9053\u8fd9\u9879\u4e3b\u8981\u9700\u6c42\u7684\u662fCPU&#xff0c;\u663e\u5361\u53ea\u8981\u80fd\u5e26\u52a8mujoco\u5c31\u884c\u3002\u4e8e\u662f\u6211\u901a\u8fc7\u4e0b\u9762\u7684\u4ee3","og_url":"https:\/\/www.wsisp.com\/helps\/116991.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-22T02:07:26+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020718-6ad96fd61cf4a.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"40 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/116991.html","url":"https:\/\/www.wsisp.com\/helps\/116991.html","name":"\u3010\u5177\u8eab\u7b14\u8bb0\u3011\u3010Piper+PI0.5\u3011\u4e00\u3001\u57fa\u4e8e\u952e\u76d8\u5b9e\u73b0\u6570\u636e\u91c7\u96c6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-22T02:07:26+00:00","dateModified":"2026-10-22T02:07:26+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/116991.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/116991.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/116991.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u5177\u8eab\u7b14\u8bb0\u3011\u3010Piper+PI0.5\u3011\u4e00\u3001\u57fa\u4e8e\u952e\u76d8\u5b9e\u73b0\u6570\u636e\u91c7\u96c6"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/116991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=116991"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/116991\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/116986"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=116991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=116991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=116991"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=116991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}