DynaFlexPro User's Manual
VERSION 1.0
Copyright 2005 by MotionPro Inc.
Example Problems
Overview of common format for examples
Each of the following examples are presented using a standard format, so that
the user can easily navigate between the commands and concepts presented
in the different examples.
Description
A description of the physical system is given, along with the relevant system
variables and parameters.
Concepts
A short list of the concepts presented in the example.
Modeling
The system is modeled using ModelBuilder to create the components and
their interconnections, and BuildEQs to generate the governing equations.
Simulation
The kinematic and dynamic equations are solved, usually numerically, to
provide a computer simulation of the time response. Plots and animations
are used to demonstrate the system motion.
References
Papers, journals, and web links are provided for further information on the
given example.
Spring-mass-damper model
This is the classical model of a vibrating system, consisting of a translating mass connected
to ground by a linear spring and damper.
Description
A prismatic joint is used to constrain the mass to translational motion along the global
X axis. The displacement of the center of mass, x(t), is measured from the position where
the spring is undeformed. Acting on the mass is an external force F(t), as well as the
restoring forces from the spring and damper.
Concepts
Modeling
You can launch this ModelBuilder example from the Maplesoft web site by clicking here.
Alternatively, if you have installed DynaFlexPro and this User's Manual on your computer
(automatically put in Maple 10 toolbox directory), you can un-comment the next line to
launch this DynaFlexPro ModelBuilder example:
| > | #DynaFlexPro:-BuildModel("Examples/SprMassDamp.mb"): |
The block diagram model of the system is shown above. The connection between the
translating Mass and the Ground is a prismatic (slider) joint, as shown below. Note
that the joint is selected into the trees of the linear graph, so that the equations are
automatically generated in the joint coordinate, x(t).
The spring, damper, and external force could all be modeled by separate connections
between the ground and translating mass. However, it is simpler to include the stiffness,
damping, and external force as elements acting in parallel with the prismatic joint; as
shown below, this is easily entered through the "Force Driver" interface for the joint.
The model is then exported to the input file "SprMassDamp.dfp".
| > | restart; |
| > | with(DynaFlexPro); |
![]()
After loading the DynaFlexPro libraries into Maple, the system equations are automatically
generated by passing the input file name to the BuildEQs command. The resulting module
is stored in "Model", so that the kinematic and dynamic exports can be easily examined.
| > | Model:= BuildEQs("Examples/SprMassDamp.dfp",[]): |
![]()
![]()
| > | with(Model); |
![]()
![]()
![]()
![]()
| > | GetDynEQs(); |
As expected, the dynamic equations comprise a single, second-order, linear ordinary differential equation
that governs the response of this vibrating 1-DOF system.
Simulation
Since the governing ODE is linear, we can obtain analytical solutions using Maple's dsolve command.
Let's start by looking at the unforced response case, i.e. with F(t) = 0.
Numerical values are set for the system parameters, and the system is released from rest with x=1 at
time=0. With m=k=1, critical damping would occur for d=2 (see Thomson and Dahleh). With d=1/2, the
dynamic response is an underdamped vibration:
| > | ParaSubs:= [m= 1, d= 1/2, k= 1, F(t)= 0]: |
| > | SysODE:= eval(GetDynEQs()[1],ParaSubs): |
| > | UnforcedSoln:= dsolve({SysODE, x(0)=1, D(x)(0)=0}); |

The dynamic response can be plotted, in order to better visualize the response:
| > | assign(UnforcedSoln); |
| > | plot(x(t),t=0..10,title="Displacement versus time"); |
| > | plot(diff(x(t),t),t=0..10,title="Speed versus time"); |
Now look at the response of the mass to a sinusoidal forcing function. Start by unassigning
the previous solution for x(t), and and then find the new solution:
| > | unassign('x(t)'); |
| > | ParaSubs:= [m= 1, d= 1/2, k= 1, F(t)= sin(omega*t)]: |
| > | SysODE:= subs(op(ParaSubs),GetDynEQs()[1]); |
| > | ForcedSoln:= dsolve({SysODE, x(0)=1, D(x)(0)=0}, x(t)); |
| > | assign(ForcedSoln); |
![]()
![]()



Notice how the forced response depends upon the frequency ω of the forcing excitation. One can
plot the displacement response for low and high frequency excitations:
| > | plot(subs(omega=1,x(t)),t=0..10,title="Displacement versus time (omega=1)"); |
| > | plot(subs(omega=10,x(t)),t=0..10,title="Displacement versus time (omega=10)"); |
When the forcing frequency is much higher than the natural frequency, one can see that the response
is essentially the unforced, underdamped response, with a superimposed high-frequency oscillation.
| > |
References
Two-dimensional particle motion
In this example, the two-dimensional motion of a simple particle mass projectile is modeled
and simulated.
Description
The particle mass is launched with some initial velocity in the XY plane of motion,
and gravity acts in the -Y direction.
Concepts
Modeling
You can launch this ModelBuilder example from the Maplesoft web site by clicking here.
Alternatively, if you have installed DynaFlexPro and this User's Manual on your computer
(automatically put in Maple 10 toolbox directory), you can un-comment the next line to
launch this DynaFlexPro ModelBuilder example:
| > | #DynaFlexPro:-BuildModel("Examples/Projectile.mb"): |
In this example, the rigid body representing the particle mass is connected to the Ground
by a Planar Joint. In that way, the mass can only translate in the XY plane, and rotate about
the Z axis out of the plane. Thus, the particle mass has 3 degrees of freedom (DOF).
The variables associated with the planar joint are denoted X, Y, and θ, and the planar joint
is selected into the tree so that the final equations are in terms of X, Y, and θ.
If one wanted to simulate the three-dimensional motion of a projectile, the planar joint
can be replaced by a Free Joint, or no joint at all.
The mass of the body is set to m, and the moment of inertia about Z is set to Inertia. Do
not use "I" as a symbol, since Maple will confuse this with the complex number I =
In the Model Properties window, the gravity is set to G in the -Y direction and the model file
name is set to "Projectile.dfp", to which the system model is exported.
After loading the DynaFlexPro package, the BuildEQs command will automatically generate
the governing equations of motion, given the name of the model file as input:
| > | restart; |
| > | with(DynaFlexPro); |
![]()
| > | Model:= BuildEQs("Examples/Projectile.dfp",[]): |
![]()
![]()
By saving the results in the module Model, the exported data and functions can easily be examined:
| > | with(Model); |
![]()
![]()
![]()
![]()
| > | GetDynEQs(); |
As expected, the dynamic equations comprise 3 second-order ODEs in terms of the
selected coordinates X, Y, and θ.
Simulation
As in the previous example, the governing ODEs are linear and can be solved analytically
using dsolve.
However, to demonstrate the features associated with BuildSimCode, optimized simulation
code will be generated for this example and numerically integrated within Maple.
Numerical values are set for the system parameters. Then, an optimized Maple procedure
(pXdot) is created, which contains a computational sequence for computing the derivatives
Xdot needed for subsequent numerical integration by Maple's dsolve/numeric.
| > | ParaSubs:= [m= 1, G=10, Inertia= 1]: |
| > | BuildSimCode(Model,{"Xdot"}, "MapleProc", "Optimize", ParaSubs); |
![]()
The projectile is launched with initial speed v0, at a 30 degree angle above the X axis. The motion
is simulated by numerically integrating the optimized procedure (pXdot):
| > | v0:= 10: |
| > | odeICs := array([v0*cos(Pi/6),v0*sin(Pi/6),10,0,0,0]); |
| > | odeVars := convert(convert([Model:-vX],Vector),list); |
| > | tr := time():
Soln := dsolve(numeric, implicit=false, procedure=pXdot, abserr = 1e-8, relerr=1e-7, start=0, initial=odeICs, output=listprocedure, procvars=odeVars, range=0..1): Time_to_integrate := time()-tr; |
Once the numerical results are obtained by dsolve/numeric, they can be plotted using plots[odeplot]:
| > | plots[odeplot](Soln, [[odeVars[4],odeVars[5]]],t=0..1, refine=1, title= "Trajectory of Projectile, Side View", labels = ["X", "Y"], scaling= constrained, view=[0..10,0..2]); |
| > | plots[odeplot](Soln, [GetFrameMotion("r", "CoM", "Ground", "Ground")[1],GetFrameMotion("r", "CoM", "Ground", "Ground")[2],GetFrameMotion("r", "CoM", "Ground", "Ground")[3]],t=0..1, refine=1, labels=["x","y","z"], refine=2, axes=framed, orientation=[-80,20],title= "Trajectory of Projectile, 3D View"); |
Note that the angular speed of the mass remains constant, since there are no torques
acting on the mass in this example:
| > | plots[odeplot](Soln, [t,odeVars[3]],0..1, refine=1, title= "Angular speed versus time", labels = ["Time", "theta_dot"], view=[0..1,0..20]); |
| > |
Two-DOF serial robot manipulator
In this example, the dynamic equations are obtained for a 2-link 2-DOF robot arm.
Description
The robot consists of two rigid bodies connected by revolute joints with parallel axes.
Thus, this "RR" robot is constrained to the XY plane, with gravity G acting in the -Y
direction. The robot is driven by two motor torques,T1 and T2, acting at the two joints.
Concepts
Modeling
You can launch this ModelBuilder example from the Maplesoft web site by clicking here.
Alternatively, if you have installed DynaFlexPro and this User's Manual on your computer
(automatically put in Maple 10 toolbox directory), you can un-comment the next line to
launch this DynaFlexPro ModelBuilder example:
| > | #DynaFlexPro:-BuildModel("Examples/RR_robot.mb"): |
Using the ModelBuilder, the links are connected to each other and Ground by revolute
joints with axes parallel to Z:
In addition to specifying the axis for each joint, the desired coordinate names
and
are entered in the joint properties menu. With the two joints selected into the trees for
rotation and translation, the final equations will be in terms of
and
.
The joint torques are easily entered through the Torque Driver menu for the joints:
Rigid body-fixed frames are created on each body where the joints are connected. In
addition, a body-fixed frame is attached to the tip P of the second link:
After defining the gravity vector, the model is exported to the file "RR_robot.dfp":
| > | restart; |
| > | with(DynaFlexPro); |
![]()
After loading the DynaFlexPro package, the system equations are generated by BuildEQs from the
given input model file and stored in the Model module. The optional argument instructs BuildEQs
to apply the Simplify command to the dynamic equations of motion:
| > | Model:= BuildEQs("Examples/RR_robot.dfp",["DynSimpType", "Simplify"]): |
![]()
![]()
| > | with(Model); |
![]()
![]()
![]()
![]()
Because the 2-DOF system is modeled by 2 independent coordinates, the governing dynamic equations
take the form of ordinary differential equations
, where
is the 2x2 mass matrix:
| > | xM; |

![]()
![]()
![]()
![]()
![]()
![]()
As expected, the mass matrix is symmetric positive-definite. The entry corresponding to β2
is the moment of inertia of the second link about the second joint axis (easily verified using the
parallel axis theorem). The entry corresponding to β1 (see order of coordinates in vQ, above)
is the combined moment of inertia of both bodies about the first joint axis.
The right-hand side F of the ODEs includes weight and quadratic velocity terms. The β2 entry
corresponds to the net moment about the second joint axis of these contributing terms, and the
β1 entry is the net moment about the first joint axis:
| > | vF; |

![]()
![]()
![]()

![]()

![]()
![]()
![]()


The (X,Y) coordinates of the tip point P are easily found in terms of the 2 independent coordinates
using the GetFrameMotion command:
| > | xP(t):= GetFrameMotion("r","P","Ground","Ground")[1]; |
| > | yP(t):= GetFrameMotion("r","P","Ground","Ground")[2]; |
![]()
![]()
![]()
![]()
Maple's Combine command is often successful at simplifying complex trigonometric
expressions that typically appear in kinematic equations:
| > | xP(t):= map(combine,xP(t)); |
| > | yP(t):= map(combine,yP(t)); |
![]()
![]()
Simulation
In this example, we assume that the joint coordinates are known functions of time. From these functions,
the trajectory of point P can be calculated --- this is known as forward kinematics. Alternatively, in an inverse
kinematic analysis, the trajectory of P is given and the joint coordinates are found by solving the previous
expressions from GetFrameMotion.
Once the joint coordinates are known, the motor torques required to produce the motion can be found by
solving the dynamic equations. This is known as inverse dynamics. In a forward dynamics problem, the
torques are given and the dynamic equations are numerically integrated to get the dynamic response (see
forward dynamic simulations in the projectile and spinning top examples).
Start by prescribing the joint motions and numerical values for the system parameters:
| > | beta_1:= t->Pi*t^2; beta_2:= t->Pi*t^2; # both angles traverse 180 degrees in 1 second.
L3:= 1: L4:= 1: L5:= 1: L6:= 1: |
| > | plot([beta_1(t),diff(beta_1(t),t)],t=0..1,legend=["beta_1","beta_1_dot"]); |
We now have enough information to solve the forward kinematics problem for the trajectory of P,
which is seen to spiral in towards the first joint axis:
| > | plot([map(eval,xP(t)),map(eval,yP(t)),t=0..1],scaling=constrained); |
For dynamics problems, we also need values for masses, moments of inertia, and gravity. Once they
are known, the torques can be obtained from the dynamic equations. Since the torques appear linearly
in the dynamic equations (see vF, above), a linear solver (solve) is all that is needed.
| > | m1:= 1: m2:= 1: I1:= 1: I2:= 1: G:= 10: |
| > | Torque1:= solve(GetDynEQs()[1],T1); |
| > | Torque2:= solve(GetDynEQs()[2],T2); |
![]()
![]()
![]()
| > | plot([Torque1,Torque2],t=0..1,legend=["Torque 1","Torque 2"]); |
In the first part of the response, centripetal effects are small because of small angular speeds. Thus,
the static weight and constant angular acceleration terms dominate. In the latter part of the response,
the increasing angular speeds begin to affect the required driving torques through the centripetal
acceleration terms.
| > |
References
In this example, the dynamic equations are generated for the 3-dimensional motion of
a spinning top. The equations are numerically integrated to obtain a simulation of the
complex motions.
Description
The base of the top is assumed to remain stationary at the origin O; this assumption is
enforced by a spherical joint between the ground and the rigid spinning body. The 3-D
rotational motion of the top is represented using 3-1-3 Euler angles: ζ for precession
about Z, η for nutation about the rotated x frame, and ξ for spin about the body's axis of
symmetry. Gravity acts through the center of mass C, located a distance L from O.
Concepts
Modeling
You can launch this ModelBuilder example from the Maplesoft web site by clicking here.
Alternatively, if you have installed DynaFlexPro and this User's Manual on your computer
(automatically put in Maple 10 toolbox directory), you can un-comment the next line to
launch this DynaFlexPro ModelBuilder example:
| > | #DynaFlexPro:-BuildModel("Examples/SpinTop.mb"): |
In this example, the rigid body is connected to the ground by a spherical
(ball-and-socket) joint, so that the base of the top remains stationary.
As shown in the spherical joint properties below, 3-1-3 Euler angles are used to
represent the three rotations in the spherical joint. Since the joint is selected into
the tree, the final equations will be in terms of ζ, η, and ξ.
The spherical joint connects the Ground frame to the body-fixed Base frame on
the rigid body. From the system description, the Base frame is -L units along the
body-fixed z axis from the center of mass.
The top itself has a mass m, a moment of inertia C about the z spin axis, and
a moment of inertia A about the two transverse axes through the joint center.
Using the parallel-axis theorem, the moment of inertia about x and y through
the center of mass is A - m
After specifying the gravity vector, the model can be exported to the file "SpinTop.dfp".
| > | restart; |
| > | with(DynaFlexPro); |
![]()
After loading the DynaFlex package, BuildEQs generates the system equations from the given input
file, with Simplify applied to the resulting dynamic equations:
| > | Model:= BuildEQs("Examples/SpinTop.dfp",["DynSimpType", "Simplify"]): |
![]()
![]()
The governing equations comprise 3 nonlinear ODEs in terms of the selected coordinates. Explicit
expressions for the mass matrix and right-hand-side vector are as follows:
| > | Model:-xM; |
| > | Model:-vF; |
](images/v13 Example Problems_161.gif)
![]()
![]()
![]()
![]()
](images/v13 Example Problems_166.gif)
](images/v13 Example Problems_167.gif)
A simpler, alternative set of equations will be generated for the same example, by using
angular velocity components in place of the Euler angle derivatives. This is accomplished
by selecting the angular velocity option in the spherical joint properties, as shown below.
The dynamic equations will now be written in terms of ζ, η, and ξ, and the three components
of the angular velocity vector associated with the spherical joint. It is generally best to
resolve these components in the End frame, i.e. the frame attached to the moving rigid
body, since the inertia matrix is a constant in this body-fixed frame.
The new model is exported to the file "SpinTopOmega.dfp", which is passed to the BuildEQs command:
| > | ModelOmega:= BuildEQs("Examples/SpinTopOmega.dfp",["DynSimpType", "Simplify"]): |
![]()
![]()
The mass matrix and right-hand-side vector are considerably simplified by this approach:
| > | map(simplify,ModelOmega:-xM); |
| > | ModelOmega:-vF; |
](images/v13 Example Problems_179.gif)
![]()
![]()
![]()
![]()
![]()
In order to solve the nonlinear system equations, the transformation from angular velocity components to
Euler angle derivatives is needed, so that the latter can be numerically integrated. This transformation is
obtained from the GetKinTrans function:
| > | ModelOmega:-GetKinTrans(); |

![]()
![]()
![]()
With all Euler angle representations, there is a mathematical singularity. In this case, it is obvious that the
singularity will occur when sin(η) = 0.
Simulation
The BuildSimCode command is used to generate an optimized Maple procedure (pXdot) that
computes the time derivatives (Xdot) of the state variables. These nonlinear differential equations
are numerically integrated using dsolve/numeric, given that the top is released from a horizontal
position (spin axis parallel to -Y) with a spin rate of 10 rad/s. Numerical values for the system
parameters are passed as arguments to BuildSimCode:
| > | BuildSimCode(Model,{"Xdot"}, "MapleProc", "Optimize",[L=1, m=1, A=2, C=1, G=9.8]): |
| > | odeVars := convert(convert(Model:-vX,Vector),list);
eulerICs := array([0,0,10,0,Pi/2,0]); |
| > | tr := time():
Soln := dsolve(numeric, implicit=false, procedure=pXdot, abserr = 1e-8, relerr=1e-7, start=0, initial=eulerICs, output=listprocedure, procvars= odeVars, range=0..10): Time_to_integrate := time()-tr; |
Note that the simulation is much faster than real time, i.e. the CPU time is significantly less
than the 10s of simulated time. As expected, the motion of the top is cuspidal:
| > | plots[odeplot](Soln, [t,odeVars[5]*180/Pi],0..10, refine=1, title= "Nutation (deg) versus Time", labels = ["time (s)", "eta (deg)"]); |
| > | L:=1: |
| > | plots[odeplot](Soln, [Model:-GetFrameMotion("r", "CoM", "Ground", "Ground")[1],Model:-GetFrameMotion("r", "CoM", "Ground", "Ground")[2],Model:-GetFrameMotion("r", "CoM", "Ground", "Ground")[3]],t=0..10, refine=1, labels=["x","y","z"], axes=framed, title="3D Motion of Center of Mass"); |
The numerical simulations are repeated, this time using the governing equations in terms
of angular velocity components:
| > | BuildSimCode(ModelOmega,{"Xdot"}, "MapleProc", "Optimize",[L=1, m=1, A=2, C=1, G=9.8]): |
| > | odeVars := convert(convert([ModelOmega:-vX],Vector),list);
omegaICs := array([0,0,10,0,Pi/2,0]); |
| > | tr := time(): |
| > | Soln := dsolve(numeric, implicit=false, procedure=pXdot, abserr = 1e-8, relerr=1e-7,
start=0, initial=omegaICs, output=listprocedure, procvars= odeVars, range=0..10): |
| > | Time_to_integrate := time()-tr; |
The simulation is usually faster using angular velocity components, since the governing equations are
more simple. Of course, the predicted motion of the top is the same in both cases:
| > | plots[odeplot](Soln, [ModelOmega:-GetFrameMotion("r", "CoM", "Ground", "Ground")[1],ModelOmega:-GetFrameMotion("r", "CoM", "Ground", "Ground")[2],ModelOmega:-GetFrameMotion("r", "CoM", "Ground", "Ground")[3]],t=0..10, refine=1, labels=["x","y","z"], axes=framed, title="3D Motion of Center of Mass"); |
| > |
References
In this example, a two-dimensional slider-crank mechanism is modeled. The
objective is to derive the kinematic and dynamic equations governing the motion
of this common mechanism.
Description
As shown in the Figure above, the crank has a mass m1 (and length L1), while
the connecting rod has a mass m2 (and length L2). Gravity in the -Y direction
is included, as is the force F acting on the piston. The equations will be generated
in the 3 joint coordinates [θ,β,s]. Since the system has only 1 degree of freedom,
2 algebraic constraint equations will be generated for these 3 coordinates, in
addition to the 3 dynamic equations.
Concepts
Modeling
You can launch this ModelBuilder example from the Maplesoft web site by clicking here.
Alternatively, if you have installed DynaFlexPro and this User's Manual on your computer
(automatically put in Maple 10 toolbox directory), you can un-comment the next line to
launch this DynaFlexPro ModelBuilder example:
| > | #DynaFlexPro:-BuildModel("Examples/Slider2d.mb"): |
ModelBuilder is used to quickly create a system model, as shown below. Joints A, B, and
C are revolute joints with axes parallel to Z, while Joint D is a prismatic joint with its axis
parallel to X.
To get the equations generated in the desired set of coordinates [θ,β,s], the corresponding
joints A, C, and D are selected into the trees for translation and rotation. This is confirmed by
viewing the R-tree from the View menu, as shown below.
The main difference between this example and the previous examples is that one joint must
be left out of the tree, in this case Joint B. The algebraic constraint equations will correspond
to closure of the kinematic loop at this joint, and the constraint force terms in the dynamic