当前位置:网站首页>Pybullet robot simulation environment construction 5 Robot pose visualization
Pybullet robot simulation environment construction 5 Robot pose visualization
2022-06-26 16:16:00 【RuiH. AI】
pybullet Robot simulation environment construction 5. Robot pose visualization
Preface
This article records how to pybullet Visualization of robot pose in .
Draw lines in the simulation environment
pybullet Provides a way to add dotted line text in the simulation environment api, such as addUserDebugLine, addUserDebugPoints etc. , And return these dotted lines id, It can be used for subsequent deletion and modification .
Here I write a function that draws the coordinate system of an object , To visualize pose , The code should be easy to understand :
def draw_pose_in_pybullet(*pose):
""" *Draw pose frame in pybullet* :param pose: np.ndarray, shape=[4, 4] or tuple of (position, orientation) """
if len(pose) == 1:
position = pose[0][:3, 3]
rotation = pose[0][:3, :3]
else:
position, orientation = pose
print(orientation)
rotation = np.array(p.getMatrixFromQuaternion(orientation)).reshape([3, 3])
print(rotation)
start_point = position
end_point_x = position + rotation[:, 0] * 2
end_point_y = position + rotation[:, 1] * 2
end_point_z = position + rotation[:, 2] * 2
p.addUserDebugLine(start_point, end_point_x, [1, 0, 0])
p.addUserDebugLine(start_point, end_point_y, [0, 1, 0])
p.addUserDebugLine(start_point, end_point_z, [0, 0, 1])
Code routines
Compare the above function with the previous one pybullet Blog combination of environment , Give the current pose of the robot :
import time
import numpy as np
import pybullet
import pybullet_data
def draw_pose_in_pybullet(*pose):
""" *Draw pose frame in pybullet* :param pose: np.ndarray, shape=[4, 4] or tuple of (position, orientation) """
if len(pose) == 1:
position = pose[0][:3, 3]
rotation = pose[0][:3, :3]
else:
position, orientation = pose
print(orientation)
rotation = np.array(pybullet.getMatrixFromQuaternion(orientation)).reshape([3, 3])
print(rotation)
start_point = position
end_point_x = position + rotation[:, 0] * 2
end_point_y = position + rotation[:, 1] * 2
end_point_z = position + rotation[:, 2] * 2
pybullet.addUserDebugLine(start_point, end_point_x, [1, 0, 0])
pybullet.addUserDebugLine(start_point, end_point_y, [0, 1, 0])
pybullet.addUserDebugLine(start_point, end_point_z, [0, 0, 1])
if __name__ == '__main__':
client = pybullet.connect(pybullet.GUI)
pybullet.setAdditionalSearchPath(pybullet_data.getDataPath())
pybullet.setPhysicsEngineParameter(numSolverIterations=10)
pybullet.configureDebugVisualizer(pybullet.COV_ENABLE_RENDERING, 0)
pybullet.configureDebugVisualizer(pybullet.COV_ENABLE_GUI, 0)
pybullet.configureDebugVisualizer(pybullet.COV_ENABLE_TINY_RENDERER, 0)
pybullet.setGravity(0, 0, -9.8)
# pybullet.setRealTimeSimulation(1)
shift = [0, 0, 0]
scale = [1, 1, 1]
visual_shape_id = pybullet.createVisualShape(
shapeType=pybullet.GEOM_MESH,
fileName="sphere_smooth.obj",
rgbaColor=[1, 1, 1, 1],
specularColor=[0.4, 0.4, 0],
visualFramePosition=[0, 0, 0],
meshScale=scale)
collision_shape_id = pybullet.createCollisionShape(
shapeType=pybullet.GEOM_MESH,
fileName="sphere_smooth.obj",
collisionFramePosition=[0, 0, 0],
meshScale=scale)
pybullet.createMultiBody(
baseMass=1,
baseCollisionShapeIndex=collision_shape_id,
baseVisualShapeIndex=visual_shape_id,
basePosition=[-2, -1, 1],
useMaximalCoordinates=True)
plane_id = pybullet.loadURDF("plane100.urdf", useMaximalCoordinates=True)
cube_ind = pybullet.loadURDF('cube.urdf', (3, 1, 1), pybullet.getQuaternionFromEuler([0, 0, 0]))
r_ind = pybullet.loadURDF('r2d2.urdf', (1, 1, 1), pybullet.getQuaternionFromEuler([0, 0, 1.57]))
# End of creation , Turn rendering back on
pybullet.configureDebugVisualizer(pybullet.COV_ENABLE_RENDERING, 1)
num_joints = pybullet.getNumJoints(r_ind)
# Get information about each joint
joint_infos = []
for i in range(num_joints):
joint_info = pybullet.getJointInfo(r_ind, i)
if joint_info[2] != pybullet.JOINT_FIXED:
if 'wheel' in str(joint_info[1]):
print(joint_info)
joint_infos.append(joint_info)
maxforce = 10
velocity = 31.4
while True:
pybullet.removeAllUserDebugItems() # Delete the previous line , Otherwise, it will always appear in the simulation environment
for i in range(len(joint_infos)):
pybullet.setJointMotorControl2(bodyUniqueId=r_ind,
jointIndex=joint_infos[i][0],
controlMode=pybullet.VELOCITY_CONTROL,
targetVelocity=velocity,
force=maxforce)
position, orientation = pybullet.getBasePositionAndOrientation(r_ind)
draw_pose_in_pybullet(position, orientation)
pybullet.stepSimulation()
time.sleep(1./240)
The visualization is as follows :
We need to pay attention to , Drawing and deleting lines will seriously affect pybullet The speed of the engine , Actually, I feel that one card after another .
边栏推荐
- 李飞飞团队将ViT用在机器人身上,规划推理最高提速512倍,还cue了何恺明的MAE...
- R language plotly visualization: Violin graph, multi category variable violin graph, grouped violin graph, split grouped violin graph, two groups of data in each violin graph, each group accounts for
- mha 切换(操作流程建议)
- Redis Guide (8): principle and implementation of Qianfan Jingfa distributed lock
- 【207】Apache崩溃的几个很可能的原因,apache崩溃几个
- What is the difference between stm32f1 and gd32f1?
- pybullet机器人仿真环境搭建 5.机器人位姿可视化
- R language uses cor function to calculate the correlation matrix for correlation analysis, uses corrgram package to visualize the correlation matrix, reorders rows and columns using principal componen
- 10 tf.data
- LeetCode 单周赛298,前三题
猜你喜欢

油田勘探问题
![[Blue Bridge Cup training 100 questions] scratch distinguishing prime numbers and composite numbers Blue Bridge Cup scratch competition special prediction programming question intensive training simul](/img/26/c0c8a406ff4ffe0ae37d277f730bd0.png)
[Blue Bridge Cup training 100 questions] scratch distinguishing prime numbers and composite numbers Blue Bridge Cup scratch competition special prediction programming question intensive training simul

Transformation of zero knowledge QAP problem

2 three modeling methods

Svg canvas canvas drag

Stepn débutant et avancé

牛客编程题--必刷101之动态规划(一文彻底了解动态规划)

【力扣刷题】二分查找:4. 寻找两个正序数组的中位数

11 cnn简介

How to implement interface current limiting?
随机推荐
redis的二进制数组命令
IAR engineering adapts gd32 chip
1-12Vmware新增SSH功能
Comprehensive analysis of discord security issues
手写数字体识别,用保存的模型跑自己的图片
4 custom model training
Redis顺序排序命令
长安链交易防重之布谷鸟过滤器
Cookie和Session详解
【力扣刷题】11.盛最多水的容器//42.接雨水
对话长安马自达高层,全新产品将在Q4发布,空间与智能领跑日系
今年高考英语AI得分134,复旦武大校友这项研究有点意思
Big talk Domain Driven Design -- presentation layer and others
STEPN 新手入门及进阶
(DFS search) acwing 2005 horseshoe
R语言使用cor函数计算相关性矩阵进行相关性分析,使用corrgram包可视化相关性矩阵、行和列使用主成分分析重新排序、下三角形中使用平滑的拟合线和置信椭圆,上三角形中使用散点图、对角线最小值和最大值
9 use of tensorboard
[untitled]
C language reading data
Net基于girdview控件实现删除与编辑行数据