Thursday, September 4, 2008

Dynamic Simulation using UG NX4 Motion Simulation Module

Which software are you using in your mechanical design project?

I have been using Solid Edge 3D CAD software for 1-2 years for my mechanical design projects in the past. But now, according to the standardization in my design organization, I have to switch to use Unigraphics software instead, or we call it in short as "UG NX4" (the latest version is NX6).

To be honest, at first I still like Solid Edge because I think I can make modeling and assembly in Solid Edge faster and easier than in UG. But one of the good thing for UG is Motion Simulation module that help me simulate the movement of mechanical assemblies before releasing for manufacturing. I know that Solid Edge also has this kind of simulation module, but I didn't have a chance to use (no license). So in this post, I would like to share how easy to set up motion simulation in UG NX4.

Let's start with a very simple modeling.

I would like to see how the cylinder moves when it is pushed by the rotating lever. So I start with making UG modeling as shown above. Those parts can be "features" in single UG file or the assembly of several UG files.

Once the assembly is ready, I can then start "Motion Simulation"

At Motion Navigator, right-click and select "New Simulation"

UG NX4 will show the pop-up Motion Joint Wizard windows for automatic setting of joints for simulation. For this example I just click at cancel button in order to set the links and joints manually.

Next, what I have to do is to set necessary links and joints for motion simulation. I have to start with creating of links. Parts or features that cannot moved and no contact with other parts, can be excluded for link setting. In the example, the fixed column can be excluded from link setting. I can leave it as it is, just for showing purpose only.

First, I would set the lever as a link in motion simulation by clicking at "link" icon and select the lever and rename it as "lever"

Do the same thing for the cylinder and the block.
Why do I need to set the block as link?

I have to set the block as link though it is not moving because I would like to set the 3D contact between the cylinder and the block, otherwise the cylinder will fall down during simulation! I have to also select "fix the link" for the block in order to prevent falling down when simulation start.

At Motion Navigator, I can see the links and joint I've created. We can see that though I don't set the joint for each link yet, but there is "J001" joint at Motion Navigator pane because UG NX4 creates "fixed joint" automatically when we select "fix the link" during creating of the link.

Next, I create a revolute joint and set motion driver for the lever. This step is very important. The point and direction of joint must be correct i.e. Z-axis should be the axis of rotation.

Then I create the 3D Contact between the cylinder and the block and also between the lever and the cylinder.

Then we're ready to start simulation. But we have to make sure that the solver environment is "Dynamics" not "Kinematics" because I would like to see the effect of 3D contact. (Click at calculator icon)

Next, start motion simulation by clicking at "Animation" and set time = 1 and step = 100 and see the result.

Watch the following video for the result.

Recommended articles related to Unigraphics NX4 Motion Simulation

Monday, September 1, 2008

Motion Simulation in Solid Edge using sketches together with Microsoft Excel VBA Programming Part III

In previous example, I showed how to control variables in Solid Edge sketch using direct link to excel spreadsheet. In this example, I am going to show how to use VBA (Visual Basic for Application) in excel to control the variables in Solid Edge sketch.

1) Create new file in Microsoft Excel

2) Press Alt+F11 to enter Microsoft Visual Basic windows as shown below

3) Right click in Project Explorer at new file name (in this example, new excel file name = Book2) > Insert > Module

4) To make Solid Edge type libraries available to the Visual Basic Object Browser, click References on the Project menu. On the References dialog box, select the Solid Edge libraries you want to access.

All variable automation is accessed through the Variables collection and Variable objects. The Variables collection serves two purposes: it allows you to create and access variable objects, and it allows you to work with dimensions as variables.

Note: When debugging programs that interact with the Variable Table, it helps to have the Variable Table displayed while stepping through the program. The Variable Table shows the results as they are executed.

5) Write the following code into VBA code area as shown below,

You can copy & paste the following code to your excel VBA.

' =================================================================
' Example of using VBA code to control variables in Solid Edge document
' By AkeBlogger
' =================================================================

Sub Simulate()
On Error Resume Next

'Declare the program variables.
Dim iAngle As Single
Dim objApp As Object
Dim objVariables As Object
Dim objVariable As Object

' Checking for the active document
Set objApp = GetObject(, "SolidEdge.Application")
If Err Then
MsgBox "You must open Solid Edge before executing this module!!", vbOKOnly + vbExclamation, "Error"
Exit Sub
'Connect to a running instance of Solid Edge.
Set objApp = GetObject(, "SolidEdge.Application")
'Access the Variables collection.
Set objVariables = objApp.ActiveDocument.Variables
End If

For iAngle = 0 To 360 Step 2
' Changing Cam_angle from 0, 2, 4, ..., 360 deg.
Call objVariables.Edit("Cam_angle", iAngle)

Next iAngle

End Sub

6) Open Solid Edge file from previous example and delete formula in Variables Table as shown below, because in this example we will control the variable (dimension) using VBA code directly.

7) We are now ready for simulation. Resize VBA Windows as shown below then click run to see the result.

Watch the following video for the actual result!