Introduction

Limited depth of field (DoF) is a very serious issue for macro photography. Focus stacking is a powerful technique used by macro photographers as a workaround for the limited DoF problem. It consists of taking a few macro photographs of your subject with gradually shifting focus - sort of "scanning microscope" approach - and then using focus stacking software to merge these multiple slices into a single photograph with a much deeper synthetic DoF.

When dealing with modest macro magnifications (around 1:1 - this is considered to be "standard" macro), focus stacking can be quite easily accomplished manually: as at these magnifications only a handful of photos is required to create a decent DoF, all you need is a good quality manual focusing rail, something like Velbon Super Mag Slider. Then one can manually move the camera using the rail's focusing knob from one shot position to the next one, and manually trigger the camera's shutter.

At much larger, "super macro" magnifications (around 3:1 or more), the situation becomes unmanageable: due to the extremely narrow DoF at such magnification (around 50 μm at 3:1; becomes ~2 μm at 20:1, and ~0.7 μm at 60:1), one often needs to shoot hundreds of photographs in a single stacking sequence to achieve the desired DoF. Doing it manually is no longer a practical option.

The solution: fully automated focus stacking rails, which would both move the camera (or the subject) between the shots, and trigger the camera's shutter to take the shots. The problem with this solution is that it is a fairly limited use gadget which can be very expensive. Likely the cheapest commercial product available, Cognysis StackShot, will run you $727 US with the camera cable and optional battery.

So I decided to design / build / program such an automated stacking rail myself, with the following three main goals:

* I wanted it to be as cheap as possible (much cheaper than the Cognysis).
* I wanted it be as fast as possible, both in terms of the time it takes to set it up and start shooting, and in terms of frames per second speed attained. (The hope was to make it fast enough that potentially even live insects could be photographed, in the wild.)
* I wanted it to be portable, to be usable for outdoor shooting.

I believe I succeeded with all the three goals, and then some more. My DIY automated focus stacking rail was built cheaply from the parts I ordered online, with the total cost around $180 US ($110 for the manual focusing rail Velbon Super Mag Slider + ~$54 for other parts + 16$ for the PCB). I haven't tested it myself, but it looks like the Neweer Pro 4-Way Macro Focusing Focus Rail Slider is an almost identical copy of the Velbon Super Mag Slider, for half of the price. Using the cheaper rail would make the project even more affordable, at around $126 US.

It was designed as a professional tool, not as a gadget, with the speed and efficiency in mind. As a consequence it doesn't use conventional menus or a touch screen for operation; all the functions it supports (around 40) are directly accessible via one or two-key commands, using its 16-keys keypad. The color 160x128 pixels LCD display is used to show all the information you'd need to know when doing focus stacking. It takes less than a second from powering up the device to starting shooting (by pressing a single key - "D").

The rail I built is very accurate - one motor step is only 0.63 μm, and the built-in full backlash compensation allows for (almost) perfect repeatability of stacking sequences. I am using different acceleration/decelerations for the rail movements which allows both highly accurate positioning of the camera and fast travel time. The device is fairly small and light (1.41 kg including batteries), and can be powered by both AC adapter and eight rechargeable AA batteries. This makes it very usable for outdoor shooting, e.g. with live insects.

The device should be able to control any camera which has a socket for a wired remote shutter control (most DSLRs, some mirrorless and perhaps some prosumer point-and-shoot cameras; if your camera only has a wireless remote shutter control, it is still possible to use it with my rail - it is a matter of a simple hack of the camera's remote control). It has a few adjustable software parameters which can be tuned to achieve the best possible performance out of your camera. For example, my previous DSLR camera - Canon 50D - can do at least 30 (likely more) shots in RAW format at 4 frames/second, when operated by my rail. This is sufficient to do a quick stacking of some live insects.

The rail supports three major modes of operation (cycled through with the key "0"):

* **Single-point continuous stacking**. ("Live insects mode"). Press a single key ("D"), and the rail will take a predefined number of shots, with given Step size ("5" key) and frames/second ("8") parameters. (The first parameter is determined by your lens' depth of field which in turn depends on the magnification and aperture, and the second - by the abilities of your camera and flash to shoot batches of shots in a rapid sequence.) One has to use a flash as the main light, to eliminate the blur due to the rail's motion and the vibrations caused by the environment (wind etc).
* **Two-points continuous stacking**. ("Outdoor mode"). For things which do not move or move very little. Fine-tune the two end positions of the camera (foreground and background points), press a single key ("D"), and the camera will travel to one of the points and will shoot a stacking sequence while moving to the other point. (The choice of the first point and the stacking direction depends on whether your camera looks up or down. Generally, the first point will be the lower one, so that stacking is done against the gravity, for the best accuracy.) Again the Step size and frames/second parameters are used. Flash is needed to freeze the camera's motion.
* **Two-points non-continuous stacking**. ("Studio mode"). You set the foreground an background points like in the *Two-points continuos stacking* mode, but the camera stops every time it takes a shot. You can fine-tune the behaviour by specifying two "delays": the time camera rests after arriving at the next shooting position (before taking the shot), and the time between taking the shot and moving to the next shooting position. This is the only mode which can be used without a flash (just with an constant light source), but ideally you still want to use flash, even in this mode. The reason: flash freezes camera vibrations which are always present (even when the camera is at rest), due to the environment. In the studio mode one can also use electronic shutter ("Full Resolution Silent Picture" feature of Magic Lantern alternative firmware for Canon cameras), with or without an external flash.

For both two-points stacking modes (continuous and non-continuous), there is an option to repeat stacks multiple times with a given time interval between stacks (so called **timelapse mode**). This for example can be used to create a timelapse video for a slowly changing macro object (like a flower bud opening). I am also thinking to try yo use this mode for photogrammetry (generating 3D models from a bunch of photos of the object, from different angles) + focus stacking experiments.

When compared to the commercial solution (Cognysis StackShot), my rail has the following advantages:

* **Price:** It is much cheaper (by a factor of 4).
* **Hardware:**
	+ It is smaller and lighter, and uses standard AA NiMh batteries - meaning it is better suited for outdoor applications.
	+ Camera shutter cable is connected to the rail in my design (and only one cable connects the controller unit to the rail), which is more convenient and safer than the Cognysis' approach (the controller unit is connected to the camera and to the rail, using two separate cables).
	+ It looks like the Cognysis gadget controls only the camera's shutter. My rail independently controls camera shutter and autofocus, which allows one to achieve the best possible performance (frames per second) out of your camera. It also allows my rail to control independently camera's shutter and external flash, which makes it possible to use external flash with electronic shutter (under Magic Lantern; only Canon cameras).
	+ From the Cognysis description, it appears that its limiting switches are triggered every time you move the rail to one or the other ends. In my design, the rail always stops by itself right before hitting one of the two limiting switches, which I think makes much more sense.
	+ The Cognysis doesn't have a manual left<->right camera movement knob, whereas the Velbon Super Mag Slider (and hence my design) has such a module, which is very convenient for framing your macro shots.
* **User Interface:**
	+ The Cognysis doesn't have the **"Pause"** feature, while my rail does. For example, if something goes wrong (e.g. flash or camera battery dies) in the middle of a lengthy (hundreds of shots) focus stacking, the Cognysis will only let you abort stacking and restart the stacking from the beginning, potentially wasting hundreds of shots. In my rail, pressing any key during a two-point stacking (and more generally, in timelapse stacking) will merely pause stacking, with the ability to travel back and fourth to any particular frame position, and then resume stacking from that position by pressing a single key ("D").
	+ My rail is **much faster to operate** than the Cognysis. All functions in my design are one click (with either one or two key bindings) away. In Cognysis, most functions (including the ones you use all the time: start stacking, setting foreground/background points, using memory registers) require a large number (5..10 or even more) of key clicks.
	+ Cognysis doesn't have a very convenient stacking mode which my rail has - *Continuous Two-point stacking*, where one specifies starting and ending points and uses the continuous stacking approach. The two-points modes the Cognysis does have are all non-continuous (much slower). Instead, the Cognysis has a bunch of modes which I consider not to be useful (Automated Step, Total Travel Distance etc.). Why would anyone let the distance between frames to be a free parameter? This parameter should be completely determined by the DoF of the lens you are using, so normally needs to be changed only when you change the lens. Overall, the Cognysis' user interface looks like it was designed by engineers, not by photographers.
	+ The Cognysis gadget is not convenient for fast stacking (when you are pushing your camera/flash to its limits, in terms of frames per second). In my design, one can find and use the highest FPS parameter the camera/flash can sustain, as a single input parameter. In Cognysis, the fps of your continuous stacking is determined by two separate parameters - Toff and Tpulse, which makes things complicated.
	+ In the Cognysis, shots are taken at equal time intervals, which is wrong - they should be taken at equal distances between frames, as is the case in my design. As a consequence, continuous stacking with the Cognysis will have too many shots at the beginning and at the end of stacking, where the rail accelerates and decelerates. My rail will always produce correct (equidistant) stacks, regardless of the acceleration/deceleration used.
	+ The software I wrote for the rail is available as Open Source: meaning you can do any modifications you want, add any features you need. With the v2.0 of Fast Stacker there is still lots of RAM and Flash memory left for adding new features.

Of course, there is always a catch - there is a price to pay for having a lighter and more portable macro rail. The notable advantages of Cognysis StackShot over my design are:

* The Cognysis rail does appear to be more durable and sturdy than the Velbon Super Mag Slider I am using, but perhaps that is an overkill; my Velbon has been performing well so far. You can always use a different, more durable rail with my controller and my software.
* The Cognysis allows for longer (100 mm or 200 mm, depending on the model, versus my 52.5 mm) maximum stacking length. I haven't found this to be a limiting factor yet - perhaps because my focus is on super macro (magnifications 2:1 ... 20:1).