-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
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] Handle M3/M5 in planner blocks #11576
Comments
I have the same problem - unfortunately this breaks especially grayscale engraving which continuously needs to modify the laser output power. Reason for the interrupted moves seems to be the call to "planner.synchronize" - of course, this is necessary to wait for the laser power change until the current moves end. But it leads to stuttering moves (and each time the laser stops moving or is slowed down, it obviously burns a deep mark into the material). This might not be a problem for a spindle, but for a laser it surely is. In contrast, M106 commands plan the fan power for the next move "block". This should also be the case for M3 commands. |
We have a laser overhaul planned, generalizing to more types of lasers such as those that require a 25KHz base frequency, allowing more freedom in the use of PWM-capable pins, making sure it works well with all our 32-bit boards in addition to AVR, and requiring |
Maybe this should be commented somewhere here: At the moment it is not a good idea to use the laser/spindle configuration (at least not for an engraving laser). Selecting one of the PWM pins described there, assigning them to a fan pin and using M106 commands is currently the best option. |
The website is also open source. https://github.com/MarlinFirmware/MarlinDocumentation |
Here you go: MarlinFirmware/MarlinDocumentation#186 ;-) |
[ If this not the right place to post such a comment - please advise and I will move it ] |
At the moment you should ignore the whole "LASER_SPINDLE..." part. Only use FAN1_PIN and M106 commands. The laser/spindle options configure M3/M5 commands which are currently broken (at least for laser usage). See initial posts of this issue. |
After a bit of work on the software, I finally have a good result with a modified 1.1.9 version. I'm currently able to run a 40w co2 laser engraving pretty small shapes accurately at 6000mm/min.
I found the function that is called at the end of a block, this is " At first, I called the void Planner::UpdateFan(){
unsigned char axis_active[NUM_AXIS] = { 0 },
tail_fan_speed[FAN_COUNT];
if (has_blocks_queued()) {
#if FAN_COUNT > 0
for (uint8_t i = 0; i < FAN_COUNT; i++)
tail_fan_speed[i] = block_buffer[block_buffer_tail].fan_speed[i];
#endif
}
else {
#if FAN_COUNT > 0
for (uint8_t i = 0; i < FAN_COUNT; i++) tail_fan_speed[i] = fanSpeeds[i];
#endif
}
#if FAN_MIN_PWM != 0 || FAN_MAX_PWM != 255
#define CALC_FAN_SPEED(f) (tail_fan_speed[f] ? map(tail_fan_speed[f], 1, 255, FAN_MIN_PWM, FAN_MAX_PWM) : 0)
#else
#define CALC_FAN_SPEED(f) tail_fan_speed[f]
#endif
#if ENABLED(FAN_SOFT_PWM)
#if HAS_FAN0
thermalManager.soft_pwm_amount_fan[0] = CALC_FAN_SPEED(0);
#endif
#if HAS_FAN1
thermalManager.soft_pwm_amount_fan[1] = CALC_FAN_SPEED(1);
#endif
#if HAS_FAN2
thermalManager.soft_pwm_amount_fan[2] = CALC_FAN_SPEED(2);
#endif
#else
#if HAS_FAN0
analogWrite(FAN_PIN, CALC_FAN_SPEED(0));
#endif
#if HAS_FAN1
analogWrite(FAN1_PIN, CALC_FAN_SPEED(1));
#endif
#if HAS_FAN2
analogWrite(FAN2_PIN, CALC_FAN_SPEED(2));
#endif
#endif
} So that way, if I really understand how planner work, each time a M106 or M107 command is received, a new empty block is added in the block buffer, and at each buffer end, UpdateFan check the new PWM value. I know that it is a dirty workaround, so if any of you have better idea I will be really happy !! =) |
What problem are you solving with this? The stepper ISR should already be updating the fan (laser) PWM as part of handling a block. The desired fan (laser) power simply has to be set before sending the next move to the planner, and the stepper ISR will set the new PWM value when it gets to that block. The only thing a sync block will do (if not actually being used to update the stepper positions) is to use up time and space in the planner queue. |
Any news on getting the M3/M4 command delays sorted out? or is this a low priority at the moment? |
So, some users in the v1engieering.com forums, have been getting some fuzzy laser results using the fan solution, and they are on a modified version of bugfix-2.0. Ryan tracked it down to a change in Marlin.cpp that only updates the fan speed every 100ms. It's in this commit: It went from this:
Reducing the speed of the fan updates seems smart, but not when someone has laser control on there. I think the solution from SmarteedCS was to basically start calling this from other places, which effectively increased the rate of the updates. So what should the next step be? If users just did a) on their own, are there any obvious side effects? |
I'd love option c) as I am using Marlin on a multi-purpose 3D printer (laser oder 3D print via quick release head). But you would have to rewrite the whole M3/M5 behaviour cause it's completely different than M106. Or option b) but allow configuration per fan (to be able to configure something like: first fan has the 100ms limitation, second fan is not limited). I guess this would be the easiest change. |
@SmarteedCS is the problem still there with latest bugfix 2.0? |
@drgrandios @SmarteedCS @jeffeb3 @boelle How are you guys driving your laser pin now? M3 or M106 (plus "fast fan update" revert as described above by @drgrandios)? My other issue is getting more than 1khz on the PWM (laser needs ~20khz) with my Due board - does anyone have some wisdom on this? |
@thinkyhead i think we can close this one |
Were there any updates on M3/M5 at all in bugfix 2.0? From my understanding, the initial issue is not fixed at all, just documented. And according to @jeffeb3 bugfix 2.0 even needs modifications to have a working M106... |
problem here is also that @SmarteedCS seems to have gone up in smoke or just lost interest in this and why should marlin work on something where the creator of the issue is not active? |
@boelle Because it's reasonably clear that others are still hanging on this item? (myself included) |
I agree, @schme16 ... this is somewhat of a showstopper for using a Laser - rastering is unusable with stock 2.0 (as evidenced by @SmarteedCS 's pictures above), and vectoring is no picnic - essentially laser power changes are delayed by a random amount between 0 and 100ms (10Hz update rate) - and my steppers can move a couple of mm in 100ms. I did try @jeffeb3 's planner.check_axes_activity(); change above, and vectoring seems pretty good (haven't tried raster). |
Obviously on 1 guy who complains and/or creates PR's with fix there are 10 who just struggling silently. Without patches included in this thread laser engraving is just not working in Marlin 2.0. |
I agree this is something that will need attention. Its on the fringe of what Marlin supports though and is not a high priority item but should remain open until resolved nonetheless. Personally, I would put a target of 2.1 on it, since we want to get all the 32-bit hals stable before worrying about timing sync on a fringe device. No offense to those using it, but its not the primary focus and there are bigger issues. |
In case anyone is too impatient (like me) for a fix for this, then GRBL: https://github.com/grbl/grbl works well with my laser cutter. |
Obviously, GRBL would work for laser-only machines, but not for the 3d printer with a laser mounted next to extruder (like some hobbyist including myself did). |
Even with the change, it's not quite as good as it could be. I think the fan speed code is still picking a fan speed from the future side of the buffer and it's still polling, just much faster. Engraving on wood is a non precise operation, but actually treating laser power as a motion command would be much better. Scaling laser power when motion slows down would be even better. Someone needs to be interested and capable of doing it. There's no amount of begging that will get it done, unfortunately. |
jeffeb3 agreed. It's not a minor undertaking since fan control would need quite a bit changed in the case of being set as a laser. One of the reasons my fan as laser feature concept awhile ago was left sitting. It is something on the edge of what I'd like to get done at some point, but too many other things open for people that support my work to go into it any time soon. |
I know almost nothing about the planner, but IMHO, the right way to fix lasers is to get them running on M3/M5 (fan pin or 5V pin, doesn't matter), but not dwell when there is a laser power command. That would be step 2. Step 1 is probably increasing the poll rate on the fan pin just to get things going with M106. Step 3 (are you still with me?) would be to make the laser power act more like a movement axis, and scale the power with the speed. |
Wouldn't it be possible to pass S values with G commands ? So these values get written whenever the planned movements are executed ... |
I have started running into the pausing as well trying to run a TTL control diode laser with the M3/M5 commands. Lots of pausing with the laser still on... Not great for a laser |
Don't use M3/M5. They are not for production use at this time. Use the |
That makes things difficult for those of us with TTL controlled lasers that need a 3.3-5v signal. |
You can change the pins to use a 5V pin. |
Define laser enable pin as FAN1_PIN and the control as the second fan :) |
Personally to make the According to #14934 this limit might not even be needed anymore. |
Since this is added in #22690, I'll close this FR. |
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. |
Hi everyone,
I'm currently trying to setup the firmware for my laser engraver.
It's working pretty good with fan M106 P0 commands, but I thought enabling SPINDLE_LASER_ENABLE can be a good idea to have M3 and M5 commands.
So i remapped my pwm pin to SPINDLE_LASER_PWM_PIN , configured SPINDLE_LASER_POWERUP_DELAY and SPINDLE_LASER_POWERDOWN_DELAY to 5ms ( it has to be as close as possible to 0 ..).
The laser wiring and pin remapping is OK, the laser fire when it has to but each time a M3 or M5 command is executed, a long pause is achieved ( I have nothing to measure this but maybe 200ms ).
I tried V1.1.9 and V2.0 firmware, it's the same behavior for both of them. I even tried to comment all "delay_for_power_down()" and "delay_for_power_up()" call of the gcode_M3_M4 function on marlin_main.cpp and that have no effect.
I will go back to M106 commands, but it can be a really good point if this can be fixed ..
I'm running marlin on ramps 1.4 with atmega2560.
It can be reproduced by running this two different "sample" gcode:
The text was updated successfully, but these errors were encountered: