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.mzph.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.…