在pybullet中查看URDF模型质心


对于在pybullet中可视化查看机器人连杆的质心位置的python脚本show_CM_for_urdf.py代码如下:
 1 #!/usr/bin/env python
 2 ######################################################################
 3 # @author : zhou 
 4 # @file : test
 5 # @created : Tuesday Feb 25, 2020 20:08:08 CST
 6 #
 7 # @description : 
 8 ######################################################################
 9 
10 import pybullet as p
11 import sys
12 import pybullet_data
13 import numpy as np
14 import time
15 
16 if __name__ == '__main__':
17     if len(sys.argv) < 2:
18         print("should input a urdf name, a format like */*/*.urdf")
19         sys.exit(0)
20     urdf_file_name = sys.argv[1]
21 
22 physicsClient = p.connect(p.GUI)#or p.GUI for non-graphical version
23 p.setAdditionalSearchPath(pybullet_data.getDataPath()) #optionally
24 ##-------initial setting ---------
25 
26 p.setGravity(0,0,0)
27 planeId = p.loadURDF("plane.urdf")
28 cubeStartPos = [0,0,0.2]
29 cubeStartOrientation = p.getQuaternionFromEuler([0,0,0])
30 boxId = p.loadURDF(urdf_file_name,cubeStartPos, cubeStartOrientation)
31 
32 num_joint = p.getNumJoints(boxId)
33 
34 link_pos = np.zeros((num_joint + 1,3))
35 obj_list = np.zeros(num_joint + 1)
36 
37 # initial state setting of the joint 
38 
39 
40 for j in range(num_joint):
41     p.resetJointState(boxId, j, targetValue=0.0, targetVelocity=0.0)
42 
43 for i in range (1):
44     p.stepSimulation()
45     state_base = p.getBasePositionAndOrientation(boxId)
46     link_pos[0,:] = state_base[0][:3]
47     obj_list[0] = p.loadURDF("sphere_1cm.urdf", link_pos[0,:], useMaximalCoordinates=True)
48     for m in np.arange(num_joint): 
49         link_pos[m+1,:] = p.getLinkState(boxId,m)[0][:3]
50         obj_list[m+1] = p.loadURDF("sphere_1cm.urdf", link_pos[m+1,:], useMaximalCoordinates=True)
51     for im in np.arange(-1,num_joint):
52        p.changeVisualShape(boxId, im, rgbaColor=[0.5, 0.5, 0.5, 0.2])   
53     time.sleep(1000000)
54 
55 p.disconnect()

 



在linux终端运行命令
 python3 show_CM_for_urdf.py "../simple_robot.urdf" 
 
 
 
 
效果如下:.

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM