CS 1112 Project 3, part B due Wed, Mar. 24, 11pm EDT

Part A, specifying problem 1 along with rules and objectives, is in a separate document.

Polar printer uniformity

Diagram of polar 3D printer

In Project 2 you wrote a script to solve for the pivot angle θ of a polar 3D printer that position its nozzle at an angle φ relative to the x-axis. Your script also computed the radial distance s between the nozzle and the center of the turntable. By spinning the turntable and continuously solving for θ with φ set to the current spin angle, a straight line will be printed. However, if the turntable spins at a constant rate, it turns out that the radial velocity of the nozzle ds/dt is not constant, meaning that the line will not be printed with uniform thickness—it will be thinner when the radial velocity is faster, and it will be thicker when the radial velocity is slower. In this problem, you will investigate the sensitivity of line uniformity to turntable velocity profiles.

Script to function

To perform this analysis, you will need to compute the radial position s of the nozzle for many different turntable angles φ. It would be convenient to be able to evaluate s as a function of φ. To that end, convert your script from Project 2 into a user-defined function armPivot() with the following specification:

function [theta, s] = armPivot(phi, r, dTheta)
% Solve for pivot angle `theta` to position printer nozzle at angle `phi`.
% Solution tolerance is `dTheta`; `phi`, `dTheta`, and `theta` are all measured
% in degrees.  Turntable has radius `r` (equal to arm length).  Also return
% radial distance to nozzle `s` (same units as `r`).

Copy the function header and the entire function comment given above into your file armPivot.m; recall that the function comment is the specification and must be complete. Be sure to remove any “side effects” from your old code that are not part of this function’s specification. Once the solutions for Project 2 have been posted to CMS, compare their results with yours in order to check for errors. You should fix any bugs you find this way, but remember not to copy the solution code directly into your own files!

Analyzing uniformity

We want to parameterize our solution in terms of the total time T taken to print the line. If our line is to have uniform thickness, the radial velocity of the nozzle must be constant, so s(t)=rt/T. This defines the ideal value of s at any time t that we will compare against. For this assignment, set T equal to 5 s and r equal to 10 cm, but be sure to leave them as parameters in your computations.

Observe that φ must travel from 0° to 30° in time T. If the turntable spins at a constant angular velocity ω, this means that ω=30°/T, and the spin angle at any time t is given by φ(t)=ωt.

Write a script PolarPrinterSensitivity to analyze the radial motion of the nozzle versus our ideal when the turntable spins at a constant angular rate. Start by defining a vector of times between 0 and T (inclusive) at which to evaluate s. Use the built-in function linspace() and include at least 50 points. At each time t, evaluate the difference between s as computed by armPivot() and the ideal value of s(t) defined above. Plot these differences vs. time, connected by lines (use a single plot() call with vector arguments).

Explore the impact of your solution tolerance dTheta on the shape of the plot. Select a tolerance small enough so that the smooth shape of this difference is visible beneath the jagged behavior of the error from your pivot angle solver (it should be no larger than 0.2°). This is our first sensitivity analysis, visualizing the sensitivity of extrusion uniformity to solver tolerance. There is almost always a tradeoff between speed and accuracy in engineering systems, so it is important to know how to study the impact of tolerances.

An ideal solution

A friendly mathematician has informed you that, in order to achieve a constant radial velocity, the spin angle—in radians—should be given by φ(t)=sin-1(t/(2T)) [challenge problem: derive this for yourself]. Compute the difference between the radial positions given by this spin profile and the ideal s(t) at each time and add this to your plot (note: the Matlab function for inverse sine is asin()). Has the situation improved over the constant-angular-velocity case?

As you plot curves in Matlab, remember to add titles and axis lables as you go, including units where necessary. Title this plot “Effect of turntable speed.” Additionally, now that we have two curves, we need a way to tell them apart. To do this in Matlab, use the command legend show. But first you need to provide labels for the curves. Do this by passing two additional arguments to plot(): first, the string 'DisplayName', and second a string labeling the curve. For example, the command plot(ts, diffs, ':', 'DisplayName', 'Constant spin') will plot the vector diffs vs. the vector ts with a dotted line, letting Matlab pick the color, and will give it the label “Constant spin” when a legend is shown. You need to make sure that each curve has a different color and/or line style so that you can tell them apart in the legend; letting Matlab pick the color (by leaving out a color code) is an easy way to do this.

Evaluating approximations

Unfortunately, it’s not always practical to achieve a motion profile with an arbitrary mathematical function like arcsin. But we may be able to approximate it by adding a constant acceleration term. Mathematically, given an initial angular velocity ω0, our spin angle will be given by φ(t)=ω0t + (1/2)αt2, where α is the angular acceleration. In order for this to be a valid motion profile for our line, we require that φ(0)=0° and φ(T)=30°. Solve for α in terms of ω0 and T so that this is guaranteed to hold.

With this constraint, we have reduced a two-dimensional search to a one-dimensional search, but we still need a way to decide what the best value of ω0 is. We seek a value that will minimize the worst-case difference between the radial distance s and its ideal value. It would be helpful to have a function that computes this figure of merit. Write a subfunction maxDiff() at the bottom of your script (remember to end it with the end keyword). Your function should take as arguments a vector of times t and an initial angular velocity ω0, as well as any parameters required by its computations. It should return a single output: the maximum magnitude of the difference between s as implied by the constant-acceleration profile and the ideal s(t) over all of the times passed to the function. Don’t forget to write a complete specification for your function!

With this function in hand, make a second plot (using figure) that shows the maximum deviation of radial distance vs. initial angular velocity for several values of ω0 between 5 and 6 °/s. Title the plot “Sensitivity to initial angular velocity” and set axis labels (with units) appropriately. Which initial velocity yields a spin profile with the least maximum deviation? Write your answer as a comment in this portion of your script.

Verification

Using the best value of ω0 that you found, add a curve to your first plot for the best constant-acceleration motion profile, showing the deviation vs. time (be sure it is labled in the legend along with your other two curves). How does it compare to the mathematician’s ideal solution? This is a good chance to do a sanity check of your work: if the constant-acceleration curve looks worse than the constant-velocity curve, then something has gone wrong.

Coin toss

Complete problem P6.1.14 in Insight. Read the problem statement on page 141 and note the additional specifications below.

Write and submit one function file coinToss.m that solves the problem through simulation—do not determine the probability using probability theory. Function coinToss() should have two input parameters:

And it should return the following output parameters:

Note that the length of vectors xOnTile and yOnTile should be exactly the number of coins that lie entirely within single tiles.

The problem statement in the book says to assume that the center of the coin lands randomly on the surface; specifically we mean that the position of the center of the coin is uniformly random on the array of tiles. Since the center of the coin can be anywhere on the array of tiles, it is possible for part of the coin to hang over the edge of the array of tiles.

You may (and are encouraged to) add subfunctions to your file to help decompose your solution, and their design is entirely up to you. Be sure that all functions are fully specified.

Consider using graphics to visualize and debug your solution (though this is not required). You may leave graphics-related subfunctions in your submission, but they should not be activated when our graders run coinToss() (since graphical side effects are not part of the specification).

Submission

Submit your files armPivot.m, PolarPrinterSensitivity.m, and coinToss.m on CMS (after registering your group), in addition to your files for Part A.