Improvements for Laser / Spindle (#17661)

This commit is contained in:
Luu Lac
2020-06-08 00:47:31 -05:00
committed by GitHub
parent 5ac66b0f95
commit eda2fd8dbe
16 changed files with 448 additions and 268 deletions

View File

@@ -244,8 +244,8 @@ xyze_long_t Stepper::count_position{0};
xyze_int8_t Stepper::count_direction{0};
#if ENABLED(LASER_POWER_INLINE_TRAPEZOID)
Stepper::stepper_laser_t Stepper::laser = {
.trap_en = false,
Stepper::stepper_laser_t Stepper::laser_trap = {
.enabled = false,
.cur_power = 0,
.cruise_set = false,
#if DISABLED(LASER_POWER_INLINE_TRAPEZOID_CONT)
@@ -1843,28 +1843,28 @@ uint32_t Stepper::block_phase_isr() {
// Update laser - Accelerating
#if ENABLED(LASER_POWER_INLINE_TRAPEZOID)
if (laser.trap_en) {
if (laser_trap.enabled) {
#if DISABLED(LASER_POWER_INLINE_TRAPEZOID_CONT)
if (current_block->laser.entry_per) {
laser.acc_step_count -= step_events_completed - laser.last_step_count;
laser.last_step_count = step_events_completed;
laser_trap.acc_step_count -= step_events_completed - laser_trap.last_step_count;
laser_trap.last_step_count = step_events_completed;
// Should be faster than a divide, since this should trip just once
if (laser.acc_step_count < 0) {
while (laser.acc_step_count < 0) {
laser.acc_step_count += current_block->laser.entry_per;
if (laser.cur_power < current_block->laser.power) laser.cur_power++;
if (laser_trap.acc_step_count < 0) {
while (laser_trap.acc_step_count < 0) {
laser_trap.acc_step_count += current_block->laser.entry_per;
if (laser_trap.cur_power < current_block->laser.power) laser_trap.cur_power++;
}
cutter.set_ocr_power(laser.cur_power);
cutter.set_ocr_power(laser_trap.cur_power);
}
}
#else
if (laser.till_update)
laser.till_update--;
if (laser_trap.till_update)
laser_trap.till_update--;
else {
laser.till_update = LASER_POWER_INLINE_TRAPEZOID_CONT_PER;
laser.cur_power = (current_block->laser.power * acc_step_rate) / current_block->nominal_rate;
cutter.set_ocr_power(laser.cur_power); // Cycle efficiency is irrelevant it the last line was many cycles
laser_trap.till_update = LASER_POWER_INLINE_TRAPEZOID_CONT_PER;
laser_trap.cur_power = (current_block->laser.power * acc_step_rate) / current_block->nominal_rate;
cutter.set_ocr_power(laser_trap.cur_power); // Cycle efficiency is irrelevant it the last line was many cycles
}
#endif
}
@@ -1920,28 +1920,28 @@ uint32_t Stepper::block_phase_isr() {
// Update laser - Decelerating
#if ENABLED(LASER_POWER_INLINE_TRAPEZOID)
if (laser.trap_en) {
if (laser_trap.enabled) {
#if DISABLED(LASER_POWER_INLINE_TRAPEZOID_CONT)
if (current_block->laser.exit_per) {
laser.acc_step_count -= step_events_completed - laser.last_step_count;
laser.last_step_count = step_events_completed;
laser_trap.acc_step_count -= step_events_completed - laser_trap.last_step_count;
laser_trap.last_step_count = step_events_completed;
// Should be faster than a divide, since this should trip just once
if (laser.acc_step_count < 0) {
while (laser.acc_step_count < 0) {
laser.acc_step_count += current_block->laser.exit_per;
if (laser.cur_power > current_block->laser.power_exit) laser.cur_power--;
if (laser_trap.acc_step_count < 0) {
while (laser_trap.acc_step_count < 0) {
laser_trap.acc_step_count += current_block->laser.exit_per;
if (laser_trap.cur_power > current_block->laser.power_exit) laser_trap.cur_power--;
}
cutter.set_ocr_power(laser.cur_power);
cutter.set_ocr_power(laser_trap.cur_power);
}
}
#else
if (laser.till_update)
laser.till_update--;
if (laser_trap.till_update)
laser_trap.till_update--;
else {
laser.till_update = LASER_POWER_INLINE_TRAPEZOID_CONT_PER;
laser.cur_power = (current_block->laser.power * step_rate) / current_block->nominal_rate;
cutter.set_ocr_power(laser.cur_power); // Cycle efficiency isn't relevant when the last line was many cycles
laser_trap.till_update = LASER_POWER_INLINE_TRAPEZOID_CONT_PER;
laser_trap.cur_power = (current_block->laser.power * step_rate) / current_block->nominal_rate;
cutter.set_ocr_power(laser_trap.cur_power); // Cycle efficiency isn't relevant when the last line was many cycles
}
#endif
}
@@ -1966,16 +1966,16 @@ uint32_t Stepper::block_phase_isr() {
// Update laser - Cruising
#if ENABLED(LASER_POWER_INLINE_TRAPEZOID)
if (laser.trap_en) {
if (!laser.cruise_set) {
laser.cur_power = current_block->laser.power;
cutter.set_ocr_power(laser.cur_power);
laser.cruise_set = true;
if (laser_trap.enabled) {
if (!laser_trap.cruise_set) {
laser_trap.cur_power = current_block->laser.power;
cutter.set_ocr_power(laser_trap.cur_power);
laser_trap.cruise_set = true;
}
#if ENABLED(LASER_POWER_INLINE_TRAPEZOID_CONT)
laser.till_update = LASER_POWER_INLINE_TRAPEZOID_CONT_PER;
laser_trap.till_update = LASER_POWER_INLINE_TRAPEZOID_CONT_PER;
#else
laser.last_step_count = step_events_completed;
laser_trap.last_step_count = step_events_completed;
#endif
}
#endif
@@ -2000,7 +2000,10 @@ uint32_t Stepper::block_phase_isr() {
return interval; // No more queued movements!
}
TERN_(HAS_CUTTER, cutter.apply_power(current_block->cutter_power));
// For non-inline cutter, grossly apply power
#if ENABLED(LASER_FEATURE) && DISABLED(LASER_POWER_INLINE)
cutter.apply_power(current_block->cutter_power);
#endif
TERN_(POWER_LOSS_RECOVERY, recovery.info.sdpos = current_block->sdpos);
@@ -2150,15 +2153,9 @@ uint32_t Stepper::block_phase_isr() {
else LA_isr_rate = LA_ADV_NEVER;
#endif
if (
#if HAS_L64XX
true // Always set direction for L64xx (This also enables the chips)
#else
current_block->direction_bits != last_direction_bits
#if DISABLED(MIXING_EXTRUDER)
|| stepper_extruder != last_moved_extruder
#endif
#endif
if ( ENABLED(HAS_L64XX) // Always set direction for L64xx (Also enables the chips)
|| current_block->direction_bits != last_direction_bits
|| TERN(MIXING_EXTRUDER, false, stepper_extruder != last_moved_extruder)
) {
last_direction_bits = current_block->direction_bits;
#if EXTRUDERS > 1
@@ -2170,33 +2167,31 @@ uint32_t Stepper::block_phase_isr() {
}
#if ENABLED(LASER_POWER_INLINE)
const uint8_t stat = current_block->laser.status;
const power_status_t stat = current_block->laser.status;
#if ENABLED(LASER_POWER_INLINE_TRAPEZOID)
laser.trap_en = (stat & 0x03) == 0x03;
laser.cur_power = current_block->laser.power_entry; // RESET STATE
laser.cruise_set = false;
laser_trap.enabled = stat.isPlanned && stat.isEnabled;
laser_trap.cur_power = current_block->laser.power_entry; // RESET STATE
laser_trap.cruise_set = false;
#if DISABLED(LASER_POWER_INLINE_TRAPEZOID_CONT)
laser.last_step_count = 0;
laser.acc_step_count = current_block->laser.entry_per / 2;
laser_trap.last_step_count = 0;
laser_trap.acc_step_count = current_block->laser.entry_per / 2;
#else
laser.till_update = 0;
laser_trap.till_update = 0;
#endif
// Always have PWM in this case
if (TEST(stat, 0)) { // Planner controls the laser
if (TEST(stat, 1)) // Laser is on
cutter.set_ocr_power(laser.cur_power);
else
cutter.set_power(0);
if (stat.isPlanned) { // Planner controls the laser
cutter.set_ocr_power(
stat.isEnabled ? laser_trap.cur_power : 0 // ON with power or OFF
);
}
#else
if (TEST(stat, 0)) { // Planner controls the laser
if (stat.isPlanned) { // Planner controls the laser
#if ENABLED(SPINDLE_LASER_PWM)
if (TEST(stat, 1)) // Laser is on
cutter.set_ocr_power(current_block->laser.power);
else
cutter.set_power(0);
cutter.set_ocr_power(
stat.isEnabled ? current_block->laser.power : 0 // ON with power or OFF
);
#else
cutter.set_enabled(TEST(stat, 1));
cutter.set_enabled(stat.isEnabled);
#endif
}
#endif
@@ -2237,15 +2232,14 @@ uint32_t Stepper::block_phase_isr() {
#if ENABLED(LASER_POWER_INLINE_CONTINUOUS)
else { // No new block found; so apply inline laser parameters
// This should mean ending file with 'M5 I' will stop the laser; thus the inline flag isn't needed
const uint8_t stat = planner.laser.status;
if (TEST(stat, 0)) { // Planner controls the laser
const power_status_t stat = planner.laser_inline.status;
if (stat.isPlanned) { // Planner controls the laser
#if ENABLED(SPINDLE_LASER_PWM)
if (TEST(stat, 1)) // Laser is on
cutter.set_ocr_power(planner.laser.power);
else
cutter.set_power(0);
cutter.set_ocr_power(
stat.isEnabled ? planner.laser_inline.power : 0 // ON with power or OFF
);
#else
cutter.set_enabled(TEST(stat, 1));
cutter.set_enabled(stat.isEnabled);
#endif
}
}