# Difference between revisions of "Projectile Launcher"

This is the page for Frances Hunter's final project.

## Motivation

To apply the concepts of projectile motion to a practical situation. Also, it seemed like a cool idea.

## Design

The main component of my project is a projectile launcher attached to a servo. The launcher is powered by a spring (compressed to the same distance each time to produce a consistent initial velocity) and loaded with a small metal ball. The servo is connected to a Matlab program which, given the range from the target, turns the launcher to the correct angle. With no variation in initial velocity, the range will be dependent on the launch angle. The spring is then released by hand.

### Launcher

A diagram of the inside of the launcher is shown above. The spring is secured at one end of the tube by a screw passing directly through its coils. The other end is hot-glued to a metal plug of the same diameter as the inside of the tube. To load the launcher, one compresses the spring using a wooden rod and secures it by pushing a nail through a hole in the plug lining up with two holes in the side of the tube. The ball rests against the flat side of the plug until the nail is pulled out, launching the ball. The launcher is attached to the servo with strong double-sided tape (the kind used for wall hooks) and secured with string.

### Programming

I ultimately wrote three programs for the launcher. The first simply translates an angle defined by the user to pulse widths and sends it to the servo. Its code is below:

function [theta] = angle_test(theta)
s=instrfind; %Find any serial links (we can have only 1)
delete(s); %... and delete.
%Create a new serial communications link
s=serial('COM1','Baudrate',115200,'Terminator','CR');
fopen(s); %... and open it
pw = ((90-theta-1)+61.884)/.10103;  %Translates angle to pulse widths
ch=1;  %Defines channel
cmd=['#' num2str(ch) 'P' num2str(round(pw)) 'T' num2str(200)];
%creates command string from given variables
fprintf(s,cmd);  %Sends the command to serial link.
end

I used this program to check that the servo wasn't crooked (which it was--notice that 1 is subtracted from theta when it is translated to pw) and to collect data later on in the experiment.

Next, I wrote a similar function which took a range as input and calculated the needed launch angle, sending it to the servo in the same manner as above. The calculations were based on the equation:

theta = 180/pi*(.5*asin(9.81*r/(v^2)))

derived from equations describing projectile motion (with angles in degrees). This program did not work--or, would have required a far more precise apparatus and many small adjustments to work properly. It would also have required a very exact calculation of the launch velocity. As it was, there were too many variables, and the ball consistently missed the target when this program was used.

Since my original idea for the program was not working, I wrote a new program based not on theoretical equations, but on collected data. First, I tracked the ranges produced by various launch angles from 50 to 80 degrees by launching the ball repeatedly over a large sheet of paper covered by carbon copy paper. The results--inverted to give angle produced by range instead of the other way around, are shown below. Each dot is an average value of between five and nine trials.

I then used Kaleidagraph to fit a quadratic equation to the data (shown on the graph). I used the equation produced in the new program to calculate the launch angle given a range. Its code is below:

function [theta] = angle(r)
theta = 127.03 - 1.0202*r + .0032744*(r^2);
s=instrfind; %Find any serial links (we can have only 1)
delete(s); %... and delete.
%Create a new serial communications link
s=serial('COM1','Baudrate',115200,'Terminator','CR');
fopen(s); %... and open it
pw = ((90-theta-1)+61.884)/.10103;  %Translates angle to pulse widths
ch=1;  %Defines channel
cmd=['#' num2str(ch) 'P' num2str(round(pw)) 'T' num2str(200)];
%creates command string from given variables
fprintf(s,cmd);  %Sends the command to serial link.
end

## Materials

- Servo with connecting cords

- Matlab

- Nail

- Plastic tubing

- Metal ball

- Assorted screws, string, and double-sided tape

- Target (piece of paper)

## Problems and Evaluation

I never did get my launcher working as accurately as I would have liked. Once I hot-glued the plug to the spring, the launcher started shooting sideways. Since is shot more sideways for different angles, it made it very difficult to line up with the target. This was probably because the diameter of the ball was smaller than the diameter of the tube, making the ball "rattle around" during launch. It would also have been because of a slight slant to the face of the plug, or some completely unknown issue. Given more time, I might have corrected the problem by adding a second, horizontal servo that would move the launcher to adjust for the sideways shooting.

Also, although the ball usually landed near the target with the final program, it didn't always hit it. The accuracy probably could have been improved by taking more data of the ranges for given angles and using it to refine the quadratic fit equation.

I think the main thing I learned from this project was that when building actual things, as opposed to theoretical models, you can sometimes get more accurate results using a rough fit based on data than you can using the correct theoretical equations. The theoretical method is affected too badly by uncontrollable or unknown variables. Also, problems raised by the theoretical equations can sometimes be ignored when using a rougher fit. My original program would have required the target to be at the same height as the mouth of the launcher. The revised program made it possible to use a piece of paper on the tabletop as the target, perhaps six inches lower than the mouth of the launcher.

## Timeline

Week of 11/17: Collect materials; plan exact design; solve physics that will underlie the Matlab program.

Week of 11/24: Construct launcher and determine initial velocity; write Matlab code.

Week of 12/1: Mount launcher on the servo and frame; debug.