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

Post by pulsar123 »

ChrisR wrote:How does that translate ..
How many microsteps per whole step?


Some rails would be 300 turns, end to end. (eg 30mm/0.1mm),so assuming a 1.8º step that's 60000 whole steps.
"microsteps per whole step" - this is the motor driver's parameter. Easy Driver by default hast it at 8.

With 60,000 whole steps (x8=480,000 microsteps) you definitely need long int type. I actually did the mod yesterday, now one can choose the coordinate type by changing a single parameter in stacker.h. CHanging all coords from short to long resulted in 5% more flash used (now it is 95% of the total), and +2% of RAM (to the total of 74%). Still usable, but I'll have to check timings first - long arithmetic takes longer, so hopefully the arduino loop is still within the specs.

There might be other issues beside the type when you have so many knob turns. For example, to keep the arduino loop timings right, you'd need to use very slow speed. One solution would be to increase the number of microsteps per whole step, but that would mean less accuracy. A more drastic solution would be to change the whole code (and find two more arduino pins) to change the motor driver's "microstep per step" parameter dynamically - use smaller values for rewinding, switch to larger values when approaching the target.

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

Post by pulsar123 »

Here are more details: in my current design, the maximum speed is limited by two totally different factors:

1) arduino loop duration: microsteps cannot be shorter than that, or else the algorithm will fall apart. One can try to work around this by (a) using two more pins and dynamically changing the number of microsteps per step - you can gain up to 8x faster speed, and/or using another arduino board, with faster cpu (you can gain a factor of 2x);

2) motor torque: at faster than ~60 RPM, stepper motor I am using starts loosing torque at a fast rate.

I think the second limitation is more fundamental, as I am not aware of ways to address it - perhaps by using a much more powerful stepper motor + motor driver?

As is, my rail is doing well up to 75 RPM. With long int type things will likely get slower - say 60 RPM. If your rail requires 300 full turns from one end to another, that would mean 5 minutes total travel time. You decide if this is something you can live with.

nsomnius
Posts: 14
Joined: Wed Nov 25, 2015 6:24 pm
Location: Berkeley, California

Post by nsomnius »

Here's what I threw together. It's an IGUS Drylin rail/carriage. The motor specs are:

Holding Torque: 0.537Nm - 5472 g/cm - 76 oz/in
Rated Current/Winding: up to 1.4A
Supply Voltage: up to 36VDC

I'm planning to drive it with the equivalent of a Big Easy Driver, the stepstick A4988 board at 12V.

Image

I was hoping for a pretty big travel distance, longer than the typical high mag. setup. There's a potential 100mm of travel. My interests at this point seem to be with 1:1 magnification. Sounds like that could be a problem. I'm not opposed to going to a beefier Arduino board if required.

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

Post by pulsar123 »

Looks interesting - keep us posted!

It sounds like you are going with higher torque specs than in my design (2x higher current per coil, Big easy Driver vs. my Easy Driver) - any particular reason for that? Do you plan to use it with very heavy camera+lens, or perhaps to use it for a vertical motion? I find my specs are totally adequate for the task - moves at least 1.7kg (horizontally) without issues.

Higher torque specs will result in less portability - heavier components, need for a beefier battery. But perhaps you only need it for studio?

nsomnius
Posts: 14
Joined: Wed Nov 25, 2015 6:24 pm
Location: Berkeley, California

Post by nsomnius »

I chose those parts because I plan to use it on household current indoors only and with a D800E and Nikon macro lenses. Well, that and because it's what I had on hand.

I admit I don't fully understand the total step count limitation. Do you see a problem in my case with using your software with half steps for example and using most of the full 100mm travel of my rig? I was hoping to start off with about 1:1 mag. shooting.

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

Post by pulsar123 »

How many full knob turns it takes to travel the whole length (100mm) of your rail? That will give you the "mm/rotation" parameter. Divide that by the number of steps in one turn (200 for 1.8 degrees motors) and by the number of microsteps in one step (8 is the default for Easy Driver) will give you the travel corresponding to one microstep (2.5 um in my case). Then divide the rail's length (say 100mm) by the previous result to get the total number of microsteps it takes to travel the whole length of the rail. If it is 32,000 or less, you should be fine with the default version of the software. If more, wait for the next version, where you can switch to long int types.

nsomnius
Posts: 14
Joined: Wed Nov 25, 2015 6:24 pm
Location: Berkeley, California

Post by nsomnius »

Thanks very much for clearing that up for me. You have made it clear there's risk involved in straying from your design but thankfully it appears this isn't one of those risks in my case. Even with the 200 steps/rotation and 16 microsteps I'm still only at 10,000 or so total travel. It also makes me glad I didn't set out to shoot higher magnification as this setup won't do that without gearing down. I'm calculating that at the finest microstep of the A4988 driver that one step will travel .01" or 254 microns. This would appear to limit my rig to about 2:1 mag. without further modification or excessive stopping down.

nsomnius
Posts: 14
Joined: Wed Nov 25, 2015 6:24 pm
Location: Berkeley, California

Post by nsomnius »

Just rereading your Wikia and noted that you said that the limit switches should have at least 2 mm of travel distance. On another machine I made I found that simple common tactile button switches worked very well as limit switches. I was planning to use them on my Fast Stacker too. I would guess that they only offer about .5mm of travel distance. What do you think will happen if I try them on this rig? I can change out the tactile buttons easily but I do like their form factor very much.

nsomnius
Posts: 14
Joined: Wed Nov 25, 2015 6:24 pm
Location: Berkeley, California

Post by nsomnius »

Never mind : ). Upon reading further I see that you wrote "there still should be enough of travel distance - 2 mm or more - left for the rail to properly decelerate and stop." I'll swap those button switches out.

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

Post by pulsar123 »

I wouldn't cheap out on micro switches - they are really important. One person who already reproduced my rail use the short travel microswitches and ended up changing the rail parameter BREAKING_DISTANCE_MM from 2mm to 0.5mm, which is not great, especially if you plan to use the rail for heavy gear (>1kg) - smaller breaking distance results in a higher acceleration/deceleration of the rail operations, which (1) wears off the rail bearings sooner, and (2) increases the camera vibrations after each move.

Look around - I found good micro switches with ~2.5mm travel distance cheaply in a local liquidation store. They have plastic levers, but sturdy enough for my purposes. If not, I'd end up gluing a lever extension to other (short travel distance) microswitches I got from ebay.

Perhaps one of these two will be good for the job?

http://www.ebay.co.uk/itm/5-x-Ultra-Min ... 1835534354

http://www.ebay.com/itm/Micro-Switch-1A ... 1805988303

nsomnius
Posts: 14
Joined: Wed Nov 25, 2015 6:24 pm
Location: Berkeley, California

Post by nsomnius »

Thanks very much, I'm going to try the first type you linked to.

A note on the second type, I've used those on another machine and 1 out of 4 was defective. I can't say it was from the same manufacturer. I opened it up and the way those are put together is far from reassuring. I trashed them as I didn't want to wait for another failure, which seemed like an eventuality to me given their crudely machined internal contact surfaces.

EDIT:

I wound up going with these since they had very good specs for this purpose and should be better quality than others I've tried:

https://www.digikey.com/product-search/ ... s=SW133-ND

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

New software s1.12

Post by pulsar123 »

UPDATE (08/02/2016): I just released a new version of my automated rail software, s1.12, which is designed to handle many more microsteps than before. You need this new software if your hardware (rail, motor and/or motor driver) is different from mine; specifically, if the total number of microsteps is larger than 32,000. If this is the case, get this new software, and change the value of the new macro parameter COORD_TYPE (in stacker.h) from "short" (default - same as before) to "long". This will increase the size of the program in flash from 90% to 95% of the available space (which is still ok), but the timings are as good as before (so no penalty in performance). I also fixed a small bug with the backlash on/off command (*B).

http://pulsar124.wikia.com/wiki/Whats_new

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

Post by pulsar123 »

I just did the first test of my rail at magnification 10:1 (the highest I've used so far was 4:1), using my new Nikon 10x/0.25 M Plan. I shot ~30GB using some random target I happened to have (lady bug). I still have to analyze more, but here is one of the stacked shots I produced (step 5um, depth 1.2mm, using electronic shutter +flash on my Canon 50D):

ImageMLV_5um_sharp by First Last, on Flickr

I am still getting to used to this magnification - the workflow I used at 4:1 didn't work well at 10:1 (the image was rather soft when zoomed out). For the image above I ended up doing multi-scale unsharp mask in Gimp. More specifically, three scales - 0.85/2 + 4/0.5 + 15/0.5; the first number is the sharpening scale length, the second number is the strength of the effect. The first scale (0.85/2) is only obvious when viewing 100% scale, the last (15/0.5) - mostly for viewing zoomed out, and the middle scale contributes to both. I also re-scaled the image to 50% of the original size, and increased saturation by 25%. At the end, the image looked much sharper than the original, but noise didn't get too bad. I suspect I might have overdone with sharpening. I still like the idea of doing it at 3 scales, but perhaps I just need to reduce the strength at all scales.

Here is the original stacked photo for comparison:

ImageMLV_5um_raw by First Last, on Flickr

The light also seems to be okay, for such a short working distance (8mm) - what do you think? I made a diffuser from a white plastic cone, probably ~2" at the widest side, with the narrow side's hole large enough to snap onto my Nikon objective and be held there securely by itself, with a narrow slit at the bottom for the pin holding the insect. The cone was sanded on both sides using finest sand paper I had (#240), and illuminated by an external flash (YN560III) from behind. I also put a piece of white paper, also with a slit for the pin, under the cone and insect, to reflect light back. So at the end I had a well diffused light, with reasonable light losses (I used 1/16 flash power at ISO 200 for proper exposure).

Another thing which was tested was the electronic shutter (FRSP) feature of Magic Lantern (alternative firmware for Canon DSLRs). As discussed in another thread, I made it work well with an external flash in my artificial tests, but not as well in real focus stacking: with 1/4s camera exposure I got ~1 dark frame every 50 shots. It doesn't really show in stacked images, but I plan to fix this issue by using larger exposure (~0.4-0.5s) and correspondingly longer flash delay.

Finally, my Arduino rail itself was tested, for the first time at 10:1 magnification. My preliminary analysis shows that it performed well even with the smallest tested step (I did stacks using 5, 7.5 and 10 um). Both 5um and 7.5um stacked photos look equally good, with 10um showing very slight degradation of quality. This was done with a non-continuous stacking (5s wait after each rail move before a shot is taken). But I also tested the "quick and dirty" mode of stacking - continuous, with the frame rate 0.5 fps, and using regular camera shutter (no mirror locking). Surprisingly, the continuous stacking (with 7.5um steps) looks pretty much as sharp as non-continuous (also 7.5um), so it almost looks like there is no point in doing stacking the slow way even at magnification 10:1, except for saving your shutter.

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

Post by ChrisR »

Interesting to find little difference using "continuous". I wonder how fast other cameras could do it.

"what do you think?" Light's a bit strong at the top?
This is Pmax, yes? Dmap has virtues :). Try retouch with Dmap.
Or start with Dmap and retouch a lot with Pmax.
Sharpening regime pretty good - maybe a tad strong, as you say.
Chris R

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

Post by pulsar123 »

ChrisR wrote:Interesting to find little difference using "continuous". I wonder how fast other cameras could do it.

"what do you think?" Light's a bit strong at the top?
This is Pmax, yes? Dmap has virtues :). Try retouch with Dmap.
Or start with Dmap and retouch a lot with Pmax.
Sharpening regime pretty good - maybe a tad strong, as you say.

Thanks. Dmap never worked for me - even when contrast is set to zero I get a tone of artifacts, would take forever to retouch it.

I played a bit more with multi-scale Unsharp masking, and ended up writing this bash script which is using the command line ImageMagick utility (to be used under Cygwin or Linux):

#!/bin/bash
# Unsharp masking for 10:1 macro shots

if test $# -ne 3
then
echo "Arguments: strength in_file out_file"
exit
fi

convert $2 -unsharp 0x24+`echo $1 | awk '{print 0.15*$1}'`+0 -unsharp 0x6+`echo $1 | awk '{print 0.3*$1}'`+0 -unsharp 0x1+`echo $1 | awk '{print 2*$1}'`+0 $3

One has to provide the overall strength ("1" seems to do a good job), and the in and out file names. Works fine with 16-bit/channel images (TIFF etc). The numbers were determined experimentally for my setup (10:1 magnification objective with Canon 50D camera). It sharpens at three different scales, with radii 24, 6, and 1 pixels (in that order). The resulting image has an acceptable amount of noise, and looks obviously sharper at all scales - from web-sized 300x200 pixels to 100% zoom.

Regarding continuous vs. non-continuous shooting: be the judge. The top image was done using continuous shooting (with shutter, no mirror locking, a shot every 2s):

ImageCR2_7.5um_sharp by First Last, on Flickr

The next shot was done using non-continuous shooting (electronic shutter = no shutter, no mirror movements, shots done 5s after the rail stops):

ImageMLV_7.5um_sharp by First Last, on Flickr

(BTW, I use my bash script to do the 3-level unsharp masking, on both images).

And here is a 100% zoom-in region:

Imagezoom_in by First Last, on Flickr

I think it is hair splitting at this point. (Perhaps the continous is just a tiny bit less sharp.) It does look like Yongnuo flash provides a short enough light impulse (when used at /16 power) to pretty much freeze out all the motions and vibrations - of the camera moving, of the shutter and mirror moving - at least up to 10:1 magnification.

The only advantage of the non-continuous shooting is the fact that I am not using shutter and moving the mirror (prolongs the camera's life span). The obvious disadvantages (or rather inconveniences) are that it takes ~3x longer to do stacking, and one needs a fairly dark studio (for electronic shutter).
Last edited by pulsar123 on Tue Mar 01, 2016 2:08 pm, edited 1 time in total.

Post Reply Previous topicNext topic