Fast Stacker (Arduino based automated focus stacking rail)

Have questions about the equipment used for macro- or micro- photography? Post those questions in this forum.

Moderators: rjlittlefield, ChrisR, Chris S., Pau

pulsar123
Posts: 146
Joined: Fri Jun 12, 2015 12:36 pm

Fast Stacker (Arduino based automated focus stacking rail)

Post by pulsar123 »

I've finally written a detailed tutorial describing how I built my portable and cheap (~150$ total) DIY macro focusing rail based on micro-controller Arduino. Have a look here:

http://pulsar124.wikia.com/wiki/DIY_aut ... on_Arduino

It also contains a link to the software I've written to drive my rail.

Here is the 35-minute long live demonstration of my rail:

https://www.youtube.com/watch?v=IsDcmt_CyNQ

I will make another video soon, showing the inner workings of my rail.

Most important technical specs:

- Maximum stacking depth: 58mm;
- Maximum framerate: 4 fps (or higher if your camera + flash can handle it; my Canon 50D can do up to 4 fps);
- Maximum speed: 5 mm/s;
- Accuracy: 2.5 microns;
- Total weight (the rail + motor unit + controller unit + battery unit + 8 AmazonBasics AA batteries): 1 kg;
- Maximum load: at least 1 kg, probably more;
- Startup time: 0.5s;
- Has 28 different functions.

A test shot: magnification 5:1, assembled from 151 shots:

ImageFly by syamastro, on Flickr
Last edited by pulsar123 on Mon Jan 11, 2016 2:25 pm, edited 1 time in total.

ChrisR
Site Admin
Posts: 8662
Joined: Sat Mar 14, 2009 3:58 am
Location: Near London, UK

Post by ChrisR »

Thanks for the report, I'm sure several of us want to do something similar "one day".

How helpful did you find the software libraries you used?
I'd been looking at larger displays - none of them cost much.

pulsar123
Posts: 146
Joined: Fri Jun 12, 2015 12:36 pm

Post by pulsar123 »

ChrisR wrote:Thanks for the report, I'm sure several of us want to do something similar "one day".

How helpful did you find the software libraries you used?
I'd been looking at larger displays - none of them cost much.
I did buy a larger display first - 16 characters x 2 lines - only to discover it is huge and heavy and would require a very large enclosure. In addition, I really like that fact that the 6-line Nokia can show all the important information all the time, no need to use menus.

I am using two libraries - for the keypad and the Nokia display - and they are very helpful. It'd take me much longer to program those functions myself. This is my very first Arduino project BTW.

ChrisR
Site Admin
Posts: 8662
Joined: Sat Mar 14, 2009 3:58 am
Location: Near London, UK

Post by ChrisR »

What about routines to drive the motor - with acceleration. They must be out there?

jnh
Posts: 160
Joined: Mon Apr 27, 2015 7:34 am
Location: US East Coast

Post by jnh »

Nice write-up of the project. I have built a stacking rig with a motorized stage that's controlled by an Arduino awhile ago, and it's slowly getting to a point where I'm satisfied with it (but these things seem to be ever evolving...). But so far I didn't get around to to make such a detailed documentation of the whole thing.

With regards to libraries, I have found a stepper motor library to be dispensable. But then all I do is sending high/low pulses to the driver and that is implemented through a simple function.

Libraries for the display on the other hand are essential, I wouldn't even know where to begin using one without. Btw, Adafruit has an OLED display, that's tiny, but packs 64x128: https://www.adafruit.com/products/326. That's not part of my current controller (it uses a common 16x2), but I have plans to built a portable rig/controller around it sometime in the future.

pulsar123
Posts: 146
Joined: Fri Jun 12, 2015 12:36 pm

Post by pulsar123 »

ChrisR wrote:What about routines to drive the motor - with acceleration. They must be out there?
No, I wrote this stuff from scratch. I am operating the motor at the lowest level (sending signals to the step and direction pins). I actually had fun with it - my background is in research (theoretical astrophysics), so it was fun to write down all those differential equations (which are all very simple to be honest), to always enforce maximum acceleration, deceleration, and speed, and still have the accurate current position, and take steps when needed. My solution is flexible enough that for example you can move at full speed in one direction and then press the rewind button in the opposite direction (without having to wait for the rail to stop). In this case the rail will do the proper thing: first decelerate to a complete stop, then instantly reverse the direction and accelerate in the opposite direction. It's not that important but does give that extra feel of a pro device.

pulsar123
Posts: 146
Joined: Fri Jun 12, 2015 12:36 pm

Post by pulsar123 »

jnh wrote:Nice write-up of the project. I have built a stacking rig with a motorized stage that's controlled by an Arduino awhile ago, and it's slowly getting to a point where I'm satisfied with it (but these things seem to be ever evolving...). But so far I didn't get around to to make such a detailed documentation of the whole thing.

With regards to libraries, I have found a stepper motor library to be dispensable. But then all I do is sending high/low pulses to the driver and that is implemented through a simple function.

Libraries for the display on the other hand are essential, I wouldn't even know where to begin using one without. Btw, Adafruit has an OLED display, that's tiny, but packs 64x128: https://www.adafruit.com/products/326. That's not part of my current controller (it uses a common 16x2), but I have plans to built a portable rig/controller around it sometime in the future.
I would be interested to know more details. Can your rail do fast stacking? My main focus was to design a system where I could potentially do focus stacking on live insects (some of them, who can freeze for at least 2-3 seconds), and which would be portable enough to be usable outdoors. I think I achieved my design goals: with my camera (Canon 50D) and radio-controlled flash (YN560-III at 1/8 power) I can reliably do at least 30 frames in a single sequence at 4 fps, with perfectly sharp shots (at 5:1 magnification). In addition, the whole thing (rail + controller + battery unit) are fairly light (1kg total, with batteries) and compact, so it's realistic to use it outdoors. One can carry the tripod with the camera + rail attached in one hand, controller in your pocket, and RF controlled flash with a small softbox in your other hand, and have almost zero setup time. When the warm season comes back I will give it a try.

ChrisR
Site Admin
Posts: 8662
Joined: Sat Mar 14, 2009 3:58 am
Location: Near London, UK

Post by ChrisR »

Can either of you see why the display unit should not show the position of the motor as "thought" by the controller? Obviously without a shaft encoder etc, you can't tell the true position of the carriage, dues to backlash and manual movements.
In the (pretty poor) software on the Stackshot there's no step count or similar display. It's also not clever with backlash.
You have to set a "Start position" just short of where things are going to be in focus. So you wind along until it's just sharp, and then need to back off some, but you don't know where the motor thinks it is. Backlash means you have to approach again from the same direction. Which means you have to guess.
If you're stepping at a micron or two, you can easily have to take dozens more frames for no purpose.
(And if you need to repeat the stack with a different step size, you have to do the whole setup again, it appears. :evil: )

jnh
Posts: 160
Joined: Mon Apr 27, 2015 7:34 am
Location: US East Coast

Post by jnh »

Can either of you see why the display unit should not show the position of the motor as "thought" by the controller?
It can be displayed without much trouble. I have implemented that with my controller in a somewhat crude fashion: On start-up the stepper motor is not enabled and the stage can be moved around by hand. This is when I dial in the approximate start of the stack. I then put the controller in manual mode, which allows to drive the stage back and forth with the motor. At this point the relative position is set 0 no matter where the stage is. Driving it back an forth then displays the travel distance in micrometer (based on the number of steps taken and the stage TPI). This is how I gauge the total travel distance for the whole stack (based on which I figure out the number of frames). Then I go back to the starting position (overshooting a bit and then going forward again - to avoid backlash) and switch into stacking mode, where I enter number of frames and travel distance per frame. I usually add a few more frames than necessary at the beginning and end of the stack just to be sure - which is not terribly effective, but it doesn't do much harm either (adds a bit of time on the acquisition and processing end, but that's all automated anyway and just requires some patience). Probably doesn't address your concerns, but then without an encoder - as you mentioned - there are limits.

ChrisR
Site Admin
Posts: 8662
Joined: Sat Mar 14, 2009 3:58 am
Location: Near London, UK

Post by ChrisR »

That sounds perfectly reasonable, and would do the job fine! Why Cognisys didn't reveal a number, I don't know.

It's almost tempting to go in there and look for pulse and direction pins to count from with a piggyback counter. It would be more difficult to go from the motor drive outputs, depending what they do with microstepping.

Trying to guess how far you are from "starting to get in focus" is maddening..

rjlittlefield
Site Admin
Posts: 23543
Joined: Tue Aug 01, 2006 8:34 am
Location: Richland, Washington State, USA
Contact:

Post by rjlittlefield »

ChrisR wrote:Why Cognisys didn't reveal a number, I don't know.

It's almost tempting to go in there and look for pulse and direction pins to count from with a piggyback counter. It would be more difficult to go from the motor drive outputs, depending what they do with microstepping.

Trying to guess how far you are from "starting to get in focus" is maddening..
If I understand correctly what you want, then those functions are done by the StackShot controller panel in Zerene Stacker.

Zero is whatever position the rail has when it is powered on, or wherever the rail is when the "Zero" button in the controller panel is pressed. After that, the controller tracks the rail position based on motor signals, including microstepping. It attempts to do backlash correction, but that's only approximate due to physical nonlinearity in the rail. So, for precise positioning I always recommend to use the "back off and pre-run" method, which is directly supported by the controller panel.

Have I missed something?

--Rik

pulsar123
Posts: 146
Joined: Fri Jun 12, 2015 12:36 pm

Post by pulsar123 »

The more I look into the Cognisys device, the more ideal my own design looks :) Starting from the simple fact that my display has 6 lines x 14 characters (Cognisys only 4), so I have the luxury to show all the relevant information all the time (e.g. the current position is always shown on line #5, in mm), with no need to travel through menus using multiple key presses. In my device, all you need is accessible with a single press (either one or two-key combinations),

My design has no issues with the zero point, and starting/ending points for stacking - read the guide I wrote, it is all very convenient. My rail is always self-calibrated automatically, using the two limiting switches; no need to move anything by hand (in fact, that could fry your motor driver via induced voltage, so I made it sure the focusing knob is fully enclosed). The zero is always at the foreground limiter. The calibration stays even when you power down the device. Very rarely recalibration is required, and if it is required, it is self-initiated automatically when the rail hits one of the switches. (One can always initiate calibration with #C key). And as long as calibration is good, the rail always knows precisely where it is, and always displays that on the screen.

Backlash is present, of course, but it is totally minimal in my rail - around 50 um, or one frame. (With my 5:1 magnification setup, DoF is 50 um, and no point to go beyond 5:1 as I am hitting the theoretical diffraction limit for optical photography, with one pixel ~ 1um). Backlash results in the first two frames looking the same, if you approached from the opposite direction, which is totally non-issue when you do 100-200 shots stacking. And if you are really picky, you can easily always start stacking approaching from the same direction, eliminating the backlash.

In addition, the foreground and background points are set separately from the zero point, and with a single key command the rail would travel to one or another, for double-checking. Another single key would move the rail to the nearest of the two points, and then instantly start stacking towards the other point. Both points (and all the rail parameters, including the current position) are always kept in the permanent (non-volatile) memory.

Overall, I believe my interface is already polished to the point that it is extremely fast (essentially zero set up time) and convenient.

I am working on one improvement now, to deal with fairly common problem (when you do massive stacks - >100 shots) - when flash turns off half way, either because the battery dies, or you used too high power setting and it got overheated. Currently, one can press any button, and stacking will simply be aborted. What I plan to do is to have the stacking paused instead, when you hit any button. You can then check how many frames were black, then rewind the rail back to the last good point (either by a single frame movements, or by 10 frames steps), fix your flash issue, and then hit a single key to resume the stacking from that point. I think this feature will be very valuable.

ChrisR
Site Admin
Posts: 8662
Joined: Sat Mar 14, 2009 3:58 am
Location: Near London, UK

Post by ChrisR »

Yes, I think the Cognisys software and manual leave a lot to be desired.
The Manual was probably written by a man, they should have got a woman to do one as well, and combined the best of both...

I daresay we could all add to features - off the top of my head:
Pause,
Separate the find focus and Stack motor speed, from the "retract so I can change the lens" speed,
Allow repeat stack with same positions, different step size
Time estimate for whole stack
Remove Toff after last shutter operation
Sort out the backlash better
Allow shutter half-press
and add various inputs and output connections..

They could have usefully added a couple more buttons.

Some issues like backlash and wasted time, take on a greater significance if you're stacking at <1 micron, or with >1000 shots in the stack. Those aren't extreme numbers, for some.

I'm glad to see tethering with 3rd party software, addresses some of these.

pulsar123
Posts: 146
Joined: Fri Jun 12, 2015 12:36 pm

Post by pulsar123 »

ChrisR wrote:Yes, I think the Cognisys software and manual leave a lot to be desired.
The Manual was probably written by a man, they should have got a woman to do one as well, and combined the best of both...

I daresay we could all add to features - off the top of my head:
Pause,
Separate the find focus and Stack motor speed, from the "retract so I can change the lens" speed,
Allow repeat stack with same positions, different step size
Time estimate for whole stack
Remove Toff after last shutter operation
Sort out the backlash better
Allow shutter half-press
and add various inputs and output connections..

They could have usefully added a couple more buttons.

Some issues like backlash and wasted time, take on a greater significance if you're stacking at <1 micron, or with >1000 shots in the stack. Those aren't extreme numbers, for some.

I'm glad to see tethering with 3rd party software, addresses some of these.
Interesting feature request list, I should take it into account for my development. Here is my device current situation:

- Pause,: not yet, but I am already working on it, seems to be straightforward;

- Separate the find focus and Stack motor speed, from the "retract so I can change the lens" speed, - need more details to understand this.

- Allow repeat stack with same positions, different step size: already here, very easy to use. Click one of two buttons to increase/decrease um/frame parameter, the fore/background points remain untouched, N_frames is automatically recomputed, then a single button press would start stacking with the new step (doesn't matter what your current position is);

- Time estimate for whole stack: already have it. The display always shows stack time, distance, and number of frames for my both modes of operation (single and two point stacking)

- Remove Toff after last shutter operation: not clear about this one.

- Sort out the backlash better: backlash is not really an issue in my rail, but I can always add a feature to have it fixed automatically (by always doing stacking moving in the same direction);

- Allow shutter half-press: work in progress. For now I am only switching the shutter wire. It works fine with my Canon DSLR, but can be a problem with other makes. I will upgrade my hardware and software shortly to have a complete control for both shutter and AF switches. My idea is to have the "half-press" on the moment you initiate stacking, then have a small delay (around 0.2s for my Canon camera, can be adjusted), and then do the actual stacking, holding "half-press" until the very end. Is it what you had in mind? If not, please elaborate, I want to make my device as flexible as possible.

- and add various inputs and output connections..: not sure about this.

ChrisR
Site Admin
Posts: 8662
Joined: Sat Mar 14, 2009 3:58 am
Location: Near London, UK

Post by ChrisR »

¶Speeds - imagine a rig surrounded by lights and reflectors. You want to change an objective, so you want to withdraw perhaps 100mm or more.
Then you need to approach the focus point to find it - slowly.

¶Remove Toff after last shutter operation:
Using mirror lock, 2 shutter operations may be needed, hence:

Move rail
Settle
First shutter
Toff 1
Second Shutter
Toff 2
Move rail
etc.

Toff 2 is redundant but can't be set separately or removed.
600 shots at 2 seconds wasted = 20 minutes wasted.

You can work around it by adding an extra, single, manual shutter press so the first exposure is made after "settle", then you don't need any Toff, but it's easy to mess it up.

¶Various inputs and output connections:
Focus lights on/off, flash trigger, vibration sensor, flash sensor, alarm....

Post Reply Previous topicNext topic