pybullet
PyBullet 物理仿真开发技能 - Python 机器人仿真、强化学习环境、GPU 加速、URDF 导入
от MIUAV★ 30 звёзд на GitHub
Установить pybullet в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
PyBullet Physics Simulation Skill
用于 PyBullet 物理仿真环境的配置和开发
何时使用
当需要以下帮助时使用此技能:
- 安装和配置 PyBullet
- 创建机器人仿真环境
- 编写强化学习训练环境
- 导入 URDF/SDF 模型
- 使用 GPU 加速仿真
快速参考
安装 PyBullet
pip install pybullet
pip install pybullet-gym # 预定义环境
# GPU 版本 (需要 CUDA)
pip install pybullet-gpu
基本使用
连接模式
import pybullet as p
import pybullet_data
# GUI 模式 - 可视化
client_id = p.connect(p.GUI)
# 或
client_id = p.connect(p.GUI, options="--width=1920 --height=1080")
# DIRECT 模式 - 无窗口,快速仿真
client_id = p.connect(p.DIRECT)
# SHARED_MEMORY - 多进程共享
client_id = p.connect(p.SHARED_MEMORY)
# 加载数据路径
p.setAdditionalSearchPath(pybullet_data.getDataPath())
基本仿真循环
import pybullet as p
import time
# 连接
p.connect(p.GUI)
# 设置重力
p.setGravity(0, 0, -9.81)
# 设置时间步
p.setTimeStep(1/240)
# 加载地面
plane_id = p.loadURDF("plane.urdf")
# 加载机器人
robot_id = p.loadURDF("franka_panda/panda.urdf", [0, 0, 0])
# 仿真循环
for _ in range(1000):
p.stepSimulation()
time.sleep(1/240)
# 断开连接
p.disconnect()
机器人模型
加载 URDF
# 基本加载
robot_id = p.loadURDF(
"robot.urdf",
basePosition=[0, 0, 0.5],
baseOrientation=[0, 0, 0, 1],
useFixedBase=True
)
# 获取关节信息
num_joints = p.getNumJoints(robot_id)
for i in range(num_joints):
info = p.getJointInfo(robot_id, i)
print(f"Joint {i}: {info[1].decode()}")
# 读取状态
joint_states = p.getJointStates(robot_id, [0, 1, 2])
positions = [state[0] for state in joint_states]
velocities = [state[1] for state in joint_states]
创建简单机器人
# 创建四轮车
def create_mobile_robot():
# 车身
body_id = p.createMultiBody(
baseMass=1.0,
baseCollisionShape=p.createCollisionShape(p.GEOM_BOX, halfExtents=[0.2, 0.1, 0.05]),
baseVisualShape=p.createVisualShape(p.GEOM_BOX, halfExtents=[0.2, 0.1, 0.05], rgbaColor=[0.3, 0.3, 0.8, 1]),
basePosition=[0, 0, 0.1]
)
# 轮子
wheel_radius = 0.05
wheel_positions = [
[0.15, 0.12, 0.05],
[0.15, -0.12, 0.05],
[-0.15, 0.12, 0.05],
[-0.15, -0.12, 0.05]
]
wheel_ids = []
for pos in wheel_positions:
wheel_id = p.createMultiBody(
baseMass=0.1,
baseCollisionShape=p.createCollisionShape(p.GEOM_CYLINDER, radius=wheel_radius, height=0.02),
baseVisualShape=p.createVisualShape(p.GEOM_CYLINDER, radius=wheel_radius, length=0.02, rgbaColor=[0.1, 0.1, 0.1, 1]),
basePosition=pos,
baseOrientation=[0, 0, 0, 1]
)
wheel_ids.append(wheel_id)
return body_id, wheel_ids
# 创建机械臂
def create_robot_arm():
links = []
parent = -1
# 基座
base_id = p.createMultiBody(
baseMass=0,
baseCollisionShape=p.createCollisionShape(p.GEOM_BOX, halfExtents=[0.05, 0.05, 0.02]),
basePosition=[0, 0, 0.02]
)
links.append(base_id)
parent = base_id
# 链接1-3
link_params = [
(0.15, 0.03, [0, 0, 0.1]),
(0.12, 0.025, [0, 0, 0.15]),
(0.1, 0.02, [0, 0, 0.12])
]
for mass, radius, pos in link_params:
link_id = p.createMultiBody(
baseMass=mass,
baseCollisionShape=p.createCollisionShape(p.GEOM_CYLINDER, radius=radius, height=0.1),
baseVisualShape=p.createVisualShape(p.GEOM_CYLINDER, radius=radius, length=0.1, rgbaColor=[0.4, 0.4, 0.4, 1]),
basePosition=pos,
baseInertialFramePosition=[0, 0, 0],
baseInertialFrameOrientation=[0, 0, 0, 1]
)
# 创建关节
p.createConstraint(
parent, -1, link_id, -1,
jointType=p.JOINT_REVOLUTE,
jointAxis=[0, 1, 0],
parentFramePosition=[0, 0, 0.05],
childFramePosition=[0, 0, -0.05]
)
links.append(link_id)
parent = link_id
return links
控制器
位置控制
# 位置控制
def position_control(robot_id, joint_indices, target_positions):
for i, target in zip(joint_indices, target_positions):
p.setJointMotorControl2(
bodyUniqueId=robot_id,
jointIndex=i,
controlMode=p.POSITION_CONTROL,
targetPosition=target,
force=100
)
# 使用
position_control(robot_id, [1, 2, 3], [0.5, -0.3, 0.8])
速度控制
# 速度控制
def velocity_control(robot_id, joint_indices, velocities):
for i, vel in zip(joint_indices, velocities):
p.setJointMotorControl2(
bodyUniqueId=robot_id,
jointIndex=i,
controlMode=p.VELOCITY_CONTROL,
targetVelocity=vel,
force=50
)
力控制
# 力控制
def torque_control(robot_id, joint_indices, torques):
for i, torque in zip(joint_indices, torques):
p.setJointMotorControl2(
bodyUniqueId=robot_id,
jointIndex=i,
controlMode=p.TORQUE_CONTROL,
force=torque
)
# 启用零重力模式 (用于位置控制)
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- physics-simulation/SKILL.md
- rl-environments/SKILL.md
- robot-control/SKILL.md
FAQ
Что делает скилл pybullet?
PyBullet 物理仿真开发技能 - Python 机器人仿真、强化学习环境、GPU 加速、URDF 导入
Как установить скилл pybullet?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл pybullet запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…