Electronics DIY blog

DIY is fun and is food for the brain and spirit. Don't be afraid to learn.



Monday, October 28, 2013

Building a CNC - Y-Axis - part 3

Yesterday, I started mounting the Y-axis ball bearing transmission to the arm.
First I had to deal with the transmission block vs stepper motor shaft difference of heights.

To address this situation I used an 0,80€ pencil rubber that I sliced to act as anti vibration pads beneath the linear transmission blocks. It's cheap and it does the job well. I'm hoping it will help me cope with the noise caused by the vibration of the steppers running, against the steel structure.


Next I made a steel plate that will act has the stepper mount plate, and weld it against the arm.


But when I mounting the arm in the CNC cage ...WTFFFF...
The ball bearing thread hits the linear rail of the Z carriage.
Fortunately I only made alignment welds. I had to cut them put the rails of the Y arm higher and re-weld them into place.

Has you can see there is now a very small gap between the Z-rail and the Y-thread, but I should suffice.
To be continued...

Wednesday, October 23, 2013

Building a CNC - Y-Axis - part 2

Here is an update of my CNC building.
Has I stated before I'm doing this in my lunch break. This resumes to 30 min. a day. It's starting to feel more like never ending story... :-P


The second arm (Y-axis) is in place and painted (don't mind the onions on the table....:-P)

CNC with X and Y axis arms mounted
If you remember part 5 of this build, you will notice that this arm is some parts short (the smaller 4x 10cm tubes). Initially I welded them, but if you remember by sketch these were not planed. Because of that if I make de Y-axis in the same manner I did the X-axis the bearing thread system + Stepper will not fit.
So I had to un-weld the hole thing. Even without these, the space to fit these components is very very tight. Let's see if I don't have to do any more changes.

This is the Z-axis linear guide bed mount (the start of it at least). This is actually the second one. I'm building this in the dark (it's all in my head. I've not sketched this or made any pre-measures). Because of the way the bearings and the metal sheet is welded the tube with the off-center holes is the one to be welded. Not the other way around. This is to avoid contact between the bearing and the metal sheet.
Z-axis linear guide bed mount build
It would be best if I just pre draw all in Sketchup to see if it fits. And I probably will. Other wise I will make a lot of mistakes in the way. We will see how it goes.

Fingers crossed...

Sunday, October 13, 2013

SketchUp 3D to GCode plugin

Since the CNC build is very slow due to the lack of time to do any real iron working I've turned into an old quest that was still pending.

A year or so ago I started experimenting with the SketchUp API to have some fun and learn something new.
I've never programmed with Ruby before but my C and C# experience made it pretty easy to learn it in no time.
Then I came to an idea. Make a plugin to convert a SketchUp model directly to GCode.
I debated for a couple of months on the API classes to try to see how I would pull this off. Other things came and I put this project aside.
Early this week I decided to pick this up again. After some intense brainstorming to my self I came with an idea that seemed to work. And it did but the process do scan the model involved boolean operations on SketchUp solids (a hole bunch of them actually) and that is a performance killer.
When I increased resolution SketchUp would stall.

NOOOOO... I found a solution and it was too slow. But then the math concepts I learn in high school came to my head and BAZINGA...

Yeah baby...
What I'm showing here are the results of my SketchUp to GCode converter plugin.

This is in a pre-alpha stage right now, so I'm not going to go in to much detail about this, but I can tell you that it works... :-D

Here are a couple of examples (SketchUp model vs NCPlot- this displays the GCode)

SketchUp modelGCode plot
Example 1
Generated GCode - Dual pass mode
Example 2
Generated GCode - Single pass mode
With some small adaptations this can be used to produce plastic printing GCode too.
I'm developing some more features on this.

Stay tuned...

Thursday, September 26, 2013

Building a CNC - Paint job

Last couple of days I've been sanding and painting the frame and the X-axis to delay corrosion (yes delay...not stop...I don't have the means to do it, but this should suffice since this is going to be indoors). This is the handicap of using regular steel instead of stainless steel for the structure. The good thing is that I will do my hole CNC structure for 40€ worth of steel instead 120€ (or a lot more) in stainless steel.

The painting is quite a tedious task but it's got to be done and that's it.

Here are a couple of shots of the painted pieces.
Sorry for the quality of the pictures but I had almost no day light and my phone does not come with flash.

CNC frame box

CNC X-Axis
Cya...

Tuesday, September 24, 2013

Building a CNC - Y-Axis - part 1

Has I said yesterday today I started building the second arm for my new CNC.

I pre fabricated most of the parts yesterday. So today was about making the remaining parts and assemble them all.

CNC Y-axis arm (pre-fabrication stage)

CNC Y-axis assembled arm (almost completed)

I'm almost finished on this one. I kind of gained some speed because this was almost a question of reproducing a similar X-axis arm with some small changes.

I also painted the X-axis that is completed (forgot to take pictures of that one but I'll show that one tomorrow).

This is going smooth so far but I'll start at work again tomorrow so I'll be back to 20-30 min. construction frames in my lunch time. :-(

Let's see how it rolls from here.

Monday, September 23, 2013

Building a CNC - X-Axis - part 3

Okay.

After a couple of well deserved vacations I'm burning my last two holidays to try to advance has much has I can on my brand new CNC.

Today I got to pre mount the ball bearing thread and motor so I could weld the supports for the thread blocks.
I all fits very nicelly.
Here is a picture.

Pre aligned transmition thread and stepper motor
This one is almost ready for the paint job to avoid runsting.
I also fabricated almost all the necessary peaces for the other arm so I thing tomorrow I can complete the second arm as well.

Lets see how tomorrow goes.

Thursday, August 29, 2013

Building a CNC - X-Axis - part 2

As promised here is the reference side of the axis full mount.
Like I said in my early post the dimensions of my linear guide forced me to make a small change  to be able to properly clamp the linear guide bearing to the rail.
Here is a couple of self explanatory photos.

Clamp tube

Axis fixed side linear guide block fully mounted
Has you can see, the this forms a claw like bearing system that holds the axis in place.
Here are also a couple of shots of the arm in position.

Fixed linear guide mounted in the rail

Fixed linear guide mounted in the rail (down side)
This linear rail slides very well. Since the steel bar (ruler) that acts like the linear rail guide has a orange peel kind surface it's not as smooth has I would like but I believe it will become smoother in time.

Now to the other side of this axis. This will be quite easy and fast. That side will have a much simpler kind of bearing system to allow some level of structural distortion. I count on having it done tomorrow.

Hurray :-) ...

Wednesday, August 28, 2013

Building a CNC - X-Axis - part 1

So here are a couple a shots for the latest developments of my newest CNC machine.
I'm almost finishing the linear rail guide for one of the arms.
Like always some adjustments are needed.

Axis arm with linear guide supports welded


For example the rail guide bar is 8mm thick. That did not allowed me to put the spacers in the threaded rods that hold the bearings. After some evaluation I will need to redo one of the tubes that holds the bearing with an offset so it can clamp to the rail guide, and hold the arm in place (this is the side that locks the arm in the axis the other will be free to avoid misalignment errors).
I'll explain it better in my next post with the finished arm. For now this just shows a general aspect of the CNC horizontal axis arm.



Linear guide partial mount and testing

Expect to finish this arm soon.
Cya...

Monday, August 12, 2013

Building a CNC - Structure frame

So I've started building the new CNC with some steel tubing.
My welding technics are far from perfect but I think I can get the job done.
Here are a couple of shots from the structure. I have a few welding points to make to reinforce the structure but it's quite solid has it is. I can stand on it and it hold good.




So far I've made the cage frame and I'm starting to build one of the arms. I still have a lot to go before this monster starts moving.

Progress is slow but it is rolling...

Thursday, July 18, 2013

Building a CNC - The start - Conceptual design

I've been cooking this idea for quite a while now.
A brand new CNC.

With Crappy CNC still in the "hospital", I've started to plan a new CNC trying to improve all the previous faults of Crappy.

Better rigidity.
Cheaper materials.
Less axis alignment issues.
Build with accessible tools.

I'm leaning towards a Momus CNC similar design with some dramatic changes.
Here is a partial sketch of Crappy 2. Has you can see the main difference between the Momus and this one is the crossed mount free double arm.




The concept is to keep the counter force that causes frame distortions closer to the milling point.

I'm in the building phase right now. but it's being painfully slow.
More updates coming.

Thursday, February 7, 2013

C# Tracing code

Tracing code is a nice way to check your app behaviour when you are running it in a machine without the comfort of your compiler/debugger.
If you have doubts about a region of your code or you want to output information from you app you can simply output Trace messages to check what's going on.

Trace can be done to a file, a control, or any text recipient via a TraceListener based class.

Following my previous articles (1, 2) on C# extensions the following extension is a nice, handy peace of software to keep in your apps or reusable libraries to perform Trace output to any TextBoxBase derived class (ex. TextBox, RichTextBox, etc...).

Did you read my article on cross thread calls? This will make use of that tool to perform in a clean easy way extend the TextBoxBase.AppendText with/without auto scroll in a thread-safe/non thread-safe context. Take a look at this.

namespace Extensions
{
    public static class TextBoxBaseExtensions
    {
        /// <summary>
        /// Appends text to TextBoxBase Control and auto-scrolls to end
        /// </summary>
        /// <param name="tbb">TextBoxBase object</param>
        /// <param name="text">Text to append</param>
        static public void AppendTextAndScroll(this TextBoxBase tbb, string text)
        {
            tbb.AppendText(text);
            tbb.SelectionStart = tbb.Text.Length;
            tbb.ScrollToCaret();
        }

        /// <summary>
        /// Appends text to TextBoxBase Control in a UI Thread safe manner
        /// </summary>
        /// <param name="tbb">TextBoxBase object</param>
        /// <param name="text">Text to append</param>
        public static void SafeAppendText(this TextBoxBase tbb, string text)
        {
            tbb.SafeInvoke(delegate
            {
                tbb.AppendText(text);
            });
        }

        /// <summary>
        /// Appends text to TextBoxBase Control and auto-scrolls to end in a UI Thread safe manner
        /// </summary>
        /// <param name="tbb">TextBoxBase object</param>
        /// <param name="text">Text to append</param>
        public static void SafeAppendTextAndScroll(this TextBoxBase tbb, string text)
        {
            tbb.SafeInvoke(delegate
            {
                tbb.AppendTextAndScroll(text);
            });
        }
    }
}

Sweet.
You can now call on any TextBoxBase derived class any of the above methods.
To make use of this to perform trace listening you can simply do this:

using Extensions
/// <summary>
/// Defines a TextBoxBase Control TraceListener.
/// </summary>
public class TextBoxBaseTraceListener : TraceListener
{
    /// <summary>
    /// Gets or sets the TraceListener Control 
    /// </summary>
    public TextBoxBase Control
    {
        get;
        set;
    }

    /// <summary>
    /// Initializes the TextBoxBaseTraceListener object.
    /// </summary>
    /// <param name="control">The target TextBoxBase control.</param>
    public TextBoxBaseTraceListener(TextBoxBase control)
    {
        this.Control = control as TextBoxBase;
        if (this.Control == null)
        {
            throw new ArgumentException("The argument is not a TextBoxBase control", "control");
        }
    }

    /// <summary>
    /// Captures and display a Trace.Write call.
    /// </summary>
    /// <param name="message">The trace text message.</param>
    public override void Write(string message)
    {
        this.Control.SafeAppendTextAndScroll(message);
    }

    /// <summary>
    /// Captures and display a Trace.WriteLine call. Add NewLine char sequence to the end of the string.
    /// </summary>
    /// <param name="message">The trace text message.</param>
    public override void WriteLine(string message)
    {
        this.Control.SafeAppendTextAndScroll(message + System.Environment.NewLine);
    }
}

And use it like any other trace listener:

TextBoxBaseTraceListener myTracer = new TextBoxBaseTraceListener(richtextBox1); // the target control goes here
Trace.Listeners.Add(myTracer);

With these to lines you now intercept any Trace.Write Trace.WriteLine calls and show the message content.

Easy as pie.

C# Getting around Illegal Thread Safe Calls

Every time you try to mess with a control from a thread other than the owner-thread you will get the IllegalCrossThreadCall exception and your app will crash.

The lazy/dangerous way to get around this is to set the Control.CheckForIllegalCrossThreadCalls on the owner/parent control to false.

If your absolutely sure of what you're doing it's ok. But still not advisable.

The right way is to perform a check on the InvokeRequired property of the control and if so Invoke/BeginInvoke (synchronously or asynchronously it's up to you) the method via a delegate.
This is fine but if you have to expand this along your code it gets kind of boring.

If you read my previous article I've talked about a cool .NET feature called Extension Methods.

What I'll show you next is a very handy peace of code that you can put in a library and reuse in any app you do.

using System;
using System.Windows.Forms;

namespace Extensions
{
    public delegate void UIDelegate();

    /// <summary>
    /// Control class extension methods
    /// </summary>
    static public class ControlExtensions
    {
        /// <summary>
        /// Performs a UI Thread safe Control.Invoke.
        /// </summary>
        /// <param name="control">Target control.</param>
        /// <param name="dlg">delegate method to be invoked.</param>
        static public void SafeInvoke(this Control control, UIDelegate dlg)
        {
            if (control.InvokeRequired)
            {
                control.Invoke(dlg);
                return;
            }

            dlg.Invoke();
        }

        /// <summary>
        /// Performs a UI Thread safe Control.BeginInvoke.
        /// </summary>
        /// <param name="control"></param>
        /// <param name="dlg">delegate method to be invoked asynchronously.</param>
        static public void BeginSafeInvoke(this Control control, UIDelegate dlg)
        {
            if (control.InvokeRequired)
            {
                control.BeginInvoke(dlg);
                return;
            }

            dlg.Invoke(null, null);
        }
    }
}

Basically I've extended the Control type class and "added" 2 new methods.

To perform a thread safe operation inside, for example a form, we only have to add our Extensions namespace and call the code like this.

this.SafeInvoke(delegate
{
    /// do stuff...
});

That's it. It's a pretty clean away of performing operations over controls in a thread safe manner.

;-)

Wednesday, February 6, 2013

C# Extension Methods

Extension methods is a good way of "adding" extra functionalities to a type without having to create a new type of class by inheritance.
This is very useful if your trying to:

  • Extend a class/type for which you don't hold the source
  • Extend a class/type without the need to create a derived type
  • Extend a sealed class/type

Here is a small example:
Ever tried to call the .ToString() method on an object that is null?
Guess what happens?
Yes. You get an exception! Your program explodes! GHAAAA!
Who to fix this?
Test if object is anything else but null. But you have to do this in every peace of code you want to convert type to string.
You could do a method that takes an argument and returns a string.

But there are cleaner/smarter ways to do this.
This is where extension methods kicks in.

Take a look at this class.

/// <summary>
/// object Extention methods
/// </summary>
public static class ObjectExtensions
{
     /// <summary>
     /// Extends the ToString Method for object types. Adds null objects support.
     /// </summary>
     /// <param name="obj">The object variable</param>
     /// <returns>String conversion of the object. Supports null objects</returns>
     public static string ToStringEx(this object obj)
     {
         return (obj == null) ? string.Empty : obj.ToString();
     }
}

The static method inside this also static class takes an argument that is the object it self (that's why the this word is before the argument).
What this actually does is to extend the object type. object type is the origin point of all classes in C# so everything derives from object.
By extending the object type like in the code above you will be able to call .ToString() or .ToStringEx() on every type.

For example lets say you have a class named Foo and you declare an object of that type.

Foo a;
a.ToStringEx(); // Will return an empty string
a.ToString(); // Will throw an exception because a is not an instance of an object

If your extension needs some input arguments it's as simple as:

public static returntype MyMethod(this targettype obj, type arg1, type arg2, ...)


There are some limitations
  • Your extensions can only come in the form of methods (forget about extending properties, events, etc...)
  • Your extension can only create new objects inside it's scope. No new object inside the class are allowed. For that you must inherit/derive a new class

For more info check out MSDN

New course for the blog

Since I broke my CNC the blog evolution has been quite "dead".
I'm waiting to get access to some nice tools to repair my CNC. Till then I've decided to widen the spectrum of this blog and talk a little about one of my other areas. Coding. I do alot of coding in my job and at home so along the years I've been getting some skill in a couple of laguages (C-like ones mostly but also VB, Java, some ASM, and others).

To keep this blog more "lively" I've decided to throw a couple of articles about coding. Mainly C# my all time favourite high end language.

So here it goes...