Autodesk Inventor Dynamic Simulation Tutorial using IN-Motion

IN-Motion is a Motion and Dynamic Simulation Addin for Autodesk Inventor. Autodesk has certified IN-Motion as a compatible addin for Inventor 2009 and 2010 versions. In this tutorial, I shall explain in brief What is Dynamic Simulation using a simple example of 2 bodies. gravityText.iam has two parts namely housing (grounded part) and bob (pendulum). We define a Mate constraint between the cylindrical sufraces of these two parts. The mate created has 2 degrees of freedom (DOF). One is relative rotation between the two parts about their common axis and relative translation about their common axis. In Kinematics, this constraint is referred to as a Cylindrical joint / pair. Now that we have our assembly ready, we go to “IN-Motion” by clicking on “Environments” ribbon tab and then “IN-Motion” as shown in the figure below. (Inventor 2009, go to Applications >> IN-Motion )

IN-Motion loads up and converts all the Inventor constraints into corresponding Kinematic joints or pairs. In this case, Mate:1 constraint is converted to a cylindrical joint. We then define the “Gravity” acting on the assembly. From the IN-Motion tab, click on “Define Gravity” and enter the value of Gravity in Y direction = “-10” m/s^2. This will make the gravity act in the downward direction with respect to the below figure.

Now, we will look briefly at what we mean by Dynamic Simulation. We can draw “free body diagram” (FBD) of pendulum bob and derive the equations of motion for it. Since only gravity is acting on it., the forces acting on it is shown in the figure below. “F” corresponds to the resultant force acting on pendulum bob. “Fr” is the reaction force between the cylindrical surfaces of both the parts and “Fj” is force acting along the axis of the joint (joint force). Their values are calculated as shown in the figure below.

Click on the “Simulation Player” button in the top panel. A dialog / form appears. Change the end-time to 0.2 seconds and click on simulate button. IN-Motion now performs mathematical analysis and shows the messages as shown in the figure below. Click on the “Playback Deck” button and you can play the animation and notice that at the end of simulation, the bob comes down due to the action of gravity, which is evident from the equations of motion.

Now, we can determine the value of reaction force by performing Dynamic Simulation using IN-Motion. Right click on Mate:1(Cylindrical) and goto “Force /Torque Graph” context menu item. A graph plot appears and upon selecting “Force” and “Magintude”, the following graph appears.

You can observe that the numerical value of Force(N) v/s Time(s) almost remains constaint (but for minor variations due to numerical methods of computation). The value can be approximated to 4.678 N and we had got same value Fr from our Mathematical Calculation (Equations of Motion).

Now, we can define the Joint Force. Right click on Mate:1(Cylindrical) node and select “Define Force”. A dialog/ form appears.

Enter the value as “-4.0” N and simulate the assembly. You would observe that the pendulum still moves down, but the resultant force acting on it has been reduced and hence its displacement at the end of simualtion is less than that under free fall. We can also test the simulation for Force = “-5.0” N. This time, the pendulum moves upwards slowly. Lets do a final check by putting the value of Force = “-4.678” N.

If you simulate the assembly now, the pendulum bob does not move at all. This is the force thats same as Fj and hence it balances the force due to gravity and hence the pendulum is in Equilibrium.

This is how IN-Motion can be used to determine characteristics of Multi body systems and then we can define appropriate forces/torques or motion to see its affect on the system.

I had recorded a screencast of the above tutorial and its embedded below. For a high clarity video, check out AR-CAD website.

Hope to bring more such tutorials in future. For some people in Dynamic Simulation domain, tutorials of this kind may be very trivial, but majority of beginners could find simple tutorials like these useful. Please comment back if there is any confusion or suggestions.

Regards,

Rajeev Lochan

ZedGraph C# Graph Data Export to CSV Using a Custom Context Menu

In continuation of my earlier post on ZedGraph example which plots a sinosoidal graph, I have extended it further to:

Add a new custom menu item in context menu(which appears on right click on the graph)

Export Graph plot data to CSV (coma separated values) file. Which can be opened by spreadsheets such as Microsoft Excel and Open Office calc.

For the custom context menu, the code has been derived from ZedGraph Wikipage. The following is the code of the Windows Form which has the ZedGraph control.

[sourcecode language=’c#’]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using System.IO;

namespace ZedGraphTest
{
public partial class Form1 : Form
{
private PointPairList m_pointPairList;
//CSV Writer
private StreamWriter m_CSVWriter;

public Form1()
{
InitializeComponent();
CreateGraph();
SetSize();

//csv
zedGraphControl.ContextMenuBuilder +=
new ZedGraphControl.ContextMenuBuilderEventHandler(MyContextMenuBuilder);
}

private void CreateGraph()
{
GraphPane myPane = zedGraphControl.GraphPane;

// Set the titles and axis labels
myPane.Title.Text = “ZedGraph Test”;
myPane.XAxis.Title.Text = “theta (angle)”;
myPane.YAxis.Title.Text = “Sin (theta)”;

// Make up some data points from the Sine function
m_pointPairList = new PointPairList();
for (double x = 0; x <= 360; x += 10) { double y = Math.Sin(x * Math.PI / 180.0); m_pointPairList.Add(x, y); } // Generate a blue curve with Plus symbols, LineItem _myCurve1 = myPane.AddCurve("Sin (theta)", m_pointPairList, Color.Blue, SymbolType.Plus); // Fill the pane background with a color gradient myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45F); //Make the MajorGrids of Axes visible myPane.XAxis.MajorGrid.IsVisible = true; myPane.YAxis.MajorGrid.IsVisible = true; // Calculate the Axis Scale Ranges zedGraphControl.AxisChange(); } private void Form1_Resize(object sender, EventArgs e) { SetSize(); } private void SetSize() { zedGraphControl.Location = new Point(10, 10); // Leave a small margin around the outside of the control zedGraphControl.Size = new Size(this.ClientRectangle.Width - 20, this.ClientRectangle.Height - 20); } private void MyContextMenuBuilder(ZedGraphControl control, ContextMenuStrip menuStrip, Point mousePt, ZedGraphControl.ContextMenuObjectState objState) { // create a new menu item ToolStripMenuItem _item = new ToolStripMenuItem(); // This is the user-defined Tag so you can find this menu item later if necessary _item.Name = "Export Data as CSV"; _item.Tag = "export_data_csv"; // This is the text that will show up in the menu _item.Text = "Export Data as CSV"; // Add a handler that will respond when that menu item is selected _item.Click += new System.EventHandler(ShowSaveAsForExportCSV); // Add the menu item to the menu,as 3rd Item menuStrip.Items.Insert(2, _item); } private void ShowSaveAsForExportCSV(object sender, System.EventArgs e) { try { //show saveAs CmdDlg saveFileDialog1.Filter = "CSV files (*.csv)|*.csv"; saveFileDialog1.ShowDialog(); m_CSVWriter = new StreamWriter(saveFileDialog1.FileName); WriteCSVToStream(); m_CSVWriter.Close(); MessageBox.Show("CSV File Saved", " ZedGraph ", MessageBoxButtons.OK); } catch (Exception ex) { m_CSVWriter.Close(); MessageBox.Show(ex.ToString()); } } private void WriteCSVToStream() { //First line is for Headers., X and Y Axis string _xAxisHeader = CheckCSVString(zedGraphControl.GraphPane.XAxis.Title.Text); string _yAxisHeader = CheckCSVString(zedGraphControl.GraphPane.YAxis.Title.Text); m_CSVWriter.Write(_xAxisHeader + "," + _yAxisHeader + "n"); //subsequent lines are having data for (int i = 0; i < m_pointPairList.Count; i++) { m_CSVWriter.Write(m_pointPairList[i].X + "," + m_pointPairList[i].Y + "n"); } } private string CheckCSVString(string _string) {//Check to see if there are any characters that can disturb the CSV delimeters. string _returnString = _string; if (_string.IndexOfAny("",x0Ax0D".ToCharArray()) > -1)
{
_returnString = “”” + _string.Replace(“””, “”””) + “””;
}
return _returnString;
}

}
}

[/sourcecode]

Zedgraph C# Graph Plot Example Application

Update : Check out ZedGraph C# Graph Data Export to CSV Using a Custom Context Menu , It has code to make a custom context menu item and also export the graph plot data as CSV.

Zedgraph is a very good opensource C# graph plotting library. Check out more details at my earlier post on Zedgraph. I have gone a step forward and made availabe source code and exe of a sample Zedgraph application which lets you have Line Plot, Bar Graph and Pie Chart.

Download Source Code (Visual Studio 2005 project in C#)

Download EXE

Below are the Screenshots of the Window Application. Copy and paste 2 columns of data from your favorite spreadsheet(eg MS Excel, Open Office Calc etc). NewLine and Tab delimiters are identified and the data is sorted accordingly, and added to graph plots. The Zedgraph plot library is so easy to use, implement and extend that it just took an afternoon to come up with this Windows application, when I was trying to convince my cousin to use ZedGraph in his college project.

ZedGraph is also being used to plot graphs in IN-Motion, a Motion Simulation Addin for Autodesk Inventor which I am co-developing along with my mentor. We are using ZedGraph to plot Postition-Velocity-Acceleration data, and intend to use it further more in Force-Torque graphs etc. Thanks to ZedGraph team for such a wonderful effort 🙂

Figure 1: ZedGraph Sample Window Application

Figure 2: The plot data for Line Plot and BarGraph are copied from a spreadsheat (eg MS Excel) and pasted in the text area. The code then uses tab and newLine delimiters to arrange data for plotting.

Figure 3: Line Plot for the above data. Notice the Titles of the X and Y axes.

Figure 4: Bargraph for the above data.

Figure 5: Data for Pie Chart. Paste 2 columns from spreadsheet. You may also use normal textbox to get the data from the user.

Figure 6: Pie Chart for the above data.

Download Source Code (Visual Studio 2005 project in C#)

Download EXE