Distance-Based Camera Trigger - Part 1

Remember back when this site had projects on it? I could say that it's because I started a new job or that I started a large-scale ongoing side project that I will hopefully be able to write about, but mostly the reason is because the latest projects have been failures. I've been rushing into too many simultaneous, unnecessary projects too quickly. I also keep forgetting to factor in the small amount of room I have to do these projects.

I took a few pictures with my camera remote recently. I decided that I don't like having the wire connecting it to my camera in every shot. It's time to build a wireless remote. If I'm going to buy parts, I should pre-plan other things I will need for future projects to avoid extra shipping charges. The only thing I really want for my R.C. Tank (yes, I will finish it one day) is an accelerometer. Because I have to write a driver for the accelerometer anyway, why not test it with my new remote?

I will make what is essentially a stop-motion video of my drive to work. I will rig my camera to face out the windshield from the passenger's seat. The trigger would release the shutter every distance D, e.g. every tenth of a mile, along my commute.

Requirements

Theory

I want to determine the amount of distance I travel. However, there is no "distance-ometer." Instead, I have to create one using other components. The only commonly-available component that can help me determine linear motion (as opposed to rotational motion) is an accelerometer. They are relatively cheap but require a little bit of math. Luckily, the required calculus is pretty simple.

Wait... Simple Calculus?

Yes. I'm not claiming that the needed calculus (integration) is simple, but when using digital signals it's greatly simplified. It only requires finding the area of a couple of rectangles (length multiplied by width) and adding them together. Calculus becomes the geometry that you learn before you learn what the word "geometry" even means.

The Physics/Calculus

When anything is moving, such as a car driving, two things can be easily measured by people: distance and time. All other aspects are derived from those two numbers. Let's say I drove 60 miles, and it took me two hours to get there.

Equation 1
Equation 1

If I drive an average speed of 30 MPH for 2 hours, then I will have driven 60 miles (30 x 2 = 60). Speed is the rate of change in the distance with respect to time. Rather than 30 miles/hour, I could have said 0.5 mile/minute, 1/120 mile/second, or 158400 feet/hour. All are equivalent, but it must be distance over time.

Let's plot out speed against time. The function is:

Equation 2
Equation 2

Accelerometer Physics 1
Accelerometer Physics 1

To find out how far the car has traveled, find the area under the line i.e. multiply the width and length of the rectangle.

Accelerometer Physics 2
Accelerometer Physics 2

30 miles/hour * 2 hours = 60 miles

Using the graph, we can find how far we traveled in 1 hour. Draw a line up from the 1 hour mark.

Accelerometer Physics 3
Accelerometer Physics 3

30 miles/hour * 1 hour = 30 miles

So, moving at a constant speed isn't very interesting. Let's travel 1.5 hours at 25 miles/hour, then 0.5 hour at 45 miles/hour.

Equation 3
Equation 3

Accelerometer Physics 4
Accelerometer Physics 4

So, how far did the car move in an hour?

Accelerometer Physics 5
Accelerometer Physics 5

25 miles/hour * 1 hour = 25 miles

How far in 2 hours, then?

Accelerometer Physics 6
Accelerometer Physics 6

45 miles/hour * 1 hour = 90 miles

Obviously, that's wrong. We're going to have to break this into pieces.

Accelerometer Physics 7
Accelerometer Physics 7

25 miles/hour * 1.5 hours + 45 miles/hour * 0.5 hour = 60 miles

The scary math way of writing this is, where A is the area of each piece:

Equation 4
Equation 4

How would we determine the distance from a more realistic line?

Accelerometer Physics 8
Accelerometer Physics 8

There aren't any obvious pieces. So, we take pieces that are as small as possible. If T is the time between each sample and t is the time of each sample was taken:

Equation 5
Equation 5

Unnecessary note: If you take an infinite number of samples of infinitely small width, it is called integration.

Equation 6
Equation 6

The Method

To calculate distance from speed, multiply each speed sample by the time period between each sample and add them all together. A negative speed is moving in reverse.

To calculate speed, do the same thing with acceleration; multiply each acceleration sample by the time period between each sample and add them all together.

Because I will have an accelerometer, the method will be to collect acceleration sample points as fast as possible and convert it to distance.

->acceleration -> speed -> distance<-

Every time I hit a certain distance, the device will tell my camera to take a picture.

In the next part, I'll show the threshold calculations and more accelerometer information.