没有合适的资源?快使用搜索试试~ 我知道了~
PyBullet Quickstart Guide.docx
需积分: 5 2 下载量 60 浏览量
2021-07-05
17:18:17
上传
评论
收藏 6.5MB DOCX 举报
温馨提示
试读
64页
方便复制查询翻译~最新2016/2021,Visit desktop doc, forums, github discussions and star Bullet!
资源详情
资源评论
资源推荐
PyBullet Quickstart Guide
Erwin Coumans, Yunfei Bai, 2016-2021
Visit desktop doc, forums, github discussions and star Bullet!
2
Introduction
PyBullet is a fast and easy to use Python module for robotics simulation and machine learning,
with a focus on sim-to-real transfer. With PyBullet you can load articulated bodies from URDF,
SDF, MJCF and other file formats. PyBullet provides forward dynamics simulation, inverse
dynamics computation, forward and inverse kinematics, collision detection and ray intersection
queries. The Bullet Physics SDK includes PyBullet robotic examples such as a simulated
Minitaur quadruped, humanoids running using TensorFlow inference and KUKA arms grasping
objects. Reduced coordinate multibodies, rigidbodies and deformables are handled by a unified
LCP constraint solver, similar to this thesis.
Aside from physics simulation, there are bindings to rendering, with a CPU renderer
(TinyRenderer) and OpenGL 3.x rendering and visualization and support for Virtual Reality
headsets such as HTC Vive and Oculus Rift. PyBullet also has functionality to perform collision
detection queries (closest points, overlapping pairs, ray intersection test etc) and to add debug
rendering (debug lines and text). PyBullet has cross-platform built-in client-server support for
shared memory, UDP and TCP networking. So you can run PyBullet on Linux connecting to a
Windows VR server.
PyBullet wraps the new Bullet C-API, which is designed to be independent from the underlying
physics engine and render engine, so we can easily migrate to newer versions of Bullet, or use
a different physics engine or render engine. By default, PyBullet uses the Bullet 2.x API on the
CPU. We will expose Bullet 3.x running on GPU using OpenCL as well. There is also a C++ API
similar to PyBullet, see b3RobotSimulatorClientAPI.
PyBullet can be easily used with TensorFlow and OpenAI Gym. Researchers from Google Brain
[1,2,3,4], X[1,2], Stanford AI Lab [1,2,3], OpenAI,INRIA [1] and many other labs use PyBullet. If
you use PyBullet in your research, please add a citation.
The installation of PyBullet is as simple as (sudo) pip install PyBullet (Python 2.x), pip3 install
PyBullet. This will expose the PyBullet module as well as pybullet_envs Gym environments.
Hello PyBullet World
3
Here is a PyBullet introduction script that we discuss step by step:
import pybullet as p
import time
import pybullet_data
physicsClient = p.connect(p.GUI)#or p.DIRECT for non-graphical version
p.setAdditionalSearchPath(pybullet_data.getDataPath()) #optionally
p.setGravity(0,0,-10)
planeId = p.loadURDF("plane.urdf")
startPos = [0,0,1]
startOrientation = p.getQuaternionFromEuler([0,0,0])
boxId = p.loadURDF("r2d2.urdf",startPos, startOrientation)
#set the center of mass frame (loadURDF sets base link frame)
startPos/Ornp.resetBasePositionAndOrientation(boxId, startPos,
startOrientation)
for i in range (10000):
p.stepSimulation()
time.sleep(1./240.)
cubePos, cubeOrn = p.getBasePositionAndOrientation(boxId)
print(cubePos,cubeOrn)
p.disconnect()
connect, disconnect, bullet_client
After importing the PyBullet module, the first thing to do is 'connecting' to the physics simulation.
PyBullet is designed around a client-server driven API, with a client sending commands and a
physics server returning the status. PyBullet has some built-in physics servers: DIRECT and
GUI. Both GUI and DIRECT connections will execute the physics simulation and rendering in
the same process as PyBullet.
Note that in DIRECT mode you cannot access the OpenGL and VR hardware features, as
described in the "Virtual Reality" and "Debug GUI, Lines, Text, Parameters" chapters. DIRECT
mode does allow rendering of images using the built-in software renderer through the
'getCameraImage' API. This can be useful for running simulations in the cloud on servers
without GPU.
You can provide your own data files, or you can use the PyBullet_data package that ships with
PyBullet. For this, import pybullet_data and register the directory using
pybullet.setAdditionalSearchPath(pybullet_data.getDataPath()).
getConnectionInfo
Given a physicsClientId will return the list [isConnected, connectionMethod]
isConnected
4
isConnected will return true if connected, false otherwise, given a physicsClientId.
setTimeOut
If a command is not processed by the server within a specific time out value, the client will
disconnect. Use setTimeOut to specify this value in seconds.
Diagram with various physics client (blue) and physics server (green) options. Dark green
servers provide OpenGL debug visualization.
connect using DIRECT, GUI
The DIRECT connection sends the commands directly to the physics engine, without using any
transport layer and no graphics visualization window, and directly returns the status after
executing the command.
The GUI connection will create a new graphical user interface (GUI) with 3D OpenGL rendering,
within the same process space as PyBullet. On Linux and Windows this GUI runs in a separate
thread, while on OSX it runs in the same thread due to operating system limitations. On Mac
OSX you may see a spinning wheel in the OpenGL Window, until you run a 'stepSimulation' or
other PyBullet command.
The commands and status messages are sent between PyBullet client and the GUI physics
simulation server using an ordinary memory buffer.
It is also possible to connect to a physics server in a different process on the same machine or
on a remote machine using SHARED_MEMORY, UDP or TCP networking. See the section
about Shared Memory, UDP and TCP for details.
5
Unlike almost all other methods, this method doesn't parse keyword arguments, due to
backward compatibility.
The connect input arguments are:
required connection mode integer:
DIRECT,
GUI,
SHARED_
MEMORY,
UDP, TCP
GUI_SERV
ER,
SHARED_
MEMORY_
SERVER,
SHARED_
MEMORY_
GUI
DIRECT mode create a new physics engine and directly
communicates with it. GUI will create a physics engine with
graphical GUI frontend and communicates with it.
SHARED_MEMORY will connect to an existing physics engine
process on the same machine, and communicates with it over
shared memory. TCP or UDP will connect to an existing
physics server over TCP or UDP networking.
GUI_SERVER is similar to GUI but also acts as a serverthat
allows external SHARED_MEMORY connections.
SHARED_MEMORY_SERVER is similar to DIRECT but also
acts as a server that allows external SHARED_MEMORY
connections. SHARED_MEMORY_GUI is similar to DIRECT
but will attempt to connect to an external graphics server for
display. The Bullet ExampleBrowser has an option to act as
Physics Server or Graphics Server.
optional key int in SHARED_MEMORY mode, optional shared memory key.
When starting ExampleBrowser or SharedMemoryPhysics_*
you can use optional command-line --shared_memory_key to
set the key. This allows to run multiple servers on the same
machine.
optional hostName
(UDP and TCP)
string IP address or host name, for example "127.0.0.1" or "localhost"
or "mymachine.domain.com"
optional port
(UDP and TCP)
integer UDP port number. Default UDP port is 1234, default TCP port
is 6667 (matching the defaults in the server)
optional options string command-line option passed into the GUI server.
You can set the background color, with red/green/blue
parameters in the range [0..1] as follows:
p.connect(p.GUI, options="--background_color_red=1 --
background_color_blue=1 --background_color_green=1")
Other options are:
--mouse_move_multiplier=0.400000 (mouse sensitivity)
--mouse_wheel_multiplier=0.400000 (mouse wheel sensitivity)
--width=<int> width of the window in pixels
--height=<int> height of the window, in pixels.
--mp4=moviename.mp4 (records movie, requires ffmpeg)
--mp4fps=<int> (for movie recording, set frames per second).
connect returns a physics client id or -1 if not connected. The physics client Id is an optional
argument to most of the other PyBullet commands. If you don't provide it, it will assume physics
client id = 0. You can connect to multiple different physics servers, except for GUI.
For example:
剩余63页未读,继续阅读
鲁米内特
- 粉丝: 59
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0