-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial_basics.py
89 lines (69 loc) · 2.52 KB
/
tutorial_basics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Welcome to Google tech talk series for PyCon 2017!
PyBullet: Physics Simulation for Robotics and Machine Learning
Basic tutorial
Questions, comments? Tweet me @hellojas :)
"""
import pybullet as p
import os
import time
# all my constants
# importing all.. forgive me. :)
from data_config import *
def basics():
p.connect(p.GUI) # see connection_types()
basic_world_control()
r2d2 = load_objects()
basic_object_states(r2d2)
# p.resetBasePositionAndOrientation(r2d2, [1,1,1], [0,0,0,1])
# basic_object_states(r2d2)
# basic_object_control(r2d2)
# step(5000)
"""Explains basic world control."""
def basic_world_control():
p.setGravity(0,0,-9.8)
# p.stepSimulation()
# or use p.setRealTimeSimulation(1)
# p.resetSimulation()
# p.disconnect()
"""Steps the simulation."""
def step(steps):
for _ in xrange(steps):
p.stepSimulation()
time.sleep(.001)
"""Loads the objects for the scene."""
def load_objects():
_ = p.loadURDF(os.path.join(MODELS_DIR, PLANE_URDF))
r2d2 = p.loadURDF(os.path.join(MODELS_DIR, R2D2_URDF),0,0,0.5)
return r2d2
"""Explains basic object states."""
def basic_object_states(r2d2):
print('number of joints:', p.getNumJoints(r2d2))
print('base position and orientation', p.getBasePositionAndOrientation(r2d2))
for joint in p.getJointStates(r2d2, R2D2_WHEEL_JOINTS):
print 'joint:', joint
# (jointPosition, jointVelocity, jointReactionForces, appliedJointMotorTorque)
"""Explains basic object control."""
def basic_object_control(r2d2):
p.setJointMotorControlArray(
r2d2, R2D2_WHEEL_JOINTS, p.VELOCITY_CONTROL, # or p.POSITION_CONTROL or p.TORQUE_CONTROL
targetVelocities=[1,1,1,1], forces=[1,1,1,1])
def connection_types():
p.connect(p.DIRECT) # non-graphical
p.connect(p.GUI, options="--opengl2") # using open gl2
p.connect(p.SHARED_MEMORY, 1234) # i.e used for VR
p.connect(p.UDP, "192.168.0.1") # connect over machines
p.connect(p.UDP, "localhost", 1234)
p.connect(p.TCP, "localhost", 6667)
def full_code():
p.connect(p.GUI)
p.setGravity(0,0,-9.8)
_ = p.loadURDF(os.path.join(MODELS_DIR, PLANE_URDF))
r2d2 = p.loadURDF(os.path.join(MODELS_DIR, R2D2_URDF),0,0,0.5)
p.setJointMotorControlArray(r2d2, R2D2_WHEEL_JOINTS,
p.VELOCITY_CONTROL, [1,1,1,1],[1,1,1,1])
for ts in xrange(10000):
print(ts)
for i in xrange(p.getNumJoints(r2d2)):
print(i, p.getJointState(r2d2, i))
p.stepSimulation()
time.sleep(.0001)