OMD for Simulink
Warning: This is an earlier version than found in PyOMD, the same documentation will not apply.
OMD is a multibody dynamics tool for modeling spatial mechanical system. OMD has been embedded in Simulink to leverage the capabilities of this ubiquitous engineering tool.
The models which describe the mechanism is defined in Python ( so Python must be installed).
Installation Instructions
- Install Simulink
- If you don't have a compiler download the latest free Visual C++
- Download Python 2.5 if you do not already have it Python Download:
- Download the zipped file that contains the example from here: OMD For Simulink Examples Download:
- Unzip the examples somewhere on your hard drive. Perhaps in you Matlab working directory, or in My Documents or wherever.
- Open Matlab and change the directory to the "OMD4Simulink" directory that was extracted from the zip file. Matlab command: >>cd "path"/OMD4Simulink
-
If you have not used the "mex" command in the past, type:
>>mex -setup
Specify Visual C++, there might be something else that works, but the compiler that ships with Matlab does not (at least not for me) -
Enter the following command at the Matlab Prompt:
>> makemex
This will run a matlab script containing a set of "mex" commands to compile the C++ code that comprises the S-Functions in the examples. If it does not work it could be because Python 2.5 can not be found. If you open the makemex.m file you will see the absolute paths to the include and lib files from python. You should be able to find them on your hard drive is you have the software installed.
If this step is succesful the following files should have been created:
- getbodyposition.mexw32
- omds.mexw32
- revjointtorque.mexw32
- Open either "doublependtest.mdl" or "robottest.mdl".
- Start the simulation.
Users Guide
OMD is partially written in Python and definning models is done using a python script. This document describes how each element is defined and includes a set of python commands that defines a model.
Body
Description
Defines a body to be included in the simulation. Bodies have mass and inertia and move in space in response to forces and interactions with other bodies to which they are joined through joints.
The following parameters need to be defined:
- Mass: 1 Scalar
- Inertia: 3x3 Matrix
Syntax
OMDPYTHONBODY = Body("name", Bool specifiying if body is fixed, mass, inertia)
Example
b1 = Body("body1",False,5,[[1,0,0],[0,1,0],[0,0,1]])
Instantiates a body b1, with the name "body1" (often the same string), which is not fixed, has a mass of 5 and the inertia isthe identity matrix.
The units are left to the user, just be consistent.
Joints
Revolute Joint
Description
Defines a kinematic connection between 2 bodies which only allows those two bodies to rotate relative to each other about a single axis.
Syntax
OMDREVJOINT = JointRev("name",Parent,Child,p2j,j2c,a,theta,omega)
where:
- name: name of the joint
- Parent: First Body of the Joint
- Child: Second Body in joint
- p2j: Vector defining the location from the Parent to the joint in the Parent's Coordinates
- j2c: Vector defining the location of the joint in the Parent's Coordinates
- a: Vector defining the axis of the joint in the Parent's Coordinates
- theta: Initial joint orientation
- omega: Initial joint angular velocity
Example
p2j = [0.,0,0]
j2c = [1,0,0.]
a = [0,1,0]
j1rev = JointRev("j1rev",irf,b1,p2j,j2c,a,0,0)
Translational Joint
Description
Defines a kinematic connection between 2 bodies which only allows those two bodies to translate relative to each other along a single axis.
Syntax
OMDTRANSJOINT = JointTrans("name",Parent,Child,p2j,j2c,a,x,xdot)
where:
- name: name of the joint
- Parent: First Body of the Joint
- Child: Second Body in joint
- p2j: Vector defining the location from the Parent to the joint in the Parent's Coordinates
- j2c: Vector defining the location of the joint in the Parent's Coordinates
- a: Vector defining the axis of the joint in the Parent's Coordinates
- x: Initial seperation
- xdot: Initial translational velocity
Example
p2j = [0.,0,0]
j2c = [1,0,0.]
a = [0,1,0]
j1trans = JointRev("j1trans",irf,b1,p2j,j2c,a,0,0)
6DOF Joint
Planer Joint
Spherical Joint
U Joint
Forces
1 Body Force
Description
A force and or torque on a body whose line of action and offset are both definable.
Syntax
f1 = Force1Body("f1",b1,fv,tv,coord)
where:
- f1: Name of the Force
- b1: Body on which the force is applies ( not the name of the body, which is a string)
- fv: The Force Vector in Global Coordinates
- tv: Torque Vector in Body Coordinates
- coord: Coordinates in Body coordintes relative to the center of mass on which the force and torque vector acts
Example
fv = [0.0,0.0,-9.81]
tv = [0,0,0]
coord = [0,0,0]
f1 = Force1Body("f1",b1,fv,tv,coord)
Revolute Joint Force
Description
Applies torque to a revolute joint, this joint is applied by the parent on the child. The Vector defining the force is applied to a child. An equal and opposite force is applied to the parent.
Syntax
f3 = ForceRevJnt("f3",j1rev,torque)
where:
- f1: Name of the Force
- j1rev: Joint to which the torque is applied
- torque: Scalar defining the torque to be applied