Marching Box Algorithm Implementation

Posted by on April 13, 2015

This implementation of the Marching Box Algorithm makes use of some clever programming for code readability, however it may not be inherently easy to read for beginners, but it is a good example of how to implement an algorithm such as this one, in a clean way.

It may not be the fastest implementation but this code has served me well in the past and it turns out to be quite easy to maintain as well.

The primary application is to traverse for example bitmaps, you could implement a bucket fill or follow a contour easily, however more patterns may be required depending on your requirements.

I’ve used this, among with a peucker implementation, to create rough vector representations of bitmaps in the past. You may have to add exclusions or rules if you don’t want to check the extra 4 directions in diagonal, this depends on the type of images or data you’ll be working with.

 

 
Probable optimizations include denesting and less error checking on the match procedure for the release version, however that’s also implementation dependent.

This original implementation was aimed toward image manipulation, hence you’ll notice some variable names aren’t generic, but relevant to the subject. You may change this as you please.

At any rate, enjoy!

Cheers,
Gus

Lathe tailstock automation #oldschoolmachinist

Posted by on January 23, 2015

When having to drill repetitive holes in parts as second operations on an engine lathe, having a means to automate the tailstock could prove valuable.

Not all lathes come with the option of a hydraulic tailstock and some only have limited action.

The following are two basic ideas that can be implemented on virtually any lathe and very quickly as well!

 

First method:

Attach a suitable pneumatic cylinder to the bed using a similar clamping method as used on the tailstock itself. Have it push the lightly clamped (but free sliding) tailstock. A restrictor to control the feed-rate is mandatory. This method requires no modification to the lathe, if you need it to also retract through pneumatic action you can use a bracket or clamp on the tailstock. Otherwise you can push it back by hand as usual. Using a second restrictor on the return valve could help lengthen the life of the cylinder, so you don’t constantly ram it to fully closed all the time.

Second method:

With a long arm and bracket mounted on the toolpost, one can have the tailstock move, when the auto-feed is engaged on the carriage. This method has several limitations but it only requires light fabrication on mild-steel or aluminum for the “pushing arm”. While you can adjust the feed, it won’t be as flexible as the pneumatic cylinder, and you’ll have travel limitations in some cases.

Of course, the obvious alternative is to have the tailstock mounted in front of the carriage, and have the carriage push the lightly clamped (but still free sliding) tailstock.

 

Whichever method you choose, be careful and keep in mind possible crashes or tool ruptures. These are NON-CNC methods, for any type of electrical control you could, in theory, easily mount a stepper motor to the quill feed on the tailstock, but that itself is a modification of the lathe and beyond the scope of these two simple methods.

As for peck-drilling, the second method won’t allow it, this is why I’m starting to work on a clamp system for a pneumatic cylinder, peck-drilling with a pneumatic setup is relatively easy (although it may be expensive for some). The whole idea however is not to modify the tailstock in any way at all.

 

Enjoy!

Quick and easy tailstock alignment procedure (lathe)

Posted by on January 8, 2015

To quickly align your tailstock:

  1. Face and center-drill some scrap steel, round 1/2″ about 5 inches long.
  2. Insert a dead center on the tailstock.
  3. Mount your dial indicator so it touches a flat section of the dead center, right after the 60°, make sure you are on a flat by moving the tailstock quill back and forth, your indicator dial shouldn’t deviate.
  4. Once you’ve setup the indicator, you can now push the dead center onto the center you drilled before. If your tailstock is misaligned your indicator will show a slight deflection as everything slightly flexes toward center.
  5. At this point, you can go back and forth adjusting the tailstock setscrews until pushing the dead center won’t yield a deflection on the indicator dial.

You can easily get your tailstock centered within a thou or less using this method in under 5 minutes. Depending on whether you use a test indicator or a dial indicator, you can improve the alignment furthermore based on the available accuracy and resolution of your indicator.

Just keep in mind a test cut is always a good way to know for sure if you’re in dead center. Of course this requires the use of a known good micrometer and lots of time and patience. The alternative is to use a calibrated rod and indicate throughout the X travel for deviation, but the rod has to be held within centers.

Step 1 is very important, the part has to be center drilled on the spot every time for a good reference. You can use the same part twice (working on either side) afterwards you’ll have to face the center marks off or start from another scrap piece.

Once you are happy with the alignment:

Don’t forget to lock the setscrews against each other. Do this while indicating to make absolutely sure you aren’t pushing the tailstock to either side.

If after the alignment you still have issues, chances are you need to look into shimming your tailstock as wear has brought it’s height down from center. This is unfortunate, but it does happen. Bigger machines have removable contact plates that can be remade to deal with this, other machines can be coated or utilize teflon contact surfaces that are replacable. But typically if you have a solid cast iron base, you have to shim it.

The alternative is to machine a new lower plate / base for the tailstock, making it so the contact areas are replacable. Problem with more parts is, more chance of the parts actually moving and causing trouble. Your choice though.

This method relies on flexing of the part and the actual tailstock quill, it doesn’t matter how big or small your lathe is, all parts flex and we can use this to our advantage.

Happy new year!

Posted by on December 31, 2014

Happy new year everyone!

(PB) FileToStringEx – FileToString – Helper functions

Posted by on December 22, 2014

Intro:

Here’s a small but useful io function, The basic routine is also included for less demanding uses.

This function will read a text file into a string, the Ex (extended) functionality allows for defining size constraints to the return string and positioning of the file pointer for location/seeking purposes.

On big text files and in cases where you want to limit memory usage, this is a very useful routine. Otherwise the basic function works just fine.

The extended routine can also be used with a callback to set a progress bar, based on data size you can also calculate the remaining time, however that’s all beyond the scope of this post.

Code:

Use example:

Keep in mind that with the basic routine the whole file will be read into memory, so you have to beware of this detail.

If you never expect file sizes to exceed a certain range, this won’t be an issue. Otherwise use the Ex function to prevent memory and other performance related issues.

If the file is not found the return string is empty, this is the expected behavior, no error codes are used but you can easily implement this.

Have fun!