test.py 766 B

123456789101112131415161718192021222324252627282930313233343536
  1. import pybullet
  2. import time
  3. #choose connection method: GUI, DIRECT, SHARED_MEMORY
  4. pybullet.connect(pybullet.GUI)
  5. #load URDF, given a relative or absolute file+path
  6. obj = pybullet.loadURDF("r2d2.urdf")
  7. posX=0
  8. posY=3
  9. posZ=2
  10. obj2 = pybullet.loadURDF("kuka_lwr/kuka.urdf",posX,posY,posZ)
  11. #query the number of joints of the object
  12. numJoints = pybullet.getNumJoints(obj)
  13. print (numJoints)
  14. #set the gravity acceleration
  15. pybullet.setGravity(0,0,-9.8)
  16. #step the simulation for 5 seconds
  17. t_end = time.time() + 5
  18. while time.time() < t_end:
  19. pybullet.stepSimulation()
  20. posAndOrn = pybullet.getBasePositionAndOrientation(obj)
  21. print (posAndOrn)
  22. print ("finished")
  23. #remove all objects
  24. pybullet.resetSimulation()
  25. #disconnect from the physics server
  26. pybullet.disconnect()