MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
16.24k stars 19.22k forks source link

Improve G29 topology report to include topology after corrections. #1978

Closed CptanPanic closed 9 years ago

CptanPanic commented 9 years ago

I understand that the auto bed correction can only handle corrections in a flat plane. I would find it useful if as part of the topology report (G29 T) not only displayed raw topology but also the calculated topology utilizing the bed level correction matrix. This way you could easily see if there is not flat plane problem with bed that wouldn't be fixed by matrix, and also the magnitude of the issue.

Is this how it work? You would to loop through each x,y,z position in the topology report, and call apply_rotation_xyz and report the z?

brainscan commented 9 years ago

G29 T can already be used to see how unflat/warped/bent/curved the bed is! Just increase the probe points and you can easily see the variation in the output. I don't understand how seeing the correction matrix would help anymore than what is already available?

Sent from my iPhone

On 27 Apr 2015, at 15:24, CptanPanic notifications@github.com wrote:

I understand that the auto bed correction can only handle corrections in a flat plane. I would find it useful if as part of the topology report (G29 T) not only displayed raw topology but also the calculated topology utilizing the bed level correction matrix. This way you could easily see if there is not flat plane problem with bed that wouldn't be fixed by matrix, and also the magnitude of the issue.

Is this how it work? You would to loop through each x,y,z position in the topology report, and call apply_rotation_xyz and report the z?

— Reply to this email directly or view it on GitHub.

nophead commented 9 years ago

It's hard to separate the tilt from the curvature just by looking at numbers. The post correction Z offset would be useful in showing how un-flat your bed is.

On 27 April 2015 at 15:42, brainscan notifications@github.com wrote:

G29 T can already be used to see how unflat/warped/bent/curved the bed is! Just increase the probe points and you can easily see the variation in the output. I don't understand how seeing the correction matrix would help anymore than what is already available?

Sent from my iPhone

On 27 Apr 2015, at 15:24, CptanPanic notifications@github.com wrote:

I understand that the auto bed correction can only handle corrections in a flat plane. I would find it useful if as part of the topology report (G29 T) not only displayed raw topology but also the calculated topology utilizing the bed level correction matrix. This way you could easily see if there is not flat plane problem with bed that wouldn't be fixed by matrix, and also the magnitude of the issue.

Is this how it work? You would to loop through each x,y,z position in the topology report, and call apply_rotation_xyz and report the z?

Reply to this email directly or view it on GitHub.

Reply to this email directly or view it on GitHub https://github.com/MarlinFirmware/Marlin/issues/1978#issuecomment-96680241 .

Roxy-3D commented 9 years ago

G29 T can already be used to see how unflat/warped/bent/curved the bed is! Just increase the probe points and you can easily see the variation in the output. I don't understand how seeing the correction matrix would help anymore than what is already available?

I tend to agree. But this is making the assumption that the bed is fairly well leveled and flat. In that case, you get the points with the mean height subtracted off and you can see how much higher or lower a point is from the mean height.

In the case where the bed is not very well leveled and/or flat, I can see where this would have value. But I almost wonder if it shouldn't be a separate command. The reason is G29 generates the correction matrix (that is its real purpose in life). To do what is being talked about very well may require many many more points to be probed. In fact, it may be you don't want to do just a grid but instead have the logic to map topographical lines.

Also, remember you have measurement and repeatability issues to deal with. For example, when trying to map out topographical lines and follow them, you would have to adjust for the fact that your measurements are not fully trustworthy. That is going to complicate what ever you are trying to accomplish.

I don't know... But it certainly is worth some discussion. And it would be an interesting piece of code to write if it really had some value.

CptanPanic commented 9 years ago

So I tried to do an example in matlab, but am not getting numbers that look correct. What am doing wrong? I was expecting something around 0.

% Matlab Code left = 58; right = 200; front = 12; back = 187;

num = 5;

x_pos = left:(right-left)/num:right; % Create array of x positions. y_pos = front:(back-front)/num:back; % Create array of y positions

topology = [+0.72043 +0.14788 -0.41823 -0.96191 -1.49031; ... +0.95981 +0.30659 -0.24449 -0.75714 -1.32516; ... +1.04907 +0.48535 +0.03427 -0.53303 -1.08864; ... +1.11064 +0.62210 +0.15408 -0.33947 -0.68363; ... +1.24167 +0.86601 +0.41828 +0.08916 -0.36334];

correction_matrix = [+0.999898 +0.000000 -0.014282; ... -0.000069 +0.999988 -0.004851; ... +0.014282 +0.004852 +0.999886];

topology_cor = topology;

for y = 1:num for x = 1:num point = [x_pos(x) y_pos(y) topology(x,y)]; correction = [x_pos(x) y_pos(y) topology(x,y)] * correction_matrix; topology_cor(x,y) = correction(3); end end

% Here is result. topology_cor =

-0.1662 -0.9085 -1.6443 -2.3577 -3.0558 -0.3325 -1.1554 -1.8762 -2.5586 -3.2963 -0.6488 -1.3823 -2.0031 -2.7401 -3.4654 -0.9929 -1.6512 -2.2889 -2.9522 -3.4661 -1.2675 -1.8129 -2.4303 -2.9292 -3.5514 `

nophead commented 9 years ago

As well as the rotation matrix there should also be a Z offset. This is where Marlin gets vague. However, the result doesn't look right even with an offset, but I don't know Matlab. Do array indices start at 1?

Roxy-3D commented 9 years ago

Do array indices start at 1?

Yes, in MatLab they thought that made sense...

Roxy-3D commented 9 years ago

I don't have a way to write this formatted correctly. But I think your point[] matrix should be 1x3 meaning 1 across and 3 down. If you change point = [x_pos(x); y_pos(y); topology(x,y)]; that might fix the problem. (I'm not a MatLab expert! But I think you want to get point into a 1x3 instead of a 3x1 format)

Alternatively... You could invert the sign of the numbers on each side of the diagonal of the correction matrix. I suspect that will get you the right numbers output (but in the wrong format --- instead of giving you a 1x3 you would get a 3x1 with the correct numbers in it).

CptanPanic commented 9 years ago

Thanks for the suggestions.

1) So matlab will not allow multiplying 1x3 matrix by 3x3. So have to use 3x1.

2) Also I tried doing the multiplication like vector_3.cpp does in vector_3::apply_rotation() like topology_cor(x,y) = x_pos(x) * correction_matrix(1,3) + y_pos(y) * correction_matrix(2,3) + topology(x,y) * correction_matrix(3,3); I get the same numbers.

3) I also tried inverting the signs of the diagonals, but that didn't give me better looking numbers, just different. Tonight when I get home I will try with the Marlin code.

Roxy-3D commented 9 years ago

1) So matlab will not allow multiplying 1x3 matrix by 3x3. So have to use 3x1.

This doesn't sound correct. I think it is 'correct' to multiply a [1x3] * [3x3] just as it is valid to multiply a [3x1] * [3x3] Please double check this because this doesn't 'correct'.

3) I also tried inverting the signs of the diagonals, but that didn't give me better looking numbers, just different. Tonight when I get home I will try with the Marlin code.

No! Do not invert the sign of the numbers going down the diagonals. Try inverting the sign of all the numbers off of the diagonal. If you notice, the matrix is symmetrical with the signs of the numbers flipped.

CptanPanic commented 9 years ago

So I was thinking about this more, and I think I was thinking about it wrong. What what help would be seeing the difference between the topology and the calculated flat plane.

CptanPanic commented 9 years ago

So I got things working in matlab, and generated a couple of cool plots. The image below shows the difference in mm between the topology and the flat plane. As you can see there is about .4mm difference between highest and lowest points, so I will definitely need to work on this, especially pulling down the front right edge. Second plot is shows flat plane, and the topology points.

Next I will try adding this calculation to Marlin

plane_fit3

flat_plane1-2

Roxy-3D commented 9 years ago

That is cool! What did you have to change to get the math to work right?

CptanPanic commented 9 years ago

I had 2 things wrong; First off I had the x/y values were from the front/left even though the topology was from back/left. Also I no longer applied correction to topology, but just to a constant z and then calculate the difference between this calculated z and topology.

brainscan commented 9 years ago

Yeah I stand corrected that is cool.

Sent from my iPhone

On 29 Apr 2015, at 16:31, CptanPanic notifications@github.com wrote:

I had 2 things wrong; First off I had the x/y values were from the front/left even though the topology was from back/left. Also I no longer applied correction to topology, but just to a constant z and then calculate the difference between this calculated z and topology.

— Reply to this email directly or view it on GitHub.

alvinavr commented 9 years ago

@CptanPanic Very good graph! Much easier to visualise than a table of numbers.

I have just modified Marlin to output a table of numbers showing the residual error after bed levelling. This helps with improving the mechanics.

Looking at your picture, your Y-bars are not parallel. I know because I had the same problem.

Roxy-3D commented 9 years ago

I have just modified Marlin to output a table of numbers showing the residual error after bed levelling. This helps with improving the mechanics.

If we had a web site where we could automatically run the code to make the chart that would be very helpful. What I'm thinking is Marlin would output: http://some.website/some_page #1 #2 #3 #4 #5 #6 #7 #8 #9 etc.

The user could copy that long line of output and paste it into a web browser. And then the page would magically get displayed with a detailed graph.

thanosd commented 9 years ago

I don't remember where I came across this, but I think it does what you want, though perhaps not with the exact URL "API" you showed:

http://www.maui-3d.com/cgi-bin/plotG29?plotG29ID=772

thinkyhead commented 9 years ago

I've been playing with THREE.js a bit and I can recommend it for doing custom 3D graphics, but if there's some already-built graphing lib that's your best bet. You can ask @Scotty1024 or @boelle (or me, I guess!) to add it to marlinfirmware.org, which is the appropriate place for all this stuff.

AnHardt commented 9 years ago

Played a bit with #2444 and realized that the map with the lowest point at zero is nice for graphical purposes but not for statistics.

Made some additions in https://github.com/AnHardt/Marlin_O/pull/11 to print out the Max, Min, Error_sum and Error²_sum of the topology blocks.

The exciting part of this is the calculation of the heights, to minimize the errors in the "Corrected Bed Height vs. Bed Topology:"-map.

diff = (eqnBVector[ind] - mean) - (z_tmp - avg2);

what means:

diff = (measured height[point] - mean_of measured_heights) -
(calculated_corrected_height[point] - mean_of_calculated_corrected_heights);
github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.