**Homework 1 -- Due 1/29** **[ENGR 52 Spring 2020](index.html)** # Setup Get your computer set up with Fusion 360, Python and Camotics by using the software installer links on the course web page. When you have finished, do these steps to finish setting up Camotics on your computer: 1. Download [this tool table for the Nomad](E52%20Nomad%20Tools%20Camotics.json) and save it locally. (*Right click* -> *Save Link As...*) 2. Launch Camotics and start a new project. 3. In Camotics, use the menu item *Tools* -> *Import tool table* to import the json file you just downloaded. 4. Finally, use the menu item *Tools* -> *Save Tool Table As Default* to use these tools for future projects. Now get set up with the starter code for this assignment: 1. Download the [starter code](hw1_starter.zip) and extract the files somewhere useful. 2. In a command prompt, navigate to the directory where you extracted the files and run the `make_square.py` script. 3. It should generate a `square.nc` file similar to the one we looked at in class (except with rounded edges). 4. In Camotics, do *File* -> *Open* to open that 'square.nc' file and preview it using the Default tool set. You should see a preview that looks like this: ![Figure [square]: Screenshot of `square.nc` in Camotics](images/camotics-square.png) By the way, unlike the code in class, this code contains arc commands in G-Code. You can find documentation for arc commands in the [LinuxCNC documentation here](http://linuxcnc.org/docs/html/gcode/g-code.html#_center_format_examples). # Spirograph Take the `spirograph.py` program from the starter code and modify it so it emits a toolpath for a spirograph as defined in the [wikipedia article](https://en.wikipedia.org/wiki/Spirograph). The `spirograph.py` program expects four parameters to be supplied on the command line: Parameter|Description ---------|----------- $R$ | Integer, radius of big gear $r$ | Integer, radius of small gear, with $r < R$ $k$ | Floating point number in $[0, 1]$, fraction of small gear radius to place pen $s$ | Floating point number, desired radius in mm of output figure From these coordinates, the program computes the following derived quantities: Quantity | Description | Value ---------|-------------|--- $f$ | Difference of gear radii | $f = R - r$ $\rho$ | Offset of pen from small gear center | $\rho = k r$ $w$ | Scale factor for output coordinates | $w = \dfrac{s}{f + \rho}$ $N$ | Number of gear revolutions | $N = \dfrac{r}{\gcd(f, r)}$ Your program should compute the parametric coordinates for the spirograph given by the functions: $$x(t) = w \left[ f \cos(t) + \rho \cos\left( \frac{f}{r} t \right) \right]$$ $$y(t) = w \left[ f \sin(t) - \rho \sin\left( \frac{f}{r} t \right) \right]$$ Notice the minus sign in the second equation! The independent variable $t$ should be evaluated over a linearly spaced range of coordinates in the interval $[0, 2 \pi N]$. Make sure that you include both endpoints of the interval to get a nice closed curve. A good step size is somewhere the ballpark of $\pi / 100$ or so. The emitted G-Code should consist of the following: * the boilerplate preamble to start all programs * change to tool 101 * turn the spindle on at 9,500 RPM * rapid motion to the starting $x(0), y(0)$ position * rapid motion down in $z$ to a safe height of 15mm * rapid motion down in $z$ to the top height of 5mm * linear motion down in $z$ to height of -2mm at a feedrate of 800 mm/min * linear motion through the remaining $x(t), y(t)$ coordinate pairs for all $t > 0$ * rapid motion up in $z$ to the safe height of 15mm * turn the spindle off * conclude the program Here is what my program's output looks like in Camotics when run as ~~~none python spirograph.py 24 11 0.75 35 ~~~ ![Figure [spirograph]: Screenshot of example `spirograph.nc` in Camotics](images/camotics-spirograph.png) # Facing In milling, a facing operation squares off the top of your stock. It consists of a lawnmower-style pattern of lines and arcs like the black path in the image below: ![Figure [face]: Basic geometry for facing](images/face.png) Take the `spirograph.py` program from the starter code and modify it so it emits a toolpath for a facing operation. The program expects the six parameters $n, d, w, h, z, d, f$ as described below. Parameter|Description ---------|----------- $n$ | Tool number $d$ | Diameter of cutting tool in mm $w$ | Width of stock in mm $h$ | Height of stock in mm $z$ | Depth to face at in mm (note $z < 0$) $f$ | Stepover fraction of diameter in $(0, 1)$ interval Note all parameters are floats except for the tool number $n$. From these parameters, we derive the following quantities: Quantity | Description | Value ---------|-------------|--- $s$ | Stepover length in mm | $d f$ $m$ | Margin length in mm | $d (1-f)$ $r$ | Cutter radius | $0.5 d$ $x_0$ | Left endpoint of linear segments | $-r - m$ $x_1$ | Right endpoint of linear segments | $w + r + m$ $y_0$ | $y$-coordinate of bottom linear segment | $r - m$ $y_1$ | Minimum $y$-coordinate for final linear segment | $h - r + m$ The emitted G-Code should begin with: * the boilerplate preamble to start all programs * change to tool $n$ * turn the spindle on at 9,500 RPM * rapid motion to the $x_0, y_0$ position * rapid motion to a safe height of 15mm * rapid motion to the top height of 5mm * linear motion to the final $z$ at a feedrate of 800 mm/min Next you should alternate between linear motion and arcs, concluding with a final linear move. The first linear segment is at $y_0$, and subsequent $y$ values are obtained by moving up by increments of $s$ until the final $y$ coordinate is greater than or equal to $y_1$. Note also that the arcs on the right-hand side of the stock are all counterclockwise, and the arcs on the left-hand side of the stock are all clockwise. The G-Code should conclude with: * rapid motion up to the safe height of 15mm * turn the spindle off * conclude the program Here is Camotics visualizing the output of my completed `face.py` program when run as ~~~none python face.py 201 6.35 30 18 -2 0.8 ~~~ ![Figure [facepath]: Screenshot of example `face.nc` in Camotics](images/camotics-face.png) # Turn-in Create a zip file containing your completed `spirograph.py` and `face.py` files. If you modify the `simple_gcode.py` module, please include that as well. Upload your zip file to the course moodle page [here](https://moodle.swarthmore.edu/mod/assign/view.php?id=382512).