mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 23:46:24 -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
|
@ -248,6 +248,48 @@ std::string GCodeWriter::set_jerk_xy(double jerk)
|
|||
|
||||
}
|
||||
|
||||
std::string GCodeWriter::set_accel_and_jerk(unsigned int acceleration, double jerk)
|
||||
{
|
||||
// Only Klipper supports setting acceleration and jerk at the same time. Throw an error if we try to do this on other flavours.
|
||||
if(FLAVOR_IS_NOT(gcfKlipper))
|
||||
throw std::runtime_error("set_accel_and_jerk() is only supported by Klipper");
|
||||
|
||||
// Clamp the acceleration to the allowed maximum.
|
||||
if (m_max_acceleration > 0 && acceleration > m_max_acceleration)
|
||||
acceleration = m_max_acceleration;
|
||||
|
||||
bool is_empty = true;
|
||||
std::ostringstream gcode;
|
||||
gcode << "SET_VELOCITY_LIMIT";
|
||||
if (acceleration != 0 && acceleration != m_last_acceleration) {
|
||||
gcode << " ACCEL=" << acceleration;
|
||||
if (this->config.accel_to_decel_enable) {
|
||||
gcode << " ACCEL_TO_DECEL=" << acceleration * this->config.accel_to_decel_factor / 100;
|
||||
}
|
||||
m_last_acceleration = acceleration;
|
||||
is_empty = false;
|
||||
}
|
||||
// Clamp the jerk to the allowed maximum.
|
||||
if (m_max_jerk > 0 && jerk > m_max_jerk)
|
||||
jerk = m_max_jerk;
|
||||
|
||||
if (jerk > 0.01 && !is_approx(jerk, m_last_jerk)) {
|
||||
gcode << " SQUARE_CORNER_VELOCITY=" << jerk;
|
||||
m_last_jerk = jerk;
|
||||
is_empty = false;
|
||||
}
|
||||
|
||||
if(is_empty)
|
||||
return std::string();
|
||||
|
||||
if (GCodeWriter::full_gcode_comment)
|
||||
gcode << " ; adjust VELOCITY_LIMIT(accel/jerk)";
|
||||
gcode << "\n";
|
||||
|
||||
return gcode.str();
|
||||
|
||||
}
|
||||
|
||||
std::string GCodeWriter::set_pressure_advance(double pa) const
|
||||
{
|
||||
std::ostringstream gcode;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue