Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBL LCD Matrix Plotting #4

Closed
Tannoo opened this issue May 26, 2017 · 346 comments
Closed

UBL LCD Matrix Plotting #4

Tannoo opened this issue May 26, 2017 · 346 comments

Comments

@Tannoo
Copy link
Owner

Tannoo commented May 26, 2017

@Roxy-3D, this is the 'new and improved' version... ready for improvement.

https://github.com/Tannoo/Marlin/tree/UBL_Mesh_Plotting

@Tannoo
Copy link
Owner Author

Tannoo commented May 26, 2017

I take that back.... I still need to scale up the 3x3 grid.

@Tannoo
Copy link
Owner Author

Tannoo commented May 27, 2017

Ok... Scaling issues..

Still trying to get this right.

    void _lcd_ubl_plot_drawing(uint8_t x_plot, uint8_t y_plot) {
      uint8_t x_frame_offset, y_frame_offset,
              x_frame_max, y_frame_max,
              x_pixel_scaling, y_pixel_scaling,
              x_pixel, y_pixel;

      // Starting points for the "box"
      x_frame_offset = (LCD_PIXEL_WIDTH / 6);
      y_frame_offset = (LCD_PIXEL_HEIGHT / 10);

      // Ending points for the "box"
      x_frame_max = x_frame_offset - 2;
      y_frame_max = y_frame_offset + 13;

      // Scaling for the pixel placement
      x_pixel_scaling = map(GRID_MAX_POINTS_X, 3, 15, 75, 10);
      y_pixel_scaling = map(GRID_MAX_POINTS_Y, 3, 15, 75, 10);

      // Points for pixel placement
      x_pixel = (x_plot * (x_pixel_scaling / 10)) + x_frame_offset + 2;
      y_pixel = (y_plot * (y_pixel_scaling / 10)) + y_frame_offset + 2;

      // Show X and Y positions at top of screen
      u8g.setColorIndex(1);
      u8g.setPrintPos(10, 8);
      lcd_print("X:");
      lcd_print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
      u8g.setPrintPos(70, 8);
      lcd_print("Y:");
      lcd_print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));

      // Draw frame and location pixel
      #if IS_KINEMATIC
        u8g.drawCircle(x_frame_offset * 2,
                       y_frame_offset * 2, y_frame_max / 2);
      #endif
      // Double the size of the "box" and pixel
      u8g.setScale2x2();
      // Draw the "box"
      u8g.drawFrame(x_frame_offset, y_frame_offset, x_frame_max, y_frame_max);
      // Plot the pixel
      u8g.drawPixel(x_pixel, y_pixel);

      // Print plot position
      u8g.undoScale();
      u8g.setPrintPos(10, 63);
      lcd_print("(");
      u8g.print(x_plot);
      lcd_print(",");
      u8g.print(y_plot);
      lcd_print(")");

      // Show the location value
      u8g.setPrintPos(60, 63);
      lcd_print("Z:");
      if (!isnan(ubl.z_values[x_plot][y_plot])) {
        lcd_print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
      }
      else {
        lcd_print(" -----");
      }
    }

@Roxy-3D
Copy link

Roxy-3D commented May 27, 2017

I don't see the problem yet...

@Tannoo
Copy link
Owner Author

Tannoo commented May 31, 2017

Okay, I've somewhat made progress, but still not ready.

3x3 maps just fine.... maybe I need the box to be the same size as the 15x15 that also maps just fine.

But, anything else between those are all jacked up.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 1, 2017

Okay, @Roxy-3D, I created a new branch to get it updated with the latest bugfix-1.1.x.

This is also the latest I have that works with 3x3 and 15x15 and removed most of the BS math that was only getting confusing and not helping much.

I've updated the posts above with current link and snipplet.

@Roxy-3D
Copy link

Roxy-3D commented Jun 1, 2017

I'll load it up as soon as I can....

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 2, 2017

I think I found that I need to scale another number.

      x_pixel = (x_plot * (x_pixel_scaling / 10)) + <<x_frame_offset + 2>>; <-- This one.
      y_pixel = (y_plot * (y_pixel_scaling / 10)) + <<y_frame_offset + 2>>; <-- And this one.

I will try in the morning with:

     x_pixel_offset = map(GRID_MAX_POINTS_X, 3, 15, x_frame-offset +2, 0);
     y_pixel_offset = map(GRID_MAX_POINTS_Y, 3, 15, y_frame-offset +2, 0);

      x_pixel = x_plot * (x_pixel_scaling / 10) + x_pixel_offset;
      y_pixel = y_plot * (y_pixel_scaling / 10) + y_pixel_offset;

@Roxy-3D
Copy link

Roxy-3D commented Jun 2, 2017

It seems like I'm at a stand still.... I need the Configuration.h files that cause the UBL Z lift problem and they are not posted yet. So... If you can have the 'current code' in your branch, I'll start debugging it tomorrow. Most likely, it will be easier to just do a re-write. But I'll start with what you have.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 2, 2017

I'm not pushing you... I'm just keeping you up to date.

It is up to date as of this morning.
https://github.com/Tannoo/Marlin/tree/UBL_Mesh_Plotting

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 2, 2017

I have some serial outputs happening to see what each variable is at any given point.

@Roxy-3D
Copy link

Roxy-3D commented Jun 2, 2017

OK! Great! If I don't have the needed Configuration.h files to duplicate the problem... I'll start trying to get the Postage Stamp map to work for all mesh dimensions in the morning....

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 2, 2017

x_pixel and y_pixel are the only ones that go out of range now.

@Roxy-3D
Copy link

Roxy-3D commented Jun 3, 2017

I'm starting to dip my toes into the water.

Probably _lcd_ubl_plot_draw(x_plot, y_plot); should be in ultralcd.cpp instead of in a .h file. If you keep working on that function.... In a day or two, I'll have a different implementation of it. And you can take what ever ideas you like and incorporate them into your code.

UPDATE: Oh! I think I see why you did that. That is the graphical version of the function. But the thing is, it is enough C++ code, it probably still belongs in ultralcd.cpp with conditional compilation flags around it.

YET ANOTHER UPDATE: I've got some problems trying to do things with Map Type 3. I have trouble even selecting it because my encoder wheel multiplier is too large. So, I have to back up and re-tune some of my settings. If you are open to suggestions.... You can work to get the title for each map type to display as the user rotates the dial. Maybe 'Map Type' should be a whole menu page with line items and when you pick one, it does it???

  • Topography to Host
  • CVS for Spreadsheet
  • Output to LCD Grid

And if you are willing to work together on this... I'll just focus on the 'Output to LCD Grid' version. The way you have 'Output to LCD Grid' setup looks nice. It would seem it isn't just a map option. It probably belongs in the map category also, but it would seem it should be a line item right under Activate and Deactivate. And maybe with a title 'Edit Mesh'.

And in fact, you have it setup so when a click happens, the mesh point gets edited. So, if you have other things you don't mind working on... Let me see if I can get the display to work right for all screen dimensions and maybe you can just paste the code in???

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 3, 2017

Yeah.... I couldn't get the u8g.fuctions to work in ultralcd.cpp.

After drowning in this for the last month or so, I was going to try and move it into ultralcd.cpp after getting it working.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 3, 2017

I have found that the scaling is not working because it's not linear. So, I'm trying to get everything to work individually and then incorporate a multimap function I found. Like mapping an array.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 3, 2017

The K.I.S.S. method is what I reminding myself. lol

@Roxy-3D
Copy link

Roxy-3D commented Jun 3, 2017

I didn't see these comments until after I edited my post up above.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 4, 2017

I didn't post them until after your edit. lol

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 4, 2017

So far, I have gotten 3x3 - 11x11 to work, the numbers are all over the place to make it work. Now, I can see why the maps were giving me such a fit.

@Roxy-3D
Copy link

Roxy-3D commented Jun 4, 2017

OK! I'm not sure how fast I'll make progress. Even with no interruptions (like more important things coming up) this is tricky code (as you know)!!!! But, it should be a fun piece of code to write!

Who knows... I might be able to get it working for all mesh sizes within 3 or 4 days....

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 4, 2017

I have some "dirty" code that works for most of it now. And I want to clean it up by implementing the multimap function:

    // note: the _in array should have increasing values
    int multiMap(int val, int* _in, int* _out, uint8_t size)
    {
      // take care the value is within range
      // val = constrain(val, _in[0], _in[size-1]);
      if (val <= _in[0]) return _out[0];
      if (val >= _in[size-1]) return _out[size-1];
    
      // search right interval
      uint8_t pos = 1;  // _in[0] allready tested
      while(val > _in[pos]) pos++;
    
      // this will handle all exact "points" in the _in array
      if (val == _in[pos]) return _out[pos];
    
      // interpolate in the right segment for the rest
      return (val - _in[pos-1]) * (_out[pos] - _out[pos-1]) / (_in[pos] - _in[pos-1]) + _out[pos-1];
    }

Unless you have a better way to handle data that looks more like an X,Y scatter chart. lol

@Roxy-3D
Copy link

Roxy-3D commented Jun 4, 2017

It would seem the simplest way would be to just enque a command for the .CSV and Topography Map to host. That would be just a "G29 T0" or a "G29 T1".

I think the problem with the current LCD Map and that code up above is I think differently than that. So I'll have to work through both and see what I can do with it.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 4, 2017

My code enques G29 T3 for the lcd map.

I have:
T0 for host output.
T1 for CSV.
T2 for X,Y list // Not sure what else you call it.
T3 for lcd map

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 4, 2017

G29 T2:

Bed Topography Report List:

M421 I 0 J 0 Z 0.000000 ; X 10.00, Y 10.00
M421 I 0 J 1 Z 0.000000 ; X 10.00, Y 26.50
M421 I 0 J 2 Z 0.000000 ; X 10.00, Y 43.00
M421 I 0 J 3 Z 0.000000 ; X 10.00, Y 59.50
M421 I 0 J 4 Z 0.000000 ; X 10.00, Y 76.00
M421 I 0 J 5 Z 0.000000 ; X 10.00, Y 92.50
M421 I 0 J 6 Z 0.000000 ; X 10.00, Y 109.00
M421 I 0 J 7 Z 0.000000 ; X 10.00, Y 125.50
M421 I 0 J 8 Z 0.000000 ; X 10.00, Y 142.00
M421 I 0 J 9 Z 0.000000 ; X 10.00, Y 158.50
M421 I 0 J 10 Z 0.000000 ; X 10.00, Y 175.00
M421 I 1 J 0 Z 0.000000 ; X 28.00, Y 10.00
M421 I 1 J 1 Z 0.000000 ; X 28.00, Y 26.50
M421 I 1 J 2 Z 0.000000 ; X 28.00, Y 43.00
M421 I 1 J 3 Z 0.000000 ; X 28.00, Y 59.50
...

@Roxy-3D
Copy link

Roxy-3D commented Jun 4, 2017

T2 for X,Y list // Not sure what else you call it.

I'm not sure how to convert it to a short and descriptive name. But it produces the gcode so that you can later print it and get it re-absorbed into the printer. Pretty much, it is an 'off printer backup of your mesh'

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 4, 2017

Pretty much, it is an 'off printer backup of your mesh'

OOOOhhhh.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 4, 2017

I'll change the name to "Mesh Backup Output".

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 4, 2017

OR "Mesh G-coded Output"

@Roxy-3D
Copy link

Roxy-3D commented Jun 4, 2017

Even "Off Printer Backup" would be good. And when people look at it and see the M421 commands... They will understand what is happening.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 4, 2017

K...done.

@Roxy-3D
Copy link

Roxy-3D commented Jun 12, 2017

Do you have time for one more quick edit?

Verifying...
sketch/ultralcd.cpp:2237:17: warning: extra tokens at end of #else directive
#else if ENABLED(ULTRA_LCD)
^
In file included from sketch/ultralcd.cpp:78:0:
sketch/ultralcd_impl_HD44780.h: In function 'void _lcd_ubl_output_char_lcd()':

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 12, 2017

K. done.. gotta go.

@Roxy-3D
Copy link

Roxy-3D commented Jun 12, 2017

See you! If it still fails... I'll fork Marlin and merge our stuff so I can fight Travis.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 12, 2017

Ok.. and you also still a collaborator staus, so you could fix the current PR.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 12, 2017

Just fix the branch we've been working in.

@Roxy-3D
Copy link

Roxy-3D commented Jun 12, 2017

Ok.. and you also still a collaborator staus, so you could fix the current PR.
Just fix the branch we've been working in.

The problem with doing that is I can't do a Pull Request. I can update your branch. But I can't make the changes go to MarlinFirmware/Marlin. So I did it the hard way. I forked Marlin... And I used ExamDiff Pro to map all of the changes in your branch over to the new fork. Then I fixed the Travis error. And it went the first time!!!

It is 'Squashed and Merged' !

Now... As soon as I get in the mood... I'll start the 20x4 LCD Work.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 12, 2017

Well, the PR is there.
Updating the branch will update the PR.
No need to re-create it.
That's all I was saying.

@Roxy-3D
Copy link

Roxy-3D commented Jun 12, 2017

Oh... Really? If I update your branch, the PR you made will automatically update? If so... That would have been much easier. I'm not very good at Git things.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 12, 2017

Yes, exactly.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 12, 2017

That's all I've been doing on these changes after the PR was made.

@Roxy-3D
Copy link

Roxy-3D commented Jun 13, 2017

I just realized something... We lost all the commit history by doing what I did. If that matters to you, it is easy for me to revert that merge and you just copy the couple of fixes I did to your branch and we do the same thing with your branch.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

Well, I had swash my branch, so the commit history is gone. Would you like me c
To create another branch and keep some commit history? That is one reason I didn't create the PR for quite a while... to get most things working before the PR and only keep history of changes AFTER the PR.

@Roxy-3D
Copy link

Roxy-3D commented Jun 13, 2017

Some people want their name in the commit history. That was my concern. But I can make it up to you. First.... if you make a branch for the 20x4 LCD work... It will be your branch that gets merged. (and you know I just give code away... I don't care about that stuff.) I'll send you my updates so you can commit them to the branch. And we can put your name in comments on all the UBL LCD stuff in the branch. Your contributions won't be forgotten.

@Roxy-3D
Copy link

Roxy-3D commented Jun 13, 2017

Well, I had swash my branch, so the commit history is gone.

Actually... Because MarlinFirmware/Marlin had a pull request from your branch.... Your branch still exists. I can re-open the pull request... Revert my commit... And you fix the one little thing I did to make Travis happy... And I think there is a chance everything is fixed....

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

I know what you did... it's what I was going to do.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

I didn't have time. I saw that it failed after I got to work.

@Roxy-3D
Copy link

Roxy-3D commented Jun 13, 2017

Yes. That is the only reason I did what I did. I wanted things merged just in case the code base got frozen for the reorganization work. I KNOW you could have fixed it and probably faster than it took me to do it.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

You can leave it... you re-wrote the main code to it anyway. It was a big deal. You can take the credit. :)

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

It also was your idea for the "postage stamp" also.

@Roxy-3D
Copy link

Roxy-3D commented Jun 13, 2017

OK... Seriously.... I like working with you... When I couldn't get the text to display... I cut and pasted your stuff into the tail end of what I did and magically everything was 'right'.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

Just leave it and maby work on the 20x4...and maybe a smoother exit routine?

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

I really don't mind, Roxy... you were a HUGE help.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

Let's just move forward with it.

@Roxy-3D
Copy link

Roxy-3D commented Jun 13, 2017

OK... Good Night! (at least for me... You are stuck working....)

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

I was going to try anf get the u8g stuff back into the dogm file.
I wasn't even thinking of going backwards.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

Yes.. g'night.

@Roxy-3D
Copy link

Roxy-3D commented Jun 13, 2017

What u8g stuff needs to be in the dogm.h file? I don't understand? Do you mean those #defines for screen positions?

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

Well, normally all u8g library calls are in the ulralcd_impl_DOGM.h, from what I've seen.

@Tannoo
Copy link
Owner Author

Tannoo commented Jun 13, 2017

I don't believe the #define's matter, due to them being global. Moving #define's would just be for organization, correct?

@Tannoo Tannoo closed this as completed Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants