Python pybullet.disconnect() Examples

The following are 20 code examples of pybullet.disconnect(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pybullet , or try the search function .
Example #1
Source File: unittests.py    From soccer-matlab with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def test_rolling_friction(self):
        import pybullet as p
        p.connect(p.DIRECT)
        p.loadURDF("plane.urdf")
        sphere = p.loadURDF("sphere2.urdf",[0,0,1])
        p.resetBaseVelocity(sphere,linearVelocity=[1,0,0])
        p.changeDynamics(sphere,-1,linearDamping=0,angularDamping=0)
        #p.changeDynamics(sphere,-1,rollingFriction=0)
        p.setGravity(0,0,-10)
        for i in range (1000):
          p.stepSimulation()
        vel = p.getBaseVelocity(sphere)
        self.assertLess(vel[0][0],1e-10)
        self.assertLess(vel[0][1],1e-10)
        self.assertLess(vel[0][2],1e-10)
        self.assertLess(vel[1][0],1e-10)
        self.assertLess(vel[1][1],1e-10)
        self.assertLess(vel[1][2],1e-10)
        p.disconnect() 
Example #2
Source File: env.py    From assistive-gym with MIT License 5 votes vote down vote up
def render(self, mode='human'):
        if not self.gui:
            self.gui = True
            p.disconnect(self.id)
            self.id = p.connect(p.GUI, options='--background_color_red=0.8 --background_color_green=0.9 --background_color_blue=1.0 --width=%d --height=%d' % (self.width, self.height))

            self.world_creation = WorldCreation(self.id, robot_type=self.robot_type, task=self.task, time_step=self.time_step, np_random=self.np_random, config=self.config)
            self.util = Util(self.id, self.np_random)
            # print('Physics server ID:', self.id) 
Example #3
Source File: bullet_client.py    From rex-gym with Apache License 2.0 5 votes vote down vote up
def __del__(self):
        """Clean up connection if not already done."""
        try:
            pybullet.disconnect(physicsClientId=self._client)
        except pybullet.error:
            pass 
Example #4
Source File: simulation_manager.py    From qibullet with Apache License 2.0 5 votes vote down vote up
def stopSimulation(self, physics_client):
        """
        Stops the simulated instance corresponding to the physics_client id

        Parameters:
            physics_client - The id of the simulated instance to be stopped
        """
        self._clearInstance(physics_client)

        try:
            pybullet.disconnect(physicsClientId=physics_client)

        except pybullet.error:
            print("Instance " + str(physics_client) + " already stopped") 
Example #5
Source File: env_bases.py    From midlevel-reps with MIT License 5 votes vote down vote up
def _close(self):
        if (self.physicsClientId>=0):
            p.disconnect(self.physicsClientId)
            self.physicsClientId = -1 
Example #6
Source File: env_bases.py    From midlevel-reps with MIT License 5 votes vote down vote up
def _close(self):
        p.disconnect() 
Example #7
Source File: env_bases.py    From GtS with MIT License 5 votes vote down vote up
def _close(self):
        if (self.physicsClientId>=0):
            p.disconnect(self.physicsClientId)
            self.physicsClientId = -1 
Example #8
Source File: env_bases.py    From GtS with MIT License 5 votes vote down vote up
def _close(self):
        p.disconnect() 
Example #9
Source File: client.py    From costar_plan with Apache License 2.0 5 votes vote down vote up
def close(self):
        '''
        Close connection to bullet sim and save collected data.
        '''
        pb.disconnect() 
Example #10
Source File: mobile_robot_env.py    From robotics-rl-srl with MIT License 5 votes vote down vote up
def __del__(self):
        if CONNECTED_TO_SIMULATOR:
            p.disconnect() 
Example #11
Source File: kuka_button_gym_env.py    From robotics-rl-srl with MIT License 5 votes vote down vote up
def __del__(self):
        if CONNECTED_TO_SIMULATOR:
            p.disconnect() 
Example #12
Source File: unittests.py    From soccer-matlab with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_connect_direct(self):
        import pybullet as p
        cid = p.connect(p.DIRECT)
        self.assertEqual(cid,0)
        p.disconnect() 
Example #13
Source File: bullet_client.py    From pyrobot with MIT License 5 votes vote down vote up
def __del__(self):
        """Clean up connection if not already done."""
        try:
            pybullet.disconnect(physicsClientId=self._client)
        except pybullet.error:
            pass 
Example #14
Source File: bullet_world.py    From NTP-vat-release with MIT License 5 votes vote down vote up
def close(self):
        """Terminate the simulation"""
        p.disconnect() 
Example #15
Source File: bullet_client.py    From soccer-matlab with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __del__(self):
    """Clean up connection if not already done."""
    try:
      pybullet.disconnect(physicsClientId=self._client)
    except pybullet.error:
      pass 
Example #16
Source File: bullet_client.py    From soccer-matlab with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __del__(self):
    """Clean up connection if not already done."""
    try:
      pybullet.disconnect(physicsClientId=self._client)
    except pybullet.error:
      pass 
Example #17
Source File: kukaCamGymEnv.py    From soccer-matlab with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __del__(self):
    p.disconnect() 
Example #18
Source File: bullet_client.py    From soccer-matlab with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __del__(self):
    """Clean up connection if not already done."""
    try:
      pybullet.disconnect(physicsClientId=self._client)
    except pybullet.error:
      pass 
Example #19
Source File: unittests.py    From soccer-matlab with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_loadurdf(self):
        import pybullet as p
        p.connect(p.DIRECT)
        ob = p.loadURDF("r2d2.urdf")
        self.assertEqual(ob,0)
        p.disconnect() 
Example #20
Source File: unittests.py    From soccer-matlab with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def testJacobian(self):
        import pybullet as p

        clid = p.connect(p.SHARED_MEMORY)
        if (clid<0):
            p.connect(p.DIRECT)

        time_step = 0.001
        gravity_constant = -9.81

        urdfs = ["TwoJointRobot_w_fixedJoints.urdf",
                 "TwoJointRobot_w_fixedJoints.urdf",
                 "kuka_iiwa/model.urdf",
                 "kuka_lwr/kuka.urdf"]
        for urdf in urdfs:
            p.resetSimulation()
            p.setTimeStep(time_step)
            p.setGravity(0.0, 0.0, gravity_constant)

            robotId = p.loadURDF(urdf, useFixedBase=True)
            p.resetBasePositionAndOrientation(robotId,[0,0,0],[0,0,0,1])
            numJoints = p.getNumJoints(robotId)
            endEffectorIndex = numJoints - 1

            # Set a joint target for the position control and step the sim.
            self.setJointPosition(robotId, [0.1 * (i % 3)
                                            for i in range(numJoints)])
            p.stepSimulation()

            # Get the joint and link state directly from Bullet.
            mpos, mvel, mtorq = self.getMotorJointStates(robotId)

            result = p.getLinkState(robotId, endEffectorIndex,
                    computeLinkVelocity=1, computeForwardKinematics=1)
            link_trn, link_rot, com_trn, com_rot, frame_pos, frame_rot, link_vt, link_vr = result
            # Get the Jacobians for the CoM of the end-effector link.
            # Note that in this example com_rot = identity, and we would need to use com_rot.T * com_trn.
            # The localPosition is always defined in terms of the link frame coordinates.

            zero_vec = [0.0] * len(mpos)
            jac_t, jac_r = p.calculateJacobian(robotId, endEffectorIndex,
                    com_trn, mpos, zero_vec, zero_vec)

            assert(allclose(dot(jac_t, mvel), link_vt))
            assert(allclose(dot(jac_r, mvel), link_vr))
        p.disconnect()