|
35 | 35 | "import matplotlib.pyplot as plt\n",
|
36 | 36 | "from mpl_toolkits.mplot3d import Axes3D\n",
|
37 | 37 | "\n",
|
| 38 | + "\n", |
38 | 39 | "def plot_poses(p):\n",
|
39 | 40 | " fig = plt.figure()\n",
|
40 | 41 | " ax = fig.add_subplot(111, projection='3d')\n",
|
41 |
| - " ax.plot(xs = p[:,0,-1], ys = p[:,1,-1],zs = p[:,2,-1],marker='o');\n", |
| 42 | + " ax.plot(xs=p[:, 0, -1], ys=p[:, 1, -1], zs=p[:, 2, -1], marker='o')\n", |
42 | 43 | "\n",
|
43 |
| - " ax.set_xlabel('X');\n", |
44 |
| - " ax.set_ylabel('Y');\n", |
45 |
| - " ax.set_zlabel('Z');\n", |
| 44 | + " ax.set_xlabel('X')\n", |
| 45 | + " ax.set_ylabel('Y')\n", |
| 46 | + " ax.set_zlabel('Z')\n", |
46 | 47 | "\n",
|
47 |
| - " ax.set_xlim(600,700);\n", |
48 |
| - " ax.set_ylim(-160,-140);\n", |
49 |
| - " ax.set_zlim(750,850);\n", |
| 48 | + " ax.set_xlim(600, 700)\n", |
| 49 | + " ax.set_ylim(-160, -140)\n", |
| 50 | + " ax.set_zlim(750, 850)\n", |
50 | 51 | "\n",
|
51 |
| - " plt.locator_params(nbins=4);\n", |
52 |
| - " plt.tight_layout();" |
| 52 | + " plt.locator_params(nbins=4)\n", |
| 53 | + " plt.tight_layout()" |
53 | 54 | ]
|
54 | 55 | },
|
55 | 56 | {
|
|
60 | 61 | "source": [
|
61 | 62 | "def compute_deviation(p):\n",
|
62 | 63 | " # compute deviation at joint-space midpoint\n",
|
63 |
| - " p1 = p[0,:-1,-1]\n", |
64 |
| - " p2 = p[1,:-1,-1]\n", |
65 |
| - " p3 = p[2,:-1,-1]\n", |
| 64 | + " p1 = p[0, :-1, -1]\n", |
| 65 | + " p2 = p[1, :-1, -1]\n", |
| 66 | + " p3 = p[2, :-1, -1]\n", |
66 | 67 | "\n",
|
67 |
| - " deviation = np.linalg.norm(np.cross(p2-p1, p1-p3))/np.linalg.norm(p2-p1)\n", |
| 68 | + " deviation = np.linalg.norm(np.cross(p2 - p1,\n", |
| 69 | + " p1 - p3)) / np.linalg.norm(p2 - p1)\n", |
68 | 70 | "\n",
|
69 | 71 | " print(f'Deviation: {deviation:.5f}mm')"
|
70 | 72 | ]
|
|
82 | 84 | "metadata": {},
|
83 | 85 | "outputs": [],
|
84 | 86 | "source": [
|
85 |
| - "from pybotics.robot import Robot\n", |
86 | 87 | "from pybotics.predefined_models import ur10\n",
|
| 88 | + "from pybotics.robot import Robot\n", |
87 | 89 | "\n",
|
88 | 90 | "robot = Robot.from_parameters(ur10())"
|
89 | 91 | ]
|
|
109 | 111 | "from pybotics.geometry import vector_2_matrix\n",
|
110 | 112 | "\n",
|
111 | 113 | "poses = np.array([\n",
|
112 |
| - " vector_2_matrix([600,-150,800,np.deg2rad(-90),0,np.deg2rad(-90)]),\n", |
113 |
| - " vector_2_matrix([700,-150,800,np.deg2rad(-90),0,np.deg2rad(-90)])\n", |
| 114 | + " vector_2_matrix([600, -150, 800,\n", |
| 115 | + " np.deg2rad(-90), 0,\n", |
| 116 | + " np.deg2rad(-90)]),\n", |
| 117 | + " vector_2_matrix([700, -150, 800,\n", |
| 118 | + " np.deg2rad(-90), 0,\n", |
| 119 | + " np.deg2rad(-90)])\n", |
114 | 120 | "])\n",
|
115 | 121 | "\n",
|
116 | 122 | "start_end_joints = [robot.ik(p) for p in poses]"
|
|
160 | 166 | "# compute joint-space midpoint\n",
|
161 | 167 | "joints = [robot.ik(p, q=start_end_joints[0]) for p in poses]\n",
|
162 | 168 | "\n",
|
163 |
| - "mid_joints = np.mean(joints,axis=0)\n", |
| 169 | + "mid_joints = np.mean(joints, axis=0)\n", |
164 | 170 | "mid_pose = robot.fk(mid_joints)\n",
|
165 | 171 | "\n",
|
166 |
| - "deviated_poses = np.insert(arr=poses,obj=1,values=mid_pose,axis=0)" |
| 172 | + "deviated_poses = np.insert(arr=poses, obj=1, values=mid_pose, axis=0)" |
167 | 173 | ]
|
168 | 174 | },
|
169 | 175 | {
|
|
214 | 220 | "outputs": [],
|
215 | 221 | "source": [
|
216 | 222 | "# split linear trajectory in half, creating two joint-space segments\n",
|
217 |
| - "mid_cartesian_point = np.mean([poses[1,:-1,-1],poses[0,:-1,-1]],axis=0)\n", |
| 223 | + "mid_cartesian_point = np.mean([poses[1, :-1, -1], poses[0, :-1, -1]], axis=0)\n", |
218 | 224 | "\n",
|
219 | 225 | "mid_pose = poses[0].copy()\n",
|
220 |
| - "mid_pose[:-1,-1] = mid_cartesian_point\n", |
| 226 | + "mid_pose[:-1, -1] = mid_cartesian_point\n", |
221 | 227 | "\n",
|
222 |
| - "segmented_poses = np.insert(arr=poses,obj=1,values=mid_pose,axis=0)" |
| 228 | + "segmented_poses = np.insert(arr=poses, obj=1, values=mid_pose, axis=0)" |
223 | 229 | ]
|
224 | 230 | },
|
225 | 231 | {
|
|
260 | 266 | ],
|
261 | 267 | "source": [
|
262 | 268 | "# compute joints for new trajectory\n",
|
263 |
| - "joints = [robot.ik(p,q=start_end_joints[0]) for p in segmented_poses]\n", |
| 269 | + "joints = [robot.ik(p, q=start_end_joints[0]) for p in segmented_poses]\n", |
264 | 270 | "\n",
|
265 | 271 | "# compute deviation for first segment\n",
|
266 |
| - "mid_joints = np.mean(joints[:2],axis=0)\n", |
| 272 | + "mid_joints = np.mean(joints[:2], axis=0)\n", |
267 | 273 | "first_mid_pose = robot.fk(mid_joints)\n",
|
268 |
| - "first_segmented_poses = np.insert(arr=poses,obj=1,values=first_mid_pose,axis=0)\n", |
| 274 | + "first_segmented_poses = np.insert(arr=poses,\n", |
| 275 | + " obj=1,\n", |
| 276 | + " values=first_mid_pose,\n", |
| 277 | + " axis=0)\n", |
269 | 278 | "compute_deviation(first_segmented_poses)\n",
|
270 | 279 | "\n",
|
271 | 280 | "# compute deviation for second segment\n",
|
272 |
| - "mid_joints = np.mean(joints[1:],axis=0)\n", |
| 281 | + "mid_joints = np.mean(joints[1:], axis=0)\n", |
273 | 282 | "second_mid_pose = robot.fk(mid_joints)\n",
|
274 |
| - "second_segmented_poses = np.insert(arr=poses,obj=1,values=second_mid_pose,axis=0)\n", |
| 283 | + "second_segmented_poses = np.insert(arr=poses,\n", |
| 284 | + " obj=1,\n", |
| 285 | + " values=second_mid_pose,\n", |
| 286 | + " axis=0)\n", |
275 | 287 | "compute_deviation(second_segmented_poses)"
|
276 | 288 | ]
|
277 | 289 | }
|
|
0 commit comments