# Machine Design

## Building Things to build other things, part 2

Together with the Mechanical Design week, this week's task was to build a three axis machine. This week, the focus was on automating the machine that we built before, which was a sky-cam like ring with a light sensor (more details on our group page). My contribution was the realization of a control algorithm that randomly samples cartesian coordinates inside the frame, converts these coordinates to a number of steps each motor has to move, and finally moves the motors accordingly. I did this by using the geometry of our frame to figure out the required change of length of each rope. To troubleshoot the algorithm, I also implemented an interactive control system.

## Making use of Geometry

Our goal is to write the lengths of the four wires holding the sensor as a function of the sensors cartesian coordinates. The frame is a cuboid with dimensions $l_x$, $l_y$, and $H$, for width, length, and height.

The four rope hinges are mounted at the pole tops at the corners of the frame. The positions of these hinges are named $A, B, C,$ and $D$, in clockwise order. The length of the corresponding rope is named $a, b, c, d$, respectively. Putting the origin of our coordinate system in the middle of the frame at zero height gives them the coordinates

$A = (-\hat l_x, -\hat l_y, H)^T$$B = (-\hat l_x, \hat l_y, H)^T$$C = (\hat l_x, \hat l_y, H)^T$$D = (\hat l_x, -\hat l_y, H)^T.$

Now, let's name the midpoint of our sensor ring $M$, and note that the mounting holes have a displacement of $R$ along the coordinate x- and y-axis, compared to the midpoint $M$. Then, assuming wires of zero thickness and a weight of the sensor large enough to pull the wires straight, we have

$\|M - A\| = a$$\|M - B\| = b$$\|M - C\| = c$$\|M - D\| = d$

This is exactly what we wanted: the length of wire as a function of the midpoint coordinates $M = (m_x, m_y, m_z)^T$. For example, the length of the wire at $A$ is $a = \sqrt{(m_x+\hat l_x)^2 + (m_y+\hat l_y)^2 + (H-m_z)^2}$.

Given the length of the wire at the starting point, we can determine the change of length for each wire, $\Delta s$. To relate $\Delta s$ with the number of steps needed to achieve this change, we calculate

$\delta w = \frac{\text{Number of steps per rotation}}{2 * \pi * r},$

where $r$ is the radius of the winding attached to the motor. Again, we are assuming an infinitely thin wire.

Now, we can implement the control algorithm.

## Controlling stepper motors

The A4988 drivers that we used make it really easy to control stepper motors; all that's needed is one pin to generate pulses to the drivers' step pin, and one pin to control the direction the motor is turning by setting the drivers dir pin to logic high or to logic low. In order to improve start and setting behavior, we used a linear acceleration and deceleration curve.