mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 07:27:41 -06:00
Optimize g-code generation for Klipper: combine accel and jerk command
This commit is contained in:
parent
d6146ecc84
commit
7a2229cae9
4 changed files with 76 additions and 10 deletions
|
@ -3457,6 +3457,7 @@ LayerResult GCode::process_layer(
|
|||
|
||||
//BBS
|
||||
if (first_layer) {
|
||||
// Orca: we don't need to optimize the Klipper as only set once
|
||||
if (m_config.default_acceleration.value > 0 && m_config.initial_layer_acceleration.value > 0) {
|
||||
gcode += m_writer.set_print_acceleration((unsigned int)floor(m_config.initial_layer_acceleration.value + 0.5));
|
||||
}
|
||||
|
@ -3483,9 +3484,10 @@ LayerResult GCode::process_layer(
|
|||
gcode += this->unretract();
|
||||
}
|
||||
}
|
||||
// BBS: reset acceleration at sencond layer
|
||||
// Reset acceleration at sencond layer
|
||||
// Orca: only set once, don't need to call set_accel_and_jerk
|
||||
if (m_config.default_acceleration.value > 0 && m_config.initial_layer_acceleration.value > 0) {
|
||||
gcode += m_writer.set_print_acceleration((unsigned int)floor(m_config.default_acceleration.value + 0.5));
|
||||
gcode += m_writer.set_print_acceleration((unsigned int) floor(m_config.default_acceleration.value + 0.5));
|
||||
}
|
||||
|
||||
if (m_config.default_jerk.value > 0 && m_config.initial_layer_jerk.value > 0) {
|
||||
|
@ -4501,6 +4503,10 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
|
|||
// compensate retraction
|
||||
gcode += this->unretract();
|
||||
m_config.apply(m_calib_config);
|
||||
|
||||
// Orca: optimize for Klipper, set acceleration and jerk in one command
|
||||
unsigned int acceleration_i = 0;
|
||||
double jerk = 0;
|
||||
// adjust acceleration
|
||||
if (m_config.default_acceleration.value > 0) {
|
||||
double acceleration;
|
||||
|
@ -4525,12 +4531,11 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
|
|||
} else {
|
||||
acceleration = m_config.default_acceleration.value;
|
||||
}
|
||||
gcode += m_writer.set_print_acceleration((unsigned int)floor(acceleration + 0.5));
|
||||
acceleration_i = (unsigned int)floor(acceleration + 0.5);
|
||||
}
|
||||
|
||||
// adjust X Y jerk
|
||||
if (m_config.default_jerk.value > 0) {
|
||||
double jerk;
|
||||
if (this->on_first_layer() && m_config.initial_layer_jerk.value > 0) {
|
||||
jerk = m_config.initial_layer_jerk.value;
|
||||
} else if (m_config.outer_wall_jerk.value > 0 && is_external_perimeter(path.role())) {
|
||||
|
@ -4545,6 +4550,13 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
|
|||
else {
|
||||
jerk = m_config.default_jerk.value;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_writer.get_gcode_flavor() == gcfKlipper) {
|
||||
gcode += m_writer.set_accel_and_jerk(acceleration_i, jerk);
|
||||
|
||||
} else {
|
||||
gcode += m_writer.set_print_acceleration(acceleration_i);
|
||||
gcode += m_writer.set_jerk_xy(jerk);
|
||||
}
|
||||
|
||||
|
@ -5017,23 +5029,31 @@ std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string
|
|||
const bool used_external_mp_once = m_avoid_crossing_perimeters.used_external_mp_once();
|
||||
std::string gcode;
|
||||
|
||||
// SoftFever
|
||||
// Orca: we don't need to optimize the Klipper as only set once
|
||||
double jerk_to_set = 0.0;
|
||||
unsigned int acceleration_to_set = 0;
|
||||
if (this->on_first_layer()) {
|
||||
if (m_config.default_acceleration.value > 0 && m_config.initial_layer_acceleration.value > 0) {
|
||||
gcode += m_writer.set_travel_acceleration((unsigned int)floor(m_config.initial_layer_acceleration.value + 0.5));
|
||||
acceleration_to_set = (unsigned int) floor(m_config.initial_layer_acceleration.value + 0.5);
|
||||
}
|
||||
if (m_config.default_jerk.value > 0 && m_config.initial_layer_jerk.value > 0) {
|
||||
gcode += m_writer.set_jerk_xy(m_config.initial_layer_jerk.value);
|
||||
jerk_to_set = m_config.initial_layer_jerk.value;
|
||||
}
|
||||
} else {
|
||||
if (m_config.default_acceleration.value > 0 && m_config.travel_acceleration.value > 0) {
|
||||
gcode += m_writer.set_travel_acceleration((unsigned int)floor(m_config.travel_acceleration.value + 0.5));
|
||||
acceleration_to_set = (unsigned int) floor(m_config.travel_acceleration.value + 0.5);
|
||||
}
|
||||
|
||||
if (m_config.default_jerk.value > 0 && m_config.travel_jerk.value > 0) {
|
||||
gcode += m_writer.set_jerk_xy(m_config.travel_jerk.value);
|
||||
jerk_to_set = m_config.travel_jerk.value;
|
||||
}
|
||||
}
|
||||
if (m_writer.get_gcode_flavor() == gcfKlipper) {
|
||||
gcode += m_writer.set_accel_and_jerk(acceleration_to_set, jerk_to_set);
|
||||
} else {
|
||||
gcode += m_writer.set_travel_acceleration(acceleration_to_set);
|
||||
gcode += m_writer.set_jerk_xy(jerk_to_set);
|
||||
}
|
||||
|
||||
// if a retraction would be needed, try to use reduce_crossing_wall to plan a
|
||||
// multi-hop travel path inside the configuration space
|
||||
if (needs_retraction
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue