Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit c5702de

Browse files
author
Nicholas Nadeau
committed
formatted
1 parent daade05 commit c5702de

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

examples/trajectory_generation.ipynb

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,22 @@
3535
"import matplotlib.pyplot as plt\n",
3636
"from mpl_toolkits.mplot3d import Axes3D\n",
3737
"\n",
38+
"\n",
3839
"def plot_poses(p):\n",
3940
" fig = plt.figure()\n",
4041
" 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",
4243
"\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",
4647
"\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",
5051
"\n",
51-
" plt.locator_params(nbins=4);\n",
52-
" plt.tight_layout();"
52+
" plt.locator_params(nbins=4)\n",
53+
" plt.tight_layout()"
5354
]
5455
},
5556
{
@@ -60,11 +61,12 @@
6061
"source": [
6162
"def compute_deviation(p):\n",
6263
" # 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",
6667
"\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",
6870
"\n",
6971
" print(f'Deviation: {deviation:.5f}mm')"
7072
]
@@ -82,8 +84,8 @@
8284
"metadata": {},
8385
"outputs": [],
8486
"source": [
85-
"from pybotics.robot import Robot\n",
8687
"from pybotics.predefined_models import ur10\n",
88+
"from pybotics.robot import Robot\n",
8789
"\n",
8890
"robot = Robot.from_parameters(ur10())"
8991
]
@@ -109,8 +111,12 @@
109111
"from pybotics.geometry import vector_2_matrix\n",
110112
"\n",
111113
"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",
114120
"])\n",
115121
"\n",
116122
"start_end_joints = [robot.ik(p) for p in poses]"
@@ -160,10 +166,10 @@
160166
"# compute joint-space midpoint\n",
161167
"joints = [robot.ik(p, q=start_end_joints[0]) for p in poses]\n",
162168
"\n",
163-
"mid_joints = np.mean(joints,axis=0)\n",
169+
"mid_joints = np.mean(joints, axis=0)\n",
164170
"mid_pose = robot.fk(mid_joints)\n",
165171
"\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)"
167173
]
168174
},
169175
{
@@ -214,12 +220,12 @@
214220
"outputs": [],
215221
"source": [
216222
"# 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",
218224
"\n",
219225
"mid_pose = poses[0].copy()\n",
220-
"mid_pose[:-1,-1] = mid_cartesian_point\n",
226+
"mid_pose[:-1, -1] = mid_cartesian_point\n",
221227
"\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)"
223229
]
224230
},
225231
{
@@ -260,18 +266,24 @@
260266
],
261267
"source": [
262268
"# 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",
264270
"\n",
265271
"# 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",
267273
"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",
269278
"compute_deviation(first_segmented_poses)\n",
270279
"\n",
271280
"# 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",
273282
"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",
275287
"compute_deviation(second_segmented_poses)"
276288
]
277289
}

0 commit comments

Comments
 (0)