Skip to content

Commit 9552997

Browse files
Making progress on the lab...
1 parent 6e4f598 commit 9552997

3 files changed

Lines changed: 209 additions & 22 deletions

File tree

‎Week_8_matrices/.OTTER_LOG‎

36 KB
Binary file not shown.

‎Week_8_matrices/Lab_8_matrices_kinematics.ipynb‎

Lines changed: 177 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"metadata": {
77
"deletable": false,
88
"editable": false
@@ -74,7 +74,7 @@
7474
},
7575
{
7676
"cell_type": "code",
77-
"execution_count": null,
77+
"execution_count": 2,
7878
"metadata": {},
7979
"outputs": [],
8080
"source": [
@@ -88,7 +88,7 @@
8888
},
8989
{
9090
"cell_type": "code",
91-
"execution_count": null,
91+
"execution_count": 3,
9292
"metadata": {},
9393
"outputs": [],
9494
"source": [
@@ -99,7 +99,7 @@
9999
},
100100
{
101101
"cell_type": "code",
102-
"execution_count": null,
102+
"execution_count": 4,
103103
"metadata": {},
104104
"outputs": [],
105105
"source": [
@@ -126,7 +126,7 @@
126126
},
127127
{
128128
"cell_type": "code",
129-
"execution_count": null,
129+
"execution_count": 5,
130130
"metadata": {
131131
"tags": [
132132
"otter_answer_cell"
@@ -144,12 +144,26 @@
144144
},
145145
{
146146
"cell_type": "code",
147-
"execution_count": null,
147+
"execution_count": 6,
148148
"metadata": {
149149
"deletable": false,
150150
"editable": false
151151
},
152-
"outputs": [],
152+
"outputs": [
153+
{
154+
"data": {
155+
"text/html": [
156+
"<p><strong><pre style='display: inline;'>square_points</pre></strong> passed! 🌈</p>"
157+
],
158+
"text/plain": [
159+
"square_points results: All test cases passed!"
160+
]
161+
},
162+
"execution_count": 6,
163+
"metadata": {},
164+
"output_type": "execute_result"
165+
}
166+
],
153167
"source": [
154168
"grader.check(\"square_points\")"
155169
]
@@ -179,7 +193,7 @@
179193
},
180194
{
181195
"cell_type": "code",
182-
"execution_count": null,
196+
"execution_count": 7,
183197
"metadata": {
184198
"tags": [
185199
"otter_answer_cell"
@@ -207,7 +221,7 @@
207221
},
208222
{
209223
"cell_type": "code",
210-
"execution_count": null,
224+
"execution_count": 8,
211225
"metadata": {
212226
"tags": [
213227
"otter_answer_cell"
@@ -224,13 +238,46 @@
224238
},
225239
{
226240
"cell_type": "code",
227-
"execution_count": null,
241+
"execution_count": 9,
228242
"metadata": {
229243
"tags": [
230244
"otter_answer_cell"
231245
]
232246
},
233-
"outputs": [],
247+
"outputs": [
248+
{
249+
"name": "stdout",
250+
"output_type": "stream",
251+
"text": [
252+
"Class name: check_name, color: Grey\n",
253+
"Key: shape_to_use, Value: wedge\n",
254+
"Key: link_length, Value: 2.0\n",
255+
"Key: link_width, Value: 2.0\n",
256+
"Key: og_size, Value: 2.0\n",
257+
"Key: length_ratio, Value: 1.0\n",
258+
"Key: width_ratio, Value: 1.0\n",
259+
"Key: current_angle, Value: 0.0\n",
260+
"Key: rotate_angle, Value: 0.0\n",
261+
"Key: pts, Value:\n",
262+
"[[-1.000000 1.000000 0.800000 -0.800000 -1.000000]\n",
263+
" [-1.000000 -1.000000 1.000000 1.000000 -1.000000]\n",
264+
" [1.000000 1.000000 1.000000 1.000000 1.000000]]\n",
265+
"Key: mat_resize_shape, Value:\n",
266+
"[[1.000000 0.000000 0.000000]\n",
267+
" [0.000000 1.000000 0.000000]\n",
268+
" [0.000000 0.000000 1.000000]]\n",
269+
"Key: mat_rotate, Value:\n",
270+
"[[1.000000 0.000000 0.000000]\n",
271+
" [0.000000 1.000000 0.000000]\n",
272+
" [0.000000 0.000000 1.000000]]\n",
273+
"Key: mat_translate_shape, Value:\n",
274+
"[[1.000000 0.000000 1.000000]\n",
275+
" [0.000000 1.000000 0.000000]\n",
276+
" [0.000000 0.000000 1.000000]]\n",
277+
"\n"
278+
]
279+
}
280+
],
234281
"source": [
235282
"# I set up a convert-the-class-to-a-string method for you, which you can use to print out the class in a sort-of readable form\n",
236283
"# See the str method in the class\n",
@@ -239,13 +286,24 @@
239286
},
240287
{
241288
"cell_type": "code",
242-
"execution_count": null,
289+
"execution_count": 10,
243290
"metadata": {
244291
"tags": [
245292
"otter_answer_cell"
246293
]
247294
},
248-
"outputs": [],
295+
"outputs": [
296+
{
297+
"data": {
298+
"text/plain": [
299+
"Ellipsis"
300+
]
301+
},
302+
"execution_count": 10,
303+
"metadata": {},
304+
"output_type": "execute_result"
305+
}
306+
],
249307
"source": [
250308
"# GUIDES: P2: Now set band_name to be your favorite band name HERE, by doing \n",
251309
"# arm_component_blank.band_name = \"band name\"\n",
@@ -258,26 +316,113 @@
258316
},
259317
{
260318
"cell_type": "code",
261-
"execution_count": null,
319+
"execution_count": 11,
262320
"metadata": {
263321
"tags": [
264322
"otter_answer_cell"
265323
]
266324
},
267-
"outputs": [],
325+
"outputs": [
326+
{
327+
"name": "stdout",
328+
"output_type": "stream",
329+
"text": [
330+
"Class name: check_name, color: Grey\n",
331+
"Key: shape_to_use, Value: wedge\n",
332+
"Key: link_length, Value: 2.0\n",
333+
"Key: link_width, Value: 2.0\n",
334+
"Key: og_size, Value: 2.0\n",
335+
"Key: length_ratio, Value: 1.0\n",
336+
"Key: width_ratio, Value: 1.0\n",
337+
"Key: current_angle, Value: 0.0\n",
338+
"Key: rotate_angle, Value: 0.0\n",
339+
"Key: pts, Value:\n",
340+
"[[-1.000000 1.000000 0.800000 -0.800000 -1.000000]\n",
341+
" [-1.000000 -1.000000 1.000000 1.000000 -1.000000]\n",
342+
" [1.000000 1.000000 1.000000 1.000000 1.000000]]\n",
343+
"Key: mat_resize_shape, Value:\n",
344+
"[[1.000000 0.000000 0.000000]\n",
345+
" [0.000000 1.000000 0.000000]\n",
346+
" [0.000000 0.000000 1.000000]]\n",
347+
"Key: mat_rotate, Value:\n",
348+
"[[1.000000 0.000000 0.000000]\n",
349+
" [0.000000 1.000000 0.000000]\n",
350+
" [0.000000 0.000000 1.000000]]\n",
351+
"Key: mat_translate_shape, Value:\n",
352+
"[[1.000000 0.000000 1.000000]\n",
353+
" [0.000000 1.000000 0.000000]\n",
354+
" [0.000000 0.000000 1.000000]]\n",
355+
"Key: band_name, Value: \n",
356+
"\n"
357+
]
358+
}
359+
],
268360
"source": [
269361
"# GUIDES: P3: When you print this time, band_name should be set to your favorite band \n",
270362
"print(arm_component_blank)"
271363
]
272364
},
273365
{
274366
"cell_type": "code",
275-
"execution_count": null,
367+
"execution_count": 12,
276368
"metadata": {
277369
"deletable": false,
278370
"editable": false
279371
},
280-
"outputs": [],
372+
"outputs": [
373+
{
374+
"data": {
375+
"text/html": [
376+
"<p><strong style='color: red;'><pre style='display: inline;'>init_method</pre> results:</strong></p><p><strong><pre style='display: inline;'>init_method - 1</pre> result:</strong></p><pre> ✅ Test case passed</pre><p><strong><pre style='display: inline;'>init_method - 2</pre> result:</strong></p><pre> ✅ Test case passed</pre><p><strong><pre style='display: inline;'>init_method - 3</pre> result:</strong></p><pre> ❌ Test case failed\n",
377+
" Trying:\n",
378+
" assert arm_component_blank.band_name != ''\n",
379+
" Expecting nothing\n",
380+
" **********************************************************************\n",
381+
" Line 1, in init_method 2\n",
382+
" Failed example:\n",
383+
" assert arm_component_blank.band_name != ''\n",
384+
" Exception raised:\n",
385+
" Traceback (most recent call last):\n",
386+
" File \"C:\\Users\\JPizzle\\AppData\\Roaming\\uv\\python\\cpython-3.12.7-windows-x86_64-none\\Lib\\doctest.py\", line 1368, in __run\n",
387+
" exec(compile(example.source, filename, \"single\",\n",
388+
" File \"<doctest init_method 2[0]>\", line 1, in <module>\n",
389+
" assert arm_component_blank.band_name != ''\n",
390+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
391+
" AssertionError\n",
392+
"</pre>"
393+
],
394+
"text/plain": [
395+
"init_method results:\n",
396+
" init_method - 1 result:\n",
397+
" ✅ Test case passed\n",
398+
"\n",
399+
" init_method - 2 result:\n",
400+
" ✅ Test case passed\n",
401+
"\n",
402+
" init_method - 3 result:\n",
403+
" ❌ Test case failed\n",
404+
" Trying:\n",
405+
" assert arm_component_blank.band_name != ''\n",
406+
" Expecting nothing\n",
407+
" **********************************************************************\n",
408+
" Line 1, in init_method 2\n",
409+
" Failed example:\n",
410+
" assert arm_component_blank.band_name != ''\n",
411+
" Exception raised:\n",
412+
" Traceback (most recent call last):\n",
413+
" File \"C:\\Users\\JPizzle\\AppData\\Roaming\\uv\\python\\cpython-3.12.7-windows-x86_64-none\\Lib\\doctest.py\", line 1368, in __run\n",
414+
" exec(compile(example.source, filename, \"single\",\n",
415+
" File \"<doctest init_method 2[0]>\", line 1, in <module>\n",
416+
" assert arm_component_blank.band_name != ''\n",
417+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
418+
" AssertionError"
419+
]
420+
},
421+
"execution_count": 12,
422+
"metadata": {},
423+
"output_type": "execute_result"
424+
}
425+
],
281426
"source": [
282427
"grader.check(\"init_method\")"
283428
]
@@ -307,7 +452,19 @@
307452
"otter_answer_cell"
308453
]
309454
},
310-
"outputs": [],
455+
"outputs": [
456+
{
457+
"ename": "AssertionError",
458+
"evalue": "",
459+
"output_type": "error",
460+
"traceback": [
461+
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
462+
"\u001b[31mAssertionError\u001b[39m Traceback (most recent call last)",
463+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[49]\u001b[39m\u001b[32m, line 18\u001b[39m\n\u001b[32m 14\u001b[39m \u001b[38;5;66;03m# to this one - we will be changing base sizes later\u001b[39;00m\n\u001b[32m 15\u001b[39m mat_base_check = np.array([[\u001b[32m0.5\u001b[39m, \u001b[32m0.0\u001b[39m, \u001b[32m0\u001b[39m], [\u001b[32m0.0\u001b[39m, \u001b[32m0.25\u001b[39m, \u001b[32m0.25\u001b[39m], [\u001b[32m0.0\u001b[39m, \u001b[32m0.0\u001b[39m, \u001b[32m1.0\u001b[39m]])\n\u001b[32m 16\u001b[39m \n\u001b[32m 17\u001b[39m \u001b[38;5;66;03m# Once this passes, copy the code into set_to_base_shape in arm component\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m18\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m np.all(np.isclose(mat_my_base, mat_base_check))\n",
464+
"\u001b[31mAssertionError\u001b[39m: "
465+
]
466+
}
467+
],
311468
"source": [
312469
"# The size of the base \n",
313470
"base_width = 1.0\n",
@@ -779,7 +936,7 @@
779936
],
780937
"metadata": {
781938
"kernelspec": {
782-
"display_name": "base",
939+
"display_name": "jpintropythonprogramming",
783940
"language": "python",
784941
"name": "python3"
785942
},
@@ -793,7 +950,7 @@
793950
"name": "python",
794951
"nbconvert_exporter": "python",
795952
"pygments_lexer": "ipython3",
796-
"version": "3.12.4"
953+
"version": "3.12.7"
797954
},
798955
"otter": {
799956
"OK_FORMAT": true,

‎Week_8_matrices/arm_component.py‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def __init__(self, name, color="Grey", shape_to_use="square"):
3333
# stored in the class
3434
self.name = name
3535
self.color = color
36+
self.shape_to_use = shape_to_use
37+
self.link_length = 2.0
38+
self.link_width = 2.0
39+
self.og_size = 2.0
40+
self.length_ratio = self.link_length / self.og_size
41+
self.width_ratio = self.link_width / self.og_size
42+
self.current_angle = 0.0
43+
self.rotate_angle = 0.0
3644

3745
# Points - one of the nice things about using a class is you can do some "fancy" initialization. In
3846
# this case we're going to duplicate the last point in pts and make sure we have a 3xn+1 matrix
@@ -62,6 +70,24 @@ def __init__(self, name, color="Grey", shape_to_use="square"):
6270
# GUIDES Step 2: Make sure you change get_shape_matrix and get_pose_matrix to return the matrices you create
6371
# YOUR CODE HERE
6472

73+
# mat_resize_shape
74+
self.mat_resize_shape = np.identity(3)
75+
scale_matrix = mt.make_scale_matrix(self.length_ratio, self.width_ratio)
76+
77+
self.mat_resize_shape = scale_matrix @ self.mat_resize_shape
78+
79+
# mat_rotate
80+
self.mat_rotate = np.identity(3)
81+
rotation_matrix = mt.make_rotation_matrix(np.deg2rad(self.current_angle + self.rotate_angle))
82+
83+
self.mat_rotate = rotation_matrix @ self.mat_rotate
84+
85+
# mat_translation_shape
86+
self.mat_translate_shape = np.identity(3)
87+
translation_matrix = mt.make_translation_matrix(self.length_ratio * self.og_size / 2, 0)
88+
89+
self.mat_translate_shape = translation_matrix @ self.mat_translate_shape
90+
6591

6692
# Using the staticmethod decorator like this means that this method does not
6793
# have/need a self pointer (notice no self)
@@ -83,18 +109,22 @@ def points_in_a_square():
83109
# Add a return statement at the end
84110
# If you're confused, look at points_in_a_wedge, above
85111
# YOUR CODE HERE
112+
pts_square = np.ones((3, 4))
113+
pts_square[0, :] = [-1, 1, 1, -1]
114+
pts_square[1, :] = [-1, -1, 1, 1]
115+
return pts_square
86116

87117
def get_shape_matrix(self):
88118
""" Return the shape matrix"""
89119
# YOUR CODE HERE
90120
# GUIDES STEP 2: Change this to return your shape matrix
91-
return ...
121+
return self.mat_resize_shape
92122

93123
def get_pose_matrix(self):
94124
""" Return the pose matrix"""
95125
# YOUR CODE HERE
96126
# GUIDES STEP 2: Change this to return your pose matrix
97-
return ...
127+
return self.mat_rotate @ self.mat_resize_shape
98128

99129
def set_to_base_shape(self, base_width=1.0, base_height=0.5):
100130
""" Position and orient the base of the arm (the wedge-shape at the bottom)

0 commit comments

Comments
 (0)