dap3d program descriptionpen/ame553/notes/dap3d_manual_v_3.5.12.pdf · 2 flowchart 1 folder:...

25
1 DAP3D (Version 3.5.12) Program Description [The program may contain logical and/or programming errors in its present form] DAP3D (Dynamic Analysis Program 3D) is a MATLAB program for multibody forward-dynamic analysis. The program is developed for educational and research purposes and, therefore, computational efficiency is not considered as a high-priority issue in its development. The program is constructed in a modular form. Understanding the structure of the program makes it easier for further revisions. The folder for program DAP3D contains three M-files and several other folders, each containing more folders and M-files (refer to Table 1). The M-file for performing an analysis is dap. The M-files anim and post are for visualization and post-processing of results. Several example models are supplied with the program. These examples (such as Fourbar3) reside in the folder named Models. New models should be added to this folder as well. Program Structure The following flowcharts describe the structure of the program. The main M-file to be executed is dap.m. Some of the function of this file are (as shown in Flowchart 1): 1. It prompts the user for some directives and information (folder’s name for the model; whether to correct the initial conditions or not; simulation time information; and method of solution). Table 1 DAP3D_v_3.5.11 anim.m dap.m post.m Formulation Analysis Constraints Forces Functions someFiles Structures Transfer Updates Models Fourbar3 inAnimate.m inBodies.m inForces.m inJoints.m inPoints.m inVectors1.m inVectors2.m Fourbar4 ... 2. It initializes some of the arrays and matrices; it determines the number of various components in the model, it establishes pointers, etc. 3. It checks for the redundancy of the constraints. If there are redundant constraints in the system, the program will use a so-called penalty method instead of the standard method (without prompting the user) to solve the equations of motion. 4. It establishes an integration array based on the initial values of the coordinates and velocities. 5. It employs ode45 for integration. (The user may manually invoke another integration scheme based of a constant time-step, forth-order Runge-Kutta.) 6. The results (time, coordinates and velocities) are saved in arrays T and uT at every reporting time step. These arrays are used for animation or any other post-processing of results.

Upload: phungliem

Post on 17-Jun-2019

276 views

Category:

Documents


2 download

TRANSCRIPT

1

DAP3D (Version 3.5.12)

Program Description

[The program may contain logical and/or programming errors in its present form] DAP3D (Dynamic Analysis Program 3D) is a MATLAB program for multibody forward-dynamic analysis. The program is developed for educational and research purposes and, therefore, computational efficiency is not considered as a high-priority issue in its development. The program is constructed in a modular form. Understanding the structure of the program makes it easier for further revisions.

The folder for program DAP3D contains three M-files and several other folders, each containing more folders and M-files (refer to Table 1). The M-file for performing an analysis is dap. The M-files anim and post are for visualization and post-processing of results.

Several example models are supplied with the program. These examples (such as Fourbar3) reside in the folder named Models. New models should be added to this folder as well. Program Structure The following flowcharts describe the structure of the program. The main M-file to be executed is dap.m. Some of the function of this file are (as shown in Flowchart 1): 1. It prompts the user for some directives and

information (folder’s name for the model; whether to correct the initial conditions or not; simulation time information; and method of solution).

Table 1

DAP3D_v_3.5.11

anim.m

dap.m

post.m

Formulation

Analysis

Constraints

Forces

Functions

someFiles

Structures

Transfer

Updates

Models

Fourbar3

inAnimate.m

inBodies.m

inForces.m

inJoints.m

inPoints.m

inVectors1.m

inVectors2.m

Fourbar4

...

2. It initializes some of the arrays and matrices; it determines the number of various components in the model, it establishes pointers, etc.

3. It checks for the redundancy of the constraints. If there are redundant constraints in the system, the program will use a so-called penalty method instead of the standard method (without prompting the user) to solve the equations of motion.

4. It establishes an integration array based on the initial values of the coordinates and velocities. 5. It employs ode45 for integration. (The user may manually invoke another integration scheme based

of a constant time-step, forth-order Runge-Kutta.) 6. The results (time, coordinates and velocities) are saved in arrays T and uT at every reporting time

step. These arrays are used for animation or any other post-processing of results.

2

Flowchart 1

folder: Analysis

Bodies_to_u

u_to_Bodies

folder: Transfer

Bodies_to_u_dot

functions

scripts

include_global

initialize

2-?

plot_system

X

X

inData

dap

ode45

diffeq_x

analyssis_x

folder: someFiles

animate

post

Post Processing

X

ic_correct

6redundant X

normal_vectors

1

3

4

5

Describing A Model A model must be described in several M-files that will be invoked by the M-file inData. As shown in Flowchart 2, the name of an input file suggests what part of the model it represents. The data must be provided based on the specified structure arrays.

These model files are described in the following sub-sections. inBodies.m Since a multibody system contains at least one body, every model must contain this file. Typical lines of data in this file are listed in Table 2. For better understanding of what these entries are, refer to the structure for Bodies shown in Table 3. Note that in DAP3D the ground carries the index 0 (zero) and it does not require any data in this file.

Flowchart 2

folder: Structures

inData

inBodies

inPoints

folder: Models/xxx

Body_struct

Point_struct

inAnimate

inJoints Joint_struct

inVectors1

inForces

Vector1_struct

Force_struct

inVectors2Vector2_struct

inFunctsFunct_struct

Typical data to be supplied in this file are: mass (.mass), rotational inertia with respect to the body-fixed frame (.Jp), initial conditions on the coordinates and velocities of the body (.r, .p, .r_dot,

.w). The default settings for some of the data could be used to simplify the construction of these input files. The output of this file is the array Bodies.

Table 2 function inBodies include_global

B1 = Body_struct; B1.mass = 1; B1.Jp = [1 0 0 0 1 0 0 0 1]; B1.r = [0;0;0]; B1.p = [1;0;0;0];

3

B1.r_dot = [0;0;0]; B1.w = [0;0;0]; B2 = Body_struct; ... Bodies = [B1; B2; ...];

Table 3

function Body = Body_struct Body = struct( ... 'r' , [0;0;0] , ... % x, y, z coordinates 'p' , [1;0;0;0] , ... % four Euler parameters 'A' , eye(3) , ... % transformation matrix 'r_dot' , [0;0;0] , ... % x_dot, y_dot, z_dot 'w' , [0;0;0] , ... % omega_x, omega_y, omega_z 'p_dot' , [0;0;0;0] , ... % time derivative of Euler parameters 'r_dot2', [0;0;0] , ... % x_double_dot, ... 'w_dot' , [0;0;0] , ... % alpha_x, ... (angular accelerations) 'irc' , 0 , ... % index of the 1st element of r in u or u_dot 'iru' , 0 , ... % index of the 1st element of r in u or u_dot 'irv' , 0 , ... % index of the 1st element of r_dot2 in v_dot 'mass' , 1 , ... % mass 'm_inv' , 1 , ... % mass inverse 'M' , eye(3) , ... % 3x3 mass matrix 'M_inv' , eye(3) , ... % 3x3 mass inverse 'Jp' , eye(3) , ... % inertia matrix in xi-eta-zeta 'J' , eye(3) , ... % inertia matrix in x-y-z 'Jp_inv', eye(3) , ... % inverse inertia matrix in xi-eta-zeta 'J_inv' , eye(3) , ... % inverse inertia matrix in x-y-z 'f' , [0;0;0] , ... % sum of forces that act on the body 'n' , [0;0;0] , ... % sum of moments that act on the body 'wp' , [0;0;0] , ... % omega_xi, omega_eta, omega_zeta 'wp_dot', [0;0;0] , ... % alpha_xi, ... (angular accelerations) 'color' , 'k' , ... % default color 'pts' , [] ... % point indexes associated with this body );

inPoints.m Every point in a model must be defined in this M-file. These points could be the attachment points of springs, dampers, or joint definition points. There is no need to define the origin of a body-fixed frame as a point since the vector of translational coordinates of a body automatically describes the origin. However, if a joint reference point, or a spring-damper attachment point, is defined at the origin of a body, the point must be defined in this file. Typical lines of data in this M-file are listed in Table 4 followed by the structure for Points as shown in Table 5. Any point attached to the ground must also be described in this file. Describing a point requires two pieces of information: the index of the body that it is attached to, and its body-fixed coordinates. The output of this file is the array Points.

Table 4 function inPoints include_global

P1 = Point_struct; P1.Bindex = 2; P1.sPp = [0.5;0;-1.6]; ... P3 = Point_struct; P3.Bindex = 0; % index of the ground is 0 P3.sPp = [1;-1;0]; ...

4

Points = [P1; P2; ...];

Table 5

function Point = Point_struct Point = struct( ... 'Bindex' , 0 , ... % body index 'sPp' , [0;0;0] , ... % s_prime; xsi, eta, zeta coordinates 'sP' , [0;0;0] , ... % x, y, z components of vector s 'rP' , [0;0;0] , ... % x, y, z coordinates of the point 'sP_dot' , [0;0;0] , ... % s_P_dot 'rP_dot' , [0;0;0] , ... % r_P_dot 'rP_dot2', [0;0;0] ... % r_P_dot2 );

inAnimate.m

In addition to the points that define attachment points of joints and force elements, other points could be defined on a body in order to describe its outline for a more realistic visualization during an animation. Since these points are not used during the analysis, they should be listed in the M-file inAnimate as shown in Table 6. This file should also contain data for some of the plot (animation) parameters. These parameters are saved in a global statement and will be used by the M-file anima.

Table 6 function inAnimate include_global

P1 = Point_struct; P1.Bindex = 2; P1.sPp = [0.5;0;-1.6]; ... Points_anim = [P1; ...];

% Parameters for defining the 3D animation axes used by plot_system xmin = -1.5; xmax = 1.5; ymin = -1.5; ymax = 1.5; zmin = -2; zmax = 1;

inVectors1.m Every vector in a model that describes an axis on a body (type 1) must be defined in this M-file. Typical lines of data in this file are listed in Table 7 followed by the structure for Vectors1 in Table 8. Any vectors defined on the ground must also be described in this file. Describing a vector requires the index of the body that it is attached to and its body-fixed components. The output of this file is the array Vectors1.

Table 7 function inVectors1 include_global

V1 = Vector1_struct; V1.Bindex = 1; V1.sp = [-1;2.1;0]; V2 = Vector1_struct; V2.Bindex = 0; V2.sp = [0;-2;1.7]; ... Vectors = [V1; V2; ...];

Table 8

function Vector = Vector1_struct Vector = struct( ...

5

'Bindex', 0 , ... % body index 'sp' , [0;0;0] , ... % s_prime; xi, eta, zeta components 's' , [0;0;0] , ... % x, y, z components 's_dot' , [0;0;0] ... % s_dot );

inVctors2.m

Vectors that are connected between two bodies (type 2) are describes in this M-file. Typical lines of data in this file are listed in Table 9 followed by the structure for Vectors2 in Table 10. Describing a type 2 vector requires the index of the two points that it connects. The output of this file is the array Vectors2. Note that if a vector connects a point on the ground to a point on a body, the arrow must be on the point on the ground (

Pj ).

Table 9 function inVectors2 include_global

V1 = Vector2_struct; V1.iPindex = 2; % tail point of vector V1.jPindex = 3; % if a point on the ground, it must be jPindex ... Vectors2 = [V1; V2; ...];

Table 10

function Vector = Vector2_struct Vector = struct( ... 'iPindex' , 0 , ... % point Pi index (tail of vector) 'jPindex' , 0 , ... % point Pj index (head of vector) 'iBindex' , 0 , ... % body i index 'jBindex' , 0 , ... % body j index 'd' , [0;0;0] , ... % x, y, z components 'd_dot' , [0;0;0] ... % d_dot );

inForces.m

Force elements, such as a spring-damper-actuator or weight, are described in this input file. The available force elements in this version of the program are:

Gravitational force (.type = ‘weight’) Point-to-point spring-damper-actuator (.type = ‘ptp’) Rotational spring-damper-actuator (.type = ‘rot_sda’) Constant force described in body frame (.type = ‘fp’) Constant moment described in body frame (.type = ‘np’) Constant force described in x-y-z frame (.type = ‘f’) Constant moment described in x-y-z frame (.type = ‘n’) User supplied forces (.type = ‘user’)

Typical lines of data for this file and the corresponding structure are listed in Tables 11 and 12. For a user’s supplied force element, the user must provide a function M-file named user_force.

Table 11 function inForces include_global

S1 = Force_struct; S1.type = 'ptp'; S1.V2index = 2; % the d vector from inVectors2 entries

6

S1.k = 50; S1.el_0 = 8; S1.c = 0; S1.f_a = 0; S2 = Force_struct; S2.type = 'rot_sda'; S2.iVindex = 2; % unit vector index on body i S2.jVindex = 4; % unit vector index on body j S2.kVindex = 3; % unit vector index along the element axis (body i or j) S2.k = 50; S2.theta_0 = pi/8; S2.c = 10; S2.n_a = 0; S3 = Force_struct; S3.type = 'weight'; % include the weight S3.gravity = 9.81; % the default gravitational constant S3.wgt = [0; 0; -1]; % the default direction S4 = Force_struct; S4.type = ‘np’; S4.iBindex = 3; S4.np = [0; 15; -1.6]; % components of the moment in local frame S5 = Force_struct; S5.type = ‘user’; ... Forces = [S1; S2; ...];

Table 12

function Force = Force_struct Force = struct( ... 'type' , 'ptp', ... % element type 'iPindex', 0 , ... % index of the tail point 'jPindex', 0 , ... % index of the head point 'iBindex', 0 , ... % index of the tail body 'jBindex', 0 , ... % index of the head body 'iVindex', 0 , ... % index of vector on body i (rotational sda) 'jVindex', 0 , ... % index of vector on body j (rotational sda) 'kVindex', 0 , ... % index of vector along rot element axiss on i or j 'V2index', 0 , ... % vector2 (d) index 'joint' , 1 , ... % joint index for Coulomb friction 'mu' , 0.5 , ... % coefficient of friction 'k' , 0 , ... % spring stiffness 'el_0' , 0 , ... % undeformed length 'theta_0', 0 , ... % undeformed angle 'c' , 0 , ... % damping coefficient 'f_a' , 0 , ... % constant actuator force 'n_a' , 0 , ... % constant actuator torque 'gravity', 9.81 , ... % gravitational constant 'wgt' , [0;0;-1], ... % gravitational direction 'fp' , [0;0;0], ... % constant force in local frame 'np' , [0;0;0], ... % constant moment in local frame 'f' , [0;0;0], ... % constant force in x-y-z frame 'n' , [0;0;0] ... % constant moment in x-y-z frame );

inJoints.m

Kinematic constraints representing joints or drivers are described in this file. Joint descriptions in DAP3D must follow specific rules. A joint is defined between two moving bodies i and j, or a moving

7

body i and the ground (j = 0). A general description of possible required points and vectors is shown in Fig. 1.

• Not all of these points and vectors are needed for every joint.

• Vectors ai , a j , and d are parallel.

• Vectors a j ,

nj , and mj form a positive reference axes; i.e.,

a jn j = m j , n jm j = a j ,

m ja j = n j .

• If one of the bodies is the ground, it must be body j.

(i) (j) Pi Pj d ai

a j

n j

mj

Figure 1: Joint definition points and vectors (most general)

The available kinematic constraints in the present version of the program are listed here. The constraint equations, Jacobian matrix, right-hand-side of the acceleration array, the required points and vectors to be provided by the user in the model file, and an example of the input statements are provided for each joint. Spherical (s, 3)

Constraints Φ ≡rj + s j

P − ri − siP = 0

Jacobian Di = −I si

P⎡⎣ ⎤⎦ D j = I −s j

P⎡⎣ ⎤⎦

Gamma γ =− si

P ω i + s jP ω j

Requirements Pi , Pj

Input statements

Jx.type = 'sph'; Jx.iPindex = 2; Jx.jPindex = 3;

Revolute (formulation III) (r, 5)

Constraints

Φ ≡

rj + s jP − ri − si

P = 0

a iTn j = 0

a iTm j = 0

⎨⎪⎪

⎩⎪⎪

Jacobian

Di =−I si

P

0T m jT

0T −n jT

⎢⎢⎢⎢

⎥⎥⎥⎥

D j =

I −s jP

0T −m jT

0T n jT

⎢⎢⎢⎢

⎥⎥⎥⎥

Gamma

γ =

− siP ω i + s j

P ω j

m jT (ω j −ωω i )

n jT (ω i −ωω j )

⎨⎪⎪

⎩⎪⎪

Requirements Pi , Pj , ai , a j

Input Jx.type = 'rev'; Jx.iPindex = 1;

Based on the defined a j , the

8

statements Jx.jPindex = 8; Jx.iVindex_a = 3; Jx.jVindex_a = 1;

program constructs nj and

mj .

Spherical-spherical (s-s, 1)

Constraint Φ≡ 1

2 (dT d − 2 ) = 0 Jacobian

Di = −dT dTsi

P⎡⎣ ⎤⎦ D j = dT −dTs j

P⎡⎣ ⎤⎦

Gamma γ = dT (ω i si

P −ω j s jP )− dTd

Requirements d , Input statements

Jx.type = 'sph-sph'; Jx.V2index = 2; Jx.el = 1.2;

Cylindrical (formulation II) (c, 4)

Constraint

Φ ≡

a iT n j = 0

a iT m j = 0

dT n j = 0

dT m j = 0

⎪⎪

⎪⎪⎪

Jacobian

Di =

0T m jT

0T −n jT

−n jT n j

TsiP

−m jT m j

TsiP

⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥

D j =

0T −m jT

0T n jT

n jT n j

T (d − s jP )

m jT m j

T (d − s jP )

⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥

Gamma

γ =

m jT (ω j −ωω i )

n jT (ω i −ωω j )

(ω i siP )T n j + (ω jd + s j

P − 2d)T n j

(ω i siP )T m j + (ω jd + s j

P − 2d)T m j

⎪⎪

⎪⎪⎪

Requirements ai , a j , d

Input statements

Jx.type = 'cyl'; Jx.iVindex_a = 3; Jx.jVindex_a = 1; Jx.V2index = 2;

Based on the defined a j , the

program constructs nj and

mj .

Translational (formulation II) (t, 5)

Constraint

Φ ≡

A iTA j − A(c) = 0

dT n j = 0

dT m j = 0

⎨⎪⎪

⎩⎪⎪

9

Jacobian

Di =

0 −I−n j

T n jTsi

P

−m jT m j

TsiP

⎢⎢⎢⎢

⎥⎥⎥⎥

D j =

0 In j

T n jT (d − s j

P )

m jT m j

T (d − s jP )

⎢⎢⎢⎢

⎥⎥⎥⎥

Gamma

γ =0

(ω i siP )T n j + (ω jd + s j

P − 2d)T n j

(ω i siP )T m j + (ω jd + s j

P − 2d)T m j

⎨⎪⎪

⎩⎪⎪

Requirements a j , d , A(c)

Input statements

Jx.type = 'tran'; Jx.jVindex_a = 1; Jx.V2index = 2; Jx.Ac = [cos(pi/3) 0 sin(pi/3) 0 1 0 -sin(pi/3) 0 cos(pi/3)];

Based on the defined a j ,

the program constructs nj

and mj .

Note Jx.Ac is the constant transformation matrix between the two bodies;

i.e., AiTA j = Ac . The default is the identity matrix; i.e., the two

frames are parallel (and should remain parallel). Universal (u, 4)

Constraint

Φ ≡

rj + s jP − ri − si

P = 0

a iT n j = 0

⎧⎨⎪

⎩⎪

Jacobian

Di =

−I siP

0T a iT n j

⎣⎢⎢

⎦⎥⎥

D j =

I −s jP

0T −a iT n j

⎣⎢⎢

⎦⎥⎥

Gamma

γ =

− siP ω i + s j

P ω j

a iT (ω j −ωω i )

⎧⎨⎪

⎩⎪

Requirements Pi , Pj , ai , nj

Input statements

Not implemented yet!

Relative-rotation (-, 1)

Constraint This constraint is defined at the velocity level as:

Φ ≡

a jT (ω j −ωω i ) = 0 if iFunct = 0

a jT (ω j −ωω i ) = f (t) if iFunct ≠ 0

⎧⎨⎪

⎩⎪

Jacobian Di =

0T −a j

T⎡⎣ ⎤⎦ D j =

0T a jT⎡⎣ ⎤⎦

Gamma

γ =

−a jTω jω i if iFunct = 0

f (t)− a jTω jω i if iFunct ≠ 0

⎧⎨⎪

⎩⎪

Requirements a j ( j = 0 or ≠ 0)

10

Input statements

Jx.type = 'rel-rot'; Jx.iBindex = 2; Jx.jVindex_a = 3;

Constrains relative rotation between body (2) and the ground.

Jx.type = 'rel-rot'; Jx.iBindex = 2; Jx.jBindex = 1; Jx.jVindex_a = 3;

Constrains relative rotation between body (2) and body (1).

Jx.type = 'rel-rot'; Jx.iBindex = 2; Jx.jBindex = 1; Jx.jVindex_a = 3; Jx.iFunct = 1;

Implements a driver constraint on relative rotation between body (2) and body (1).

This constraint assumes that a revolute joint has also been defined between the two bodies.

Relative-translation (-, 1) Constraint This constraint is defined at the velocity level as:

Φ ≡

a jT (rj − ri ) = 0 if iFunct = 0

a jT (rj − ri ) = f (t) if iFunct ≠ 0

⎧⎨⎪

⎩⎪

Jacobian Di =

0T −a j

T⎡⎣ ⎤⎦ D j =

0T a jT⎡⎣ ⎤⎦

Gamma

γ =

0 if iFunct = 0f (t) if iFunct ≠ 0

⎧⎨⎩

Requirements a j ( j = 0 or ≠ 0)

Input statements

Jx.type = 'rel-tran'; Jx.iBindex = 2; Jx.jVindex_a = 3;

Constrains relative translation between body (2) and the ground.

Jx.type = 'rel-tran'; Jx.iBindex = 2; Jx.jBindex = 1; Jx.jVindex_a = 3;

Constrains relative translation between body (2) and body (1).

Jx.type = 'rel-tran'; Jx.iBindex = 2; Jx.jBindex = 1; Jx.jVindex_a = 3; Jx.iFunct = 1;

Implements a driver constraint on relative translation between body (2) and body (1).

This constraint assumes that a translational joint has also been defined between the two bodies.

Coordinate of a point (rP, 1) Constraint

Φ ≡a j=0T ri

P − c = 0

Jacobian Di =

a j=0

T −a j=0T si

P⎡⎣ ⎤⎦

Gamma γ =− a j=0

T ω isiP

Requirements a j ( j = 0) , c

a j is normally a unit vector along the x or y or z axis.

Input statements

Jx.type = 'rP'; Jx.iBindex = 2; Jx.jVindex_a = 3; Jx.el = 0.65; % constant coordinate c

11

Fix (fix, 6) Constraint This constraint is defined at the velocity level as:

Φ ≡

ri = 0ω i = 0

⎧⎨⎪

⎩⎪

Jacobian Di =

I⎡⎣ ⎤⎦6×6

Gamma γ = 0{ }6×1

Requirements Input statements

Jx.type = 'fix'; Jx.iBindex = 2;

This joint rigidly attaches a body to the ground.

Disk (disk, x) This constraint assumes a circular disk with no thickness remains in point contact with the horizontal ground at z = 0. Depending on whether and how the contact point may slip, different constraints are implemented by the program. Note that the body-fixed frame must have the η -axis

perpendicular to the disk’s plane.

Type 'z' (disk, 1) Constraint The contact point stays on the ground but may slip on the ground

plane. Jacobian Gamma Requirements Disk radius Input statements Jx = Joint;

Jx.type = 'disk'; Jx.disk = 'z'; Jx.iBindex = 5; Jx.R = 0.2;

Type 'nz' or 'tz' (disk, 2) Constraint The contact point stays on the ground it should not slip lateral to

(or along) the disk’s plane. Jacobian Gamma Requirements Disk radius Input statements Jx = Joint;

Jx.type = 'disk'; Jx.disk = 'nz'; (or Jx.disk = 'tz'); Jx.iBindex = 4; Jx.R = 0.2;

Type 'xyz' (disk, 3) Constraint The contact point stays on the ground with no slip. Jacobian Gamma Requirements Disk radius Input statements Jx = Joint;

Jx.type = 'disk'; Jx.disk = 'xyz'; Jx.iBindex = 3; Jx.R = 0.2;

12

Typical lines of data for this file and the corresponding structure are listed in Tables 13 and 14. For a disk joint, a separate function is provided for its “struct”.

Table 13 function inJoints include_global

J1 = Joint_struct; J1.type = 'sph'; J1.iPindex = 2; J1.jPindex = 3; % if a ground point, it must be this one ... Joints = [J1; J2; ...];

Table 14

function Joint = Joint_struct Joint = struct( ... 'type' , 'sph' , ... % joint type 'iPindex' , 0 , ... % point Pi index 'jPindex' , 0 , ... % point Pj index 'iQindex' , 0 , ... % point Qi index 'iVindex_a', 0 , ... % vector a_i index (along the joint axis) 'iVindex_n', 0 , ... % vector n_i index (normal to the joint axis) 'jVindex_a', 0 , ... % vector a_j index (along the joint axis) 'jVindex_n', 0 , ... % vector n_j index (normal to the joint axis) 'jVindex_m', 0 , ... % vector m_j index (normal to the joint axis) 'V2index' , 0 , ... % vector2 (d) index 'iBindex' , 0 , ... % body index i 'jBindex' , 0 , ... % body index j 'iFunct' , 0 , ... % function index 'disk' , 'xyz' , ... % type of disk: xyz, nz, tz, z 'iDisk' , 0 , ... % disk number 'el' , 0 , ... % constant length 'R' , 1 , ... % constant radius 'Ac' , eye(3), ... % constant rotational matrix between two frames 'mu' , 0 , ... % coefficient of friction 'nbody' , 2 , ... % number of moving bodies involved 'mrows' , 3 , ... % number of rows (constraints) 'rows' , 0 , ... % row index-start 'rowe' , 0 , ... % row index-end 'colis' , 0 , ... % column index for body i-start 'colie' , 0 , ... % column index for body i-end 'coljs' , 0 , ... % column index for body j-start 'colje' , 0 , ... % column index for body j-end 'lagrange' , zeros(6,1) ... % Lagrange multipliers ); function Disk = Disk_struct Disk = struct( ... 'iBindex' , 1 , ... % body index i 'type' , 'xyz' , ... % disk type (xyz z zt zn) 'mrows' , 3 , ... % number of constraints 'R' , 1 , ... % disk radius 'mu' , 0 , ... % coefficient of friction 'sine' , 1 , ... % sine of disk angle (camber) 'eta' , [ 0; 1; 0], ... % eta vector 't' , [-1; 0; 0], ... % longitudinal unit vector 'n' , [ 0; 1; 0], ... % lateral unit vector 's' , [ 0; 0;-1], ... % s (or d) vector 's_dot' , [ 0; 0; 0], ... % s-dot vector 't_dot' , [ 0; 0; 0], ... % t-dot vector 'n_dot' , [ 0; 0; 0], ... % n-dot vector 'd_dot' , [ 0; 0; 0] ... % d-dot vector );

13

inFuncts.m

User may define various functions and apply them to a system, for example, to describe nonlinear characteristics of a spring, or a driver’s time function. In this version of the program, three types of functions are available: Type “a”: This function and its first and second derivatives are:

f = c1 + c2x + c3x2

df / dx = c2 + 2c3x

d 2 f / dx2 = 2c3

The user must supply values for the three coefficients. Type “b”: This function and its first and second derivatives are:

f = c1x3 + c2x4 + c3x

5

df / dx = 3c1x2 + 4c2x3 + 5c3x

4

d 2 f / dx2 = 6c1x + 12c2x2 + 20c3x3

This function and its derivatives are depicted in Fig. 2. The function has zero first and second derivatives at the start and end points. For this function there is no need for the user to provide values for the three coefficients—the user must supply start and end values for x and f. The program then computes the three coefficients (this computation is performed automatically once in the M-file functData).

f

x_start

f_start

f_end

x_end x_start x_end x_start x_end

df/dx d f/dx 2 2

0

0

Figure 2: Type “b” function and its first and second derivatives

Type “c”: This function and its first and second derivatives are:

f = c1x3 + c2x4 + c3x

5 + c4x6 + c5x7

df / dx = 3c1x2 + 4c2x3 + 5c3x

4 + 6c4x5 + 7c5x6

d 2 f / dx2 = 6c1x + 12c2x2 + 20c3x3 + 30c4x4 + 42c5x5

This function and its derivatives are depicted in Fig. 3. The function has zero first and second derivatives at the start and end points. For this function there is no need for the user to provide values for the three coefficients—the user must supply start, end, and maximum values for x and f. The program computes the five coefficients of the function (this computation is done once in the M-file functData).

14

Figure 3: Type “c” function and its first and second derivatives

Type “d”: This function and its first, second, and third derivatives are:

f = c1+ c

2x4

+ c3x5

+ c4x6

df / dx = 4c2x3

+ 5c3x4

+ 6c4x5

d 2 f / dx2= 12c

2x2

+ 20c3x3

+ 30c4x4

d 3 f / dx3= 24c

2x + 60c

3x2

+120c4x3

This function and its derivatives are depicted in Fig. 4, where the function has zero first, second, and third derivatives at the start points, and zero second and third derivatives at the end points. Furthermore, the first derivative has a non-zero value at the end point. The user must supply start and end values for x, start value for f, and end value for the first derivative. The program computes the four coefficients of the function (this computation is done once in the M-file functData). This function can be useful in simulations where a driver function should raise the velocity (first derivative) from zero to a final value during a specified time period, and then keep the velocity at that final value for the remaining time of simulation.

Figure 4: Type “d” function and its first, second, and third derivatives

Functions are described in the input file inFuncts. Typical lines of data for this file and the corresponding structure are listed in Tables 15 and 16.

Table 15 function inFuncts include_global % type “a” function

C1 = Funct_struct; C1.type = 'a'; C1.coeff = [0 2*pi 0];

% type “b” function C2 = Funct_struct; C2.type = 'b'; C2.x_start = 0;

15

C2.f_start = 0; C2.x_end = 0.8; C2.f_end = 0.8;

% type “c” function C3 = Funct_struct; C3.type = 'c'; C3.x_start = 0; C3.f_start = 0; C3.x_end = 0.8; C3.f_end = 0.8; C3.x_max = 0.4; C3.f_max = 1.0;

% type “d” function

C4 = Funct_struct; C4.type = 'd'; C4.x_start = 0.5; C4.x_end = 2.0; C4.f_start = 0; C4.fp_end = 2*pi; ... Functs = [C1; C2; ...];

Table 16

function Funct = Funct_struct Funct = struct( ... 'type' , 'a' , ... % function type 'x_start' , 0 , ... 'f_start' , 0 , ... 'x_end' , 1 , ... 'f_end' , 1 , ... 'x_max' , 0 , ... 'f_max' , 0 , ... 'ncoeff' , 4 , ... % number of coefficients 'coeff' , [] ... % array of coefficients );

A General Note If a model does not require a particular set of data, the user must still provide the corresponding M-file containing an empty structure array. For example, if the model does not have any force elements, the user must provide the M-file inForces as shown in Table 17.

Table 17 function inForces include_global F1 = Force_struct;

Forces = [];

16

Analysis

The M-files that perform an analysis are listed in Flowchart 3. Since the program gives the user several solution options, the M-file analysis (and the corresponding M-file diffeq) is organized (split) into several M-files:

analysis_p : solves equations of motion using the penalty method analysis_s : solves equations of motion using the standard method analysis_uc : solves an unconstrained set of equations of motion

Flowchart 3

analyssis_x

Update_Position

Update_Velocity

Inertia_Matrix

Forces

Constraints

Jacobian

RHSAcc

Matrix_A

p_dot

Matrix_J_inv

SDA_ptp

folder: Updates Matrix_G

folder: Forces SDA_zu

ic_correct

folder: Constraints

folder: spherical

. . .

spherical_C

spherical_A

spherical_J

tilde3

RHSVel

. . . .

folder: rel_rot

rel_rot_C

rel_rot_J

rel_rot_A

rel_rot_V

17

DAP3D (Version 3.5.12)

Simulating the Dynamics of A Model

DAP3D consists of three programs: • dap.m (the main program for dynamic simulations)

• anim.m (this program animates the results obtained from dap.m)

• post.m (this program prepares simulation results from dap.m for post-processing)

Performing A Simulation Execute dap.m!

• The program prompts you for the followings: o Which folder contains the model?

• Enter the name of the folder that contains your model M-files. This folder must reside in the folder named Models. As an example, enter:

o Fourbar3

• If the model contains any constraints, the program asks you: o Do you want to correct the initial conditions? [(y)es/(n)o]?

• Enter y for yes or n for no: o y

• If your answer was “y”, the program corrects the initial conditions and reports the corrected values for the coordinates and velocities.

• At this point the program checks for any redundancy in the constraints. If there is no redundancy, the program reports redundancy = 0, otherwise it reports the number of redundant constraints.

• The program then asks for the integration time data, starting with the time period for simulation (the program assumes the initial time to be t = 0 ):

o Final time = ?

• If you want the solution at t = 0 only, then answer 0: o 0

o The program solves the equations and then terminates. o This is a useful option if you have set up a new model and you are testing it for

correctness. Answering yes to this question allows the program to construct the equations of motion and to solve them at t = 0 without entering into an integration process.

• Otherwise enter the desired time period, for example 2 seconds: o 2

• The program then asks you for the reporting time steps: o Reporting time-step in seconds = ?

• Enter the desired reporting time interval in seconds. For example, Δt = 0.05 seconds: o 0.05

• The program asks you for the solution method: o Standard or Penalty method? [(s)/(p)]?

• If you are not familiar with the penalty method, ask for the standard method: o s

• The program will then enter the integration process. After the completion of simulation, the program reports the number of function evaluations. This number could be interpreted as a measure of computational efficiency of the solution methodology.

18

The results of a simulation are saved in arrays T and uT:

• The array T contains a record of reporting times. For example if we asked for the final time to be

2 seconds and the reporting time steps to be 0.05 seconds, the number of recorded times in T

would be nt = 2/0.05 + 1 = 41. Hence T would be a 41x1 array. Note that the first time step is at t = 0.

• For a system containing nB bodies, the array uT would be of the size nt x(13*nB). The columns

of uT contain the coordinates and the velocities of the bodies in the following order:

riT, pi

T; i = 1,...,nB, riT, ω i

T; i = 1,...,nB

That means the first 7*nB columns contain the coordinates and the following 6*nB columns

contain the velocities. For example the y-coordinate of body 3 at the 5th time step is located as uT(5,16), and the angular velocity of body 2 in the x-direction, in a system of 4 bodies, at the

5th time step is located as uT(5,38).

• Other results such as accelerations and reaction forces (Lagrange multipliers) are not saved by the integration routine.

Since working with T and uT arrays is not convenient, and also since some other useful results is not saved by the program, a post processor program called post.m is developed.

Animation Following a simulation the user may execute the program anim.m. This program accesses the

coordinates of the bodies from the uT array and creates an animation of the response in the form of stick-drawings. If any extra points are defined in the input file inAnimate.m, they will be appended to the

other points in the file inPoints.m. At every time step lines are drawn from the origin of each body to all the points that are defined on that body. Different colors are used for different bodies. The drawings are repeated at each time step to create the animation. If a simulation is performed at only t = 0, the animation would create only one snapshot of the model (this is a good exercise do debug newly developed models). Post-Processor The program post.m can be

executed following a simulation, or following an animation. This program takes the contents of the uT

array at each time step, re-computes the accelerations and other results, and saves the results in a more convenient format. The saved results can be found in the arrays shown in the table. Example 1: The acceleration of body 4 in the y-direction at the 6th time step is located at rdd(6,4,2).

Array Size Contents r (nt,nB,3) Translational coordinates p (nt,nB,4) Euler parameters rd (nt,nB,3) Translational velocity w (nt,nB,3) Angular velocity (x-y-z) wp (nt,nB,3) Angular velocity (ξ−η−ζ) rdd (nt,nB,3) Translational acceleration wd (nt,nB,3) Angular acceleration (x-y-z) wpd (nt,nB,3) Angular acceleration (ξ−η−ζ) rP (nt,nP,3) Coordinates of points rPd (nt,nP,3) Velocity of points Jac (nt,nConst,nB6) Jacobian matrix Lam (nt,nConst) Lagrange multipliers

Example 2: To plot the acceleration of body 4 in the y-direction versus time, enter

plot(T,rdd(:,4,2))

19

Note: If this program is executed following the animation program, the animation points will also be included in arrays rP and rPd; i.e., nP represents the number of the original and animation points.

DAP3D (Version 3.5.10)

Examples For these examples refer to the individual folders inside the folder Models. Example 1—An Unconstraind System (no kinematic joints) Sub-folder: Bodies2 The system consists of two moving bodies and two spring-damper elements. One element is connected between a point on the ground and a point on body (1), and the second element connects a point on body (1) to a point on body (2). The object is to release the bodies from their initial positions (with zero or non-zero initial angular velocities) and simulate the response for several seconds. The dimensions, mass, and moments of inertia of the objects are given as (SI units):

m1 = 1.5, ′J1 = diag 0.06 0.06 0.06⎡⎣ ⎤⎦m2 = 2.0, ′J2 = diag 0.1 0.1 0.1⎡⎣ ⎤⎦

(1)

(2)

[1]

[2]

[3]

[4]

[5]

[6]

[7]

Q

A

B

Cxy

z

r0Q =

00

3.0

⎧⎨⎪

⎩⎪

⎫⎬⎪

⎭⎪, ′s1

A =0.500

⎧⎨⎪

⎩⎪

⎫⎬⎪

⎭⎪, ′s1

B =0

0.60

⎧⎨⎪

⎩⎪

⎫⎬⎪

⎭⎪, ′s2

C =0

−0.60

⎧⎨⎪

⎩⎪

⎫⎬⎪

⎭⎪

• Execute dap to perform a simulation. There is no need to ask for the initial conditions to be corrected, since they are already correct. Perform the simulation for several seconds. Set the reporting time intervals to 0.02 sec.

• Execute animate to observe the motion. Example 2—An Unconstraind System (no kinematic joints) Sub-folder: Ball1 This example shows how to introduce a non-standard force element in a model using the user defined M-file user_force.

The system consists of a single body (a ball) bouncing up and down. It is assumed the ball is elastic and could be modeled as a linear spring-damper when in contact with the ground. The data for the ball are given as (SI units):

m = 1.0, jξξ = jζζ = jηη = 0.007

R = 0.1 (radius), k = 2000, c = 5

The ball is dropped from a certain height with zero velocity. We can simulate for 4-5 seconds with reporting time steps of 0.02 sec. x

y

z

The nonstandard contact force between the ball and the ground is modeled in the following M-

file. It is assumed that the ground level is at z = 0. If the z-coordinate of the ball is lower than its radius, then the ball is in contact and has deformed (penetrated) by δ = z − R . This penetration value and its time

20

derivative ( δ = z ) are used to compute the elastic deformation force, which is applied to the ball in the z-direction. Please note that there is no moment caused by this force. However, if the ball hits the ground with a velocity not perpendicular to the ground, and also if the ball contains angular velocity, other force components and their moments must be included in the model. This M-file must reside in the folder Ball1.

function user_force include_global % Unilateral spring-damper in z-direction del = Bodies(1).r(3) - 0.1; % z - R if del < 0 fz = -2000*del - 5*Bodies(1).r_dot(3); f1 = [0; 0; fz]; Bodies(1).f = Bodies(1).f + f1; % Bodies(1).n = Bodies(1).n + cross([0;0;-(0.1 + del)], f1); end Example 3—A Single Pendulum Sub-folder: Pen1 A cone-shaped object is connected to the ceiling by a ball joint. The object is released from the horizontal position with an initial angular velocity of -10 rad/sec about the cone axis (negative with respect to the

defined body-fixed η−axis). The dimensions, mass, and moments of inertia of the object are given as (SI units):

a = 0.3, b = 0.1, R = 0.15

m = 4, jξξ = jζζ = 0.0375, jηη = 0.0270

x

y

z

a b

gravity

The model for this system consists of 1 body, 2 points, 1 spherical joint, and the gravity. For visualization purposes, we define 4 additional points on the perimeter of the base as shown.

x

y

z

(1)

a b

ξ η

ζ

P 1P 2

P 3

P 4

P 6

P 5

• Execute dap to perform a simulation. There is no need to ask for the initial conditions to be

corrected, since they are already correct. Perform the simulation for several seconds. Set the reporting time intervals to 0.02 sec., and use the standard method of solution.

• Perform an animation to observe the motion.

21

• Plot the x-coordinate of the mass center versus its y-coordinate by typing in: plot(uT(:, 1), uT(:, 2))

• Execute post.

• Plot the x-coordinate of the mass center versus its y-coordinate by typing in: plot(r(:,1,1), r(:,1,2))

Example 4—Rotating Double Pendulum Sub-folder: Pen2 Two bodies form a rotating pendulum system. A revolute joint connects the two moving bodies, and a spherical joint connects one of the bodies (body 1) to the ground as shown. The pendulum is released from the horizontal configuration with body 2 having an initial angular velocity of 25 rad/sec about the pendulum axis. The dimensions, masses, and moments of inertia of the bodies are given as (SI units): a = 0.5, b = 0.2, c = 0.1, R = 0.2

Body 1: m = 0.5, jξξ = jζζ = 0.0417, jηη = 0.001

Body 2: m = 10, jξξ = jζζ = 0.2333, jηη = 0.2

The DAP model for this system consists of 2 bodies, 4 points, 2 unit vectors, 1 spherical joint, 1 revolute joint, and the gravity. For visualization purposes, we define 4 additional points on the perimeter of the cylinder (body 2).

x

y

z

ω

a a b

gravity

b c

R

(2) (1)

x

y

z

P 1P 2P 3P 4ξ η

ζ

ξ η

ζ

V 1 V 2

P 5

P 6

7

8

• Simulate the dynamic response of the pendulum for several seconds. There is no need to correct the

initial conditions. • Perform an animation to observe the motion. • Execute post.

• Plot the y-coordinate of the mass center of body 2 versus its x-coordinate: plot(r(:,2,1), r(:,2,2))

• Plot the angular velocity of body 2 about the y-axis versus time: plot(T, w(:,2,2))

• Plot the angular velocity of body 2 about the η-axis versus time overlapping the previous plot: hold on plot(T, wp(:,2,2),’r’)

22

Example 5—A Four-bar Mechanism In this example a spatial four-bar mechanism is considered for modeling. The system contains three moving bodies, a non-moving body (the ground), two revolute joints and two spherical joints. A motor (driver) operated between the crank and the ground about the revolute joint axis. In order to demonstrate how different components are included in a model, although not necessary, a spring-damper is included in the model. The revolute joint that connects the crank to the ground is along the x-axis; the revolute joint that connects the

follower to the ground is in the x-y plane and makes a 45o angle with the y-axis. The length of the links are (SI):

crank = 2.0, coupler = 6.4, follower = 7.0, ground = 4.0 x

y

z

45 o

crank

coupler

follower/ rocker

The crank is rotated with a constant angular velocity of 2π rad/sec. At the initial time the crank

is along the z-axis and the other two moving links are in the y-z plane. Since this is a kinematically driven system, it does not make any difference what values we assign to the mass and the moments of inertia of each body (unless we are interested in the reaction forces). For the same reason, there is no need to know the exact location on the mass center on each body—we can position the origin of the body-fixed frame anywhere on a body. For the driver we will use the function “type a” as a “relative rotational” constraint. The four bar mechanism is modeled in three different ways to demonstrate various possibilities in modeling a system. Sub-folder: Fourbar3 This model consists of 3 bodies, 2 revolute joints, 2 spherical joints, 1 driver constraint, and 1 spring-damper. We need to define 8 points and 4 unit vectors. One end of the spring-damper can be either at point 1 or 8, and the other end at point 4 or 5.

P 5

P 6

B 3 7.0

ξ

η ζ

V 3 P 7

P 8

B 0 V 2

x y

z

4.0

V 4

P 3

P 4

B 2 3.2

3.2

ξ

η

ζ

d 1

P 1

P 2

B 1

V 1

2.0

J 5

ξ η

ζ d 1

23

Sub-folder: Fourbar2 This model consists of 2 bodies, 2 revolute joints, 1 spherical-spherical joint, 1 driver constraint, and 1 spring-damper. We define 6 points, 4 unit vectors, and 1 d vector for the model.

l = 6.4

B 0 V 2

x y

z

4.0

V 4

P 6 P 5

7.0

ξ

η ζ

V 3

P 3

P 4

B 2

d 1

d 2

P 1

P 2

B 1

V 1

2.0

J 4

ξ η

ζ d 1

d 2

Sub-folder: Fourbar4 This model consists of 4 bodies, 3 revolute joints, 3 spherical joints, 1 driver constraint, 1 “fix” constraint on the fourth body, and 1 spring-damper. This model demonstrates how the ground link can initially be modeled as a moving body, then all of its six DoF could be eliminated using the fix constraint.

P 5

P 6

B 3 7.0

ξ

η ζ

V 3

P 3

P 4

B 2 3.2

3.2

ξ

η

ζ

d 1

P 1

P 2

B 1

V 1

2.0

J 5

ξ η

ζ d 1

x y

z

P 7

P 8

B 4 V 2

4.0

V 4 ξ

η

ζ

Example 6—A Tri-cycle Sub-folder: Tri

This simple tricycle model consists of 5 bodies and 4 revolute joints. The defined bodies and dimensions are shown in the figure. For the body masses and moments of inertia refer to the inBodies file. A revolute joint connects body (1) to body (2) that provides steering. Another revolute joint connects body (2) to the front wheel, body (3). Two more revolute joints connect body (1) to the rear wheels. A rel-rot constraint with type-c function controls the steering of the front wheel. A torque is applied to the front wheel to move the tricycle forward.

24

x

y

z

(2)

(1)

(3)

(4)

(5)

ξ

η

ζ

0.2 0.2 0.5

0.3

0.3

ξ

η

ζ

ξ

η

ζ

ξ

η

x y

z

(1)

(3) 0.2

ξ η

ζ

ξ η ζ

(2)

(4) (5)

ξ

ζ ξ η ζ

0.1

0.125

The wheels are modeled as disks. The front disk is considered as type xyz; i.e., the instantaneous

contact point is not allowed to move in the z-direction, and it cannot slip in the x-y plane. The left-rear disk is modeled as type nz; i.e., the instantaneous contact point is not allowed to move in the z-direction, and it cannot slip in the normal (n) to the wheel axis (it can slip in the lateral direction). The right-rear disk is modeled as type z; i.e., the instantaneous contact point is not allowed to move in the z-direction (it can slip in the ground plane). If we model all three disks to be xyz type, the model will have redundant constraints.

25

P 1

P 5

7

(2)

(1) (3)

(4)

(5)

ξ

η

ζ

ξ

η

ζ

ξ

η

ζ

ξ

η

5

P 6

8

6

7

(3)

ξ

η

4P 4

3

P 3

(1) ξ η

ζ

(2) ξ η ζ

P 2

P 1