4. Velocity and Acceleration

## Overview

This chapter covers MechanicalSystems' velocity and acceleration solution blocks, and issues related to the representation of angular orientation and velocity in spatial systems. Mech automatically differentiates the kinematic equations with respect to time and can solve for the velocity and acceleration of each body in a model without any further input from the user. Output functions are provided for utilizing the higher-order solution data, and definitions for the derivatives of Mech dependent variables are automatically made in the Global` context so that expressions containing Mech dependent variables can be properly differentiated.

# 4.1 Velocity and Acceleration Solutions

MechanicalSystems calculates all velocities and accelerations with respect to the time variable (the symbol T by default). As was shown in Chapter 2, the use of the time variable in a model is optional, if the model is to be used to generate a location solution only. However, a model must have some explicit functional dependence on the time variable in order to have a nontrivial solution to the higher-order (velocity and acceleration) equations.

## 4.1.1 2D Example Mechanism

To demonstrate the use of the Mech velocity and acceleration solutions, a 2D model is developed that can be measured. A 3D model is treated in the same manner as 2D with regard to higher-order solutions. The model is be a pull-rod and rocker rear suspension linkage for a car, consisting of three moving bodies: the chassis, the carrier, and the rocker. A real suspension linkage would have three more moving bodies: the upper and lower A-arms, and the pull-rod between the wheel carrier and the rocker.
The input to the model is the chassis moving vertically relative to the ground. This model could have been reduced in size by making the ground body the chassis, and simply moving the wheel carrier relative to the chassis, but the chosen method allows more flexibility and makes for better graphics.
The wheel carrier is attached to the chassis by two A-arms. These A-arms are not modeled as independent bodies because their function can be represented by a pair of relative distance constraints between the chassis and the wheel carrier.
The rocker pivots about an axis on the chassis and is attached to the wheel carrier by the pull-rod, a connecting link in tension. This pull-rod is also modeled with a relative distance constraint, not a separate body.
The shock absorber is connected between the other end of the rocker and the chassis. The damper is not actually part of the kinematic model at all, but the length of the damper as a function of wheel motion is a primary point of interest for any suspension linkage. Thus, the shock absorber exists only as a pair of mounting points on the chassis and the rocker, the separation of which can be measured as the car is bounced.

### Bodies

Four body objects are defined for the pull-rod suspension model.

• The ground body (body 1) requires two point definitions.
P1 is the origin of the ground body.
P2 is a point directly above the origin that defines a vertical translation line upon which the chassis slides.
• The chassis (body 2) requires six local point definitions.
P1 is the local origin, which is a point at the bottom of the chassis.
P2 is a second point that, with P1, defines the vertical translation line of the chassis.
P3 is the pivot point of the lower A-arm.
P4 is the pivot point of the upper A-arm.
P5 is the pivot point of the rocker.
P6 is the upper mounting point of the shock absorber.
• The wheel carrier (body 3) requires three local point definitions.
P1 is the local origin, which is the attachment point of the lower A-arm.
P2 is the attachment point of the upper A-arm and the pull-rod.
P3 is the bottom of the tire where the tire contacts the road.
• The rocker arm (body 4) requires three local point definitions.
P1 is the local origin, which is the rotational axis of the rocker.
P2 is the lower attachment point of the shock absorber.
P3 is the attachment point of the connecting rod.
• ### Constraints

Seven constraints, one of which is a driving constraint with explicit dependence on time, are used to model the pull-rod suspension.

• A RelativeY1 constraint, used as a driving constraint, controls the vertical position of the chassis. This constraint is a driving constraint because it is functionally dependent on the time variable T.
• A Translate2 prismatic constraint controls the chassis rotation and horizontal position and allows the chassis to move only vertically relative to the ground.
• A RelativeDistance1 constraint models the upper A-arm.
• A RelativeDistance1 constraint models the lower A-arm.
• A RelativeY1 constraint forces the bottom of the tire to remain in contact with the ground.
• A Revolute2 constraint places the axis of the rocker arm.
• A RelativeDistance1 constraint models the pull-rod. The length of the pull-rod is specified by rodlength, which must be given a numerical value before Modeler2D attempts to find a solution.
• Note that the explicit symbol that is used to represent time in Modeler2D (T by default) may be changed. The SymbolBasis option for SetSymbols is a nested list of strings that determines the basis for all of the Global` symbols created by Modeler2D. Redefining the first element of SymbolBasis changes the symbol that is recognized as the time variable.

### Runtime

Before the model can be run, the symbol rodlength, which determines the length of the pull-rod, must be defined. Because of the presence of T in the driving constraint (constraint 1), the model can be run through its intended range of motion by varying T directly with the first argument to the SolveMech command. The way that this model is defined, the numerical value of T specifies the distance between the chassis and the ground.

## 4.1.2 The Solution Option

When a Mech model is constructed with a functional dependence on the time variable T its time-domain motion is fully defined. Thus, nothing further needs to be done to generate velocity and acceleration solutions other than to ask for them. This is done with the Solution option for SolveMech.

An option for SolveMech.

The Modeler2D pull-rod suspension model defined in Section 4.1.1 is used to demonstrate the velocity and acceleration solutions. The Solution -> Velocity option causes SolveMech to calculate the location and velocity of each body in the model.

Mech creates a new set of symbols to represent the velocities and accelerations by appending a lowercase d or dd to each of the symbols that were used to represent body locations. Thus, while {X2, Y2} represents the location of the origin of body 2, {X2d, Y2d} represents the velocity of the origin of body 2.
Note that in this case, {X2d, Y2d} is equal to {0, 1}. This is expected since the driving constraint forces the height of the chassis to be T; therefore, its vertical velocity is equal to one.
The Solution -> Acceleration option causes SolveMech to calculate the location, velocity, and acceleration of each body in the model.

The location, velocity, and acceleration of the rocker (body 4) reflect the fact that its origin is stationary on the chassis, but its rotation is controlled in a nonlinear manner by the suspension linkage.

 Out[25]//MatrixForm=

When SetConstraints is called to build the mathematical model, all of the expressions required for the velocity and acceleration solutions are not immediately built. Some parts of the mathematical model are built only when they are needed for the first time by SolveMech. Thus, the first time that SolveMech is called requesting a velocity or acceleration solution, it may take much longer to return a result than in any subsequent calls.
SetConstraints accepts the BuildMech option to force the modeling equations to be built to any level immediately, instead of waiting until they are needed.

An option for SetConstraints.

BuildMech can be used to build a model's velocity and acceleration equations before all of the symbolic parameters in the model have been defined, so that the parameters will remain variable in the model. If undefined parameters are present in a model, SolveMech cannot be called to seek a solution, but BuildMech can still build the required equations.

## 4.1.3 3D Example Mechanism

A Modeler3D example model is developed to demonstrate the different angular velocity and acceleration formulations used by Modeler3D. This model is of a MacPherson strut automotive front suspension.
The model consists of only two moving bodies: the chassis and the wheel carrier. The wheel carrier is attached to the chassis by a lower A-arm, a MacPherson strut, and a steering tie rod that controls the steer angle of the wheel carrier. The A-arm, strut, and tie rod are not modeled as independent bodies in the model. They are each modeled as constraints that entirely represent the function they perform in the suspension. The input to the model is the chassis being moved vertically relative to the ground.
A MacPherson strut is attached to the chassis of a car by a ball joint, but it is attached to the wheel carrier in a cantilever fashion, not by another ball joint such as would be used in a more conventional double A-arm suspension. Thus, the MacPherson strut not only provides vertical support for the wheel carrier, it also provides the axis about which the wheel carrier pivots for steering. Since the strut cannot pivot with respect to the wheel carrier, it is modeled simply by forcing a ray on the wheel carrier to pass through a point on the chassis (the upper mounting point of the strut).

### Bodies

Three body objects are defined for the MacPherson strut front suspension model.

• The ground body (body 1) requires four point definitions.
P1 is the origin of the ground body.
P2 is a point directly above P1 that is used in conjunction with P1 to define a vertical translation axis for the chassis.
P3 is a point on the X axis that is used with P1 to define a longitudinal axis that references the rotational orientation of the chassis.
P4 is a point on the Y axis that is used with P1 and P3 to define the horizontal plane of the ground upon which the tire rests.
• The chassis (body 2) requires seven local point definitions.
P1 is the origin of the chassis. This point lies at the center of the bottom of the chassis.
P2 is used in conjunction with P1 to define the vertical translation line of the chassis.
P3 is used with P1 to define a transverse axis on the chassis that is used to reference the rotational orientation of the chassis.
P4 and P5 are the two attachment points of the lower A-arm.
P6 is the upper mounting point of the MacPherson strut.
P7 is the attachment point of the steering tie rod. This point has a symbolic definition so that it can be moved in a transverse direction to steer the car.
• The wheel carrier (body 3) requires five local point definitions.
P1 is the local origin, which is the attachment point of the lower A-arm.
P2 is used with P1 to define the axis of the MacPherson strut on the carrier.
P3 is the center of the tire.
P4 is used with P3 to define the axis of the tire.
P5 is the attachment point of the steering tie rod on the wheel carrier.
• ### Constraints

Eight constraints, including a driving constraint that is explicitly dependent on the time variable, are required to model the MacPherson strut front suspension.

• A Cylindrical4 constraint forces a vertical axis on the ground to be coincident with a vertical axis on the chassis, effectively allowing the chassis to slide up and down on a post.
• An Orthogonal1 constraint forces a longitudinal line on the ground to be orthogonal to a transverse line on the chassis. This constraint prevents the chassis from rotating about the vertical axis of rotation allowed by constraint 1.
• A RelativeZ1 constraint controls the vertical position of the chassis. This constraint is a function of the time variable T so it is the driving constraint.
• A RelativeDistance1 constraint models the front of the lower A-arm.
• A RelativeDistance1 constraint models the back of the lower A-arm.
• A PointOnLine2 constraint forces the axis of the MacPherson strut to pass through its upper mounting point on the chassis.
• A PlaneToCircle1 constraint forces the bottom of the tire to remain in contact with the ground. PlaneToCircle1 places the surface of a torus (or a circle) in contact with a plane.
• A RelativeDistance1 constraint models the steering tie rod.
• Note that the explicit symbol used to represent time in Modeler3D (T by default) may be changed. The SymbolBasis option for SetSymbols is a nested list of strings that determines the basis for all of the symbols created by Modeler3D in the Global` context. Changing the first element of SymbolBasis changes the symbol that is recognized as the time variable.

### Runtime

Because of the presence of T in the driving constraint (constraint 3) the model can be run through its intended range of motion by varying T directly with the first argument to the SolveMech command. The way that this model is defined, the numerical value of T specifies the distance between the chassis and the ground.

## 4.1.4 3D Euler and Angular Formulations

Velocity and acceleration solutions are calculated in a 3D model in the same manner as in a 2D model. However, there are three options in a 3D model as to how the higher-order data is represented.
Since the angular orientation of Modeler3D bodies is specified by four Euler generalized parameters, {Eon, Ein, Ejn, Ekn}, one way of representing the angular velocity and acceleration of a body in 3-space is with the first and second derivatives of the Euler parameters, {Eond, ...} and {Eondd, ...}. Another more familiar way of representing angular velocity and acceleration is with the angular velocity and acceleration vectors, {omegaX, omegaY, omegaZ} and {alphaX, alphaY, alphaZ}, in either global coordinates or local coordinates attached to each individual body. Modeler3D can formulate the higher-order solutions in any of these representations, each of which requires that different sets of equations be built by the SetConstraints function. Which formulation is used is specified with the Method and Coordinates options for SetSymbols.

A system set-up function.

The Method option for SetSymbols may also be used with Modeler2D to specify angular coordinates or a degenerate version of Euler coordinates, although the Euler coordinates are seldom used in 2D models. Specifying Method -> Euler in a Modeler2D model causes the angular orientation of each body to be represented by a pair of coordinates {Ejn, Ekn} = {cos(n), sin(n)} instead of a single coordinate, n. Velocity and acceleration are also represented by the coordinate pairs {Ejnd, Eknd} and {Ejndd, Ekndd}. The inclusion of this feature in Modeler2D is largely academic; specifying Method -> Euler causes four equations to be generated for each body, instead of only three, and usually slows down the solution phase. There are two advantages afforded by 2D degenerate Euler coordinates: no trigonometric functions are generated in the constraint expressions so all of the constraints are purely algebraic, and the second derivative of a 2D rotation matrix is very simple which leads to faster solutions in some dynamical systems.

### 2D/3D

An option for SetSymbols.

### 3D

An option for SetSymbols.

The MacPherson strut front model defined in Section 4.1.3 is used to demonstrate the 3D velocity and acceleration solutions. The Solution -> Velocity option causes SolveMech to calculate the location and velocity of each body in the model.

Note that the angular velocity of each body is returned in the form of derivatives of Euler parameters. This is because the constraint equations were built with all default options for SetSymbols. If the model is rebuilt with the Method -> Angular option for SetSymbols, the first derivatives of the Euler parameters will be replaced by angular velocities.

The angular velocity of the chassis in global coordinates is represented by the symbols {x2, y2, z2}.
The Solution -> Acceleration option causes SolveMech to calculate the location, velocity, and acceleration of each body in the model. Note that it takes more time to execute the following command the first time than it will on all subsequent executions. This is because the acceleration equations must be built the first time through.

Since angular acceleration is the first derivative of angular velocity, the angular acceleration vector of the carrier, is represented by the derivatives of the angular velocity {x3d, y3d, z3d}.
The model is now rebuilt with the Coordinates -> Local option so that angular velocity is represented in local, instead of global, coordinates.

Note that the local angular velocity of body 3 is only slightly different from the global angular velocity. This is because the angular orientation of the wheel carrier is very close to being aligned with the global coordinate system.

# 4.2 Velocity and Acceleration Output

Now that the velocity and acceleration of each mechanism body has been calculated, useful output may be generated by developing expressions that are functions of Mech velocity and acceleration variables, and subjecting those expressions to the standard solution rules produced by SolveMech.

## 4.2.1 3D Example Mechanism

The 3D MacPherson strut suspension model is used to demonstrate various methods of producing velocity and acceleration output with Mech. The model is redefined as follows in abbreviated form.

## 4.2.2 Output Functions

While Mech provides a wide array of output functions that return various quantities related to body location or orientation, only a small subset of those output functions are available in versions that are related to body velocities or accelerations. The most basic of those are the two higher-order analogies of the Location function. For each of the following functions, the point argument can be a Mech point object or just the arguments to a Mech point object.

Velocity and acceleration output functions.

The velocity of the steering tie rod attachment point on the wheel carrier is very near zero in the global reference frame because the chassis is allowed to move up and down while the bottom of the tire (the carrier body) remains in contact with the ground. Thus the motion of the carrier with respect to the ground is just a small tipping about the bottom of the tire.

A related velocity function.

The velocity of the steering tie rod attachment point with respect to the chassis has a much larger vertical component, while the longitudinal and transverse components remain the same.

Two functions provide the higher-order analogies to the Rotation function.

### 2D

2D angular velocity and acceleration functions.

### 3D

3D angular velocity and acceleration functions.

Note that all Mech output functions formulate expressions in terms of derivatives of Euler parameters, or global angular velocities and accelerations, or local angular velocities and accelerations. Which form is returned depends on the settings of the Method and Coordinates options for SetSymbols that were in effect the last time that the model was built.
For example, the current model was built with the default Method -> Euler setting in SetSymbols; therefore, all output functions will return expressions in terms of derivatives of Euler parameters that can be replaced by a solution rule.

The Method -> Angular option is now used with SetSymbols. This changes the formulation of the Modeler3D output functions, but the numbers remain the same.

Again, the internal representation of the angular velocity can be changed to local coordinates, but the numerical results from the output functions remain the same.

Two more higher-order output functions.

There is a slight difference between using the velocity output functions Velocity, DDistanceDT, and so on, and simply differentiating their first-order counterparts Location and Distance. The first- and second-order output functions use the Mathematica D operator to differentiate the local coordinates of each point, thereby assuming that the local coordinates are constant unless they are explicitly functions of time T.

## 4.2.3 Differentiating Expressions

Although Mech provides only a small number of predefined output functions that relate to velocity and acceleration, any expression that is written in terms of Mech dependent variables can be differentiated with Dt because definitions have been automatically made for Dt[X, T], where X is any Mech dependent variable.

Note that Dt automatically replaced derivatives of dependent variables with the appropriate symbols. This form of differentiation is valid even when crossing from Euler to angular coordinates.
Consider the following example. With the Method -> Euler setting for SetSymbols, differentiating the seven Modeler3D location coordinates associated with body 3 with respect to T has the apparent effect of appending a d to the name of each variable. These new symbols are explicitly included in the solution rules returned by SolveMech.
However, with the Method -> Angular option set, differentiating the seven Modeler3D symbols with respect to T produces different symbolic results. This shows the functional relationship between the Euler parameters and the angular velocity. After replacement with a SolveMech solution rule, the results are numerically identical.

Note that the only difference between the derivatives of the Euler parameters in terms of global or local coordinates is that a few of the signs are swapped.

## 4.2.4 Euler's Angles

As shown in Sections 4.2.2 and 4.2.3, Euler parameters and their derivatives are directly related to the angular velocity vector of a spatial body, and a direct conversion between angular velocity and the derivatives of Euler parameters is possible. However, there is no vector representation of spatial angular orientation so other representations must be used.
One method of representing the angular orientation of a spatial body is to define a sequence of three finite rotations about three fixed axes that take a body from one orientation to another. These three rotations are called Euler's angles. Angular orientations represented by Euler's angles are readily converted to and from Euler parameters with a combination of Modeler3D output functions. Mech does not provide a single function to make this conversion, because there are many possible combinations of successive rotations that can be used to represent the angular orientation of a body.
The following example shows the general procedure required to convert an angular orientation from a sequence of finite rotations to a set of Euler parameters. In this particular case, the sequence of rotations are the most commonly used Euler's angles.

• Rotation 1 is a rotation phi about the global Z axis.
• Rotation 2 is a rotation theta about the X axis in the new reference frame created by rotation 1.
• Rotation 3 is a rotation psi about the Z axis in the new reference frame created by rotation 2.
•  Out[43]//MatrixForm=

The conversion of Euler parameters to a sequence of finite rotations is not such a straightforward process. The general procedure is to measure the angle between an appropriate pair of axes located in the global and local reference frames. The following example shows how to convert the Euler parameters eulpars back to three Euler's angles.

Any angular orientation can be represented by a single finite rotation about a fixed axis. This single rotation angle and axis are directly related to the Euler parameters so a direct conversion can be made with the Rotation function.

Some readers may be more familiar with the use of quaternions to represent the orientations of spatial bodies. Quaternions are four-dimensional complex quantities, with associated rules for multiplication, that allow them to be used much like 3D rotation matrices. The numerical values of the four elements of the quaternion qw + qx i + qy j + qz k are equivalent to the numerical values of the four Euler parameters {eo, ei, ej, ek} representing the same orientation. Quaternions and Euler parameters are notationally and conceptually quite different, but they are computationally equivalent.

## 4.2.5 2D Example Mechanism

The 2D pull-rod suspension model that was presented in Section 4.1 is used to demonstrate various methods of producing velocity and acceleration output with Mech. The model is redefined as follows in abbreviated form.

## 4.2.6 Interpolation

MechanicalSystems provides a function that enhances the functionality of the Mathematica Interpolation function when used with a Mech model. This function is described in Section 3.2, but this subsection covers its capability of automatically utilizing higher-order data to obtain higher accuracy the interpolated results.

Interpolation utilities.

To demonstrate the use of TimeInterpolate, we must have an expression to interpolate and a list of rules to interpolate it over.

The following plot shows a course representation of the shock length versus time. Only three data points were calculated by the previous call to SolveMech, T = 3, 1.5, and 0, so the ListPlot graphic consists of only two straight line segments.

If we use TimeInterpolate to interpolate among the three points, the curve looks much smoother, but it is still a very poor representation, because there is no way for the InterpolatingFunction to know that the curvature increases as T approaches zero.

A new table of three solution rules is calculated, but this time velocity and acceleration data is included. To avoid recalculating all of the location solution points, SolveMech is passed the list of location solutions that have already been generated.

The higher-order slope and curvature information contained in acctab is automatically included in the new InterpolatingFunction object returned by TimeInterpolate.

### Interpolating Solutions

Another method of applying interpolation is to directly interpolate the rules returned by SolveMech. SolveMech accepts the symbol Interpolation as an option name to tell SolveMech to interpolate the rules it returns. Note that SolveMech does not interpolate variables that are constant.

An option for SolveMech.

Because the Solution -> Acceleration option is given in the following example, the InterpolatingFunction objects returned contain slope and curvature information from the velocity and acceleration solutions.