def __init__(self, client=0, renderer: BaseRenderer = None): """Load plugin Arguments: physicsClientId {int or BulletClient} -- physics client Keyword Arguments: renderer {BaseRenderer} -- renderer to load (default: None) """ self._client_id = client if isinstance(client, int) else client._client # load plugin self._plugin_id = pb.loadPlugin(plugin_lib_file, '_RenderingPlugin', physicsClientId=self._client_id) assert self._plugin_id != -1, 'Cannot load PyBullet plugin' # workaround to connect python bindings with a physicsClientId retcode = pb.executePluginCommand(self._plugin_id, "register", intArgs=[self._client_id], physicsClientId=self._client_id) assert retcode != -1, 'Cannot register render interface' # bind a renderer if renderer is not None: self.set_renderer(renderer)
import pybullet as p import time useDirect = False usePort = True p.connect(p.GUI) id = p.loadPlugin("grpcPlugin") #dynamically loading the plugin #id = p.loadPlugin("E:/develop/bullet3/bin/pybullet_grpcPlugin_vs2010_x64_debug.dll", postFix="_grpcPlugin") #start the GRPC server at hostname, port if (id < 0): print("Cannot load grpcPlugin") exit(0) if usePort: p.executePluginCommand(id, "localhost:12345") else: p.executePluginCommand(id, "localhost") while p.isConnected(): if (useDirect): #Only in DIRECT mode, since there is no 'ping' you need to manually call to handle RCPs: numRPC = 10 p.executePluginCommand(id, intArgs=[numRPC]) else: dt = 1. / 240. time.sleep(dt)
useRealTimeSim = True p.setRealTimeSimulation(useRealTimeSim) p.setTimeStep(0.001) while p.isConnected(): if (pd>=0): desiredPosCart = p.readUserDebugParameter(desiredPosCartId) desiredVelCart = p.readUserDebugParameter(desiredVelCartId) kpCart = p.readUserDebugParameter(kpCartId) kdCart = p.readUserDebugParameter(kdCartId) maxForceCart = p.readUserDebugParameter(maxForceCartId) link = 0 p.executePluginCommand(pd,"test",[1, pole, link], [desiredPosCart, desiredVelCart, kdCart, kpCart, maxForceCart]) desiredPosPole = p.readUserDebugParameter(desiredPosPoleId) desiredVelPole = p.readUserDebugParameter(desiredVelPoleId) kpPole = p.readUserDebugParameter(kpPoleId) kdPole = p.readUserDebugParameter(kdPoleId) maxForcePole = p.readUserDebugParameter(maxForcePoleId) link = 1 p.executePluginCommand(pd,"test",[1, pole, link], [desiredPosPole, desiredVelPole, kdPole, kpPole, maxForcePole]) if (not useRealTimeSim): p.stepSimulation() time.sleep(1./240.)
def __init__(self, assets_root, task=None, disp=False, shared_memory=False, hz=240): """Creates OpenAI Gym-style environment with PyBullet. Args: assets_root: root directory of assets. task: the task to use. If None, the user must call set_task for the environment to work properly. disp: show environment with PyBullet's built-in display viewer. shared_memory: run with shared memory. hz: PyBullet physics simulation step speed. Set to 480 for deformables. Raises: RuntimeError: if pybullet cannot load fileIOPlugin. """ self.pix_size = 0.003125 self.obj_ids = {'fixed': [], 'rigid': [], 'deformable': []} self.homej = np.array([-1, -0.5, 0.5, -0.5, -0.5, 0]) * np.pi self.agent_cams = cameras.RealSenseD415.CONFIG self.assets_root = assets_root color_tuple = [ gym.spaces.Box(0, 255, config['image_size'] + (3, ), dtype=np.uint8) for config in self.agent_cams ] depth_tuple = [ gym.spaces.Box(0.0, 20.0, config['image_size'], dtype=np.float32) for config in self.agent_cams ] self.observation_space = gym.spaces.Dict({ 'color': gym.spaces.Tuple(color_tuple), 'depth': gym.spaces.Tuple(depth_tuple), }) # TODO(ayzaan): Delete below and uncomment vector box bounds. position_bounds = gym.spaces.Box(low=-1.0, high=1.0, shape=(3, ), dtype=np.float32) # position_bounds = gym.spaces.Box( # low=np.array([0.25, -0.5, 0.], dtype=np.float32), # high=np.array([0.75, 0.5, 0.28], dtype=np.float32), # shape=(3,), # dtype=np.float32) self.action_space = gym.spaces.Dict({ 'pose0': gym.spaces.Tuple((position_bounds, gym.spaces.Box(-1.0, 1.0, shape=(4, ), dtype=np.float32))), 'pose1': gym.spaces.Tuple((position_bounds, gym.spaces.Box(-1.0, 1.0, shape=(4, ), dtype=np.float32))) }) # Start PyBullet. disp_option = p.DIRECT if disp: disp_option = p.GUI if shared_memory: disp_option = p.SHARED_MEMORY client = p.connect(disp_option) file_io = p.loadPlugin('fileIOPlugin', physicsClientId=client) if file_io < 0: raise RuntimeError('pybullet: cannot load FileIO!') if file_io >= 0: p.executePluginCommand(file_io, textArgument=assets_root, intArgs=[p.AddFileIOAction, p.CNSFileIO], physicsClientId=client) p.configureDebugVisualizer(p.COV_ENABLE_GUI, 0) p.setPhysicsEngineParameter(enableFileCaching=0) p.setAdditionalSearchPath(assets_root) p.setAdditionalSearchPath(tempfile.gettempdir()) p.setTimeStep(1. / hz) # If using --disp, move default camera closer to the scene. if disp: target = p.getDebugVisualizerCamera()[11] p.resetDebugVisualizerCamera(cameraDistance=1.1, cameraYaw=90, cameraPitch=-25, cameraTargetPosition=target) if task: self.set_task(task)
import pybullet as p p.connect(p.GUI) plugin = p.loadPlugin("D:/develop/bullet3/bin/pybullet_testplugin_vs2010_x64_debug.dll", "_testPlugin") print("plugin=", plugin) p.executePluginCommand(plugin, "r2d2.urdf", [1, 2, 3], [50.0, 3.3]) while (1): p.getCameraImage(320, 200) p.stepSimulation()
POSITION = 1 ORIENTATION = 2 BUTTONS = 6 controllerId = -1 print("waiting for VR controller trigger") while (controllerId < 0): events = p.getVREvents() for e in (events): if (e[BUTTONS][33] == p.VR_BUTTON_IS_DOWN): controllerId = e[CONTROLLER_ID] if (e[BUTTONS][32] == p.VR_BUTTON_IS_DOWN): controllerId = e[CONTROLLER_ID] print("Using controllerId=" + str(controllerId)) #plugin = p.loadPlugin("d:/develop/bullet3/bin/pybullet_vrSyncPlugin_vs2010_x64_release.dll","_vrSyncPlugin") plugin = p.loadPlugin("vrSyncPlugin") print("PluginId=" + str(plugin)) p.executePluginCommand(plugin, "bla", [controllerId, pr2_cid, pr2_cid2, pr2_gripper], [50, 3]) while (1): #b = p.getJointState(pr2_gripper,2)[0] #print("b = " + str(b)) #p.setJointMotorControl2(pr2_gripper, 0, p.POSITION_CONTROL, targetPosition=b, force=3) p.setGravity(0, 0, -10) p.disconnect()
import pybullet as p import time p.connect(p.GUI) fileIO = p.loadPlugin("fileIOPlugin") if (fileIO >= 0): p.executePluginCommand(fileIO, "pickup.zip", [p.AddFileIOAction, p.ZipFileIO]) objs = p.loadSDF("pickup/model.sdf") dobot = objs[0] p.changeVisualShape(dobot, -1, rgbaColor=[1, 1, 1, 1]) else: print("fileIOPlugin is disabled.") p.setPhysicsEngineParameter(enableFileCaching=False) while (1): p.stepSimulation() time.sleep(1. / 240.)
POSITION = 1 ORIENTATION = 2 BUTTONS = 6 controllerId = -1 print("waiting for VR controller trigger") while (controllerId<0): events = p.getVREvents() for e in (events): if (e[BUTTONS][33]==p.VR_BUTTON_IS_DOWN): controllerId = e[CONTROLLER_ID] if (e[BUTTONS][32]==p.VR_BUTTON_IS_DOWN): controllerId = e[CONTROLLER_ID] print("Using controllerId="+str(controllerId)) #plugin = p.loadPlugin("d:/develop/bullet3/bin/pybullet_vrSyncPlugin_vs2010_x64_release.dll","_vrSyncPlugin") plugin = p.loadPlugin("vrSyncPlugin") print("PluginId="+str(plugin)) p.executePluginCommand(plugin ,"bla", [controllerId,pr2_cid, pr2_cid2,pr2_gripper],[50,3]) while (1): #b = p.getJointState(pr2_gripper,2)[0] #print("b = " + str(b)) #p.setJointMotorControl2(pr2_gripper, 0, p.POSITION_CONTROL, targetPosition=b, force=3) p.setGravity(0,0,-10) p.disconnect()
import pybullet as p p.connect(p.GUI) plugin = p.loadPlugin( "D:/develop/bullet3/bin/pybullet_testplugin_vs2010_x64_debug.dll", "_testPlugin") print("plugin=", plugin) p.executePluginCommand(plugin, "r2d2.urdf", [1, 2, 3], [50.0, 3.3]) while (1): p.getCameraImage(320, 200) p.stepSimulation()
import pybullet as p import time p.connect(p.GUI) fileIO = p.loadPlugin("fileIOPlugin") if (fileIO>=0): p.executePluginCommand(fileIO, "pickup.zip", [p.AddFileIOAction, p.ZipFileIO]) objs= p.loadSDF("pickup/model.sdf") dobot =objs[0] p.changeVisualShape(dobot,-1,rgbaColor=[1,1,1,1]) else: print("fileIOPlugin is disabled.") p.setPhysicsEngineParameter(enableFileCaching=False) while (1): p.stepSimulation() time.sleep(1./240.)
def __init__(self, assets_root, task=None, disp=False, shared_memory=False, hz=240, use_egl=False): """Creates OpenAI Gym-style environment with PyBullet. Args: assets_root: root directory of assets. task: the task to use. If None, the user must call set_task for the environment to work properly. disp: show environment with PyBullet's built-in display viewer. shared_memory: run with shared memory. hz: PyBullet physics simulation step speed. Set to 480 for deformables. use_egl: Whether to use EGL rendering. Only supported on Linux. Should get a significant speedup in rendering when using. Raises: RuntimeError: if pybullet cannot load fileIOPlugin. """ if use_egl and disp: raise ValueError('EGL rendering cannot be used with `disp=True`.') self.pix_size = 0.003125 self.obj_ids = {'fixed': [], 'rigid': [], 'deformable': []} self.homej = np.array([-1, -0.5, 0.5, -0.5, -0.5, 0]) * np.pi self.agent_cams = cameras.RealSenseD415.CONFIG self.assets_root = assets_root color_tuple = [ gym.spaces.Box(0, 255, config['image_size'] + (3, ), dtype=np.uint8) for config in self.agent_cams ] depth_tuple = [ gym.spaces.Box(0.0, 20.0, config['image_size'], dtype=np.float32) for config in self.agent_cams ] self.observation_space = gym.spaces.Dict({ 'color': gym.spaces.Tuple(color_tuple), 'depth': gym.spaces.Tuple(depth_tuple), }) self.position_bounds = gym.spaces.Box(low=np.array([0.25, -0.5, 0.], dtype=np.float32), high=np.array([0.75, 0.5, 0.28], dtype=np.float32), shape=(3, ), dtype=np.float32) self.action_space = gym.spaces.Dict({ 'pose0': gym.spaces.Tuple((self.position_bounds, gym.spaces.Box(-1.0, 1.0, shape=(4, ), dtype=np.float32))), 'pose1': gym.spaces.Tuple((self.position_bounds, gym.spaces.Box(-1.0, 1.0, shape=(4, ), dtype=np.float32))) }) # Start PyBullet. disp_option = p.DIRECT if disp: disp_option = p.GUI if shared_memory: disp_option = p.SHARED_MEMORY client = p.connect(disp_option) file_io = p.loadPlugin('fileIOPlugin', physicsClientId=client) if file_io < 0: raise RuntimeError('pybullet: cannot load FileIO!') if file_io >= 0: p.executePluginCommand(file_io, textArgument=assets_root, intArgs=[p.AddFileIOAction], physicsClientId=client) self._egl_plugin = None if use_egl: assert sys.platform == 'linux', ( 'EGL rendering is only supported on ' 'Linux.') egl = pkgutil.get_loader('eglRenderer') if egl: self._egl_plugin = p.loadPlugin(egl.get_filename(), '_eglRendererPlugin') else: self._egl_plugin = p.loadPlugin('eglRendererPlugin') print('EGL renderering enabled.') p.configureDebugVisualizer(p.COV_ENABLE_GUI, 0) p.setPhysicsEngineParameter(enableFileCaching=0) p.setAdditionalSearchPath(assets_root) p.setAdditionalSearchPath(tempfile.gettempdir()) p.setTimeStep(1. / hz) # If using --disp, move default camera closer to the scene. if disp: target = p.getDebugVisualizerCamera()[11] p.resetDebugVisualizerCamera(cameraDistance=1.1, cameraYaw=90, cameraPitch=-25, cameraTargetPosition=target) if task: self.set_task(task)
import pybullet as p import time import pybullet_data p.connect(p.GUI) p.setAdditionalSearchPath(pybullet_data.getDataPath()) fileIO = p.loadPlugin("fileIOPlugin") if (fileIO >= 0): #we can have a zipfile (pickup.zip) inside a zipfile (pickup2.zip) p.executePluginCommand(fileIO, pybullet_data.getDataPath() + "/pickup2.zip", [p.AddFileIOAction, p.ZipFileIO]) p.executePluginCommand(fileIO, "pickup.zip", [p.AddFileIOAction, p.ZipFileIO]) objs = p.loadSDF("pickup/model.sdf") dobot = objs[0] p.changeVisualShape(dobot, -1, rgbaColor=[1, 1, 1, 1]) else: print("fileIOPlugin is disabled.") p.setPhysicsEngineParameter(enableFileCaching=False) while (1): p.stepSimulation() time.sleep(1. / 240.)