Assignment1 3
Assignment1 3
Assignment 1
(100 pts is the perfect score - 10% of the course credit)
Submission Process: You are asked to upload a zip file on Canvas containing all necessary files
of your submission. Only 1 student per team needs to upload a submission.
You should create a top-level folder named with your NETID, (e.g., xyz007-abc001 for teams of
2 students or just xyz007 for students working independently). Include at least the following files
by following this folder structure:
• xyz007-abc001/create_scene.py (p1)
• xyz007-abc001/collision_checking.py (p2)
• xyz007-abc001/2d_rigid_body.py (p3)
• xyz007-abc001/2d_rigid_body_animation.gif/mp4 (p3)
• xyz007-abc001/planar_arm.py (p4)
• xyz007-abc001/planar_arm_animation.gif/mp4 (p4)
• xyz007-abc001/report.pdf
Please zip this xyz007-abc001 folder and submit the xyz007-abc001.zip on Canvas. You can also
create a utils.py file that contains helper functions under the xyz007-abc001 folder.
On the first page of the report’s PDF indicate the name and Net ID of the students in the team
(up to 2 students).
Extra Credit for LATEX: You will receive 6% extra credit points if you submit your answers as a
typeset PDF, i.e., one generated using LaTeX. For typeset reports in LaTeX, please also submit your
.tex source file together with the report, e.g., by adding a report.tex file under the xyz007-abc001
folder. There will be a 3% bonus for electronically prepared answers (e.g., using MS Word, etc.)
that are not typeset. Remember that these bonuses are computed as a percentage of your original
grade, i.e., if you were to receive 50 points and you have typeset your report using LaTeX, then
you get a 3-point bonus. If you want to submit a handwritten report, scan it or take photos of it
and submit the corresponding PDF as part of the zip file on Canvas. You will not receive any bonus
in this case. For your reports, do not submit Word documents, raw ASCII text files, or hardcopies
etc. If you choose to submit scanned handwritten answers and we cannot read them, you will not
be awarded any points for the unreadable part of the solution.
Failure to follow the above rules may result in a lower grade on the assignment.
Requirements: Standard Python libraries are allowed. Additionally, Numpy, Scipy and Matplotlib
can be used. Please use the following script to build your Python environment under conda.
• Sample uniformly at random coordinates (center , ycenter ), which will correspond to the center
of the polygon.
• Sample the number N of vertices of the polygon by uniformly sampling in the range
[Nmn , Nm ].
• For each vertex n of the N vertices, sample uniformly at random an angle αn in the range of
[0, . . . , 360] degrees. Then, generate the coordinates of the N vertices by placing them on a
circle centered at (center , ycenter ) with radius rmn and at the angle αn .
• For each vertex, also uniformly sample a number r in the range [0, rm − rmn ]. Extrude each
vertex outward from the center (center , ycenter ) by moving it away by the value r.
• For each vertex, use the sign of the cross product between each pair of adjacent vertices and
the origin to determine convexity. If a vertex makes your polygon non-convex, then remove
it. Iterate over all of your vertices until the polygon is convex or you are down to 3 vertices,
where convexity is guaranteed.
• Alternatively for the last step you could also compute the convex hull of the N sampled
vertices by using the "convexHull" function from scipy (scipy.spatial.ConvexHull).
Consider that your polygonal map is defined in a continuous space of dimensions 2m × 2m, i.e.,
the coordinates of the vertices should be represented in this continuous space. You should be able
to visualize the corresponding map. For this you will have to pick a resolution and select the size
of your visualization, e.g., 800pixels x 800pixels that will represent the 2m × 2m polygonal map.
Polygons can be represented using numpy arrays, which will allow you to store the vertices of
the polygons. You should then be able to store the corresponding files as well as load them.
In your report provide the following:
• 4 examples of maps that you have generated and the corresponding parameters you used
for the generation of these maps. Use different parameters for the 4 different maps and
discuss the choice of your parameters in the resulting environments you generated, i.e., try
to generate some maps that are dense with obstacles and some that are sparse.
• A visualization of one additional map, which you have manually constructed, where you use
convex polygons to form two letters inside the space. These two letters should correspond to
the first letter of the first name of each team member (or the first letters of the first and last
name for students working individually). You do not have to spend much time here to make
the letters accurately represented and the convex polygons perfectly aligned. As long as the
letters are recognizable when visualized, this is sufficient. See example Fig. 1 for letter “E”.
• Describe the exact approach you followed in order to generate the convex polygons. If you
followed the above mentioned strategy describe the operations you performed so as to i)
rotate each polygon, ii) extrude vertices and iii) how you determine/enforce the convexity of
each polygon. If you deviated from the above strategy indicate so and explain your choices.
• Load a map (2 × 2m2 ) using the following code inside your software:
polygons = np.load(’2d_rigid_body.npy’, allow_pickle=True)
You can test different scenes by renaming them as "2d_rigid_body.npy" (the TAs will use
a different scene other than the one shown in Fig. 3). Create a rectangular polygon (with
dimensions: 0.2 × 0.1m2 ) as a 2D rigid body and initialize it in a random collision-free position
and orientation. Treat the boundary of the 2m × 2m region as obstacles.
• Use the keyboard to control the rectangle: (i) forward/backward motion along the long axis
of the rectangle, and (ii) clockwise and counterclockwise rotation about the center. Include
in the report which 4 keys you have assigned to the corresponding control (e.g., up/down,
left/right arrows).
• Make use of your collision checking code from the previous step so as to avoid the rectan-
gular object penetrating the convex polygonal obstacles. In particular, every time that the
keyboard command would result in a motion that leads to a collision, the rectangle should
be returned to its previous collision-free position and orientation. The example video didn’t
have the “avoid penetrating” function but gives a general example of when collision will be
detected.
• Generate animations on your maps that show that you can move the rectangle from a random
collision-free configuration to another collision-free part of the scene using keyboard control
in a collision-free manner. Save your animations in .gif or .mp4 format (you can use an
external recording tool, keep file size less than 1MB, for example, ScreenToGif).
• Compute and visualize the collision-free configuration space of the rectangular object for the
5 different scenes you generated in part 1 of this assignment. Fig. 3 (right) provides an
example of this computation for the scene shown in Fig. 3 (left). Do so for three different
orientations of the rectangle, 0o as shown in Fig. 3, 45o and 90o . Use for computation the
Minkowski sum operation. Include the corresponding visualizations in your report.
Figure 3: Rectangular object collision-free example. You don’t need to draw the rectangle object
in the right figure; this is just to illustrate that obstacles have been “expanded” based on the
rectangle.
• You should be able to load your polygonal scenes and create an arm with two rectangular
polygons and two joints inside them. The length between joint 1 and joint 2 should be 0.4m,
and the length between joint 1 and joint 2 should be 0.25m. The width of the rectangles
should be 0.1m. The joints correspond to circles of radius 0.05m. The first joint is fixed at
coordinates [1,1]. Initialize your arm so that both joint angles are at 0 degrees, i.e., the arm
points to the right. At this configuration detect all of the polygons that the arm is colliding
with and remove them from the scene. Plot the rest of the convex polygons and the arm
using matplotlib. The links should touch the joints, see Figure 4 for an example. Provide
visualizations of the corresponding scenes in your report.
• Use the keyboard to control the two joints individually (you can achieve unlimited rotation
with each joint). Indicate in your report what keys you used in order to control the arm.
• Make use of your collision checking code from step 2 of the assignment so as to avoid the
robotic arm penetrating the convex polygonal obstacles remaining in the scene. In particular,
every time that the keyboard command would result in a motion that leads to a collision, the
arm should be returned to its previous collision-free position and orientation. The example
video didn’t have the “avoid penetrating” function but gives a general example of when a
collision will be detected, and the workspace in this example is different from this assignment.
• Generate animations on your maps that show that you can move the planar arm from the
initial collision-free configuration to other collision-free configuration using keyboard control
in a collision-free manner. Save your animations in .gif or .mp4 format (you can use an
external recording tool, keep file size less than 1MB, for example, ScreenToGif).
• Compute and visualize the collision-free configuration space for the planar arm by discretizing
each joint angle with a resolution of 2π/ 100 in the range of [−π, π]. See Fig. 4 (right) for an
example. A 100x100 occupancy grid is generated where each cell corresponds to values
for the two joint angles. The x-axis is the first joint angle and the y-axis is the second one.
The yellow color corresponds to collisions with polygonal obstacles in the scene. You do not
need to consider self-collision of arm for this part of the assignment. For this plot, please use
provided map:
polygons = np.load(’arm_polygons.npy’, allow_pickle=True)