|On this page…|
This section shows you a set of examples of orienting a test body and its attached coordinate systems (CSs). It makes detailed use of the rotation representations and conversions explained in the preceding section, Representations of Body Orientation, and shows how to use MATLAB® workspace variables in your SimMechanics™ block dialogs.
This sequence of examples assumes you are familiar with the basics of setting up and visualizing bodies and machines.
The later examples require a configured body to work with. Here you set up a simple body with one Body coordinate system (CS), located at the center of gravity (CG).
First, create, connect, and visualize the initial body:
Leave the other defaults. The CG CS is located at Origin position vector[0 0 0]. Select Show port for the CG CS and deselect it for CS1. Delete the CS1 entry. Click Apply.
Now configure the body's mass and geometric properties:
Switch from ellipsoid display to displaying individual body settings. This defaults back to convex hull display. But here, the CG CS triad alone displays. (There are no other CSs.) The x-, y-, and z-axes are red, green, and blue, respectively.
Turn the ellipsoid back on.
Test Body Ellipsoid: Initial Orientation, with Detail of CG CS Axes
In this example, you rotate the body, along with its CG CS axes, with respect to the World CS. The CG CS axes continue to have the same orientation with respect to the body shape. The rotation is a positive turn of 75 deg (degrees) about the axis (1,1,1) in World. In this example, you rotate with a quaternion.
The unit vector n in the (1,1,1) direction is (1,1,1)/. The rotation angle is θ = 75 deg = 1.3090 rad. At the MATLAB command line, define th = pi*75/180 and compute the quaternion components:
q = [sin(th/2)/sqrt(3) sin(th/2)/sqrt(3) sin(th/2)/sqrt(3) ... cos(th/2)] q = 0.3515 0.3515 0.3515 0.7934
To rotate the body and the CG CS coordinate axes together by this rotation,
Under Orientation vector, enter q. Leave the other defaults. The Relative to coordinate system field indicates that the rotation represented by q is oriented with respect to the World axes. Click Apply.
Test Body Ellipsoid: Body and Its CG CS Axes Rotated Together
You can also rotate the body without rotating its CG CS axes. To accomplish this requires leaving the Body CSs unchanged while rotating the body's inertia tensor relative to the CG CS. Here you use the same rotation as in the preceding example, but represent it as a rotation matrix.
The unit vector n in the (1,1,1) direction is (1,1,1)/. The rotation angle is θ = 75 deg = 1.3090 rad. Compute the rotation matrix:
nDotJ = [0 -1/sqrt(3) 1/sqrt(3); 1/sqrt(3) 0 -1/sqrt(3); ... -1/sqrt(3) 1/sqrt(3) 0] nDotJ = 0 -0.5774 0.5774 0.5774 0 -0.5774 -0.5774 0.5774 0 R = eye(3) + nDotJ*sin(th) + nDotJ^2*(1-cos(th)) R = 0.5059 -0.3106 0.8047 0.8047 0.5059 -0.3106 -0.3106 0.8047 0.5059
The components of the inertia tensor that you enter into the Body dialog are always defined relative to the CG CS axes. If you hold the CG CS axes fixed and rotate the body by a rotation matrix R, the inertia tensor transforms according to Inew = R*Iold*RT. Compute this with MATLAB:
I = [18 0 0; 0 56 0; 0 0 56] I = 18 0 0 0 56 0 0 0 56 Irot = R*I*R' Irot = 46.2753 -15.4698 5.9711 -15.4698 31.3911 9.4987 5.9711 9.4987 52.3336
Symmetrize Irot by entering Irot = (Irot + Irot')/2. Then rotate the body alone relative to World and the CG CS.
Test Body Ellipsoid: Body Rotated Relative to Its CG CS Axes
In the preceding examples, you work with only one Body CS, the CG CS. In this example, you set up additional Body CSs and learn how to rotate them. It is common in mechanical applications to require extra Body CSs to locate sensors and actuators on bodies. Their axis orientations do not, in general, align with the orientation of the CG CS axes.
You visualize the body here using convex hulls, instead of ellipsoids, to articulate the Body CSs more clearly. Obtaining a full convex hull, with a surface enclosing a volume, requires at least four non-coplanar Body CSs.
This example also shows you how to obtain Euler angles and rotate with them.
To change the visualization display to convex hulls,
To create and visualize the new Body CSs,
Test Body Convex Hull with CG CS and Three Body Coordinate Systems
The preceding examples used two rotation representations, the quaternion and the rotation matrix, based on the axis-angle representation. In this example, you use the same rotation as before, but represented as a set of Euler angles.
The rotation axis sequence convention is Z-X-Z, with Φ, θ, Ψ as the first, second, and third angles, respectively, the same as presented in Converting Rotation Representations preceding. To obtain the angles, you equate the rotation matrix form for that convention:
to the numerical form of R you computed in Rotating the Body Relative to Its Center of Gravity preceding:
R = 0.5059 -0.3106 0.8047 0.8047 0.5059 -0.3106 -0.3106 0.8047 0.5059
and invert the resulting equations. The solution for θ and Ψ is
theta = acos(R(3,3)) theta = 1.0404 psi = asin(R(3,1)/sin(theta)) psi = -0.3684
or about 60 and -21 deg, respectively.
Here is a method that yields a unique solution by using the structure of the Euler convention, R = R1(Φ)*R2(θ)*R3(Ψ). Multiply R on the right by R3(Ψ)T*R2(θ)T, isolating R1(Φ):
R3 = [cos(psi) -sin(psi) 0; sin(psi) cos(psi) 0; 0 0 1] R3 = 0.9329 0.3601 0 -0.3601 0.9329 0 0 0 1.0000 R2 = [1 0 0; 0 cos(theta) -sin(theta); 0 sin(theta) cos(theta)] R2 = 1.0000 0 0 0 0.5059 -0.8626 0 0.8626 0.5059 R1 = R*R3'*R2' R1 = 0.3601 -0.9329 -0.0000 0.9329 0.3601 -0.0000 0.0000 0.0000 1.0000 phi = acos(R1(1,1)) phi = 1.2024
or about 69 deg.
Here you rotate one of the Body CS axis triads, using the Z-X-Z rotation axis sequence convention and, for Euler angles, the Φ, θ, and Ψ you just found.
Under Orientation vector, enter [phi theta psi]. In the Units pull-down menu, select rad. In the Specified using convention pull-down menu, select Euler Z-X-Z. Click Apply.
This rotated orientation of the CS2 axis triad is the same as that of the rotated CG CS in Rotating the Body and Its CG CS Relative to World preceding. The two rotations are the same and produce the same result.