我正在尝试模拟机器人到达气泡。目标是将其导出到 CAD 文件中并可视化可能的工作空间。我的方法是使用机器人的正向运动学绘制所有潜在的端点,考虑连杆长度和关节限制。这可能是生成端点(Rx、Ry、Rz)的蛮力方式,但结果非常准确(至少对于 2D 示例)。[此图显示了为 IRB 机器人提供的工作空间以及我在 2D 中绘制点时的结果][1]
[1]:https://i.stack.imgur.com/g3cP7.jpg
我可以将气泡的三维图形显示为散点图;但是,要将其导出为 CAD 文件,我需要先对其进行网格化,据我所知,这需要将其转换为表面。这是我遇到麻烦的部分。
使用 matplotlib 的 ax.surface_plot(Rx, Ry, Rz) 我收到一条错误消息,指出 Rz 必须是二维值。我摆弄了 np.meshgrid() 和 np.mgrid() 函数,但无法创建一个简单的气泡表面。我该怎么做才能将此散点图转换为曲面?我还缺少另一种方法吗?
我突然想到的另一件事是,我可能想要删除到达气泡内的一些中间点。理想情况下,表面将由外端和中心半径的空心点组成。
下面是产生一维数组的代码:
# Reach bubble 3D
import NumPy as np
import matplotlib.pyplot as plt
# Initialize figure and label axes
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
dr = np.pi/180 # Degree to radian multiple
pi = np.pi
# Define important robot dimensions and axis limits for IRB 1100
z0 = 0.327 # Fixed height from base to A1
link1 = 0.28
link2 = 0.3
a1 = np.linspace(0, 2*pi, 8) # Angle limits for axes
a2 = np.linspace(-115*dr, 113*dr, 12)
a3 = np.linspace(-205*dr, 55*dr, 12)
Rx = []
Ry = []
Rz = []
for i1 in a1:
for i2 in a2:
for i3 in a3:
r = link1*np.sin(i2) + link2*np.sin(pi/2+i2+i3)
Rx.append(r*np.cos(i1))
Ry.append(r*np.sin(i1))
Rz.append(z0 + link1*np.cos(i2) + link2*np.cos(pi/2+i2+i3))
# Plot reach points
ax.scatter(Rx, Ry, Rz, c='r', marker='o', alpha = 0.2)
plt.show()
下面是生成 3D 数组但不使用 for 循环的代码:
# 3D Reach bubble for robot
import numpy as np
import matplotlib.pyplot as plt
# Initialize figure and label axes
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
pi = np.pi
dr = pi/180 # Degree to radian multiple
# Define important robot dimensions and axis limits for GP8
z0 = 0.327 # Fixed height from base to A1
link1 = 0.28
link2 = 0.3
link3 = 0.064
a1, a2, a3 = np.mgrid[0:2*pi:15j, -115*dr:113*dr:13j, -205*dr:55*dr:17j]
r = link1*np.sin(a2) + link2*np.sin(pi/2+a2+a3)
Rx = r*np.cos(a1)
Ry = r*np.sin(a1)
Rz = z0 + link1*np.cos(a2) + link2*np.cos(pi/2+a2+a3)
# Plot reach points
ax.plot_surface(Rx, Ry, Rz, color = 'Red', alpha = 0.2)
ax.scatter(Rx, Ry, Rz, c='r', marker='o', alpha = 0.2)