Tuesday, September 11, 2012

Sediment Feeder

Eriez Hi-Vi Compact Electro-Magnetic Feeders

Monday, August 20, 2012

First program to control a motor using Galil DMC-4133

In a previous blog, I discussed connecting to the Galil DMC-4133 using Gilal Tools. This blog now discusses a very simple set of commands to get the motor moving. I will list each command and discuss them as I type them.

:MT 2 'The MT is required for setting up communication with a stepper motor. The variable can be 2, -2, 2.5, or -2.5 depending on active low step or active high step and whether it is reverse direction.
:SH 'Turns motor on
:PRA = 13000
:BGA
:MO A  'Turns motor A off

Thursday, August 16, 2012

Connecting to Gilal DMC-4133 using USB and VB 2010

I followed guild for connecting to a Gilal controller using VB. I downloaded the tutorial and I found the a readme in subfolders. The steps were as follows:



  1. Install GalilTools version 1.3.0.0 or newer on Windows XP or newer.  Lite is free of charge, the full version required a purchased password.  Either is fine for this walkthrough.
    http://www.galilmc.com/support/software-downloads.php
  2. Connect to the controller using GalilTools
    http://www.galilmc.com/support/manuals/galiltools/connections.html#available
  3. Open Microsoft Visual Basic .Net 2010 Express, select File | New Project | Windows Forms Application and type "Hello_Galil" for the name.  Click OK. 
  4. Add a Label to the form by double clicking "Label" under "All Windows Forms" in the Toolbox.  
  5.  In the Solution Explorer window, right click "Hello_Galil" and choose "Add Reference".  The Reference dialog may take a few moments to populate.
  6. Click the COM tab.  Find "Galil" in the list.  Highlight it and click OK.
  7. Double click on the title bar of the form to enter the code section.
  8. Enter the following code in the public Class Form1:

        Dim WithEvents g As New Galil.Galil
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                Label1.Text = g.libraryVersion() + vbCrLf
                g.address = ""
                Label1.Text = Label1.Text + g.connection() + vbCrLf
                Label1.Text = Label1.Text + "MG TIME " + g.commandValue("MG TIME").ToString + vbCrLf
            Catch ex As Runtime.InteropServices.COMException
                Label1.Text = Label1.Text + ex.Message
            End Try
        End Sub
  9. Push F5 to compile and run the application.  The program will display the connections dialog, identical to GalilTools.  Choose the same controller you connected to in step (2).  The output should be similar to:
    GalilClass0.dll 0.4.0.0
    Galil1.dll 1.4.0
    192.168.1.155, RIO47100 Rev 1.0c1, 1155, IHA IHB
    MG TIME 4799941
When I run the program, I got an error: Network Failure, Address Not Available. After I click OK a few times, the following window shows up:

I click on COM3 115200, then clikc Connect.

The Form 1 output shows:


This indicates that the connection was successful.

On earlier times, the Windows Firewall screen also showed up. I gave it full privileges, then the next time, the screen did not appear when running the program.




Connecting to A Gilal Motion Controller

Gilal provides motion controllers that have small amplifiers built in. These motion controllers come equipped with a USP port, Serial Port, and Ethernet port. Gilal also provides software for connecting to the motion controller. I am working on a DMC-4133. It comes complete with a case.


I am connecting to it using GilalTools. When I first fire up GilalTools, it states that it is offline. I click on the Controller|Connect. Then the following window pops up.


At first, the addresses did not show. I keep clicking on the Available and Saved until the above list appears. Then I select COM3 115200.

After that, the terminal screen should look like this which means you are connected. 
The above lines mean it is using COM3 serial port (or a simulated serial port using the USB port), the Model of the Gilal Motion Controller is DMS4133 Rev 1.1a1, and the serial number is 603.

Friday, June 29, 2012

Updating Code to VB.Net

I am building in VB.Net to try to get around the overflow error. Also, as the application gets bigger, it is better to build in in Visual Studio rather than using VBA.

The following site has links for access the binary file using VB.Net http://msdn.microsoft.com/en-us/library/aa711203%28v=vs.71%29.aspx

Thursday, June 28, 2012

STL Files: Reading the Number of Triangles in VBA

The file format for the STL file is described at http://en.wikipedia.org/wiki/STL_%28file_format%29.

It states that the number of triangles is and unsigned 32 bit integer. Unsigned integers are not a native data type in VB. So what needs to be done is convert a Long signed integer into an unsigned integer. Microsoft has a good description of this at http://support.microsoft.com/kb/189323.

The key function that needs to be used is:


      Private Const OFFSET_4 = 4294967296#

      Function LongToUnsigned(Value As Long) As Double
        If Value < 0 Then
          LongToUnsigned = Value + OFFSET_4
        Else
          LongToUnsigned = Value
        End If
      End Function
 
The code to read the number of triangles then is:
 
Sub ReadBlockStl()
    Open "C:\Block.STL" For Binary Access Read As #1
    Dim NumOfTrian As Long
    Get #1, 81, NumOfTrian
    Close #1
    MsgBox LongToUnsigned(NumOfTrian)
End Sub

This code worked find on a cube that had 12 triangles.

However, I tried it on an object that 33924 triangles and I got an overflow error on a for-loop for NumOfTrian. Of course, NumOfTrian is a Long with a maximum positive value of 32768. But when I used a double precission, I still get the same overflow error.

STL Files: Opening an STL file for reading in VBA

STL files when they are stored from solidworks are in Binary format. Thus, VB needs to open a binary file for reading.

The general format of the open command is:

Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength]

The format of this command that I used was:

Open "C:\Block.STL" For Binary Access Read As #1

With that, I opened a file located at C:\Block.STL for Binary mode and I associated it with file #1.





Sunday, June 3, 2012

The crash of the Eurozone and why it makes sense for contries to have their own currency

Greece is currently in the throws of anquish as it looks at the cliff edge of falling off the eurozone.

Why did all these contries ban together and create the Eurozone in the first place. They were trying to compete against the strength of the U.S. dollar. They had a dream of becoming world super-power and world dominant economy. For a couple of years it was going great, but now the problems are showing up and we look back to why contries have their own currency. Before currency existed, there was gold. Gold has consistent value all over the world (give or take a bit of transportation costs). This worked well for global trade.

After a while they got tired of lugging gold all over the world to make a transaction, so they resorted to gold backed securities. The countries would keep the gold in the bank and issue notes representing the gold. That is why Fort Knox exists - to hold all the gold which is to back the U.S. Dollar. After a while, countries gave up this idea of having a gold backed currency. One very strong example of this is the hyper-inflation in Germany. This happened because the government took liberty to print money as their way to finance their activities rather than taking on debt or taxation. This type of problem has also happened in South America multiple times.

Over time, hopefully countries are begining to wisen up and realize that printing to much money destroys their country. It is a lesson that a country can learn - because it has to face its own consenquences of being irrisponsible with its ficsal policies.

That is the exact problem with one Eurozone currency. Countries do unwise fiscal acts like Greece's deception to the rest of the world about its actual debt level, and they expect the other countries to bail them out. Greece for many years was riding of cheap debt that was offered it because it was part of the Eurozone and it began to finance many of its activities using increasing levels of debt rather than taxation. It was spending more many than it was making off its citizens and going deeper in the whole as a result. They were able to keep doing this for a sustained period of time because the rating agencies such as Moody's still gave them good debt ratings because they were part of the Eurozone.

This is an example of disconnect between individual countries making fiscal policy decisions, and the Eurozone as a whole having to take responsiblity for those decisions. Now the rest of the world is realizing how fiscally irresponsible Greece has been over the past few years (much like Germany was back in the 1920's), and they want to have no part of it. Germany had to learn it lesson and get it's hand slapped by the rest of the world. Now it is the strongest economy in Europe. If Germany was not shielded from the consequences of its actions, why should Greece be?

I know that the bleeding heart sociallists amonst us do not want to see anyone suffer. However, there has to be some balance between helping people think for themselves and act wisely, and giving a helping hand. I do not hear stories of rampant deaths occuring in Greece because their current crisis.

We should let Greece spread its own wings and figure out how to fly on its own again. It it the oldest country in europe - I think that it can draw on its years of wisdom to figure out how to handle itself in this situation.