Change laser power based on feedrate?
Moderators: TomKerekes, dynomotion
Change laser power based on feedrate?
After experimenting with vector laser engraving a little bit, I think it would be ideal to be able to vary the laser power based on velocity, because otherwise as the machine decelerates around curves the laser burns deeper, with wider line width.
Has anyone done something like this? Is there a method that returns the current feed rate? If it were done in a C program that was running constantly, would that be reasonably fast? I know in the documentation about synchronized bit operations it says that C programs can be slow, but is that just if they need to be compiled and downloaded each time they are run? I'm somewhat unclear on that.
I think that even if laser power were changed in a fairly crude, non-deterministic way it would be helpful, e.g. if you could have even a single velocity threshold for increasing laser power on long, relatively straight paths. I don't think it would need to be done very fast, but it would probably need to be done in the middle of a motion, after the velocity has ramped up, and I don't know if that is possible...
Has anyone done something like this? Is there a method that returns the current feed rate? If it were done in a C program that was running constantly, would that be reasonably fast? I know in the documentation about synchronized bit operations it says that C programs can be slow, but is that just if they need to be compiled and downloaded each time they are run? I'm somewhat unclear on that.
I think that even if laser power were changed in a fairly crude, non-deterministic way it would be helpful, e.g. if you could have even a single velocity threshold for increasing laser power on long, relatively straight paths. I don't think it would need to be done very fast, but it would probably need to be done in the middle of a motion, after the velocity has ramped up, and I don't know if that is possible...
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Change laser power based on feedrate?
Hi amowry,
A C Program running constantly would be very fast (every 180us). Only downloading the Code under Windows would not be real-time deterministic.
See the VelocityToPWM.c example:
A C Program running constantly would be very fast (every 180us). Only downloading the Code under Windows would not be real-time deterministic.
See the VelocityToPWM.c example:
Code: Select all
#include "KMotionDef.h"
// Drives PWM output proportional to current Speed
#define FACTOR 0.01f // factor to convert speed to PWM counts
main()
{
float Speed;
int PWM;
SetBitDirection(26,1); // define bit as an output
FPGA(IO_PWMS_PRESCALE) = 13; // divide clock by 13 (5 KHz)
FPGA(IO_PWMS) = 0; // PWM off
FPGA(IO_PWMS+1) = 1; // Enable
for(;;)
{
WaitNextTimeSlice();
// compute xy speed in counts/sec
Speed = sqrtf(ch0->last_vel*ch0->last_vel + ch1->last_vel*ch1->last_vel);
PWM = (int)(Speed * FACTOR); // scale PWM
if (PWM>255) PWM=255; // limit to max PWM
FPGA(IO_PWMS) = PWM; // output PWM
}
}
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Change laser power based on feedrate?
Oh, great, thanks! I hadn't seen that example. That looks easier than I expected.
Would a reasonable approach be to add a similar for(;;) loop to my existing spindle speed program, which gets compiled/downloaded/run when it receives an M Code with the spindle speed? The program would set the initial speed received from the M code, and then the loop would constantly adjust that speed based on velocity. Then, when another M code is received it would start the program again in the same thread. Does that make sense, or would the code that runs continuously need to be in its own thread, separate from the one that gets run once when the M Code is received?
Would a reasonable approach be to add a similar for(;;) loop to my existing spindle speed program, which gets compiled/downloaded/run when it receives an M Code with the spindle speed? The program would set the initial speed received from the M code, and then the loop would constantly adjust that speed based on velocity. Then, when another M code is received it would start the program again in the same thread. Does that make sense, or would the code that runs continuously need to be in its own thread, separate from the one that gets run once when the M Code is received?
Re: Change laser power based on feedrate?
Sorry, if it wasn't clear, when I mentioned spindle speed I was referring to PWM/laser power in this case.
Re: Change laser power based on feedrate?
Also, is it possible to get the current commanded feed rate? it probably makes sense to monitor actual velocity as a percentage of the commanded feed rate, and reduce laser power proportionally.
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Change laser power based on feedrate?
Hi amowry,
I think the code would work best added to a forever loop in your Init Program that always runs in Thread #1.
Test a Virtual Bit to determine whether the power should be on or off. I recall you are sending the power via the UART to your Arduino? If on, compute the desired Power based on S Word Power and current Speed and periodically send out UART. You will probably need a timer to send the data only every few milliseconds or you may flood the UART.
The S action can then be basically a do-nothing program who's only purpose is to set the "Speed" in a Persist Var that the above code can access.
M3 and M5 commands can be configured to turn on or off the Virtual Bit that controls Power On/Off.
HTH
I think the code would work best added to a forever loop in your Init Program that always runs in Thread #1.
Test a Virtual Bit to determine whether the power should be on or off. I recall you are sending the power via the UART to your Arduino? If on, compute the desired Power based on S Word Power and current Speed and periodically send out UART. You will probably need a timer to send the data only every few milliseconds or you may flood the UART.
The S action can then be basically a do-nothing program who's only purpose is to set the "Speed" in a Persist Var that the above code can access.
M3 and M5 commands can be configured to turn on or off the Virtual Bit that controls Power On/Off.
HTH
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Change laser power based on feedrate?
Okay, thanks, I understand all that except where you said "compute the desired Power based on S Word Power", does that refer to the spindle speed that has been stored in a persist variable by the S action? If I wanted to calculate the current velocity as a percentage of the feedrate commanded by the G code, is that possible?
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Change laser power based on feedrate?
Well I was thinking S would be something like an exposure setting (maybe Joules/mm?). When multiplied by current speed (mm/sec) would give the power setting in Watts.I understand all that except where you said "compute the desired Power based on S Word Power", does that refer to the spindle speed that has been stored in a persist variable by the S action? If I wanted to calculate the current velocity as a percentage of the feedrate commanded by the G code, is that possible?
There isn't currently a command to read the Interpreter F Word. I suppose something could be added. There might be some issues with Interpreter lookahead where the Job changes the Feedrate.
Seems to me like using S would be more flexible allowing the feedrate and exposure to be set independently.
What do you think?
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
Re: Change laser power based on feedrate?
I guess my thinking is this:
Typically my G code will have a single feed rate for cuts (F word) and a single spindle speed (S word, in this case representing laser power) that is optimized for that feed rate and a particular material. So, all is well when the machine has fully accelerated to that feed rate.
If I know both the F word and the S word, then I can tell if the machine had reached maximum acceleration, and if not, I can throttle the laser power based on whatever the current velocity is. If the machine has reached maximum acceleration, I can just use the S word.
If I don't know the F word, then I could just set laser power based on velocity, but that wouldn't take the material into consideration, in other words it would be ignoring the F word in the the G code, which I chose based on material. So, it might work fine for wood, but not aluminum.
Does that make sense? It's quite possible I'm misunderstanding something that you've said.
I think what I can do is just have my post processor insert an M command at the beginning of my G code that passes the feedrate as a parameter to a persist variable. That could also be used to tell whether the G code is for the laser or my spindle, in which case I would always just send the S word to the Arduino without modification.
Typically my G code will have a single feed rate for cuts (F word) and a single spindle speed (S word, in this case representing laser power) that is optimized for that feed rate and a particular material. So, all is well when the machine has fully accelerated to that feed rate.
If I know both the F word and the S word, then I can tell if the machine had reached maximum acceleration, and if not, I can throttle the laser power based on whatever the current velocity is. If the machine has reached maximum acceleration, I can just use the S word.
If I don't know the F word, then I could just set laser power based on velocity, but that wouldn't take the material into consideration, in other words it would be ignoring the F word in the the G code, which I chose based on material. So, it might work fine for wood, but not aluminum.
Does that make sense? It's quite possible I'm misunderstanding something that you've said.
I think what I can do is just have my post processor insert an M command at the beginning of my G code that passes the feedrate as a parameter to a persist variable. That could also be used to tell whether the G code is for the laser or my spindle, in which case I would always just send the S word to the Arduino without modification.
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: Change laser power based on feedrate?
I think I understand that. So for example when burning wood at 100mm/min you might set the S=100 Watts. But when burning wood at 50mm/min you might set S=50 Watts to have the same exposure. Or with S tweaked some to correct for some non-linear power effects. Say for example 10% more S=55 Watts.Typically my G code will have a single feed rate for cuts (F word) and a single spindle speed (S word, in this case representing laser power) that is optimized for that feed rate and a particular material. So, all is well when the machine has fully accelerated to that feed rate.
Using my approach (without involving the set feedrate) when burning wood at 100mm/min you might set the S=1.0 Watts/(mm/min). When moving at 100mm/min the power would be 100 Watts. But when burning wood at 50mm/min you might leave S=1.0 Watts/(mm/min) to have the same exposure. Or S=1.1 Watts/(mm/min) to achieve the 10% more required for the slower feedrate. So you can achieve the same final results. I like this approach better because S value to be used will be mostly based on the material.
Otherwise yes the approach of the post processor setting an MCode Parameter with the Feedrate should work as well.
HTH
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.