-
-
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
Laser Refactor #22721
Laser Refactor #22721
Conversation
a19d6d6
to
bb75471
Compare
bb75471
to
5e50c6f
Compare
7415ace
to
6e85b00
Compare
6e85b00
to
f04109a
Compare
f04109a
to
c259045
Compare
As I understand it there are situations when the spindle ENA pin ought to be left in the ON state even though the PWM is being set to 0 so that the capacitors are able to remain charged up. There may also be some rationale for setting the power value without applying it to the PWM right away. A good first step would be to go through all the existing spindle/laser code and add lots of commentary that explains exactly what is being done and why. If there are questions about some things, we can refer back to previous Pull Requests and post questions tagging the authors. |
|
Concerning
Other words M3 S0 command Code Block// ocr_power - have next roles: current out power for PWM; current angle for SERVO; enable/disable ENA_PIN; and state FSM for laser/spindel (0 - disable; > 0 - enable)
// Control ENA_PIN in mode PWM. If defined ENA_PIN can be disabled throught M5 only. If it isn't defined when call M3 S0 ENA_PIN will be disable.
#define SPINDLE_LASER_PWN_SEPARATE_PIN
void SpindleLaser::ocr_set_power(const uint8_t opwr, const bool on = true);
/**
* Set cutter ocr_power value for PWM, Servo, and on/off pin.
*
* @param opwr Power value. Range 0 to MAX. When 0 disable spindle/laser.
* @param on Only for PWM. Separate control ENA_PIN,
* if true - enable pin; false - disable pin (default true)
*/
void SpindleLaser::ocr_set_power(const uint8_t opwr, const bool on) {
static uint8_t last_power_applied = 0;
switch (get_event(opwr)) {
case SpindleLaserEvent::ON:
if (opwr == last_power_applied) break;
last_power_applied = ocr_power = opwr;
#if ENABLED(SPINDLE_LASER_PWM)
ocr_set(ocr_power);
isReady = true;
#endif
#if ENABLED(SPINDLE_SERVO)
MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power);
#else
#if BOTH(SPINDLE_LASER_PWM, SPINDLE_LASER_PWN_SEPARATE_PIN)
ena_pin_set(on);
// isReady = on; - ???
#else
ena_pin_set(true);
isReady = true;
#endif
#endif
break;
case SpindleLaserEvent::TO_ON:
last_power_applied = ocr_power = opwr;
#if ENABLED(SPINDLE_LASER_PWM)
ocr_set(ocr_power);
isReady = true;
#endif
#if ENABLED(SPINDLE_SERVO)
MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power);
#else
#if BOTH(SPINDLE_LASER_PWM, SPINDLE_LASER_PWN_SEPARATE_PIN)
ena_pin_set(on);
// isReady = on; - ???
#else
ena_pin_set(true);
isReady = true;
#endif
#endif
power_delay(true);
break;
case SpindleLaserEvent::OFF: break;
case SpindleLaserEvent::TO_OFF:
last_power_applied = ocr_power = opwr;
#if ENABLED(SPINDLE_LASER_PWM)
isReady = false;
ocr_set(0);
#endif
#if ENABLED(SPINDLE_SERVO)
MOVE_SERVO(SPINDLE_SERVO_NR, ocr_power);
#else
isReady = false;
ena_pin_set(false);
#endif
power_delay(false);
break;
}
} Now |
Welcome aboard @shizacat I have, over the last 30 days walked the cutter code in an effort to fully understand it, I have also observed issues in the same. Here are some examples of what I have found: The "cutter" has a multitude of operating requirements depending on what the CNC hardware target use case will be. Then there is the Spindle/Servo cutter targets. These are generally less complex and have their own set of requirements. What becomes clear to me is that the G-CODE processing has limitations and should be the first area of concern. Within any cutter G-CODE power input we currently have 4 unitPower inputs to deal with. OCR 0-255, Servo angle 0-180, Percent 1-100, and RPM, the latter two need to be converted to either OCR or in the absence of PWM an output logic of on/off. We also have to scale the min/max limits and any inversion requirements. Also some G-CODE generation software products like LaserGRBL use a format of 0-1000. (compatibility modes could be useful) FYI GRBL is the basis for the planner and stepper code in Marlin. An even more complex state is when we add movement, power and tools. All these elements need careful consideration. Currently my approach is to use operational Mode Flags and this method was proven successful in GRBL. |
@descipher Thank you ) Ohhh, How all difficult ) laser/spindel module - LPM I looked at your 'PR', it is very big (it touch many side of firmware). This PR doesn't change behave LPM. Its goal is to make code LPM maintainable, readable, and testable. Thoughts:
|
Should only be 7 files, I messed up the PR with a commit from a different system which was not pointing to the correct position.
At a minimum: detect dir change Please note the flag isReady is really not appropriate. I believe it is related to menu based controls and from what I gather is used to prevent applying power from the menu at the wrong time e.g. a spindle that currently on being reversed while in forward etc. The state machine would need to handle that. At some point the state machine could also work with a cutter_mode flag method like the approach I used.
This is integrated as the enable pin in almost all cases, for example on the popular K40 laser. The PSU enable pin is pulled high with a pullup resister and this kills the power. The same enable pin is interrupted serially by safety switches etc.
Yes, however the enable should be blocked when a fault or other lockout is active. e.g. cutter_mode = -1 or Error state.
Yes this is abstracted and the state machine is not aware of it. The spindle_laser module does have routines for this and the state machine can just apply power that is already converted. This is the Snnnnn G-Code power parameter processing and yes it could have a future option for a 16 bit PWM but not currently. |
Take note that cutter.power is not necessarily OCR based and that renaming brings confusion with the ocr calls. |
FYI I cleaned up some of my PR so you can now see just the actual file changes. Will do some history cleanup later. |
@descipher Thank you |
The purpose of isReady is clear after some elimination tests. It is used to determine if the display should reveal the active power output level. When isReady is false no value is presented to the user. We should add this information to the comments. |
@shizacat What hardware do you have to test with? |
f4c2f00
to
02ae11e
Compare
9238431
to
3966910
Compare
cc92a7a
to
2ded50b
Compare
80cd234
to
3d2b2ca
Compare
21a37a8
to
d3c406d
Compare
627f8ef
to
20dea22
Compare
97117d0
to
5979aab
Compare
43e0584
to
6ad5711
Compare
52a9e5e
to
7e60d15
Compare
a71a62c
to
250fd60
Compare
40e1292
to
339773d
Compare
e90c213
to
4b9bb85
Compare
If it is possible to apply the improvements outlined in this PR to the latest Marlin code, then please update this PR. If the changes are no longer compatible or required, then we can simply close this PR. |
Hello.
Description
I request improvement in code of laser. Was to make on finite state machime conception.
it have four state: ON, OFF, and transitional - TO_ON, TO_OFF.
Benefits