<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/13532" />

	<title>Real-Time Physics Simulation Forum</title>
	
	<link href="https://pybullet.org/Bullet/phpBB3/index.php" />
	<updated>2023-02-08T16:48:56+00:00</updated>

	<author><name><![CDATA[Real-Time Physics Simulation Forum]]></name></author>
	<id>https://pybullet.org/Bullet/phpBB3/app.php/feed/topic/13532</id>

		<entry>
		<author><name><![CDATA[Yogha001]]></name></author>
		<updated>2023-02-08T16:48:56+00:00</updated>

		<published>2023-02-08T16:48:56+00:00</published>
		<id>https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=44237#p44237</id>
		<link href="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=44237#p44237"/>
		<title type="html"><![CDATA[How to turn off gravity only for some Objects ?]]></title>

		
		<content type="html" xml:base="https://pybullet.org/Bullet/phpBB3/viewtopic.php?p=44237#p44237"><![CDATA[
I am currently working on a VR simulation in VRED, utilizing PyBullet as the physics simulation engine to support real-time simulation with objects affected by gravity. However, there are instances where it may be necessary to turn off gravity for specific objects in the simulation.<br><br>My current solution to achieve this is by setting the mass of these objects to 0, but this does not result in a realistic scenario of objects floating in space. I am seeking a solution to have some objects float in space with no gravity, while others are affected by gravity in the simulation.<br><br>The most realistic solution is to run the Physics client on multiple Server.<br>My current code looks like this.<br><div class="codebox"><p>Code: </p><pre><code>newScene()from pybullet_utils import bullet_client as bcimport pybulletimport mathimport timeimport pybullet_dataclass TestAction(vrAEBase):   def __init__(self):       vrAEBase.__init__(self)       self.physicsClient1 = bc.BulletClient(connection_mode=pybullet.DIRECT)       self.physicsClient2 = bc.BulletClient(connection_mode=pybullet.DIRECT)              self.physicsClient1.setAdditionalSearchPath(pybullet_data.getDataPath())       self.physicsClient2.setAdditionalSearchPath(pybullet_data.getDataPath())              self.physicsClient1.setRealTimeSimulation(1)       self.physicsClient2.setRealTimeSimulation(1)              # Set gravity to zero in the first instance       self.physicsClient1.setGravity(0,0,0) # 0 gravity in the GUI              # Set gravity for the sphere object in the second instance       self.physicsClient2.setGravity(0,0,-9.8) # -9.8 in Z-axis (typical earth gravity)              #loadURDF       self.planeId = self.physicsClient1.loadURDF("plane.urdf", [0, 0, 0], [0, 0, 0, 1])              self.boxId1 = self.physicsClient1.loadURDF("BOX.urdf",[-1, -1, 10], [0, 0, 0, 1])       self.boxId2 = self.physicsClient2.loadURDF("BOX.urdf",[1, 1, 10], [0, 0, 0, 1])              self.createNodes()       self.addLoop()   def __del__(self):       self.physicsClient1.disconnect()       self.physicsClient2.disconnect()       print("end")          def createNodes(self):              if not getRootNode().getChild("Box").isValid():           self.boxNode = createBox(1000, 1000, 1000, 1, 1, 1, 0.0, 1.0, 0.0, 0.0)           self.boxNode.setName("Box")           getRootNode().addChild(self.boxNode)       if not getRootNode().getChild("Box2").isValid():           self.boxNode2 = createBox(1000, 1000, 1000, 1, 1, 1, 0.0, 0.0, 1.0, 0.0)           self.boxNode2.setName("Box2")           getRootNode().addChild(self.boxNode2)   def loop(self):       pos, rot = self.physicsClient1.getBasePositionAndOrientation(self.boxId1    def loop(self):       pos, rot = self.physicsClient1.getBasePositionAndOrientation(self.boxId1)       eulerRot = self.physicsClient1.getEulerFromQuaternion(rot)       self.boxNode.setWorldTranslation(pos[0]*1000, pos[1]*1000, pos[2]*1000)       self.boxNode.setRotation(math.degrees(eulerRot[0]), math.degrees(eulerRot[1]), math.degrees(eulerRot[2]))             pos2, rot2 = self.physicsClient2.getBasePositionAndOrientation(self.boxId2)       eulerRot2 = self.physicsClient2.getEulerFromQuaternion(rot2)       self.boxNode2.setWorldTranslation(pos2[0]*1000, pos2[1]*1000, pos2[2]*1000)       self.boxNode2.setRotation(math.degrees(eulerRot[0]), math.degrees(eulerRot[1]), math.degrees(eulerRot[2])) ta = TestAction() ta.setActive(true)</code></pre></div>When i run this script i don't get any error, so i guess it seems to work. But the Simulation is not working.<br><br>I tried another approche to have a better prespective this time without VRED.<br><br>So first i run the Example script "runServer.py"<br><div class="codebox"><p>Code: </p><pre><code>#add parent dir to find package. Only needed for source code build, pip install doesn't need it.import osimport inspectcurrentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))parentdir = os.path.dirname(os.path.dirname(currentdir))os.sys.path.insert(0, parentdir)import pybullet_dataimport pybullet as pimport timep.connect(p.GUI_SERVER)p.setAdditionalSearchPath(pybullet_data.getDataPath())while (1):  #this is a no-op command, to allow GUI updates on Mac OSX (main thread)  p.setPhysicsEngineParameter()  p.setRealTimeSimulation(1)</code></pre></div>then I run my script it's so similar to the "multipleScenes.py"<br><div class="codebox"><p>Code: </p><pre><code>from pybullet_utils import bullet_client as bcimport pybulletimport pybullet_dataphysicsClient1 = bc.BulletClient(connection_mode=pybullet.SHARED_MEMORY)physicsClient2 = bc.BulletClient(connection_mode=pybullet.SHARED_MEMORY)planeID = physicsClient1.loadURDF(pybullet_data.getDataPath() + "/plane.urdf", [0, 0, 0])sphereId1 = physicsClient1.loadURDF(pybullet_data.getDataPath() + "/r2d2.urdf", [1,1,2])sphereId2 = physicsClient2.loadURDF(pybullet_data.getDataPath() + "/r2d2.urdf", [-1,-1,2])physicsClient1.setGravity(0,0,-9.8) # 0 gravity in the GUIphysicsClient2.setGravity(0,0,0) # -9.8 in Z-axis (typical earth gravity)physicsClient1.setRealTimeSimulation(1)physicsClient2.setRealTimeSimulation(1)physicsClient1.disconnect()physicsClient2.disconnect()</code></pre></div>The Problem here seems that the same Gravity is applied on both spheres.<p>Statistics: Posted by <a href="https://pybullet.org/Bullet/phpBB3/memberlist.php?mode=viewprofile&amp;u=14517">Yogha001</a> — Wed Feb 08, 2023 4:48 pm</p><hr />
]]></content>
	</entry>
	</feed>
