Here is a quick Least Squares computation (unchecked):

pdl>use PDL::Slatec;
pdl> ($circle,$xp,$xi,$yp,$yi,) = rcols('cmm.txt',0,1,2,4,5);
pdl> $A = cat(-$yi,$xi,pdl(1),pdl(0),$xi,$yi,pdl(0),pdl(1))->mv(0,1)->splitdim(0,4)->clump(1,2);
pdl> $b = cat($xp,$yp)->mv(0,1)->clump(2);
pdl> p matinv($A->mv(0,1) x $A) x $A->mv(0,1) x $b(*1);

Hope this helps.
Chris

On 4/9/2017 15:59, Chris Marshall wrote:
Hi Erik-

Here is a sequence of commands in the pdl2 shell that
show how you can read the data from your coordinates files
and generate the A matrix as in your URL link:

# read in these columns into piddles
pdl> ($circle,$xp,$xi,$yp,$yi,) = rcols('cmm.txt',0,1,2,4,5);

# generate the A matrix from colum data, the sequence shows
# how the data ordering and dimensions are rearranged.
pdl> p cat(-$yi,$xi,pdl(1),pdl(0),$xi,$yi,pdl(0),pdl(1));

pdl> p cat(-$yi,$xi,pdl(1),pdl(0),$xi,$yi,pdl(0),pdl(1))->mv(0,1);

pdl> p cat(-$yi,$xi,pdl(1),pdl(0),$xi,$yi,pdl(0),pdl(1))->mv(0,1)->splitdim(0,4);

pdl> p cat(-$yi,$xi,pdl(1),pdl(0),$xi,$yi,pdl(0),pdl(1))->mv(0,1)->splitdim(0,4)->clump(1,2);

pdl> $A = cat(-$yi,$xi,pdl(1),pdl(0),$xi,$yi,pdl(0),pdl(1))->mv(0,1)->splitdim(0,4)->clump(1,2);
pdl> p $A

[
 [ -56.986366 -0.00536711 1           0]
 [-0.00536711   56.986366 0           1]
 [ -58.030087  0.01315322 1           0]
 [ 0.01315322   58.030087 0           1]
 [ -59.001671  0.00179112 1           0]
 [ 0.00179112   59.001671 0           1]
 [ -59.998104  0.02253121 1           0]
 [ 0.02253121   59.998104 0           1]
 [ -61.004448  0.00609248 1           0]
 [ 0.00609248   61.004448 0           1]
 [ -61.990383  0.01154447 1           0]
 [ 0.01154447   61.990383 0           1]
 [ -62.993629  0.00199315 1           0]
 [ 0.00199315   62.993629 0           1]
 [ -63.989956  0.02241261 1           0]
 [ 0.02241261   63.989956 0           1]
 [ -65.007301  0.00174078 1           0]
 [ 0.00174078   65.007301 0           1]
 [ -65.987686  0.01188208 1           0]
 [ 0.01188208   65.987686 0           1]
 [ -67.993156 -0.00039018 1           0]
 [-0.00039018   67.993156 0           1]
 [ -69.007614   0.0049898 1           0]
 [  0.0049898   69.007614 0           1]
]

I hope that gets you started.  You should take a look at the PDL Book
which goes into more details about using and working with PDL:

http://pdl.perl.org/?page=FirstSteps

Looking at the problem, I would consider combining the measurements
for each circle to estimate the coordinates of the hole centers and
using those reduced set of positions for your alignment calculation.

Also, you may wish to verify that the least squares estimates for the
sin and cos of the rotation have sin*sin + cos*cos = 1.

Cheers,
Chris

On 4/9/2017 15:03, butchert erik wrote:

Sorry for using too large attachments with the previous copy of my message.

Erik Butchert
---------- Original Message ----------
From: butchert erik <[email protected]>
To: [email protected]
Date: 09 April 2017 at 17:51
Subject: RE: [Pdl-general] 2d rigid transformation


Hi
Perhaps I can explain my issue better if I send you a copy of part of one of the text files I get from the co-ordinate measuring instrument (attached). The rows are the data for each hole in a test piece for assessing XY accuracy of a drilling machine.
Column 1 is the hole number
2 is the X program position
3 is the X measured position
4 is the X error
5, 6 and 7 are the same but for the Y axis
You can ignore the rest for the purposes of this exercise.
The problem is that when the test piece is aligned to the measuring machine it uses 2 drilled holes that have the same programmed X (or Y) position to establish a line parallel to the instrument axis, but of course there’s nothing magical about these “datum” holes they are as inaccurate as any other hole, this skews the panel against the CMM axes so the measured positions become more inaccurate as the distance from the constructed origin increases. What I am trying to get to is to calculate the best fit of the measured values to the programmed ones, and therefor the X,Y positions with the alignment error removed. If you examine the Xerror v Yerror plot in the pdf you will see instead of being round it is elongated in the Y axis,as typically the test piece is longer in the Y than in the X so I wonder how much of this is rotational error.
I can see references to the problem such as
https://elonen.iki.fi/code/misc-notes/2d-rigid-fit/
but haven’t found anything similar within Perl/PDL

BTW I use PDL’s extracted from the measurement files and GnuPlot to show very useful interactive plots so to be able to build the alignment correction within the existing Perl script would be a good step forward.

Erik



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
pdl-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdl-general

Reply via email to