本文整理汇总了Python中pybullet.connect方法的典型用法代码示例。如果您正苦于以下问题:Python pybullet.connect方法的具体用法?Python pybullet.connect怎么用?Python pybullet.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybullet
的用法示例。
在下文中一共展示了pybullet.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def __init__(self, connection_mode=None):
"""Creates a Bullet client and connects to a simulation.
Args:
connection_mode:
`None` connects to an existing simulation or, if fails, creates a
new headless simulation,
`pybullet.GUI` creates a new simulation with a GUI,
`pybullet.DIRECT` creates a headless simulation,
`pybullet.SHARED_MEMORY` connects to an existing simulation.
"""
self._shapes = {}
if connection_mode is None:
self._client = pybullet.connect(pybullet.SHARED_MEMORY)
if self._client >= 0:
return
else:
connection_mode = pybullet.DIRECT
self._client = pybullet.connect(connection_mode)
示例2: setup_inverse_kinematics
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def setup_inverse_kinematics(self):
"""
This function is responsible for doing any setup for inverse kinematics.
Inverse Kinematics maps end effector (EEF) poses to joint angles that
are necessary to achieve those poses.
"""
# Set up a connection to the PyBullet simulator.
p.connect(p.DIRECT)
p.resetSimulation()
# get paths to urdfs
self.robot_urdf = pjoin(
self.bullet_data_path, "sawyer_description/urdf/sawyer_arm.urdf"
)
# load the urdfs
self.ik_robot = p.loadURDF(self.robot_urdf, (0, 0, 0.9), useFixedBase=1)
# Simulation will update as fast as it can in real time, instead of waiting for
# step commands like in the non-realtime case.
p.setRealTimeSimulation(1)
示例3: setup_inverse_kinematics
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def setup_inverse_kinematics(self):
"""
This function is responsible for doing any setup for inverse kinematics.
Inverse Kinematics maps end effector (EEF) poses to joint angles that
are necessary to achieve those poses.
"""
# Set up a connection to the PyBullet simulator.
p.connect(p.DIRECT)
p.resetSimulation()
# get paths to urdfs
self.robot_urdf = pjoin(
self.bullet_data_path, "panda_description/urdf/panda_arm.urdf"
)
# load the urdfs
self.ik_robot = p.loadURDF(self.robot_urdf, (0, 0, 0.9), useFixedBase=1)
# Simulation will update as fast as it can in real time, instead of waiting for
# step commands like in the non-realtime case.
p.setRealTimeSimulation(1)
示例4: __init__
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def __init__(self, robot_name, print_debug, email_cred_file='', log_file='', control_rate=100, gripper_attached='default'):
super(WidowXController, self).__init__(robot_name, print_debug, email_cred_file, log_file, control_rate, gripper_attached)
self._redist_rate = rospy.Rate(50)
self._arbotix = ArbotiX('/dev/ttyUSB0')
assert self._arbotix.syncWrite(MAX_TORQUE_L, [[servo_id, 255, 0] for servo_id in SERVO_IDS]) != -1, "failure during servo configuring"
assert self._arbotix.syncWrite(TORQUE_LIMIT, [[servo_id, 255, 0] for servo_id in SERVO_IDS]) != -1, "failure during servo configuring"
self._joint_lock = Lock()
self._angles, self._velocities = {}, {}
rospy.Subscriber("/joint_states", JointState, self._joint_callback)
time.sleep(1)
self._joint_pubs = [rospy.Publisher('/{}/command'.format(name), Float64, queue_size=1) for name in JOINT_NAMES[:-1]]
self._gripper_pub = rospy.Publisher('/gripper_prismatic_joint/command', Float64, queue_size=1)
p.connect(p.DIRECT)
widow_x_urdf = '/'.join(__file__.split('/')[:-1]) + '/widowx/widowx.urdf'
self._armID = p.loadURDF(widow_x_urdf, useFixedBase=True)
p.resetBasePositionAndOrientation(self._armID, [0, 0, 0], p.getQuaternionFromEuler([np.pi, np.pi, np.pi]))
self._n_errors = 0
示例5: __init__
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def __init__(self,
render_mode='DIRECT',
hidden_drift=False,
urdf_root=''):
"""Construct a Duck pose prediction task.
Args:
render_mode: Whether to render headless or with a GUI.
hidden_drift: If True, each task will assign a hidden random drift where
the rendered pose differs from the true pose. Requires meta-learning
adaptation to solve.
urdf_root: Path to URDF files.
"""
if render_mode == 'GUI':
self.cid = pybullet.connect(pybullet.GUI)
elif render_mode == 'DIRECT':
self.cid = pybullet.connect(pybullet.DIRECT)
self._width, self._height = 64, 64
self._urdf_root = urdf_root
self._hidden_drift = hidden_drift
self._hidden_drift_xyz = None
self._setup()
self.reset_task()
示例6: _start_ros
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def _start_ros(self, name):
'''
Simple function to boot up a ROS core and make sure that we connect to
it. The goal is to manage internal ROS stuff via this script to provide
an easy and repeatable interface when running experiments.
'''
self._start_process(['roscore'], 1.)
started = False
tries = 0
while not started:
try:
rospy.init_node(name)
started = True
except Exception, e:
pass
finally:
示例7: open
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def open(self):
'''
Decide how we will create our interface to the underlying simulation.
We can create a GUI connection or something else.
'''
options = ""
if self.opengl2:
connect_type = pb.GUI
options = "--opengl2"
elif self.gui:
connect_type = pb.GUI
else:
connect_type = pb.DIRECT
self.client = pb.connect(connect_type, options=options)
GRAVITY = (0,0,-9.8)
pb.setGravity(*GRAVITY)
# place the robot in the world and set up the task
self.task.setup()
示例8: __init__
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def __init__(self, connection_mode=None):
"""Creates a Bullet client and connects to a simulation.
Args:
connection_mode:
`None` connects to an existing simulation or, if fails, creates a
new headless simulation,
`pybullet.GUI` creates a new simulation with a GUI,
`pybullet.DIRECT` creates a headless simulation,
`pybullet.SHARED_MEMORY` connects to an existing simulation.
"""
self._shapes = {}
if connection_mode is None:
self._client = pybullet.connect(pybullet.SHARED_MEMORY)
if self._client >= 0:
return
else:
connection_mode = pybullet.DIRECT
self._client = pybullet.connect(connection_mode)
示例9: __init__
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def __init__(self, render=False):
self._observation = []
self.action_space = spaces.Discrete(9)
self.observation_space = spaces.Box(np.array([-math.pi, -math.pi, -5]),
np.array([math.pi, math.pi, 5])) # pitch, gyro, com.sp.
if (render):
self.physicsClient = p.connect(p.GUI)
else:
self.physicsClient = p.connect(p.DIRECT) # non-graphical version
p.setAdditionalSearchPath(pybullet_data.getDataPath()) # used by loadURDF
self._seed()
# paramId = p.addUserDebugParameter("My Param", 0, 100, 50)
示例10: main
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def main(unused_args):
timeStep = 0.01
c = p.connect(p.SHARED_MEMORY)
if (c<0):
c = p.connect(p.GUI)
params = [0.1903581461951056, 0.0006732219568880068, 0.05018085615283363, 3.219916795483583, 6.2406418167980595, 4.189869754607539]
evaluate_func = 'evaluate_desired_motorAngle_2Amplitude4Phase'
energy_weight = 0.01
finalReturn = evaluate_params(evaluateFunc = evaluate_func, params=params, objectiveParams=[energy_weight], timeStep=timeStep, sleepTime=timeStep)
print(finalReturn)
示例11: readLogFile
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def readLogFile(filename, verbose = True):
f = open(filename, 'rb')
print('Opened'),
print(filename)
keys = f.readline().decode('utf8').rstrip('\n').split(',')
fmt = f.readline().decode('utf8').rstrip('\n')
# The byte number of one record
sz = struct.calcsize(fmt)
# The type number of one record
ncols = len(fmt)
if verbose:
print('Keys:'),
print(keys)
print('Format:'),
print(fmt)
print('Size:'),
print(sz)
print('Columns:'),
print(ncols)
# Read data
wholeFile = f.read()
# split by alignment word
chunks = wholeFile.split(b'\xaa\xbb')
log = list()
for chunk in chunks:
if len(chunk) == sz:
values = struct.unpack(fmt, chunk)
record = list()
for i in range(ncols):
record.append(values[i])
log.append(record)
return log
#clid = p.connect(p.SHARED_MEMORY)
示例12: test_connect_direct
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def test_connect_direct(self):
import pybullet as p
cid = p.connect(p.DIRECT)
self.assertEqual(cid,0)
p.disconnect()
示例13: test_loadurdf
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def test_loadurdf(self):
import pybullet as p
p.connect(p.DIRECT)
ob = p.loadURDF("r2d2.urdf")
self.assertEqual(ob,0)
p.disconnect()
示例14: main
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def main():
pybullet.connect(pybullet.DIRECT)
env = gym.make("AntBulletEnv-v0")
env.render(mode="human")
pi = SmallReactivePolicy(env.observation_space, env.action_space)
env.reset()
while 1:
frame = 0
score = 0
restart_delay = 0
obs = env.reset()
while 1:
time.sleep(1./60.)
a = pi.act(obs)
obs, r, done, _ = env.step(a)
#print("reward")
#print(r)
score += r
frame += 1
distance=5
yaw = 0
still_open = env.render("human")
if still_open==False:
return
if not done: continue
if restart_delay==0:
print("score=%0.2f in %i frames" % (score, frame))
restart_delay = 60*2 # 2 sec at 60 fps
else:
restart_delay -= 1
if restart_delay==0: break
示例15: test
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import connect [as 别名]
def test(args):
p.connect(p.GUI)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
fileName = os.path.join("mjcf", args.mjcf)
print("fileName")
print(fileName)
p.loadMJCF(fileName)
while (1):
p.stepSimulation()
p.getCameraImage(320,240)
time.sleep(0.01)