MV-9001: Simple Pendulum Tutorial
In this tutorial, you will learn how to model a simple 1 DOF mechanism using the Msolve MotionSolve Python API.
If you are running this tutorial as IPython notebook, you can interactively execute each code cell by clicking SHIFT-ENTER. The output of the Python code (if any) will be displayed and the execution will jump to the next cell.
A rigid body is suspended by a mass-less wire and is connected to the ground via a hinge joint. The only force acting on the system is gravity, directed along the negative vertical direction. The simulation shows a part swinging from its initial resting position. There is no friction force in the joint, nor any type of energy dissipating force acting on the part, therefore the ball reaches 180 degrees of angular displacement for each full swing.
You will examine the reaction force in the joint.
Load the Msolve Module
In [1]: from msolve import*
The above command requires the msolve module to be in your computer path. Assuming the above is successful, you have imported the msolve names into the current namespace. This means that you have access to all classes and functions defined in msolve and you can start creating the simple pendulum.
Create a Model
To create the pendulum mechanism, you must first create a model. A model is nothing but a container that serves as a parent for all the entities. The model class takes a keyword argument to specify the output file name for MotionSolve. You can use the name 'pendulum'.
In [2]: model = Model(output='pendulum')
Add Units and Gravity
After creating a model, you can add details, units, and other entities such as gravity and ground. Most entities have default properties. For example, when you create the solver unit set without specifying arguments, you are essentially creating SI units.
Note that in msolve class names, use the CapWords convention and be aware that you can use the Python help system to learn about each msolve class, its use, and properties. Complete the steps below as an example.
Define Points
Some models in MBS are defined using points. Points are a special auxiliary object with an x, y, z location and a handful of convenient methods. They are a powerful way to define a mechanism and can be used anywhere in the model where an X,Y,Z quantity is needed (for example, to position a part or position a marker origin).
In this example, use points to locate various objects (such as markers) in the three dimensional space. You can use points when defining marker locations and orientations.
In [8]: p0=Point()
Create Markers
You can use this point to locate the origin of the ground marker. A marker is defined by a geometric point in space and a set of three mutually perpendicular coordinate axes emanating from that point.
In the marker class, the property qp corresponds to the location of the marker origin in the body reference frame. Since you are using ground as the body, the qp propery is the location of the marker in the global reference frame. Use the zp, xp method to orient the Z and X axes.
Verify the Part Creation
Every entity can be interactively validated. This is a way to help ensure that only correct models are simulated. The part that you created in the code cell above has mass properties but it does not have a Center of Mass marker. Therefore, it is incorrect. You can
Create a Geometry Object
For animation purposes, you can create a geometry object, a sphere in this case. According to the documentation, a sphere requires a center marker and a radius.
In [13]: sphere=Sphere (cm=part.cm, radius=20)
Add Joints and Requests
You will need to properly constraint our sphere, otherwise it will fall. A pendulum can be modeled using a revolute joint at the hinge point p0. This will effectively capture the undeformable, infinitely rigid mass-less connection of the pendulum body to ground. The revolute joint will connect two markers, one on the pendulum sphere and one on ground, and these markers need to be properly positioned in the three dimensional space.
A requirement of the revolute joints is that the i and j markers need to be coincident and need to have their Z axes properly aligned.
You will also create a request. Requests define output channels in MotionSolve and are written to MotionSolve output files so that they may be used for plotting and signal processing by HyperGraph. Requests can be defined using runtime expressions, built-in functions (MOTION, FORCE, FIELD, and so on,) or user written functions.
In this case, you can create a force request using the predefined "FORCE" method and create another request tracking angular displacement using the AX MotionSolve runtime function. AX measures the angular displacement in radians between two markers.
Run the Simulation
At this point, you are ready to run a transient analysis. The simulate method in invoked on the MBS model. A validation process is performed on each of the entities that make up the model. This is a necessary step to ensure that only correct models are being simulated. Note that the simulate command can be invoked with an optional flag returnResults set to True. This stores the results of the simulation into a run container for further post-processing, as shown in the following code.