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

[FR] laser control for the Mega Pro #49

Closed
hp-pepster opened this issue Jan 7, 2021 · 37 comments
Closed

[FR] laser control for the Mega Pro #49

hp-pepster opened this issue Jan 7, 2021 · 37 comments
Assignees
Labels
new feature New feature or request stale-closing-soon

Comments

@hp-pepster
Copy link

Hi,

are there any plans to work on the laser control of the new Mega Pro? If so, how is the progress? I might be of help as I digged a little bit through the source code from Anycubic for the Mega Pro.

@knutwurst
Copy link
Owner

Hi,
I don't see any mega pro sourcecode on github fron anycubic. Do you have a link? If so, I'll do my best to implement the laser functionality asap <3

@hp-pepster
Copy link
Author

It's not on github (yet), but a user posted it on thingiverse. As it's marlin-based, which is GPL3, anycubic has to give out the source. Link to the source: https://www.thingiverse.com/groups/anycubic-i3-mega-pro

The laser-part is very "interesting" implemented. As far as I've seen the relevant parts are in Marlin_main.cpp functions:
void Read_BMP(unsigned char* gray, unsigned int y, unsigned int x)
void Laset_print_picture(void)
void prepare_laser_print()

Maybe something in temperature.cpp is relevant as well.

I tried to describe the functionality as far as I understood it here: https://drucktipps3d.de/forum/topic/steuerung-laser-anycubic-mega-pro/?part=4#postid-131852 . But honestly, the code gave me an headache. Have a look at the Backup-Folder in the source for example :-) , so I might be completely mistaken.

There are some other code parts regarding the laser. One is for a basic gcode-control inline void gcode_G6() and the rest is for the display I think.

As other users mentioned before one has to fake the temp sensor on the nozzle with a resistor, otherwise the printer complains about a strange temperature of 0 °C (see https://drucktipps3d.de/forum/topic/steuerung-laser-anycubic-mega-pro/?part=2#postid-126858 )

Let me know if I can support you. Unfortunately I don't have the Mega Pro yet but I hope to receive it soon.

@knutwurst
Copy link
Owner

Wow! Thank you very much! That's probably the dirtiest and hackiest code I've ever seen but it looks very promising!

I'll dig into it and let you know what I found out so far and if I could implement the laser functionality. Sadly I don't have Mega P to test it :/

@hp-pepster
Copy link
Author

hp-pepster commented Jan 8, 2021

I have to thank you :-)

As soon as I get mine I can test your code.

@knutwurst knutwurst self-assigned this Jan 21, 2021
@Wirelessless
Copy link

Hi!
Thank you for your hard work!
I just got the Mega Pro with the LCD displaying V1.2.9 firmware and I can confirm that using the G6 command with S1-S100 turns the laser on full power and ignores any power setting (various forums suggest otherwise). I used a GCODE sequence that draws 6 different boxes at different power levels (S1-S10-S20-S30-S40-S50) and all cut the paper in the same way,
I am a little hesitant to keep using it like this as it might affect the lifespan of the laser.
I hope to see laser power support for the Mega Pro in a future release of your firmware.
Please let me know if I there is a release I can test!

@sims-60
Copy link

sims-60 commented Feb 5, 2021

Hi
@knutwurst are there any updates about the Laser?

@knutwurst
Copy link
Owner

Nope. Sorry but I'll update the thread and the readme when it's done.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label / comment or this will be closed in 5 days.

@0o0will0o0
Copy link

I believe this issue is still relevant and warrants attention due to this firmware being the best alternative I have found in comparison to anycubic's effort for the Ai3M Pro. I believe if piezoelectric leveling and/or laser control functionality is added, it would add immense value to this printer and I'd happily donate more to the project if an update came for these features

@sims-60
Copy link

sims-60 commented Mar 27, 2021

hi @knutwurst are there any updates about the laser?

@knutwurst
Copy link
Owner

HI @sims-60 , thank you very much, but I already have the original MEGA Pro firmware laying around ;)
Take a look at my current sourcecode. The Laser is already prepared ;)

@knutwurst
Copy link
Owner

Thanks a lot. I'll come back to you when I have any updates :)

@0o0will0o0
Copy link

Is there any way to get the piezo leveling to function like the original firmware?

@hp-pepster
Copy link
Author

Hi, my printer also arrived (I guess). As soon as I'm home again I could start testing. @knutwurst Are you planing to work on the laser any time soon? If you are interested I could have a look at you commits regarding the laser and help with some coding.

@knutwurst knutwurst added the new feature New feature or request label Apr 23, 2021
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label / comment or this will be closed in 5 days.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label / comment or this will be closed in 5 days.

@knutwurst
Copy link
Owner

The Chiron Support is finally done and now I'll take a look at the Mega Pro Laser ;)

@InoxDragoon
Copy link

InoxDragoon commented Jul 11, 2021

I'm also interested in getting the laser to work on Marlin 2.x. I'm planning on upgrading to your firmware soon, so please keep up the good work!

FYI: You can get the laser from Anycubic's website to "upgrade" to a P. the Mega S and the P are the same machine, just the P comes with the Laser.

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label / comment or this will be closed in 5 days.

@knutwurst
Copy link
Owner

Reopened, because it's not done yet ;)

@aman-tiwari
Copy link

aman-tiwari commented Aug 17, 2021

Hi!
Thank you for your hard work!
I just got the Mega Pro with the LCD displaying V1.2.9 firmware and I can confirm that using the G6 command with S1-S100 turns the laser on full power and ignores any power setting (various forums suggest otherwise). I used a GCODE sequence that draws 6 different boxes at different power levels (S1-S10-S20-S30-S40-S50) and all cut the paper in the same way,
I am a little hesitant to keep using it like this as it might affect the lifespan of the laser.
I hope to see laser power support for the Mega Pro in a future release of your firmware.
Please let me know if I there is a release I can test!

EDIT:
I skimmed the source code, it looks like there is no PWM laser power control in the raster engraving functionality! They use the heater pin to turn on/off the laser, and just stop at each pixel for f(grayscale value of pixel) cycles.
Relevant snippet:

for(j=0;j<x_max;j++)
{
  Read_BMP(&Y,i,x_max-j);
  if( Y>MIN_GRAY_VLAUE&&j!=0 ) 
{								 
    if(Laser_printer_st.pic_x_mirror==1)
    destination[X_AXIS]=x_end+j*Laser_printer_st.pic_pixel_distance;
    else
    destination[X_AXIS]=x_end-j*Laser_printer_st.pic_pixel_distance;									 
    line_to_destination(ftemp);
    set_current_to_destination();
    while (planner.blocks_queued());
    WRITE(HEATER_0_PIN, 1);
  if(Laser_printer_st.pic_vector==0)
  {
    time = Y*Laser_printer_st.pic_laser_time;
    while(time--)
    {
    WRITE(HEATER_0_PIN, 1); 
    }
    WRITE(HEATER_0_PIN, 0);
  }
... some screen stuff

Interestingly, it contains some unfinished code for vector engraving functionality (the above if(Laser_printer_st.pic_vector==0) doesn't have a corresponding else).

Previously below I wrote:

It could be that one of the fan PWM commands is used to control the laser: https://www.youtube.com/watch?v=1cyZCpfglAg, https://marlinfw.org/docs/configuration/laser_spindle.html
I just got my Mega Pro, I'll give some of those sequences a try after I get it set up

@mlewis-everley
Copy link

It's probably not of any help, but I noticed that some commands in marlin support a laser as well (eg: https://marlinfw.org/docs/gcode/M003.html)

I also noticed some other standard commands seem to also support a laser as well.

Just wondering if this is how laser support is intended to be added, or are we still going to have to do the weird BMP thing?

@knutwurst
Copy link
Owner

Unfortunately, since I don't have a laser, I can't test the Marlin features.

Actually, I wanted to recreate exactly the anycubic feature so that the original display would continue to work.

That's why I recreated the auto leveling for the Chiron instead of just using Marlin features.

@stklcode
Copy link
Contributor

stklcode commented Oct 2, 2021

I do own a Mega Pro and tried a first step towards the laser.

The wiring is (mis)using the hotend heater pins (A1, A2) for the laser power.

Setting a target temperature results in Error:MINTEMP triggered, system stopped! Heater_ID: 0

Simulating an arbitrary temperature with a resistor between A6/7 (see linked post above) enables laser control with M104 S0 (target temperature 0 = off) and a value greater current temperature enabled the PWM output.
In my case, the simulated temperature is 37.24°C, so with M104 S38 it starts with ~4Hz and ramps up with higher values. S37 or below makes the laser stop.

So with real ugly G-code sequences I was able to do some laser engraving in stock KW 1.3.1 firmware.

That's exactly what's represented in the disabled code fragments, e.g. WRITE(HEATER_0_PIN, 0).


There is obviously some work to do for the code fragments. Reordering and some declarations eventually makes it compiling, but not working.

#if ENABLED(KNUTWURST_MEGA_P)
  #define LASER_FEATURE
  #define SPINDLE_LASER_PWM_PIN HEATER_0_PIN
#endif

results in failing sanity check

Marlin/src/HAL/shared/../../inc/SanityCheck.h:2768:8: error: #error "SPINDLE_LASER_PWM_PIN conflicts with E0_AUTO_FAN_PIN."

Seems obvious, as the pin is used for both functions...

Are there any (unpublished) updates on the laser code fragments to build on or do I have to start off from the current master branch to - maybe - get it working?
(doen't seem to be too complex, but I've never worked with Marlin code til an hour ago)

@stklcode
Copy link
Contributor

stklcode commented Oct 4, 2021

Update:
Got the laser working with barely minimal changes to my Marlin 2.0.9 branch:
(branch stklcode@feature/laser, commit stklcode@d63b238)

It's now merged into the master branch: a161093

This does not yet feature display support, but it enables Marlin M003 G-Code support M3 S0 to M3 S254. Working nicely on my Mega P.

Unfortunately a trivial backport does not work. Maybe I just missed something or should have reloaded settings... Just spent ~10s of testing with the old branch.

@nilsacht
Copy link

Hi,

i own a Mega Pro now for one Week and I am very happy with this firmware. I wanted to test the Laser and found this topic.

Is there any progress in Laser functionality? Is it possible to use the Laser soon? Or is it possible to store my settings (e.g. mesh leveling), install original firmware, laser something, install this firmware and restore my settings?

Thanks.

@knutwurst
Copy link
Owner

Hi,
since the original firmware doesn't use the EEPROM at all, you can switch back and forth as you like ;)
Currently there is no progress in the laser development.. sorry :/

Olli

@nilsacht
Copy link

So i can install the original firmware, use the laser, install your firmware and my mesh leveling is still set up? That would by nice.

@knutwurst
Copy link
Owner

Yes, that should work.
I do it by myself and also switch to klipper and back to my firmware. The settings are still stored :)

@knutwurst
Copy link
Owner

knutwurst commented Nov 2, 2021

Laser Support added in Release 1.4.1 Beta 1

Thank you so much @stklcode !

@stklcode
Copy link
Contributor

stklcode commented Nov 2, 2021

Is "rudimentary" really the correct term here?

Fair to say, the Anycubic features are not yet supported. This requires some work in the TFT routine, so you can't "print" bitmaps from SD.

But unlike the (misused) G6 command of the stock FW the laser is dimmable with M3. (at least on my printer 1-255 were all the same intensity, so basically it's on/off). Good enough for use with lightburn or similar software in the current state.

So, it's a different implementation.

@knutwurst
Copy link
Owner

Is "rudimentary" really the correct term here?

You're right. Your work makes it possible to use the laser in the first place. Rudimentary was more related to the entire anycubic-related implementation. In the case of the Chiron, I called "can print and level, but the display doesn't work yet" also "rudimentary".

That should in no way reduce the value of your work and I would like to buy you a coffee ;)

@stklcode
Copy link
Contributor

stklcode commented Nov 2, 2021

I am not offended in any way, should have places a 😉 maybe.

Let’s see if we can get the not so straight-forward part for the built-in feature. I’ve seen the code snippets, but focused on the Marlin part to get any light out of it first place.

We should drink the coffee together. Likely never have started playing with the code without your prior work.

@knutwurst
Copy link
Owner

The marlin part is a pretty good start and when everything else works, connecting the display shouldn't be a problem. Maybe wen can reuse the anycubic bitmap parsing code to feed the marlin implementation.

@stklcode
Copy link
Contributor

stklcode commented Nov 3, 2021

Started working on the integration based on the 1.2.9 sources that have been partially ported already: stklcode@feature/anycubic-laser

It compiles, but it completely untested so far. But no need to start from scratch, if anyone wants to join development.

@github-actions
Copy link

github-actions bot commented Dec 4, 2021

This issue is stale because it has been open 30 days with no activity. Remove stale label / comment or this will be closed in 5 days.

@github-actions
Copy link

github-actions bot commented Feb 7, 2022

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.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new feature New feature or request stale-closing-soon
Projects
None yet
Development

No branches or pull requests

10 participants