Multibody System Dynamics
Multibody System Dynamics
We will review
Scalar product
Vector product
Skew-symmetric form associated to Linear application
the cross product
Angular velocity properties follow Fig.: Differential geometry of the derivative of a rotating vector: Angular velocity
and
Comparing both
Showing how to get ang. vel. components from the rotation or base change matrix components
Same idea using rotation matrix
Exercise
Exercise
Exercise
Analytical Kinematics - Problem 2
Analyst work
Example: Problem #2
Abstraction
Set of generalized coordinates
Set of parameters
Analytical Kinematics: Constraint equations
Coordinates, velocity and acceleration, level eqs.
Coordinate level eq
J in contact with the ground (height is null)
Example: Problem #2
Abstraction
2. Velocity level eqs must be satisfied by , used to obtain a set of constrained velocities
Nonlinear problem in
Linear problem in
Linear problem
Example: Problem #2
Example: Problem #2
In the classroom, we’ve worked with Problem #2:
Parametrization, Bases, Points and Frame definition, and
setup of the constraint equations at the coordinate, velocity
and acceleration levels.
We’ve done this by hand and using the library.
Lib_3D_MEC_MATLAB
Lib_3D_MEC_MATLAB Manual:
The final slides in this set is a short manual on how to use the library, and are
based on this example.
For the different algorithms or problems in MBSD that we are going to present in these slides,
we will explain symbolic determination of required functions, export of these functions and
numerical implementation of the algorithms using MATLAB with Lib_3D_MEC_MATLAB
naming conventions.
We’ll do it in the slides using Problem #2, because it is general enough as to guide us
throughout the different algorithms that we are going to review.
Hopefully these slides will help you to go through MBSD problem implementation and
solution using MATLAB and Lib_3D_MEC_MATLAB within and beyond the scope of the
methods and algorithms that we are going to review.
Example: Problem #2 Parameterization
Do_you_want_to_run_the_script_again
%% Clean environment
close all
clear all Library Initialization
clc
%----Begin Edit----
g = newParam('g', 9.80665);
GravityVector = Vector3D([0, 0, - g]
','xyz');
%Integration step
Delta_t = 0.003;
simplify_expressions = true;
%----End Edit----
newFrameDraw('abs', 1);
newFrameDraw('Slider', 1);
newFrameDraw('Arm', 1);
newFrameDraw('Disc', 1);
camlight('headlight');
material('dull');
Example: Problem #2 Parameterization
%% Draw Sketch of Parametrization
if exist('./draw_dimensions.m', 'file') Draw Parameterization
%% Draw Dimensions
save_extended_state(
'extended_state_parametrization'
camproj('perspective');
);
Advanced!!
view([78.5263671875, 13.61328125]);
camtarget([- 0.328233934776823, 0.419858424492971, 1.673164190664704])
camva(8);
draw_dimensions;
setDrawTextSize(0.033)
load_extended_state(
'extended_state_parametrization'
);
Help(['Graphical Output shows the parametrization.'
, newline 'The situation is as-given (no Assembly or Initial Assembly
problem solved)']);
delete(dimensions_handle);
camproj('orthographic');
else
Warning('You need to provide dimension drawing instructions on ''./draw_dimensions.m'' file'
);
end
Exercise: Problem #1 Parameterization
Parameterize and determine constraint equations
scad2stl('Mast', 'Mast', 'r_out', size_rod, 'height', 2.25, 'size_x', 1.5 * size_guide, 'size_y', size_guide, 'size_z', size_z);
Mast = newSolid('Mast', 'Mast', 'Mast.stl', rho);
scad2stl('Arm', 'Arm', 'rod_r', size_rod, 'r_in', size_rod, 'r_out', 2 * size_rod, 'height', 0.6, 'l', 5, 'd', 2.1);
Arm = newSolid('Arm', 'Arm', 'Arm.stl', rho);
scad2stl('Gr', 'Gr', 'size_x', Get_value(4 * l), 'size_y', Get_value(2 * l), 'size_z', size_z, 'size_guide', size_guide)
newSolidExt('Gr', 'abs', 'Gr.stl');
No cylinder translation
/rotation required because
cylinder is naturally drawn
from the origin in the +Z axis
We will review
Annex
Assembly Problem @ coordinate level
Coordinate Level (geometric eqs.)
Newton-Raphson iteration
e_Bpsi_3=Vector3D([0,0,1]','Bpsi');
expression Phi
% Phi, dPhiH
newPhi(dot(Pos('O','J'),e_Bpsi_3),true);
Generic code
where therefore
Vel_J_Disc=Vel('abs','J','Disc')
% Phi, dPhiH
newdPhiNH([dot(Vel_J_Disc,e_Bpsi_1);... expresion dPhiNH
dot(Vel_J_Disc,e_Bpsi_2)],true);
Generic code
Exercise: You cannot see graphically if velocity level constraints are satisfied. Unless you draw velocities. Drawing
before calling assembly_problem will help, as it will disappear ( ) as soon as the velocity
level eqs. get satisfied. If not done already, find the lines drawing that vector and execute them before solving
assembly problem. Have you seen how disappears?
Initial Assembly Problem @ coordinate level
Problem #2
psi0=newParam('psi0',0);
h0=newParam('h0',0.5);
expresion PhiInit
newPhiInit([psi-psi0;
h-h0],true);
Generic code
dpsi0=newParam('dpsi0',3);
expression dPhiInit
newdPhiInit([dpsi-dpsi0],true);
Generic code
Exercise: Can you see any other differences?. Clue, what in the hell are the _aux?
Initial Assembly Problem (another algorithm)
Think twice: It makes sense for the initial conditions to be satisfied with some error. Think, for instance, that the user of
your software is introducing too many conditions leading to an incompatible system of equations. But still you want for the
solution to satisfy exactly the constraint equations. How would you solve the problem?.
A possibility would be to use a minimization with constraints, such as the Lagrange multipliers minimization approach or
fmincon in MATLAB optimization toolbox. You will use the initial conditions to define the optimum function to be
minimized, while the constraints equations will be coincident with the constraints in this minimization setup.
Advanced
Where
Is the so called weighting matrix (positive definite in general, but most frequently diagonal)
MATLAB’s Optimization Toolbox fmincon has a stack of algorithms that allows to do such a constrained minimization.
Even using inequality type constraints that can be helpful in a number of situations.
Advanced
Auxiliar Assembly Problem
Sometimes we have auxiliary constraints, constraints that are somehow different to standard constraints.
1. For example, in contact problems they can be used to locate the contact point and determine normals and
tangents to the contact plane. This may require the definition of additional coordinates.
2. Also, when using 4 parameters to parametrize a general tridimensional rotation, such as Euler parameters,
Advanced
quaternions, and related rotation parametrizations. A constraint must be satisfied among the 4 parameters,
because a general rotation has only 3 degrees of freedom.
Generally, these auxiliary constraints need to be solved only @ the position and velocity levels. Also generally,
acceleration level constraints do not need to be considered at the dynamics solution procedure.
% Auxiliar Assembly Problem (Coordinate Level) % Auxiliar Assembly Problem (Velocity Level)
PhiAux_num = PhiAux_(q_value,t_value,param_value); dPhiAux_dq_num=dPhiAux_dq_(q_value,t_value,param_value);
while norm(PhiAux_num)> Geom_Eq_tol dq_value=dq_value + pinv(
q_value = q_value - Geom_Eq_relax * pinv( dPhiAux_dq_num ) * (beta_aux_(q_value,t_value,param_value) -
dPhiAux_dq_num * dq_value);
PhiAux_q_(q_value,t_value,param_value) ) * PhiAux_num;
PhiAux_num = PhiAux_(q_value,t_value,param_value);
end Auxiliar Assembly problem is solved before and not together
with Assembly Problem (it could be possible but slower)
% Initial Assembly Problem (Coordinate Level) % Initial Assembly Problem (Velocity Level)
function_num=[Phi_(q_value,t_value,param_value); jacobian_num=[dPhi_dq_(q_value,t_value,param_value);
PhiInit_(q_value,t_value,param_value); dPhiInit_dq_(q_value,t_value,param_value);
PhiAux_(q_value,t_value,param_value)]; dPhiAux_dq_(q_value,t_value,param_value)];
while norm(function_num)> Geom_Eq_init_tol dq_value=dq_value + pinv( jacobian_num ) *
q_value = q_value - Geom_Eq_init_relax * pinv( ([beta_(q_value,t_value,param_value);
[Phi_q_(q_value,t_value,param_value); betaInit_(q_value,t_value,param_value);
PhiInit_q_(q_value,t_value,param_value); beta_aux_(q_value,t_value,param_value)] -
PhiAux_q_(q_value,t_value,param_value)] ) * jacobian_num * dq_value);
function_num;
function_num=[Phi_(q_value,t_value,param_value); Initial Auxiliar Assembly problem, assembled with constraint
PhiInit_(q_value,t_value,param_value); and initial condition equations, and solved together
PhiAux_(q_value,t_value,param_value)];
end
Symbolic Modeling. Recursivity.
%% Define Solids
%----Begin Edit----
rho = 7850;
newSolid('Sol1', 'O1B1', 'Sol1.stl', rho);
newSolid(...);
%----End Edit----
Rotated vector
Rotation Tensor
Alternate expression
Angle-Axis rotation specification
The 3 components of the vector (axis) The constraint between parameters becomes
*
Alternate expression
Advanced
Exponential map
The rotation matrix can also be expressed as:
Advanced
For a constant rot axis
Note that the argument of the exponential is a matrix, and therefore this is a
matrix exponential. This is the, so called, Exponential Map:
SO(3), is the so-called 3-dimensional special orthogonal group, is a collection of matrices. The word orthogonal
means that the columns of the matrix are orthogonal to one another, and the word special means the matrices have
to have determinant 1.
The eigenvector of the rotation matrix corresponding to the eigenvalue 1, is the
rotation direction
Special Orthogonal Group SO(3), Euler Angles, Angle-axis, Rodriguez Vector and Unit-Quaternion: Overview, Mapping and Challenges
Hashim A. Hashim
arXiv:1909.06669v2 [math.OC]
Euler Rodrigues formula from the exponential map
Advanced
Example: Simple or Basic Rotation revisited
Based on
1 2
Making one obtains the same results :
1.- Note that:
and
and
2.- Note that also:
Obviously, base change matrix can be computed using the same formula:
Advanced
preferred in a symbolic setup
where
* & **, used for of rotations
% Base defined using Euler parameters defined in terms of Euler
newBase('xyz','BBody',[e0,e1,e2,e3]') parameters
Euler Parameters: Quaternions
Note that Euler parameters are the equivalent to the components of unit quaternions frequently used to
describe rotations.
So, the only important think about quaternions is not the parametrization, because is the same than for
Euler parameters, but the special algebra that they offer: composition of rotations using quaternions,...
Lib_3d_MEC Does not implement quaternion algebra, but any rotation elsewhere defined using
quaternions can implemented defining the rotations by the way of Euler parameters, that are
implemented in Lib_3D_MEC
Advanced
Freshen Up Dynamics
Action enter the dynamics of solids through their resultant forces and
moments
Note: These are frequently referred as D’Alembert inertia force and moment
Constraint force and moment characterization
First notice that, for a body, the pair angular velocity + velocity of one of its points (so called Twist)
completely determine its motion.
Second, that the Twist can be defined w.r.t. any of the points of the body.
Constraints exactly remove a number of d.o.f. of a body w.r.t. the body to which it’s joined, by the
way of unknown forces and moments.
“If for a given point and orientation, fixed to one of the bodies, the twist is so that the
non-zero components are independent translational and rotational velocities, then:
For each null translational or rotational component of the twist, there is a
corresponding force moment component for a constraint wrench referred to the same
point.”
% Slider->Arm
[FC_Slider_Arm,
MC_Slider_Arm_A]=newConstraint_Force_Moment([1,1,1],[1,0,1],'A','Bpsi','Arm','Slider')
% Arm->Disc
[FC_Arm_Disc, MC_Arm_Disc_C]=newConstraint_Force_Moment([0,1,1],[0,1,1],'C','Btheta','Disc','Arm') epsilon =
% Ground->Disc FC_Gr_Slider_1
[FC_Gr_Disc, MC_Gr_Disc_J]=newConstraint_Force_Moment([1,1,1],[0,0,0],'J','Bpsi','Disc','Gr') FC_Gr_Slider_2
%----End Edit---- MC_Gr_Slider_1
epsilon, n_epsilon MC_Gr_Slider_2
FC_Slider_Arm_1
Output Output FC_Slider_Arm_2
FC_Slider_Arm_3
MC_Slider_Arm_1
FC_Gr_Slider = MC_Slider_Arm_3
FC_Arm_Disc_2
FC_Gr_Slider_1
FC_Arm_Disc_3
FC_Gr_Slider_2
0 MC_Arm_Disc_2
'Bpsi' Helper functions automatically define joint MC_Arm_Disc_3
FC_Gr_Disc_1
MC_Gr_Slider_A = constraint variables FC_Gr_Disc_2
FC_Gr_Disc_3
MC_Gr_Slider_1
MC_Gr_Slider_2 n_epsilon =
0
'Bpsi'
16
FV_Gr_Disc =
0
0
0
% Constitutive 'Bpsi'
%----Begin Edit---- Output
% Visc Ground-ous>Disc (rolling) MV_Gr_Disc_J =
c_Gr_Disc=newParam('c_Gr_Disc',10.0);
c_Gr_Disc*(dtheta*sin(psi) + dphi*cos(psi)*cos(theta))
FV_Gr_Disc=Vector3D([0,0,0]','Bpsi'); -c_Gr_Disc*(dtheta*cos(psi) - dphi*cos(theta)*sin(psi))
MV_Gr_Disc_J=-Omega('abs','Disc')*c_Gr_Disc; -c_Gr_Disc*(dpsi + dphi*sin(theta))
_'xyz'
% Spring-Damper Ground->Slider
k_Gr_Slider =newParam('k_Gr_Slider',900);
rho0=newParam('rho0',1); Output FSD_Gr_Slider =
c_Gr_Slider=newParam('c_Gr_Slider',30);
0
FSD_Gr_Slider=Vector3D([0,0,-k_Gr_Slider*(h-rho0)-c_Gr_Slider*dh]','Bpsi'); 0
MSD_Gr_Slider_A=Vector3D([0,0,0]','Bpsi'); - c_Gr_Slider*dh - k_Gr_Slider*(h -
%----End Edit---- rho0)
'Bpsi'
MSD_Gr_Slider_A =
0
0
0
'Bpsi'
% Gravity
%----Begin Edit----
% Slider
FG_Slider=Vector3D([0,0,-m_Slider*g]','Bpsi');
MG_Slider_G_Slider=Vector3D([0,0,0]','Bpsi');
% Arm
[FG_Arm, MG_Arm_G_Arm]=newGravity_Force_Moment('Arm','G_Arm');
% Note that moment is defined in the solids frame origin
% Disc
[FG_Disc, MG_Disc_G_Disc]=newGravity_Force_Moment('Disc','G_Disc');
%----End Edit----
% Inertia
%----Begin Edit----
% Slider
FI_Slider=-m_Slider*Accel('IF','G_Slider');
h_Slider_A=I_Slider_A*Omega('IF','Slider');
MI_Slider_A=-(timederivative(h_Slider_A,'IF')+m_Slider*cross(Pos('A','G_Slider'),Accel('IF','A')));
% Arm
[FI_Arm,MI_Arm_A]=newInertia_Force_Moment('Arm')
% Disc
[FI_Disc,MI_Disc_C]=newInertia_Force_Moment('Disc')
%----End Edit----
%% Newton-Euler Dynamic Equations
% using Forces and Moments
%----Begin Edit----
% Slider
Sum_Forces_Slider= FI_Slider+FG_Slider+FC_Gr_Slider-FC_Slider_Arm+FSD_Gr_Slider;
Sum_Moments_Slider_A= MI_Slider_A+(MG_Slider_G_Slider+cross( Pos('A','G_Slider') ,
FG_Slider))+MC_Gr_Slider_A-MC_Slider_Arm_A+MSD_Gr_Slider_A;
% Arm
AC=Pos('A','C');
AG_Arm=Pos('A','G_Arm');
Sum_Forces_Arm= FI_Arm+FG_Arm+FC_Slider_Arm-FC_Arm_Disc;
Sum_Moments_Arm_A= MI_Arm_A+(MG_Arm_G_Arm+cross(AG_Arm,FG_Arm))+MC_Slider_Arm_A-(MC_Arm_Disc_C + cross ( AC ,FC_Arm_Disc) );
% Disc
CG_Disc=Pos('C','G_Disc');
CJ=Pos('C','J');
Sum_Forces_Disc= FI_Disc+simplify(FG_Disc)+FC_Gr_Disc+FV_Gr_Disc+FC_Arm_Disc;
Sum_Moments_Disc_C= MI_Disc_C+(MG_Disc_G_Disc+cross(CG_Disc,FG_Disc))+(MC_Gr_Disc_J+cross( CJ , FC_Gr_Disc)) + (MV_Gr_Disc_J +
cross ( CJ , FV_Gr_Disc) ) + MC_Arm_Disc_C;
%----End Edit----
%% Newton-Euler
%----Begin Edit----
newDyn_eq_NE([Sum_Forces_Slider;
Sum_Moments_Slider_A;
Sum_Forces_Arm;
Sum_Moments_Arm_A;
Sum_Forces_Disc;
Sum_Moments_Disc_C]);
%----End Edit----
%So mass matrix is positive definite
Dyn_eq_NE=-Dyn_eq_NE; %
%Dyn_eq_NE=simplify(Dyn_eq_NE);
Wrench: The couple, force/moment acting on a body w.r.t. one of its points. It is a 6D
vector.
Where the scalar (inner) product is defined to produce power. With components
Sum of wrenches: The sum of two wrenches defined w.r.t. the same point, represent, the wrench
corresponding to the set of forces associated to both wrenches. Multiplying a set of forces by a constant has
associated the wrench of the original set times the constant. Wrenches are a vector space.
Sum of twists: The sum of two twist defined w.r.t. the same point, represent, the twist of a body undergoing
the sum of both translational and both rotational velocities. Multiplying the velocities of the particles of a
rigid body by a constant the twist becomes that the initial twist times the constant. Twists are a vector
space.
Screws: Twist and Wrenches
A twist fully characterizes the the motion of a rigid body. Using velocity composition
So, if the point B used to define the twist is changed to B’, we can define the new twist in
terms of the old one one. Therefore, to refer a twist to a new point:
note: and
A wrench fully characterizes the effect of a system of forces on the dynamics of a rigid
body. We know that the moment of a system of forces can be “translated” as:
So, if the point B used to define the wrench is changed to B’, we can define the new wrench
in terms of the old one. Therefore, to refer a wrench to a new point:
note: and
So, the change of point of reference is accomplished in the same way for any screw, for
either twist or wrenches
We can do addition of two screws, product by an scalar, and scalar product. In order to do these operations both
screws must be referred to the same point, and the previous translation tensor (in 6D Vector Space) becomes
handy. A class of 6D Vectors (screws) can be defined to work following the rules defined. Just in the same way that
a class of 3D Vectors was defined in order to follow the rules of the 3D euclidean space vectors in mechanics.
Screws: Kinetic Energy
Given the Twist:
Where
is the generalized momenta of the solid, for the given twist velocity components. It
takes a specific form a soon as bases are chosen to express twist as a 6-tuple, Given
bases we define
Defining, the generalized twists velocity tuple as the -tuple , the system kinetic energy
Analogously, the kinetic energy w.r.t. the generalized velocity pair , with
Finally, the kinetic energy w.r.t. the generalized velocity couple , with
Screws: Twist and Wrenches. Implementation
We can do addition of two screws, product by an scalar, an scalar product. In order to do these operation both
screws must be referred to the same point, and the previous translation tensor (in 6D Vector space) becomes
handy. A class of 6D Vectors (screws) can be defined to work following the rules defined. Just in the same way
that a class of 3D Vectors was defined in order to follow the rules of the 3D euclidean space in mechanics.
% Vector6D Class definition
classdef (InferiorClasses = {?sym}) Vector6D
properties
FW %Force or Omega: a vector 3D
Class Def. MV %Moment or Velocity: a vector 3D
Point %Reference Point: name or point number
Action %Solid over which twist or wrench is defined: name or solid number
Reaction %Solid from which the action is coming or frame w.r.t. which the twist is defined
end
Methods
...
% Basic construction of objects
% Twist
v_B_SolB=Vector3D(...
omega_SolB=Vector3D(...
twist_SB=Vector6D(omega_SolB, v_B_SolB, 'B','SolB')
Examples
% Wrench
F_SolA_SolB=Vector3D(...
M_SolA_SolB_B=Vector3D(...
wrench_SA_SB=Vector6D(F_SolA_SolB, M_SolA_SolB_B, 'B','SolB')
%Helper functions
Twist_SolB = Twist('SolB');
WrenchIG_SolB=newInertia_and_Gravity_Wrench('SolB');
% Operations
dW_wrench_SA_SB_dtheta=dot( jacobian(twist_SB, dtheta), wrench_SA_SB )
...
Vector Theorems or Newton-Euler Eqs.
Linear momentum theorem
Constraint Actions
%% Wrench Definition
%----Begin Edit----
% Constraint Wrenches (Definition using helper function newConstraint_Wrench)
% Ground->Slider
Wrench_Gr_Slider=newConstraint_Wrench([1,1,0],[1,1,0],'A','Bpsi','Slider','Gr');
% Slider->Arm
Wrench_SliderArm=newConstraint_Wrench([1,1,1],[1,0,1],'A','Bpsi','Arm','Slider');
epsilon =
% Arm->Disc
Wrench_ArmDisc=newConstraint_Wrench([0,1,1],[0,1,1],'C','Btheta','Disc','Arm');
FC_Gr_Slider_1
FC_Gr_Slider_2
% Ground->Disc
MC_Gr_Slider_1
Wrench_Gr_Disc=newConstraint_Wrench([1,1,1],[0,0,0],'J','Bpsi','Disc','Gr');
MC_Gr_Slider_2
%----End Edit----
FC_Slider_Arm_1
epsilon, n_epsilon
FC_Slider_Arm_2
FC_Slider_Arm_3
Output Output MC_Slider_Arm_1
MC_Slider_Arm_3
Important things to note: they are defined in terms of constraint FC_Arm_Disc_2
Wrench_Gr_Slider =
variables/unknowns FC_Arm_Disc_3
MC_Arm_Disc_2
FGrSlider1 MC_Arm_Disc_3
FGrSlider2 These variables are unknowns along with the generalized
FC_Gr_Disc_1
0 coordinates in the direct dynamics problem FC_Gr_Disc_2
'Bpsi' FC_Gr_Disc_3
MGrSlider1
Helper functions automatically define joint constraint
MGrSlider2 n_epsilon =
0
variables/unknowns
'Bpsi' 16
'A'
Characterization of Actions (Wrench)
Constitutive Actions
% Constitutive
%----Begin Edit----
% Viscous Ground->Disc (rolling)
c_Gr_Disc=newParam('c_Gr_Disc',10.0);
Output WrenchV_GrDi =
FV_Gr_Disc=Vector3D([0,0,0]','Bpsi');
0
MV_Gr_Disc_J=-Omega('abs','Disc')*c_Gr_Disc;
0
WrenchV_GrDisc=newWrench(Vector6D(FV_Gr_Disc,MV_Gr_Disc_J,'J'),'Dis,’Gr’c')
0
'Bpsi'
c_Gr_Disc*(dtheta*sin(psi) +dphi*cos(psi)*cos(theta))
-c_Gr_Disc*(dtheta*cos(psi) -dphi*cos(theta)*sin(psi))
% Spring-Damper Ground->Slider
-c_Gr_Disc*(dpsi + dphi*sin(theta))
k_Gr_Slider =newParam('k_Gr_Slider',900);
'xyz'
rho0=newParam('rho0',1);
'J'
c_Gr_Slider=newParam('c_Gr_Slider',30);
FSD_Gr_Slider=Vector3D([0,0,-k_Gr_Slider*(h-rho0)-c_Gr_Slider*dh]','Bpsi');
MSD_Gr_Slider_A=Vector3D([0,0,0]','Bpsi');
WrenchSD_Gr_Slider=newWrench(Vector6D(FSD_Gr_Slider,MSD_Gr_Slider_A,'A'),'Slider','Gr') WrenchSD_Gr_Slider =
%----End Edit----
0
Output 0
-c_Gr_Slider*dh -k_Gr_Slider*(h -rho0)
'Bpsi'
0
0
0
'Bpsi'
'A'
Characterization of Actions (Wrench)
% Gravity + Inertia
%----Begin Edit----
% Gravity Gravity Actions
% Slider
% WrenchG_Chassis=newGravity_Wrench('Slider');
% Arm
% WrenchG_Wheel_L=newGravity_Wrench('Arm');
% Disc
% WrenchG_Wheel_R=newGravity_Wrench('Disc');
% Previous wrench definitions commented because they are defined along with inertia forces.
% Arm
% WrenchI_Wheel_L=newInertia_Wrench('Arm');
% Disc
% WrenchI_Wheel_R=newInertia_Wrench('Disc');
% Arm
WrenchIG_Arm=newInertia_and_Gravity_Wrench('Arm');
% Disc
WrenchIG_Disc=newInertia_and_Gravity_Wrench('Disc');
%----End Edit----
Dynamic Equations
Newton-Euler Formalism (Wrench)
%% Newton-Euler Dynamic Equations
Automatizable
% using Forces and Moments
%----Begin Edit----
% Slider
Sum_Wrenches_Slider_NE= WrenchIG_Slider+Wrench_Gr_Slider-Wrench_SliderArm+WrenchSD_Gr_Slider;
% Arm
Sum_Wrenches_Arm_NE= WrenchIG_Arm+Wrench_SliderArm-Wrench_ArmDisc;
% Disc
Sum_Wrenches_Disc_NE= WrenchIG_Disc+Wrench_Gr_Disc+WrenchV_GrDi+Wrench_ArmDisc;
%----End Edit----
% Arm
AC=Pos('A','C'); Prone to Error
AG_Arm=Pos('A','G_Arm');
Sum_Forces_Arm= FI_Arm+FG_Arm+FC_Slider_Arm-FC_Arm_Disc;
Sum_Moments_Arm_A= MI_Arm_A+(MG_Arm_G_Arm+cross(AG_Arm,FG_Arm))+MC_Slider_Arm_A-(MC_Arm_Disc_C + cross ( AC
,FC_Arm_Disc) );
% Disc
CG_Disc=Pos('C','G_Disc');
Sum_Forces_Disc= FI_Disc+simplify(FG_Disc)+FC_Gr_Disc+FV_Gr_Disc+FC_Arm_Disc;
Sum_Moments_Disc_C= MI_Disc_C+(MG_Disc_G_Disc+cross(CG_Disc,FG_Disc,'Bphi'))+(MC_Gr_Disc_J+cross( CJ ,
FC_Gr_Disc)) + (MV_Gr_Disc_J + cross ( CJ , FV_Gr_Disc) ) + MC_Arm_Disc_C;
%----End Edit----
Dynamic Equations
Newton-Euler Formalism (Wrench)
%% Newton-Euler
%----Begin Edit----
newDyn_eq_NE([Sum_Wrenches_Slider_NE;
Sum_Wrenches_Arm_NE;
Sum_Wrenches_Disc_NE])
%----End Edit----
%So mass matrix is positive definite
Dyn_eq_NE=-Dyn_eq_NE; % Dyn_eq_NE=simplify(Dyn_eq_NE);
Helper function:
newDyn_eq_NE([eqs_1;
eqs_2;
...
]);
Direct Dynamics Problem with Newton Euler Equations
Mass matrix
(not square in NE formalism)
delta_v=subs(Dyn_eq_NE,epsilon,sym(zeros(size(epsilon))));
delta_v=-subs(delta_v,ddq,zeros(size(ddq)));
FC_vepsilon=-jacobian(Dyn_eq_NE,epsilon);
matlabFunction(FC_vepsilon,'File','FC_vepsilon_','Vars',{q,t,param});
matlabFunction(M_vq,'File','M_vq_','Vars',{q,t,param});
matlabFunction(delta_v,'File','delta_v_','Vars',{q,dq,t,param});
Direct Dynamics Problem:
Newton-Euler formalism
Generalized accel.
Generic code
coeff_matrix_A=...
[M_vq_(q_value,t_value,param_value), -FC_vepsilon_value;
dPhiAux_dq_value, zeros(n_ddPhiAux,n_epsilon);
dPhi_dq_(q_value,t_value,param_value),zeros(n_dPhi,n_epsilon)];
indep_term_vector_b=
[delta_v_(q_value,dq_value,t_value,param_value);
gammaAux_(q_value,dq_value,t_value,param_value); Trick: we always export auxiliary functions
gamma_(q_value,dq_value,t_value,param_value)];
dPhi_dq_(q_value,t_value,param_value),zeros(n_dPhi,n_epsilon)]
;
indep_term_vector_b=
Don’t forget to actualize the Drawing: [delta_v_(q_value,dq_value,t_value,param_value);
gammaAux_(q_value,dq_value,t_value,param_value);
updateDraws;
gamma_(q_value,dq_value,t_value,param_value)];
unknown_vector_x=pinv(coeff_matrix_A)*indep_term_vector_b;
ddq_value=unknown_vector_x(1:n_ddq,1);
epsilon_value=unknown_vector_x(n_ddq+1:n_ddq+n_epsilon,1);
Direct Dynamics Problem. Exercise:
Newton-Euler formalism
Prerequisite: execute problem_name_W.m up to, and including, the introduction of the %% Export Direct Dynamics Problem Newton-Euler
M_vq=jacobian(Dyn_eq_NE,ddq);
dynamic equations
delta_v=subs(Dyn_eq_NE,epsilon,sym(zeros(size(epsilon))));
newDyn_eq_NE(...) delta_v=-subs(delta_v,ddq,zeros(size(ddq)));
FC_vepsilon=-jacobian(Dyn_eq_NE,epsilon);
Then, proceed as in the previous example…
matlabFunction(FC_vepsilon,'File','FC_vepsilon_','Vars',{q,t,param}
);
matlabFunction(M_vq,'File','M_vq_','Vars',{q,t,param});
The presented code to export the dynamics equations, as is general, is packaged into the matlabFunction(delta_v,'File','delta_v_','Vars',{q,dq,t,param});
script
Export_Direct_Dynamics_Problem
The presented code to solve the dynamics equations, as is general, is packaged into script
direct_dynamics_problem
In order for this script to choose the Naive NE solver the global variable
%% Naive NE Direct Dynamics Problem solution (with auxiliary
constraints)
dyn_equations_type='Newton-Euler'; dPhiAux_dq_value=dPhiAux_dq_(q_value,t_value,param_value);
coeff_matrix_A=...
So you can export and solve the the direct dynamics using the Naive NE problem as follows [M_vq_(q_value,t_value,param_value), -FC_vepsilon_value;
dPhiAux_dq_value,
Export_Direct_Dynamics_Problem zeros(n_ddPhiAux,n_epsilon);
dPhi_dq_(q_value,t_value,param_value),zeros(n_dPhi,n_epsilon)];
dyn_equations_type='Newton-Euler';
indep_term_vector_b=
direct_dynamics_problem [delta_v_(q_value,dq_value,t_value,param_value);
gammaAux_(q_value,dq_value,t_value,param_value);
gamma_(q_value,dq_value,t_value,param_value)];
unknown_vector_x=pinv(coeff_matrix_A)*indep_term_vector_b;
ddq_value=unknown_vector_x(1:n_ddq,1);
epsilon_value=unknown_vector_x(n_ddq+1:n_ddq+n_epsilon,1);
Exercise: Four-Bar Direct Dynamics Problem
% Computing k1 direct_dynamics_problem;
direct_dynamics_problem;
q_k1=Delta_t*dq_value; q_k3=Delta_t*dq_value;
dq_k1=Delta_t*ddq_value; dq_k3=Delta_t*ddq_value;
%% Dynamic Simulation
% Computing k2 % Computing k4
% Setup time step and integration span
t_value=t_value_0+Delta_t/2; t_value=t_value_0+Delta_t;
% Each time you run this section you get T_span additional time q_value=q_value_0+q_k1/2; q_value=q_value_0+q_k3;
% of simulation dq_value=dq_value_0+dq_k1/2; dq_value=dq_value_0+dq_k3;
% Velocity Actualization
dq_value=dq_value_0+1/6*(dq_k1+2*dq_k2+2*dq_k3+dq_k4);
% Open Extended State file for writing
fid = fopen('dynamics_extended_state_series.txt','w');
%% Direct Dynamics
direct_dynamics_problem;
initial_assembly_problem;
direct_dynamics problem;
%% Dynamic Simulation
% Setup time step and integration span
% Each time you run this section you get T_span additional time of
% simulation
T_span=6
t_end=Get_value(t)+T_span;
t_refresh=Get_value(t);
integrator_type=’Euler’;
dynamic_simulation(fid);
updateDraws_automatic=true;
Exercise: Four-Bar Direct Dynamics Simulation
Chapter 3 in
Virt. Power principle for a System of Particles
Principle
Systematization
Generalized forze
Virt. Power principle for a System of Bodies
Principle
Generalized forze
Example: Problem 2 (Virtual Power Principle Dynamics)
for i=1:n_q
newDyn_eq_VP( dot( Sum_Wrenches_Slider_NE , diff( Twist_Slider , dq(i) ) )+...
dot( Sum_Wrenches_Arm_NE , diff( Twist_Arm , dq(i) ) )+...
dot( Sum_Wrenches_Disc_NE , diff( Twist_Disc , dq(i) ) ) );
end
%----End Edit----
@ Export_Direct_Dynamics_Problem_NE.m unknown_vector_x=pinv(coeff_matrix_A)*indep_term_vector_b;
ddq_value=unknown_vector_x(1:n_ddq,1);
lambda_value=unknown_vector_x(n_ddq+1:n_ddq+n_lambda,1);
lambda_aux_value=unknown_vector_x(n_ddq+n_lambda+1:n_ddq+n_lambda+n_lambda_aux,1);
epsilon_value=pinv(-FC_qepsilon_(q_value,t_value,param_value))*...
Don’t forget to actualize the Drawing: updateDraws; dPhi_dq_value'*lambda_value;
@ ddq_lambda_epsilon_from_Lagrange_Naive.m
Exercise: Problem Four-Bar (Virtual Power Principle Dynamics)
%----Begin Edit----
Twist_... = Twist('...');
...
for i=1:n_q
newDyn_eq_VP( dot( ... , diff( .. , dq(i) ) ) +...
+...
+... );
end
%----End Edit----
matlabFunction(FC_qepsilon,'File','FC_qepsilon_','Vars',{q,t,param});
matlabFunction(M_qq,'File','M_qq_','Vars',{q,t,param});
matlabFunction(delta_q,'File','delta_q_','Vars',{q,dq,t,param});
Direct Dynamics Problem:
Virtual Power formalism
Set of equations
Generalized accel.
Joint unknowns
Linear in the unknowns
Mass matrix
Velocity Jacobian
All the required functions are exported when exporting the Constraint Equations and the
VP Dynamic Eqs. Then
for for
These are the so called naive/trivial solutions, much faster solution can be obtained using the Udwadia & Kabala or even faster using Independent Coordinates solution
procedures.
Equilibrium Problem
Well, we will see, that an equilibrium state can be stable, marginally stable and unstable. Meaning that if a
small perturbation is introduced to the state, the perturbation will vanish, will keep the amplitude of some
of its components, and some of its components will increase amplitude exponentially with time.
Dyn_Eq_eq_L_num=Dyn_Eq_eq_VP_(q_value,dq_value,ddq_value,t_value,lambda_value,param_value);
x_value=[q_value;
dq_value;
ddq_value;
lambda_value];
while norm(Dyn_Eq_eq_L_num)> Dyn_Eq_tol
x_value=x_value- Dyn_Eq_relax * pinv(J_Dyn_Eq_eq_L_(q_value,dq_value,ddq_value,t_value,lambda_value,param_value) ) * Dyn_Eq_eq_L_num;
q_value=x_value(1:n_q,1);
dq_value=x_value(n_q+1:2*n_q,1);
ddq_value=x_value(2*n_q+1:3*n_q,1);
lambda_value=x_value(3*n_q+1:end,1);
Dyn_Eq_eq_VP_num=Dyn_Eq_eq_L_(q_value,dq_value,ddq_value,t_value,lambda_value,param_value);
end
dPhi_dq_num=dPhi_dq_(q_value,t_value,param_value)
epsilon_value=pinv(-FC_qepsilon_(q_value,t_value,param_value))*dPhi_dq_num'*lambda_value;
Direct Dynamics Problem: Solution on Independent Coordinates
with
Direct Dynamics Problem
[ddq_value,epsilon_value,lambda_value]=ddq_lambda_epsilon_from_Lagrange
_dz(q_value, dq_value, t_value)
with
with
Advanced
dPhi_dz=dPhi_dq(row_perm,perm_dd); dPhi_dz=dPhi_dq(row_perm,perm_dz);
U_dd=U(:,perm_dd); U_dz=U(:,perm_dz)
Solving
% L*U(:,perm_dd) * dd = (beta(row_perm,:) - dPhi_dz *dz);
y=L\(beta(row_perm,:)- dPhi_dz*dz); % L * y = beta(row_perm,:) - dPhi_dz*dz;
dd=U(:,perm_dd)\y % U(:,perm_dd) * dd = y;
This is the trick for really fast implementations. ddq_lambda_epsilon_from_Lagrange_dz uses inverse because of readability/simplicity. But a
really quick implementation cannot be done using MATLAB. A C or C++ LU based (along the previous lines) implementation is recommended.
Direct Dynamics Problem: Linearization on independent coordinates
Repeating the algebraic manipulations (explained but not developed in full) shown in the previous slide, but with this
generalized linearizations instead, the linearization procedure obtained would give
M_dzdz=R'*M_dddzdddz_num*R+...
C_dzdz=R'*C_dddzdddz_num*R+...
K_dzdz=R'*K_dddzdddz_num*R+...
Therefore:
%Assembling the eigenproblem matrix (state space
form)
A=[zeros(n_dz,n_dz),eye(n_dz);
-M_dzdz^-1*K_dzdz,-M_dzdz^-1*C_dzdz];
From which we determine stability
[V,D]=eig(A)
Direct Dynamics Problem: Stability
Meaning that the linearized motion is described in terms of . The time evolution clearly shows that x and y
evolution deviates completely from the linearization point.
We conclude that we are obtaining the eigenvalues of a dynamic system that w.r.t. the independent coordinate parameterization is
not at equilibrium. And therefore those eigenvalues do not speak about stability.
Stability: a curious example
I instead we choose the partition of coordinates, so that the angular
coordinates are the independent coordinate set,
As expected, because there is no friction, with this parameterization the system is marginally stable.
The video and figures show a simulation with a small perturbation on the angle w.r.t the plane.
The complex part of the eigenvalues can be estimated from the periodic plots
of any of the independent velocities. It can be observed a perfect match with
the imaginary part of the first eigenvalue.
Stability: a curious example
I instead we choose the partition of coordinates, so that the angular
coordinates are the independent coordinate set,
General conclusion:
To determine the stability we require to do linearization w.r.t a set of independent coordinates that do not change while at the
equilibrium point used for the linearization.
Animating a mode shape
on Indep. Coord.
It’s rare to compute the matrix function using this formula. For different reasons,
one of them being that the matrix can become singular. Usually a Padé
approximant of the function is used to implement directly this matrix function
Due to time limitations we are not presenting in these slides the basic ideas of
mechanics: forces, moments, wrenches, derivative of vectors or computations of
velocity accelerations, twists angular velocity and acceleration, base frame
reference and base change matrixes,...
Also, we are not covering the initial assembly problem, not the perturbed
equilibrium problem, as these are trivially problems.
Most of the algorithms/ideas can be obtained also by looking at the MATLAB code
in lib_3D_MEC_MATLAB.
Numerical Linearization
END OF MATERIAL