11.11.2014 Views

Exercise on Units and Quaternions - Percro

Exercise on Units and Quaternions - Percro

Exercise on Units and Quaternions - Percro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Elements of MATLAB <strong>and</strong> Simulink<br />

Scuola Superiore S.Anna<br />

Lecture 5 <str<strong>on</strong>g>Exercise</str<strong>on</strong>g>s, 05/05/2009<br />

Lecturer: Emanuele Rualdi<br />

1 Subsystems<br />

1.1 Wiring <strong>and</strong> Triggering<br />

Create a sequence of Subsystems that are activated <strong>on</strong>ly <strong>on</strong>ce at the start of the<br />

Simulati<strong>on</strong> <strong>and</strong> are executed in the correct order of dependencies<br />

1.2 Math <strong>and</strong> Libraries<br />

1.2.1 Quaterni<strong>on</strong>s<br />

A unit quaterni<strong>on</strong> (normalized) is a four dimensi<strong>on</strong>al vector that can be used for<br />

expressing rotati<strong>on</strong> in Three dimensi<strong>on</strong>al space. Create a library of blocks that can<br />

be used for manipulating quaterni<strong>on</strong>s:<br />

Quaterni<strong>on</strong>: (w, (x, y, z)) also for a quaterni<strong>on</strong> p expressed as (p r , p v ) where p v<br />

is a vector<br />

From Axis Angle (a, (x, y, z)) becomes (cos a/2, (x sin a/2, y sin a/2, z sin a/2))<br />

A real value (scalar) is a quaterni<strong>on</strong> with q v = 0 while a vector is a quaterni<strong>on</strong><br />

with no scalar part q r = 0<br />

1. C<strong>on</strong>jugate <strong>and</strong> Inverse (q r , −q v )<br />

2. C<strong>on</strong>versi<strong>on</strong> From Axis Angle representati<strong>on</strong><br />

3. Multiplicati<strong>on</strong> (p r q r − p v q v , p r q v + q r p v + p v × q v )<br />

4. Rotati<strong>on</strong> of Vector by Quaterni<strong>on</strong><br />

5. Decompositi<strong>on</strong> of Quaterni<strong>on</strong> in Axis Angle<br />

6. Exp<strong>on</strong>entiati<strong>on</strong> q t = (cos t · q r , q v sin t · q r )<br />

7. Slerp (Linear Interpolati<strong>on</strong>): Slerp(q0, q1, t) = q 0 (q −1<br />

0 q 1 ) t<br />

8. Finally package the Blocks in a Library<br />

References: some functi<strong>on</strong>alities are already in the Aerospace Blockset— <strong>and</strong> in an<br />

<strong>on</strong>line QLib Toolbox (http://www.mathworks.com/matlabcentral/leexchange/259)<br />

Elements of MATLAB <strong>and</strong> Simulink-1


1.3 Masking<br />

1.3.1 Unit C<strong>on</strong>versi<strong>on</strong><br />

Create a simple unit c<strong>on</strong>versi<strong>on</strong> block that takes some input dimensi<strong>on</strong>. Examples<br />

of units:<br />

ˆ Mass<br />

ˆ Length<br />

ˆ Currency (input currency rate as a matrix or as input)<br />

1. Example of parameter specied c<strong>on</strong>versi<strong>on</strong><br />

2. Example of Fixed Unit (e.g. kg) to user specied Unit<br />

3. Example of double unit<br />

1.3.2 Unit Check with Bus<br />

Create a set of blocks that allows to manage values with their associated unit. Each<br />

dimensi<strong>on</strong>ed value is now represented by a Bus object with two signals the value<br />

<strong>and</strong> the unit (value, unit). For the moment the unit can be chosen from a limited<br />

list (e.g. 1 for kg, 2 for t<strong>on</strong>, 3 for pund, 4 for ounces).<br />

Required Blocks:<br />

1. From Adimensi<strong>on</strong>al value to Dimensi<strong>on</strong>al (selecting Dimensi<strong>on</strong> by popup)<br />

2. Unit check between 2 inputs (Stop Simulati<strong>on</strong> in case of mismatch)<br />

3. Unit c<strong>on</strong>versi<strong>on</strong> from input bus to selected Dimensi<strong>on</strong><br />

4. From Dimensi<strong>on</strong>al to Value (just a Bus Selector)<br />

Note: ideally this unit check <strong>and</strong> propagati<strong>on</strong> should be d<strong>on</strong>e <strong>on</strong>ly at Editing time<br />

before the start of the Simulati<strong>on</strong><br />

Opti<strong>on</strong>al variant of this approach: instead of unit scalar comp<strong>on</strong>ent use a vector<br />

comp<strong>on</strong>ent in which the sec<strong>on</strong>d value is a scaling factor. In this way it is possible<br />

to represent the unit as: (coreunit, scale) for example kg are (1, 1) <strong>and</strong> t<strong>on</strong> are<br />

(1, 1000) .<br />

Opti<strong>on</strong>al variant II: a more sophisticated approach uses instead a vector unit plus<br />

scale in which each element of the vector is the power of an SI unit. For example<br />

(length, mass, time, current, temp) <strong>and</strong> for example Energy is (2, 1, −2).<br />

Elements of MATLAB <strong>and</strong> Simulink-2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!