0
0

Pybullet公式gitリポジトリのサンプルコードを解説するシリーズです(一覧はこちら)。


今回は、hello_pybullet.pyを解説します。(コードのリンクはこちら

本コードを実行すると、r2d2のモデルが生成されます。

hello_pybullet.gif

本コードでは、「Pybulletへの接続」「重力の設定」「urdfモデルの生成」「リアルタイムシミュレーションモードの設定」などPybulletでよく使う基礎的な機能が使用されています。

コメントをつけたサンプルコード

サンプルコードにコメントをつけたものが以下になります(もともとあった不要と思われるコメント等については削除しています)

import pybullet as p
from time import sleep
import pybullet_data

# PybulletにGUIモードで接続
physicsClient = p.connect(p.GUI)

# Pybulletに関するデータパスを取得
p.setAdditionalSearchPath(pybullet_data.getDataPath())

# 重力を設定
p.setGravity(0, 0, -10)

# 床のオブジェクトを生成
planeId = p.loadURDF("plane.urdf")

# キューブの位置、姿勢を指定して生成
cubeStartPos = [0, 0, 1]
cubeStartOrientation = p.getQuaternionFromEuler([0, 0, 0])
boxId = p.loadURDF("r2d2.urdf", cubeStartPos, cubeStartOrientation)

# 生成したキューブの位置、姿勢を取得
cubePos, cubeOrn = p.getBasePositionAndOrientation(boxId)

# リアルタイムシミュレーションモードをOFFにする
useRealTimeSimulation = 0
if (useRealTimeSimulation):
  p.setRealTimeSimulation(1)

while 1:
  if (useRealTimeSimulation):
    p.setGravity(0, 0, -10)
    sleep(0.01)
  else:
    # シミュレーションを1時刻分進める
    p.stepSimulation()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0