External Interface Example for MechanicalSystems-- Solid Designer Connectivityby Robert Beretta
Pendulum GraphicDiscussionThis sample notebook analyzes the motion of a pendulum which is attached to a sliding mass and a spring. This mechanism is used to demonstrate the use of the SDLink2D package that allows 3D bodies in Hewlett-Packard Solid Designer to be moved by MechanicalSystems.
The interface to Solid Designer uses the Solid Designer macro language. MechanicalSystems uses Mathematica's file writing capability to write a sequence of Solid Designer macros to the hard disk which contain commands to create an instance of each mechanism body and then move the instance to a new location in Solid Designer. The macros are read into Solid Designer when the bodies are to be moved; Mathematica need not be running at the time the macros are read. Kinematic ModelPreparationThe Modeler2D package is loaded into Mathematica. The SDLink2D package must be explicitly loaded; it is not auto-loaded just by calling one of its functions. The following names are used to reference each of the bodies in the pendulum model. Body DefinitionsThree points are defined on the ground body (body 1). P1. A point at the left end of the slider track. P2. A point at the right end of the slider track. P3. The attachment point of the spring. One point is defined on the pendulum (body 2). P1. The attachment point of the connecting rod. Two points are defined on the slider (body 3). P1. A point at the left bottom surface of the slider. P2. A point at the right bottom surface of the slider. An initial guess for the location of the slider is also given. Two points are used on the connecting rod (body 4). P0. The left attachment point of the connecting rod, at the local origin. P1. The right attachment point of the connecting rod. An initial guess for the location of the connecting rod is also given. The data contained in each of the body objects is entered into the current model with the Modeler2D SetBodies command. Constraint DefinitionsFive constraints, including one driving constraint, are required to model the pendulum mechanism. 1. A driving constraint to rotate the pendulum. 2. A revolute constraint to place the axis of the pendulum The parameter, drfreq, is the frequency, in hertz of the driver. The frequency is set with SetParameters so that it remains variable throughout the notebook. 3. A translational joint. 4. A revolute joint between the connecting rod and the pendulum. 5. A revolute joint between the connecting rod and the slider. The data contained in each of the constraint objects is entered into the current model with the Modeler2D SetConstraints command. Running the ModelCheckSystem tests for certain modeling errors. A return value of True is OK. SolveMech[t] runs the current model at time t and returns a list of rules containing the X, Y, and coordinates of each body. Mechanism Image
Solid DesignerTo access the Solid Designer macros written by Mech, Solid Designer needs a toolbox button added. The following command can be added to the ~/pesd_customize file to add the appropriate button. Before MechanicalSystems can determine where to move the bodies in Solid Designer, it must know where they currently are. Mech must know the "base location" of the Solid Designer bodies--the Mech location coordinates of each body which correspond to the current location of each body in Solid Designer.
If the mechanism has been drawn in Solid Designer in a valid assembled configuration, determining the base location is done by simply moving the Mech model to the corresponding location. The base location of the bodies is usually equal to the Mech location at some time T (often T = 0). If not, a set of solution rules that represents the Solid Designer base location must be explicitly written out. In this case, the Solid Designer base location is equal to the Modeler2D location at T = 0. SetBaseLocation[rules] specifies the base location of the mechanism bodies in Solid Designer in Mech global coordinates. The rules should be a list of Mech solution rules specifying the location of each body as it is currently found in Solid Designer. Calling SetBaseLocation resets the current location of the bodies to the base location. The SetBaseLocation function is used to tell the Solid Designer interface where the Solid Designer bodies currently are.
SDMoveMech[
newlocation
,
bodynums
,
bodynames
,
options
]
writes a set of Solid Designer macros to the hard disk. The macros move the
bodynums
from the last position that was input to
SolidDesignerDump
to
newlocation
(a list of
Mech
solution rules).
SetBaseLocation
is used to define the base position of all of the bodies in the model, as found in Solid Designer. The Solid Designer body name of each body that is to be moved is given by
bodynames
. The
bodynames
argument is a list of strings corresponding to each body number in
bodynums
. Each body name must be a full Solid Designer body path such as "/pivot". The
bodynames
list may be longer than
bodynums
, in which case the extra bodies are simply displayed in Solid Designer. The options
Origin
and
Orientation
are defined such that:
Solid_Designer_Location
= Origin + Orientation .
Mech_Location
The Solid Designer bodies can now be moved to any new location as specified by Mech. The bodies are moved to the locations corresponding to T = 0.10. Three files were created by SolidDesignerDump: setmech, movemech.1, and unmech. The setmech file adds the Set Mech, Move Mech, and Un Mech buttons to the toolbox and creates an assembly containing shared copies of each body to be displayed.
The movemech.1 file moves the bodies, and changes the Move Mech toolbox button so that it reads the next movemech.n file, if one exists.
The unmech file deletes the assembly and resets everything to the way it was before the setmech file was first executed.
Each subsequent call to SolidDesignerDump represents a move from the last location specified to SolidDesignerDump, to a new location. Each new move writes another macro file named movemech.n, where n is the move number. Thus, a sequence of n moves can be saved to the hard disk in a sequence of movemech.n files; these moves are stepped through each time the Move Mech button is clicked in Solid Designer.
Note that the movemech.3 file has been created, but it is an empty file. Thus, when all the stored moves are used up, clicking the Move Mech button has no effect. Un Mech and then Set Mech are clicked again to restart the entire sequence.
SolidDesignerDump has three options. The Origin and Orientation options are used if the global coordinate systems of the Solid Designer and MechanicalSystems models are not aligned.
Offset
is an option for
SolidDesignerDump
that specifies the location of the
Mech
global coordinate origin in the Solid Designer global coordinate system. The default setting is
Offset -> {0,0,0}
.
Orientation
is an option for
SolidDesignerDump
that specifies the 3D rotation matrix that transforms vectors from the
Mech
global coordinate system to the Solid Designer global coordinate system. Each column is the direction vector of the
Mech
axis in Solid Designer coordinates. The default setting is
Orientation -> {{1,0,0},{0,1,0},{0,0,1}}
.
DumpFileNames
is an option for
SolidDesignerDump
that specifies the basis of the file names of the Solid Designer macro files. Default:
DumpFileNames->{
~/macros/setmech, ~/macros/movemech, ~/macros/unmech
}
End
|