Verified the function that converts the error in the NASS base

This commit is contained in:
Thomas Dehaeze 2019-12-11 09:43:30 +01:00
parent b3e630459a
commit 98555355d3
5 changed files with 137 additions and 73 deletions

View File

@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2019-12-11 mer. 09:33 -->
<!-- 2019-12-11 mer. 09:43 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Metrology</title>
@ -283,25 +283,25 @@ for the JavaScript code in this tag.
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#orge36f66d">1. How do we measure the position of the sample with respect to the granite</a></li>
<li><a href="#orgcafd665">2. Verify that the function to compute the reference pose is correct</a>
<li><a href="#org2effdbf">1. How do we measure the position of the sample with respect to the granite</a></li>
<li><a href="#org57e56b3">2. Verify that the function to compute the reference pose is correct</a>
<ul>
<li><a href="#orgf839195">2.1. Prepare the Simulation</a></li>
<li><a href="#org64c331a">2.2. Verify that the pose of the sample is the same as the computed one</a></li>
<li><a href="#org5dd1a72">2.3. Conclusion</a></li>
<li><a href="#org57ba635">2.1. Prepare the Simulation</a></li>
<li><a href="#org1da3199">2.2. Verify that the pose of the sample is the same as the computed one</a></li>
<li><a href="#org62ac4b9">2.3. Conclusion</a></li>
</ul>
</li>
<li><a href="#orgc313664">3. Verify that the function to convert the position error in the frame fixed to the nano-hexapod is working</a>
<li><a href="#orga7fd6e3">3. Verify that the function to convert the position error in the frame fixed to the nano-hexapod is working</a>
<ul>
<li><a href="#org2e27929">3.1. Prepare the Simulation</a></li>
<li><a href="#org3480bf2">3.2. Compute the wanted pose of the sample in the NASS Base from the metrology and the reference</a></li>
<li><a href="#org028d055">3.3. Verify that be imposing the error motion on the nano-hexapod, we indeed have zero error at the end</a></li>
<li><a href="#org1a89029">3.4. Conclusion</a></li>
<li><a href="#org7abb67d">3.1. Prepare the Simulation</a></li>
<li><a href="#org41022d3">3.2. Compute the wanted pose of the sample in the NASS Base from the metrology and the reference</a></li>
<li><a href="#org32b9b63">3.3. Verify that be imposing the error motion on the nano-hexapod, we indeed have zero error at the end</a></li>
<li><a href="#orgfd4276a">3.4. Conclusion</a></li>
</ul>
</li>
<li><a href="#org99c9716">4. Functions</a>
<li><a href="#org4a7e02c">4. Functions</a>
<ul>
<li><a href="#orgf3522b3">4.1. computeReferencePose</a></li>
<li><a href="#orgca5b1d1">4.1. computeReferencePose</a></li>
</ul>
</li>
</ul>
@ -314,25 +314,25 @@ Also, all the stages can be perfectly positioned.
</p>
<p>
First, in section <a href="#org96a102f">1</a>, is explained how the measurement of the position of the sample with respect to the granite is performed.
First, in section <a href="#orga4b40c4">1</a>, is explained how the measurement of the position of the sample with respect to the granite is performed.
</p>
<p>
In section <a href="#orgeb725b9">2</a>, we verify that the function developed to compute the wanted pose (translation and orientation) of the sample with respect to the granite can be determined from the wanted position of each stage (translation stage, tilt stage, spindle and micro-hexapod).
In section <a href="#org8d1551f">2</a>, we verify that the function developed to compute the wanted pose (translation and orientation) of the sample with respect to the granite can be determined from the wanted position of each stage (translation stage, tilt stage, spindle and micro-hexapod).
To do so, we impose a perfect displacement and all the stage, we perfectly measure the position of the sample with respect to the granite, and we verify that this measured position corresponds to the computed wanted pose of the sample.
</p>
<p>
Then, in section <a href="#org32bd651">3</a>, we introduce some positioning error in the position stages.
Then, in section <a href="#org869831b">3</a>, we introduce some positioning error in the position stages.
The positioning error of the sample expressed with respect to the granite frame (the one measured) is expressed in a frame connected to the NASS top platform.
Finally, we move the NASS such that it compensate for the positioning error that are expressed in the frame of the NASS, and we verify that the positioning error of the sample is well compensated.
</p>
<div id="outline-container-orge36f66d" class="outline-2">
<h2 id="orge36f66d"><span class="section-number-2">1</span> How do we measure the position of the sample with respect to the granite</h2>
<div id="outline-container-org2effdbf" class="outline-2">
<h2 id="org2effdbf"><span class="section-number-2">1</span> How do we measure the position of the sample with respect to the granite</h2>
<div class="outline-text-2" id="text-1">
<p>
<a id="org96a102f"></a>
<a id="orga4b40c4"></a>
A transform sensor block gives the translation and orientation of the follower frame with respect to the base frame.
</p>
@ -358,18 +358,18 @@ We can then determine extract other orientation conventions such that Euler angl
</div>
</div>
<div id="outline-container-orgcafd665" class="outline-2">
<h2 id="orgcafd665"><span class="section-number-2">2</span> Verify that the function to compute the reference pose is correct</h2>
<div id="outline-container-org57e56b3" class="outline-2">
<h2 id="org57e56b3"><span class="section-number-2">2</span> Verify that the function to compute the reference pose is correct</h2>
<div class="outline-text-2" id="text-2">
<p>
<a id="orgeb725b9"></a>
<a id="org8d1551f"></a>
</p>
<p>
The goal here is to perfectly move the station and verify that there is no mismatch between the metrology measurement and the computation of the reference pose.
</p>
</div>
<div id="outline-container-orgf839195" class="outline-3">
<h3 id="orgf839195"><span class="section-number-3">2.1</span> Prepare the Simulation</h3>
<div id="outline-container-org57ba635" class="outline-3">
<h3 id="org57ba635"><span class="section-number-3">2.1</span> Prepare the Simulation</h3>
<div class="outline-text-3" id="text-2-1">
<p>
We load the configuration.
@ -439,6 +439,7 @@ No position error for now (perfect positioning).
Rye = <span class="org-highlight-numbers-number">0</span>; <span class="org-comment">% [rad]</span>
Rze = <span class="org-highlight-numbers-number">0</span>; <span class="org-comment">% [rad]</span>
Dhe = zeros<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-highlight-numbers-number">6</span>,<span class="org-highlight-numbers-number">1</span><span class="org-rainbow-delimiters-depth-1">)</span>; <span class="org-comment">% [m,rad]</span>
Dhle = zeros<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-highlight-numbers-number">6</span>,<span class="org-highlight-numbers-number">1</span><span class="org-rainbow-delimiters-depth-1">)</span>; <span class="org-comment">% [m]</span>
Dne = zeros<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-highlight-numbers-number">6</span>,<span class="org-highlight-numbers-number">1</span><span class="org-rainbow-delimiters-depth-1">)</span>; <span class="org-comment">% [m,rad]</span>
</pre>
</div>
@ -453,8 +454,8 @@ And we run the simulation.
</div>
</div>
<div id="outline-container-org64c331a" class="outline-3">
<h3 id="org64c331a"><span class="section-number-3">2.2</span> Verify that the pose of the sample is the same as the computed one</h3>
<div id="outline-container-org1da3199" class="outline-3">
<h3 id="org1da3199"><span class="section-number-3">2.2</span> Verify that the pose of the sample is the same as the computed one</h3>
<div class="outline-text-3" id="text-2-2">
<p>
Let's denote:
@ -530,8 +531,8 @@ ans =
</div>
</div>
<div id="outline-container-org5dd1a72" class="outline-3">
<h3 id="org5dd1a72"><span class="section-number-3">2.3</span> Conclusion</h3>
<div id="outline-container-org62ac4b9" class="outline-3">
<h3 id="org62ac4b9"><span class="section-number-3">2.3</span> Conclusion</h3>
<div class="outline-text-3" id="text-2-3">
<div class="important">
<p>
@ -544,11 +545,11 @@ Both the measurement and the theory gives the same result.
</div>
</div>
<div id="outline-container-orgc313664" class="outline-2">
<h2 id="orgc313664"><span class="section-number-2">3</span> Verify that the function to convert the position error in the frame fixed to the nano-hexapod is working</h2>
<div id="outline-container-orga7fd6e3" class="outline-2">
<h2 id="orga7fd6e3"><span class="section-number-2">3</span> Verify that the function to convert the position error in the frame fixed to the nano-hexapod is working</h2>
<div class="outline-text-2" id="text-3">
<p>
<a id="org32bd651"></a>
<a id="org869831b"></a>
</p>
<p>
We now introduce some positioning error in the stage.
@ -559,8 +560,8 @@ This will induce a global positioning error of the sample with respect to the de
We want to verify that we are able to measure this positioning error and convert it in the frame attached to the Nano-hexapod.
</p>
</div>
<div id="outline-container-org2e27929" class="outline-3">
<h3 id="org2e27929"><span class="section-number-3">3.1</span> Prepare the Simulation</h3>
<div id="outline-container-org7abb67d" class="outline-3">
<h3 id="org7abb67d"><span class="section-number-3">3.1</span> Prepare the Simulation</h3>
<div class="outline-text-3" id="text-3-1">
<p>
We load the configuration.
@ -578,6 +579,23 @@ We set a small <code>StopTime</code>.
</pre>
</div>
<p>
We initialize all the stages.
</p>
<div class="org-src-container">
<pre class="src src-matlab">initializeGround<span class="org-rainbow-delimiters-depth-1">()</span>;
initializeGranite<span class="org-rainbow-delimiters-depth-1">()</span>;
initializeTy<span class="org-rainbow-delimiters-depth-1">()</span>;
initializeRy<span class="org-rainbow-delimiters-depth-1">()</span>;
initializeRz<span class="org-rainbow-delimiters-depth-1">()</span>;
initializeMicroHexapod<span class="org-rainbow-delimiters-depth-1">()</span>;
initializeAxisc<span class="org-rainbow-delimiters-depth-1">()</span>;
initializeMirror<span class="org-rainbow-delimiters-depth-1">()</span>;
initializeNanoHexapod<span class="org-rainbow-delimiters-depth-1">(</span>struct<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-string">'actuator'</span>, <span class="org-string">'piezo'</span><span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>;
initializeSample<span class="org-rainbow-delimiters-depth-1">(</span>struct<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-string">'mass'</span>, <span class="org-highlight-numbers-number">50</span><span class="org-rainbow-delimiters-depth-2">)</span><span class="org-rainbow-delimiters-depth-1">)</span>;
</pre>
</div>
<p>
We setup the reference path to be constant.
</p>
@ -606,12 +624,12 @@ initializeReferences<span class="org-rainbow-delimiters-depth-1">(</span>opts<sp
Now we introduce some positioning error.
</p>
<div class="org-src-container">
<pre class="src src-matlab">Dye = <span class="org-highlight-numbers-number">0</span>; <span class="org-comment">% [m]</span>
Rye = <span class="org-highlight-numbers-number">0</span>; <span class="org-comment">% [rad]</span>
Rze = <span class="org-highlight-numbers-number">0</span>; <span class="org-comment">% [rad]</span>
Dhe = <span class="org-rainbow-delimiters-depth-1">[</span><span class="org-highlight-numbers-number">1e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">3</span> ; <span class="org-highlight-numbers-number">0</span> ; <span class="org-highlight-numbers-number">2e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">3</span> ; <span class="org-highlight-numbers-number">1e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">3</span> ; <span class="org-highlight-numbers-number">0</span> ; <span class="org-highlight-numbers-number">3e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">3</span><span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-comment">% [m,rad]</span>
% Dhe = zeros(<span class="org-highlight-numbers-number">6</span>,<span class="org-highlight-numbers-number">1</span>);
<pre class="src src-matlab">Dye = <span class="org-highlight-numbers-number">1e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">6</span>; <span class="org-comment">% [m]</span>
Rye = <span class="org-highlight-numbers-number">2e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">4</span>; <span class="org-comment">% [rad]</span>
Rze = <span class="org-highlight-numbers-number">1e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">5</span>; <span class="org-comment">% [rad]</span>
Dhe = zeros<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-highlight-numbers-number">6</span>,<span class="org-highlight-numbers-number">1</span><span class="org-rainbow-delimiters-depth-1">)</span>;
% Dne = [<span class="org-highlight-numbers-number">1e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">3</span> ; <span class="org-highlight-numbers-number">0</span> ; <span class="org-highlight-numbers-number">2e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">3</span> ; <span class="org-highlight-numbers-number">0</span> ; <span class="org-highlight-numbers-number">3e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">3</span> ; <span class="org-highlight-numbers-number">1e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">3</span>]; % [m,rad]
Dhle = <span class="org-rainbow-delimiters-depth-1">[</span><span class="org-highlight-numbers-number">1e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">6</span> ; <span class="org-highlight-numbers-number">2e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">6</span> ; <span class="org-highlight-numbers-number">3e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">6</span> ; <span class="org-type">-</span><span class="org-highlight-numbers-number">2e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">6</span> ; <span class="org-highlight-numbers-number">1e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">6</span> ; <span class="org-highlight-numbers-number">2e</span><span class="org-type">-</span><span class="org-highlight-numbers-number">6</span><span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-comment">% [m]</span>
Dne = zeros<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-highlight-numbers-number">6</span>,<span class="org-highlight-numbers-number">1</span><span class="org-rainbow-delimiters-depth-1">)</span>;
</pre>
</div>
@ -626,8 +644,8 @@ And we run the simulation.
</div>
</div>
<div id="outline-container-org3480bf2" class="outline-3">
<h3 id="org3480bf2"><span class="section-number-3">3.2</span> Compute the wanted pose of the sample in the NASS Base from the metrology and the reference</h3>
<div id="outline-container-org41022d3" class="outline-3">
<h3 id="org41022d3"><span class="section-number-3">3.2</span> Compute the wanted pose of the sample in the NASS Base from the metrology and the reference</h3>
<div class="outline-text-3" id="text-3-2">
<p>
Now that we have introduced some positioning error, the computed wanted pose and the measured pose will not be the same.
@ -750,20 +768,20 @@ Rz = <span class="org-rainbow-delimiters-depth-1">[</span>cos<span class="org-ra
<tbody>
<tr>
<td class="org-left">Error</td>
<td class="org-right">-1.0e-03</td>
<td class="org-right">1.0e-06</td>
<td class="org-right">-2.0e-03</td>
<td class="org-right">-1.0e-03</td>
<td class="org-right">3.0e-06</td>
<td class="org-right">-3.0e-03</td>
<td class="org-right">2.8e-06</td>
<td class="org-right">-2.0e-06</td>
<td class="org-right">-1.3e-06</td>
<td class="org-right">-5.1e-06</td>
<td class="org-right">-1.8e-04</td>
<td class="org-right">4.2e-07</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-org028d055" class="outline-3">
<h3 id="org028d055"><span class="section-number-3">3.3</span> Verify that be imposing the error motion on the nano-hexapod, we indeed have zero error at the end</h3>
<div id="outline-container-org32b9b63" class="outline-3">
<h3 id="org32b9b63"><span class="section-number-3">3.3</span> Verify that be imposing the error motion on the nano-hexapod, we indeed have zero error at the end</h3>
<div class="outline-text-3" id="text-3-3">
<p>
We now keep the wanted pose but we impose a displacement of the nano hexapod corresponding to the measured position error.
@ -845,20 +863,20 @@ Verify that the pose error is small.
<tbody>
<tr>
<td class="org-left">Error</td>
<td class="org-right">-3.0e-09</td>
<td class="org-right">-1.0e-09</td>
<td class="org-right">3.0e-09</td>
<td class="org-right">2.0e-09</td>
<td class="org-right">-1.0e-09</td>
<td class="org-right">3.0e-09</td>
<td class="org-right">1.0e-16</td>
<td class="org-right">-1.1e-18</td>
<td class="org-right">3.3e-20</td>
<td class="org-right">1.5e-16</td>
<td class="org-right">5.8e-17</td>
<td class="org-right">-6.1e-16</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-org1a89029" class="outline-3">
<h3 id="org1a89029"><span class="section-number-3">3.4</span> Conclusion</h3>
<div id="outline-container-orgfd4276a" class="outline-3">
<h3 id="orgfd4276a"><span class="section-number-3">3.4</span> Conclusion</h3>
<div class="outline-text-3" id="text-3-4">
<div class="important">
<p>
@ -870,15 +888,15 @@ Indeed, we are able to convert the position error in the frame of the NASS and t
</div>
</div>
<div id="outline-container-org99c9716" class="outline-2">
<h2 id="org99c9716"><span class="section-number-2">4</span> Functions</h2>
<div id="outline-container-org4a7e02c" class="outline-2">
<h2 id="org4a7e02c"><span class="section-number-2">4</span> Functions</h2>
<div class="outline-text-2" id="text-4">
</div>
<div id="outline-container-orgf3522b3" class="outline-3">
<h3 id="orgf3522b3"><span class="section-number-3">4.1</span> computeReferencePose</h3>
<div id="outline-container-orgca5b1d1" class="outline-3">
<h3 id="orgca5b1d1"><span class="section-number-3">4.1</span> computeReferencePose</h3>
<div class="outline-text-3" id="text-4-1">
<p>
<a id="org8505281"></a>
<a id="org9e21b70"></a>
</p>
<p>
@ -971,7 +989,7 @@ This Matlab function is accessible <a href="src/computeReferencePose.m">here</a>
</div>
<div id="postamble" class="status">
<p class="author">Author: Dehaeze Thomas</p>
<p class="date">Created: 2019-12-11 mer. 09:33</p>
<p class="date">Created: 2019-12-11 mer. 09:43</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>

View File

@ -145,6 +145,7 @@ No position error for now (perfect positioning).
Rye = 0; % [rad]
Rze = 0; % [rad]
Dhe = zeros(6,1); % [m,rad]
Dhle = zeros(6,1); % [m]
Dne = zeros(6,1); % [m,rad]
#+end_src
@ -250,6 +251,20 @@ We set a small =StopTime=.
set_param(conf_simscape, 'StopTime', '0.5');
#+end_src
We initialize all the stages.
#+begin_src matlab
initializeGround();
initializeGranite();
initializeTy();
initializeRy();
initializeRz();
initializeMicroHexapod();
initializeAxisc();
initializeMirror();
initializeNanoHexapod(struct('actuator', 'piezo'));
initializeSample(struct('mass', 50));
#+end_src
We setup the reference path to be constant.
#+begin_src matlab
opts = struct( ...
@ -273,12 +288,12 @@ We setup the reference path to be constant.
Now we introduce some positioning error.
#+begin_src matlab
Dye = 0; % [m]
Rye = 0; % [rad]
Rze = 0; % [rad]
Dhe = [1e-3 ; 0 ; 2e-3 ; 1e-3 ; 0 ; 3e-3]; % [m,rad]
% Dhe = zeros(6,1);
Dye = 1e-6; % [m]
Rye = 2e-4; % [rad]
Rze = 1e-5; % [rad]
Dhe = zeros(6,1);
% Dne = [1e-3 ; 0 ; 2e-3 ; 0 ; 3e-3 ; 1e-3]; % [m,rad]
Dhle = [1e-6 ; 2e-6 ; 3e-6 ; -2e-6 ; 1e-6 ; 2e-6]; % [m]
Dne = zeros(6,1);
#+end_src
@ -371,8 +386,8 @@ Verify that the pose error corresponds to the positioning error of the stages.
#+RESULTS:
| | Edx [m] | Edy [m] | Edz [m] | Erx [rad] | Ery [rad] | Erz [rad] |
|-------+----------+---------+----------+-----------+-----------+-----------|
| Error | -1.0e-03 | 1.0e-06 | -2.0e-03 | -1.0e-03 | 3.0e-06 | -3.0e-03 |
|-------+---------+----------+----------+-----------+-----------+-----------|
| Error | 2.8e-06 | -2.0e-06 | -1.3e-06 | -5.1e-06 | -1.8e-04 | 4.2e-07 |
** Verify that be imposing the error motion on the nano-hexapod, we indeed have zero error at the end
We now keep the wanted pose but we impose a displacement of the nano hexapod corresponding to the measured position error.
@ -422,8 +437,8 @@ Verify that the pose error is small.
#+RESULTS:
| | Edx [m] | Edy [m] | Edz [m] | Erx [rad] | Ery [rad] | Erz [rad] |
|-------+----------+----------+---------+-----------+-----------+-----------|
| Error | -3.0e-09 | -1.0e-09 | 3.0e-09 | 2.0e-09 | -1.0e-09 | 3.0e-09 |
|-------+---------+----------+---------+-----------+-----------+-----------|
| Error | 1.0e-16 | -1.1e-18 | 3.3e-20 | 1.5e-16 | 5.8e-17 | -6.1e-16 |
** Conclusion
#+begin_important

Binary file not shown.

View File

@ -0,0 +1,31 @@
% Inverse Kinematics of the Hexapod
% :PROPERTIES:
% :header-args:matlab+: :tangle ../src/inverseKinematicsHexapod.m
% :header-args:matlab+: :comments org :mkdirp yes
% :header-args:matlab+: :eval no :results none
% :END:
% <<sec:inverseKinematicsHexapod>>
% This Matlab function is accessible [[file:src/inverseKinematicsHexapod.m][here]].
function [L] = inverseKinematicsHexapod(hexapod, AP, ARB)
% inverseKinematicsHexapod - Compute the initial position of each leg to have the wanted Hexapod's position
%
% Syntax: inverseKinematicsHexapod(hexapod, AP, ARB)
%
% Inputs:
% - hexapod - Hexapod object containing the geometry of the hexapod
% - AP - Position vector of point OB expressed in frame {A} in [m]
% - ARB - Rotation Matrix expressed in frame {A}
% Wanted Length of the hexapod's legs [m]
L = zeros(6, 1);
for i = 1:length(L)
Bbi = hexapod.pos_top_tranform(i, :)' - 1e-3*[0 ; 0 ; hexapod.TP.thickness+hexapod.Leg.sphere.top+hexapod.SP.thickness.top+hexapod.jacobian]; % [m]
Aai = hexapod.pos_base(i, :)' + 1e-3*[0 ; 0 ; hexapod.BP.thickness+hexapod.Leg.sphere.bottom+hexapod.SP.thickness.bottom-hexapod.h-hexapod.jacobian]; % [m]
L(i) = sqrt(AP'*AP + Bbi'*Bbi + Aai'*Aai - 2*AP'*Aai + 2*AP'*(ARB*Bbi) - 2*(ARB*Bbi)'*Aai);
end
end