Mujoco robosuite 機器人模型

import ctypes
import os# 獲取當前腳本所在的目錄
script_dir = os.path.dirname(os.path.abspath(__file__))# 構建庫文件的相對路徑
lib_relative_path = os.path.join('dynamic_models', 'UR5e', 'Jb.so')# 拼接成完整的路徑
lib_path = os.path.join(script_dir, lib_relative_path)try:fun_grav = ctypes.CDLL(lib_path)print("庫文件加載成功!")
except OSError as e:print(f"加載庫文件時出錯: {e}")

<mujoco model="ur5"><compiler angle="radian" meshdir="ur5/collision/" /><size njmax="500" nconmax="100" /><asset><mesh name="base" file="base.stl" /><mesh name="shoulder" file="shoulder.stl" /><mesh name="upperarm" file="upperarm.stl" /><mesh name="forearm" file="forearm.stl" /><mesh name="wrist1" file="wrist1.stl" /><mesh name="wrist2" file="wrist2.stl" /><mesh name="wrist3" file="wrist3.stl" /></asset><worldbody><geom type="mesh" contype="0" conaffinity="0" group="1" rgba="0.7 0.7 0.7 1" mesh="base" /><geom type="mesh" rgba="0.7 0.7 0.7 1" mesh="base" /><body name="shoulder_link" pos="0 0 0.089159"><inertial pos="0 0 0" mass="3.7" diaginertia="0.0102675 0.0102675 0.00666" /><joint name="shoulder_pan_joint" pos="0 0 0" axis="0 0 1" limited="true" range="-3.14159 3.14159" /><geom type="mesh" contype="0" conaffinity="0" group="1" rgba="0.7 0.7 0.7 1" mesh="shoulder" /><geom type="mesh" rgba="0.7 0.7 0.7 1" mesh="shoulder" /><body name="upper_arm_link" pos="0 0.13585 0" quat="0.707107 0 0.707107 0"><inertial pos="0 0 0.28" mass="8.393" diaginertia="0.226891 0.226891 0.0151074" /><joint name="shoulder_lift_joint" pos="0 0 0" axis="0 1 0" limited="true" range="-3.14159 3.14159" /><geom type="mesh" contype="0" conaffinity="0" group="1" rgba="0.7 0.7 0.7 1" mesh="upperarm" /><geom type="mesh" rgba="0.7 0.7 0.7 1" mesh="upperarm" /><body name="forearm_link" pos="0 -0.1197 0.425"><inertial pos="0 0 0.196125" mass="2.275" diaginertia="0.0312168 0.0312168 0.004095" /><joint name="elbow_joint" pos="0 0 0" axis="0 1 0" limited="true" range="-3.14159 3.14159" /><geom type="mesh" contype="0" conaffinity="0" group="1" rgba="0.7 0.7 0.7 1" mesh="forearm" /><geom type="mesh" rgba="0.7 0.7 0.7 1" mesh="forearm" /><body name="wrist_1_link" pos="0 0 0.39225" quat="0.707107 0 0.707107 0"><inertial pos="0 0.093 0" mass="1.219" diaginertia="0.0025599 0.0025599 0.0021942" /><joint name="wrist_1_joint" pos="0 0 0" axis="0 1 0" limited="true" range="-3.14159 3.14159" /><geom type="mesh" contype="0" conaffinity="0" group="1" rgba="0.7 0.7 0.7 1" mesh="wrist1" /><geom type="mesh" rgba="0.7 0.7 0.7 1" mesh="wrist1" /><body name="wrist_2_link" pos="0 0.093 0"><inertial pos="0 0 0.09465" mass="1.219" diaginertia="0.0025599 0.0025599 0.0021942" /><joint name="wrist_2_joint" pos="0 0 0" axis="0 0 1" limited="true" range="-3.14159 3.14159" /><geom type="mesh" contype="0" conaffinity="0" group="1" rgba="0.7 0.7 0.7 1" mesh="wrist2" /><geom type="mesh" rgba="0.7 0.7 0.7 1" mesh="wrist2" /><body name="wrist_3_link" pos="0 0 0.09465"><inertial pos="0 0.06505 0" quat="1.73123e-12 0.707107 -0.707107 1.73123e-12" mass="0.1879" diaginertia="0.000132117 8.46959e-05 8.46959e-05" /><joint name="wrist_3_joint" pos="0 0 0" axis="0 1 0" limited="true" range="-3.14159 3.14159" /><geom type="mesh" contype="0" conaffinity="0" group="1" rgba="0.7 0.7 0.7 1" mesh="wrist3" /><geom type="mesh" rgba="0.7 0.7 0.7 1" mesh="wrist3" /><site name="ee" pos="0 0 0" rgba="1 0 0 1" size="0.01" type="sphere"/></body></body></body></body></body></body></worldbody><actuator><motor name='motor1' ctrllimited="true" ctrlrange="-100 100" joint='shoulder_pan_joint' gear="1"/><motor name='motor2' ctrllimited="true" ctrlrange="-100 100" joint='shoulder_lift_joint' gear="1"/><motor name='motor3' ctrllimited="true" ctrlrange="-100 100" joint='elbow_joint' gear="1"/><motor name='motor4' ctrllimited="true" ctrlrange="-100 100" joint='wrist_1_joint' gear="1"/><motor name='motor5' ctrllimited="true" ctrlrange="-100 100" joint='wrist_2_joint' gear="1"/><motor name='motor6' ctrllimited="true" ctrlrange="-100 100" joint='wrist_3_joint' gear="1"/></actuator>
</mujoco>

雅克比

from dm_control.mujoco.wrapper import mjbindings
import numpy as npmjlib = mjbindings.mjlibdef get_site_jac(model, data, site_id):"""Return the Jacobian' translational component of the end-effector ofthe corresponding site id."""jacp = np.zeros((3, model.nv))jacr = np.zeros((3, model.nv))mjlib.mj_jacSite(model, data, jacp, jacr, site_id)jac = np.vstack([jacp, jacr])return jacdef get_fullM(model, data):M = np.zeros((model.nv, model.nv))mjlib.mj_fullM(model, M, data.qM)return M

任務空間慣量矩陣

def task_space_inertia_matrix(M, J, threshold=1e-3):"""Generate the task-space inertia matrixParameters----------M: np.arraythe generalized coordinates inertia matrixJ: np.arraythe task space Jacobianthreshold: scalar, optional (Default: 1e-3)singular value threshold, if the detminant of Mx_inv is less thanthis value then Mx is calculated using the pseudo-inverse functionand all singular values < threshold * .1 are set = 0"""# calculate the inertia matrix in task spaceM_inv = np.linalg.inv(M)Mx_inv = np.dot(J, np.dot(M_inv, J.T))if abs(np.linalg.det(Mx_inv)) >= threshold:# do the linalg inverse if matrix is non-singular# because it's faster and more accurateMx = np.linalg.inv(Mx_inv)else:# using the rcond to set singular values < thresh to 0# singular values < (rcond * max(singular_values)) set to 0Mx = np.linalg.pinv(Mx_inv, rcond=threshold * 0.1)return Mx, M_inv
def set_state(model, data, qpos, qvel):assert qpos.shape == (model.nq, ) and qvel.shape == (model.nv, )# old_state = data.get_state()# new_state = mujoco.MjSimState(old_state.time, qpos, qvel, old_state.act,#                                  old_state.udd_state)# data.set_state(new_state)# model.forward()data.qpos[:] = qposdata.qvel[:] = qveldef get_contact_force(mj_model, mj_data, body_name):bodyId = mujoco.mj_name2id(mj_model, MJ_BODY_OBJ, body_name)force_com = mj_data.cfrc_ext[bodyId, :]trn_force = force_com.copy()return np.hstack((trn_force[3:], trn_force[:3]))def get_geom_pose(model, geom_name):"""Return the geom pose (relative to parent body).:param mujoco_py.MjModel model::param str geom_name::return: position, quaternion:rtype: tuple(np.array(3), np.array(4))"""geom_id = mujoco.mj_name2id(model, MJ_GEOM_OBJ, geom_name)pos = model.geom_pos[geom_id, :]quat = model.geom_quat[geom_id, :]return pos, quatdef get_geom_size(model, geom_name):"""Return the geom size.:param mujoco_py.MjModel model::param str geom_name::return: (radius, half-length, _) for cylinder geom, and(X half-size; Y half-size; Z half-size) for box geom:rtype: np.array(3)"""geom_id = mujoco.mj_name2id(model, MJ_GEOM_OBJ, geom_name)if model.geom_type[geom_id] == MJ_BOX or model.geom_type[geom_id] == MJ_CYLINDER:return model.geom_size[geom_id, :]else:return Nonedef get_geom_friction(model, geom_name):geom_id = mujoco.mj_name2id(model, MJ_GEOM_OBJ, geom_name)return model.geom_friction[geom_id, :]def get_body_mass(model, body_name):body_id = mujoco.mj_name2id(model, MJ_BODY_OBJ, body_name)return model.body_mass[body_id]def get_body_pose(model, body_name):body_id = mujoco.mj_name2id(model, MJ_BODY_OBJ, body_name)return model.body_pos[body_id], model.body_quat[body_id]def get_mesh_vertex_pos(model, geom_name):geom_id = mujoco.mj_name2id(model, MJ_GEOM_OBJ, geom_name)assert model.geom_type[geom_id] == MJ_MESHmesh_id = model.geom_dataid[geom_id]first_vertex_id = model.mesh_vertadr[mesh_id]no_vertex = model.mesh_vertnum[mesh_id]vertex_pos = model.mesh_vert[first_vertex_id:first_vertex_id + no_vertex]return vertex_posdef set_geom_size(model, geom_name, size):geom_id = mujoco.mj_name2id(model, MJ_GEOM_OBJ, geom_name)model.geom_size[geom_id, :] = sizedef set_body_mass(model, body_name, mass):body_id = mujoco.mj_name2id(model, MJ_BODY_OBJ, body_name)model.body_mass[body_id] = massdef set_geom_friction(model, geom_name, friction):geom_id = mujoco.mj_name2id(model, MJ_GEOM_OBJ, geom_name)model.geom_friction[geom_id, :] = frictiondef set_body_pose(model, body_name, pos, quat):body_id = mujoco.mj_name2id(model, MJ_BODY_OBJ, body_name)model.body_pos[body_id, :] = posmodel.body_quat[body_id, :] = quatdef set_body_pose_rotm(model, body_name, pos, R):quat = mat2quat(R)body_id = mujoco.mj_name2id(model, MJ_BODY_OBJ, body_name)model.body_pos[body_id, :] = posmodel.body_quat[body_id, :] = quat# -------- GEOMETRY TOOLs
def quat_error(q1, q2):"""Compute the rotation vector (expressed in the base frame), that if followin a unit time, will transform a body with orientation `q1` toorientation `q2`:param list/np.ndarray q1: Description of parameter `q1`.:param list/np.ndarray q2: Description of parameter `q2`.:return: a 3D rotation vector:rtype: np.ndarray"""if isinstance(q1, list):q1 = np.array(q1)if isinstance(q2, list):q2 = np.array(q2)dtype = q1.dtypeneg_q1 = np.zeros(4, dtype=dtype)err_rot_quat = np.zeros(4, dtype=dtype)err_rot = np.zeros(3, dtype=dtype)if q1.dot(q2) < 0:q1 = -q1mujoco.mju_negQuat(neg_q1, q1)mujoco.mju_mulQuat(err_rot_quat, q2, neg_q1)mujoco.mju_quat2Vel(err_rot, err_rot_quat, 1)return err_rotdef quat2mat(q):"""Tranform a quaternion to rotation amtrix.:param type q: Description of parameter `q`.:return: 3x3 rotation matrix:rtype: np.array"""mat = np.zeros(9)mujoco.mju_quat2Mat(mat, q)return mat.reshape((3, 3))def pose_transform(p1, q1, p21, q21):"""Coordinate transformation between 2 frames:param np.ndarray p1: position in frame 1:param np.ndarray q1: orientation (quaternion) in frame 1:param np.ndarray p21: relative position between frame 1 and 2:param np.ndarray q21: relative orientation between frame 1 and 2:return: position and orientation in frame 2:rtype: type"""# quat to rotation matrixR21 = quat2mat(q21)p2 = p21 + R21.dot(p1)q2 = np.zeros_like(q1)mujoco.mju_mulQuat(q2, q21, q1)  # q2 = q21*q1return p2, q2def integrate_quat(q, r, dt):"""Integrate quaternion by a fixed angular velocity over the duration dt.:param np.array(4) q: quaternion.:param np.array(3) r: angular velocity.:param float dt: duration.:return: result quaternion.:rtype: np.array(4)"""qres = np.zeros(4)qe = np.zeros(4)r = r * dtangle = np.linalg.norm(r)if angle < 1e-9:# if angle too small then return current qreturn q.copy()axis = r / anglemujoco.mju_axisAngle2Quat(qe, axis, angle)mujoco.mju_mulQuat(qres, qe, q)return qresdef transform_spatial(v1, q21):"""Coordinate transformation of a spatial vector. The spatial vector can be eithertwist (linear + angular velocity) or wrench (force + torque):param type v1: Spatial vector in frame 1:param type q21: transformation matrix (in terms of quaternion):return: Description of returned object.:rtype: type"""R21 = quat2mat(q21)R = np.block([[R21, np.zeros((3, 3))], [np.zeros((3, 3)), R21]])return R.dot(v1)def similarity_transform(A1, q21):"""Similarity transformation of a matrix from frame 1 to frame 2A2 = R21 * A1 * R12:param np.array((3, 3)) A1: 3x3 matrix.:param np.array(4) q21: quaternion representation.:return: 3x3 matrix:rtype: np.array"""R21 = quat2mat(q21)return R21.dot(A1.dot(R21.T))# NOTE: there are infinite rotation vector solutions for a particular
# orientation, the `ref` is to find the closest solution to a reference.
# Is there another minimal representation that could avoid this?
def quat2vec(q, ref=None):"""Transform quaternion representation to rotation vector representation"""r = np.zeros(3)scale = 1mujoco.mju_quat2Vel(r, q, scale)if ref is not None:if r.dot(ref) < 0:angle = np.linalg.norm(r)r = r / angleangle = angle - 2 * np.pir = r * anglereturn rdef inverse_frame(p, q):pi, qi = np.zeros(3), np.zeros(4)mujoco.mju_negPose(pi, qi, p, q)return pi, qidef mat2quat(R):R = R.flatten()q = np.zeros(4)mujoco.mju_mat2Quat(q, R)return qdef mul_quat(q1, q2):q = np.zeros(4)mujoco.mju_mulQuat(q, q1, q2)return q

https://github.com/google-deepmind/mujoco_menageriehttps://github.com/google-deepmind/mujoco_menagerie

https://github.com/ARISE-Initiative/robosuitehttps://github.com/ARISE-Initiative/robosuite

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/80080.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/80080.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/80080.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【重學Android】02.Java環境配置的一些分享

背景說明 其實只是學習Android的話&#xff0c;只要下載好Android Studio開發工具&#xff0c;是自帶JDK環境的&#xff0c;所以不需要再額外去進行配置&#xff0c;我之所以還要進行單獨配置&#xff0c;是因為我其他的工具需要Java的環境&#xff0c;而且我目前用的是JDK 12…

Linux 網絡編程:select、poll 與 epoll 深度解析 —— 從基礎到高并發實戰

一、IO 多路復用&#xff1a;解決并發 IO 的核心技術 在網絡編程中&#xff0c;當需要同時處理大量客戶端連接時&#xff0c;傳統阻塞式 IO 會導致程序卡在單個操作上&#xff0c;造成資源浪費。IO 多路復用技術允許單線程監聽多個文件描述符&#xff08;FD&#xff09;&#…

制作你的時間管理“局”#自制軟件,5款AI編程對比測試

玩 AI 編程最有意思的地方&#xff0c;就是當你有想法的時候&#xff0c;可以隨時測試、把想法具體化&#xff0c;甚至產品化。今天我們制作一個事件管理器&#xff0c;用來量化我們每天的時間安排&#xff0c;提高時間的利用率&#xff0c;提升生產力。 同樣的一組 prompt &am…

大數據系列 | 詳解基于Zookeeper或ClickHouse Keeper的ClickHouse集群部署--完結

大數據系列 | 詳解基于Zookeeper或ClickHouse Keeper的ClickHouse集群部署 1. ClickHouse與MySQL的區別2. 在群集的所有機器上安裝ClickHouse服務端2.1. 在線安裝clickhouse2.2. 離線安裝clickhouse 3. ClickHouse Keeper/Zookeeper集群安裝4. 在配置文件中設置集群配置5. 在每…

宏碁筆記本電腦怎樣開啟/關閉觸摸板

使用快捷鍵&#xff1a;大多數宏碁筆記本可以使用 “FnF7” 或 “FnF8” 組合鍵來開啟或關閉觸摸板&#xff0c;部分型號可能是 “FnF2”“FnF9” 等。如果不確定&#xff0c;可以查看鍵盤上的功能鍵圖標&#xff0c;一般有觸摸板圖案的按鍵就是觸摸板的快捷鍵。通過設備管理器…

使用Mybaitis-plus提供的各種的免寫SQL的Wrapper的使用方式

文章目錄 內連接JoinWrappers.lambda和 new MPJLambdaWrapper 生成的MPJLambdaWrapper對象有啥區別&#xff1f;LambdaQueryWrapper 和 QueryWrapper的區別&#xff1f;LambdaQueryWrapper和MPJLambdaQueryWrapper的區別&#xff1f;在作單表更新時建議使用&#xff1a;LambdaU…

基于微信小程序的走失兒童幫助系統-項目分享

基于微信小程序的走失兒童幫助系統-項目分享 項目介紹項目摘要管理員功能圖用戶功能圖系統功能圖項目預覽首頁走失兒童個人中心走失兒童管理 最后 項目介紹 使用者&#xff1a;管理員、用戶 開發技術&#xff1a;MySQLJavaSpringBootVue 項目摘要 本系統采用微信小程序進行開…

P3916 圖的遍歷

P3916 圖的遍歷 題目來源-洛谷 題意 有向圖中&#xff0c;找出每個節點能訪問到的最大的節點 思路 每個節點的最大節點&#xff0c;不是最長距離&#xff0c;如果是每個節點都用dfs去找最大值&#xff0c;顯然1e6*1e6 超時了&#xff0c;只能60分從第一個節點開始遍歷&…

掌握常見 HTTP 方法:GET、POST、PUT 到 CONNECT 全面梳理

今天面試還問了除了 get 和 post 方法還有其他請求方法嗎&#xff0c;一個都不知道&#xff0c;這里記錄下。 &#x1f310; 常見 HTTP 請求方法一覽 方法作用描述是否冪等是否常用GET獲取資源&#xff0c;參數一般拼接在 URL 中? 是? 常用POST創建資源 / 提交數據&#xff…

裸金屬服務器的應用場景有哪些?

隨著云計算技術不斷發展&#xff0c;裸金屬服務器作為一臺既具有傳統物理服務器特點的硬件設備&#xff0c;還具備云計算技術的服務器化服務功能&#xff0c;是硬件和軟件相結合的網絡設備&#xff0c;逐漸被越來越多的企業所關注&#xff0c;那么&#xff0c;裸金屬服務器的應…

【得物】20250419筆試算法題

文章目錄 前言第一題1. 題目描述2. 思路解析3. AC代碼 第二題1. 題目描述2. 思路解析3. AC代碼 第三題1. 題目描述2. 思路解析3. AC代碼 前言 三道題目都比較簡單&#xff0c;大家都可以試著做一下。 第一題 1. 題目描述 題目鏈接&#xff1a;矩陣變換 2. 思路解析 按題…

明遠智睿2351開發板四核1.4G Linux處理器:驅動創新的引擎

在科技日新月異的今天&#xff0c;創新成為了推動社會進步的核心動力。而在這場創新的浪潮中&#xff0c;一款性能卓越、功能全面的處理器無疑是不可或缺的引擎。今天&#xff0c;我們介紹的這款四核1.4G處理器搭配Linux系統的組合&#xff0c;正是這樣一款能夠驅動未來創新的強…

Oracle Database Resident Connection Pooling (DRCP) 白皮書閱讀筆記

本文為“Extreme Oracle Database Connection Scalability with Database Resident Connection Pooling (DRCP)”的中文翻譯加閱讀筆記。覺得是重點的就用粗體表示了。 白皮書版本為March 2025, Version 3.3&#xff0c;副標題為&#xff1a;Optimizing Oracle Database resou…

VS Code + GitHub:高效開發工作流指南

目錄 一、安裝 & 基本配置 1.下載 VS Code 2.安裝推薦插件(打開側邊欄 Extensions) 3.設置中文界面(可選) 二、使用 VS Code 操作 Git/GitHub 1.基本 Git 操作(不輸命令行!) 2.連接 GitHub(第一次使用) 三、克隆遠程倉庫到 VS Code 方法一(推薦): 方…

【LLM】llama.cpp:合并 GGUF 模型分片

GGUF&#xff08;GPT-Generated Unified Format&#xff09;是一種專為大規模語言模型設計的二進制文件格式&#xff0c;支持將模型分割成多個分片&#xff08;*-of-*.gguf&#xff09;。當從開源社區&#xff08;如 HuggingFace 或 ModelScope&#xff09;下載量化模型時&…

Ubuntu 系統下安裝和使用性能分析工具 perf

在 Ubuntu 系統下安裝和使用性能分析工具 perf 的步驟如下&#xff1a; 1. 安裝 perf perf 是 Linux 內核的一部分&#xff0c;通常通過安裝 linux-tools 包獲取&#xff1a; # 更新軟件包列表 sudo apt update# 安裝 perf&#xff08;根據當前內核版本自動匹配&#xff09; …

Buffer of Thoughts: Thought-Augmented Reasoningwith Large Language Models

CODE: NeurIPS 2024 https://github.com/YangLing0818/buffer-of-thought-llm Abstract 我們介紹了思想緩沖(BoT)&#xff0c;一種新穎而通用的思想增強推理方法&#xff0c;用于提高大型語言模型(大型語言模型)的準確性、效率和魯棒性。具體來說&#xff0c;我們提出了元緩沖…

Java面試中問單例模式如何回答

1. 什么是單例模式? 單例模式(Singleton Pattern)是一種設計模式,確保某個類在整個應用中只有一個實例,并且提供全局訪問點。它有以下特點: 確保只有一個實例。提供全局訪問點。防止多次實例化,節約資源。2. 如何實現單例模式? 單例模式有多種實現方式,以下是最常見…

實戰華為1:1方式1 to 1 VLAN映射

本文摘自筆者于2024年出版&#xff0c;并得到廣泛讀者認可&#xff0c;已多次重印的《華為HCIP-Datacom路由交換學習指南》。 華為設備的1 to 1 VLAN映射有1:1和N :1兩種方式。1:1方式是將指定的一個用戶私網VLAN標簽映射為一個公網VLAN標簽&#xff0c;是一種一對一的映射關系…

認識Vue

認識Vue 文章目錄 認識Vue一、vue是什么二、Vue核心特性數據驅動&#xff08;MVVM)組件化指令系統 三、Vue跟傳統開發的區別1. **開發模式&#xff1a;MVVM vs 模板驅動**2. **組件化開發**3. **狀態管理**4. **路由管理**5. **構建與工程化**6. **性能優化**7. **學習曲線**8.…