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

Correct Laser/Spindle issues #17661

Merged
merged 22 commits into from
Jun 8, 2020

Conversation

shitcreek
Copy link
Contributor

@shitcreek shitcreek commented Apr 22, 2020

When using non PWM pin with just on/off, laser/spindle setPower uses SPEED_POWER_STARTUP instead of SPEED_POWER_MIN.
Changed inline_enabled call to inline_ocr_power to inline_power.

Fixed an issue that I had created in the other PR: laser wasn't turning off between moves. Solution: relocated translate_power back over to spindle_laser.cpp from spindle_laser.h.

@shitcreek shitcreek changed the title Laser/Spindle use max power for non PWM Correct Laser/Spindle issues Apr 30, 2020
@shitcreek shitcreek mentioned this pull request Apr 30, 2020
@mentaldemise
Copy link

mentaldemise commented May 5, 2020

Looks like I have this commit already in my local but the laser is occasionally not turning off. It doesn't seem to matter what I do with the S0/G0/M5 commands the laser will still stay on for a few of the first movements and then work like normal. The same will happen at various times through the etch but I'm having issue defining exactly where. Fire pin is tied to 5V with a 10K resistor.

The minimum I can manage to get to reproduce it is:

; LightBurn 0.9.11
; Marlin device profile, absolute coords
G21
G90
; Scan @ 80 mm/sec, 15% power
M106 S0 
G0 X181.39 Y40.4 F4800
G91
G1 X-0.03 F4800 I S38.3
M5 I
G0 X-7.13 Y-0.1 F4800
G1 X0.16 F4800 I S38.3
G0 X6.93 F4800
G1 X0.11 F4800 I S38.3
G0 X6.94 F4800
G1 X0.16 F4800 I S38.3
G0 X0.13 Y-0.1 
G1 X-0.31 I S38.3
G0 X-6.88 F4800
G1 X-0.19 F4800 I S38.3
G0 X-6.87 F4800
G1 X-0.32 F4800 I S38.3
M5 I
G1 X-0.13 Y-0.1 I S0
G90
M5 I
G90
; return to user-defined finish pos
G0 X0 Y0 F12000

@shitcreek
Copy link
Contributor Author

No, I don't mind it.

I was experiencing a similar thing before where the laser doesn't turn off for the first couple cuts, but it's all working now.

First off G0 and G1 don't take the I parameter. If you are using LASER_POWER_INLINE, LASER_MOVE_POWER and LASER_MOVE_G0_OFF then M3/M5 aren't even needed.

@mentaldemise
Copy link

OMG I love you! This is broken right now in the main bugfix branch though, so heads up.

Is there something I should tell them as to when to include the I or not?

@shitcreek
Copy link
Contributor Author

I'll add a note to the documentation

@thinkyhead thinkyhead force-pushed the max-power-non-pwm branch 4 times, most recently from 31c3595 to eb97cd1 Compare May 10, 2020 00:24
@thinkyhead thinkyhead force-pushed the max-power-non-pwm branch from eb97cd1 to bdc6eac Compare May 10, 2020 00:26
@thinkyhead
Copy link
Member

git fetch origin
git checkout max-power-non-pwm
git reset --hard origin/max-power-non-pwm

@thinkyhead thinkyhead added the Needs: Testing Testing is needed for this change label May 10, 2020
@shitcreek
Copy link
Contributor Author

Tested. With CUTTER_POWER_DISPLAY set to PWM255, power sent via gcode is being interpreted as percent but shown as PWM on the LCD, ie M3 S10 shows laser power at 25 on the LCD which is 10% of 255. Power set via the LCD is off by one to three degrees except for certain power such as at 204 and 255 which were spot on.

@thinkyhead thinkyhead force-pushed the max-power-non-pwm branch from c14a48f to edfccc7 Compare May 11, 2020 06:32
@thinkyhead
Copy link
Member

Corrected some unit conversions, and maybe even all of them.

@thinkyhead thinkyhead force-pushed the max-power-non-pwm branch 2 times, most recently from 0d21faa to 5fa7f05 Compare May 11, 2020 07:12
@thinkyhead thinkyhead force-pushed the max-power-non-pwm branch from 5fa7f05 to 8d586d3 Compare May 11, 2020 07:19
@shitcreek
Copy link
Contributor Author

Tested, same exact issues. I didn't mention before but power beyond min and max range are not corrected to min/max. And effective power range (where the laser actual power output is affected) appears to be between 0 and 25 via the LCD.

There were a couple obvious mistakes. The main cause here I believe is that there is a confusion between Unit power, Display power and what is set for min, max and startup power in config_adv. I think I am close with my local patch.

@thinkyhead thinkyhead force-pushed the max-power-non-pwm branch from c4d426d to da31ff4 Compare May 12, 2020 05:28
shitcreek added 4 commits May 23, 2020 16:58
cpower = power set in config_adv ie SPEED_POWER_MAX | for spindle it is in RPM, for laser it is in percent.
upower = unit power = set by CUTTER_POWER_UNIT in PWM, percent or RPM

power_to_range will take any value and puts it within the min and max power range.

In Relative mode, M3 S0 will not turn off the spndle/laser except if unit power is in RPM.
Menu power = laser/spindle control via LCD menu. Note: The dial can set the laser/spindle in the off state. Whe the laser is on, it can adjust the power, and turn off the power when dialed to zero.
@shitcreek
Copy link
Contributor Author

shitcreek commented May 24, 2020

'cpower' = power set in config_adv ie SPEED_POWER_MAX - for spindle it is in RPM, for laser it is in percent.
'upower' = unitPower = set by CUTTER_POWER_UNIT in PWM255, PERCENT or RPM
'power_to_range()' will take any value and puts it within the min and max power range.

In CUTTER_POWER_RELATIVE mode, 'M3 S0' won't turn off the spindle/laser except if unit power is in RPM.
mpower = menuPower = laser/spindle control via LCD menu.
Note: The dial can set the laser/spindle while in the off state. When the laser/spindle is on, the dial can adjust the power, and turn off the power when dialed to zero.

Todos/Notes:

  • M18 G28 at the end of file turns the pin on again.
  • Enabling SPEAKER interferes with laser/spindle - timer issue?
  • At and above 20Khz PWM frequency on my K40, the spindle/laser power is no longer modular, it is always on max. This is probably the limit of my laser power supply. Between 2.5Khz and 18Khz works well, but higher frequency demands faster moves.

@mentaldemise
Copy link

I'll have to pull latest and merge later. It's interesting that I'm running mine on an LPC1768 at 50kHz, was on the RAMPS as well and had no issue with power scale. I did on the LPC prior to adding a level shift.

Here's some of my videos of your code running(thought last time I had to update something to have it build lol) - This is a Mega2560(Ramps)
https://www.youtube.com/watch?v=vAA65vcwuIo

Raster(LPC required):
https://www.youtube.com/watch?v=EFzJmyRZ6YY

@shitcreek
Copy link
Contributor Author

Added LASER_MOVE_G28_OFF to disable the laser when homing.

@thinkyhead thinkyhead merged commit eda2fd8 into MarlinFirmware:bugfix-2.0.x Jun 8, 2020
@gminadak
Copy link

gminadak commented Jun 8, 2020

I don't know if this is the right place to report this.
After the latest merge i have the following errors
Compiles fine if i download it from @shitcreek or overwrite the files mentioned after every error (this is the first).

In file included from Marlin\src\MarlinCore.cpp:124:

Marlin\src\feature/spindle_laser.h: In static member function 'static void SpindleLaser::inline_disable()':
Marlin\src\feature/spindle_laser.h:228:37: error: no match for 'operator=' (operand types are 'power_status_t' and 'int')
  228 |       planner.laser_inline.status = 0;
      |                                     ^
In file included from Marlin\src\MarlinCore.cpp:44:
Marlin\src\module/planner.h:124:5: note: candidate: 'constexpr power_status_t& power_status_t::operator=(const power_status_t&)'
  124 |   } power_status_t;
      |     ^~~~~~~~~~~~~~
Marlin\src\module/planner.h:124:5: note:   no known conversion for argument 1 from 'int' to 'const power_status_t&'
Marlin\src\module/planner.h:124:5: note: candidate: 'constexpr power_status_t& power_status_t::operator=(power_status_t&&)'
Marlin\src\module/planner.h:124:5: note:   no known conversion for argument 1 from 'int' to 'power_status_t&&'
In file included from Marlin\src\MarlinCore.cpp:124:
Marlin\src\feature/spindle_laser.h: In static member function 'static void SpindleLaser::inline_ocr_power(uint8_t)':
Marlin\src\feature/spindle_laser.h:262:55: error: no match for 'operator=' (operand types are 'power_status_t' and 'int')
  262 |         planner.laser_inline.status = ocrpwr ? 0x03 : 0x01;
      |                                                       ^~~~
In file included from Marlin\src\MarlinCore.cpp:44:
Marlin\src\module/planner.h:124:5: note: candidate: 'constexpr power_status_t& power_status_t::operator=(const power_status_t&)'
  124 |   } power_status_t;
      |     ^~~~~~~~~~~~~~
Marlin\src\module/planner.h:124:5: note:   no known conversion for argument 1 from 'int' to 'const power_status_t&'
Marlin\src\module/planner.h:124:5: note: candidate: 'constexpr power_status_t& power_status_t::operator=(power_status_t&&)'
Marlin\src\module/planner.h:124:5: note:   no known conversion for argument 1 from 'int' to 'power_status_t&&'
Compiling .pio\build\LPC1768\src\src\feature\cancel_object.cpp.o
*** [.pio\build\LPC1768\src\src\MarlinCore.cpp.o] Error 1

@shitcreek
Copy link
Contributor Author

@gminadak I can confirm this new issue and have resolved it with this PR: #18237

Thanks for reporting the issue.

@gminadak
Copy link

gminadak commented Jun 9, 2020

I have the following issue but i can't be sure if it is Marlin related or from my machine/configuration.
The laser starts out of the designated path as you can see from the pictures.
This also happens with squares but its not visible always(on wood at least if i run the same gcode on other thinner material is visible).
On circles you can clearly see it every time.
I have change many parametres on my configuration microsteps, speeds, acceleration, laser delay, arc segment, junction deviation, tighten belts but the problem persists.
I find it hard to be mechanical because happens every time at the same shape spot where the laser starts firing but i could be wrong.
below is my configs and the Gcode.

Thank you.

pictures
config.zip

@shitcreek
Copy link
Contributor Author

It should be M5, not M05 and G0 and G1 do not take the I parameter because they are inlined already.
I corrected those, then ran your gcode and cannot reproduce your issue and your config seems fine after a quick glance.

@shitcreek
Copy link
Contributor Author

IMG_20200609_195131785

jmp0x0000 pushed a commit to jmp0x0000/Marlin that referenced this pull request Aug 7, 2020
HairingX pushed a commit to HairingX/Marlin that referenced this pull request Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Testing Testing is needed for this change PR: Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants