Support Marlin 2

This commit is contained in:
SoftFever 2023-08-30 23:39:00 +08:00
parent 702ad817e5
commit 33ac24d35a
16 changed files with 97 additions and 106 deletions

View file

@ -45,8 +45,8 @@
"5000"
],
"machine_max_acceleration_travel": [
"9000",
"9000"
"20000",
"20000"
],
"machine_max_acceleration_x": [
"20000",

View file

@ -38,8 +38,8 @@
"5000"
],
"machine_max_acceleration_travel": [
"9000",
"9000"
"20000",
"20000"
],
"machine_max_acceleration_x": [
"20000",

View file

@ -47,6 +47,10 @@
"200",
"200"
],
"machine_max_acceleration_travel": [
"4000",
"4000"
],
"host_type": "prusalink",
"printable_height": "220",
"machine_end_gcode": "{if layer_z < max_print_height}G1 Z{z_offset+min(layer_z+1, max_print_height)} F720 ; Move print head up{endif}\nM104 S0 ; turn off temperature\nM140 S0 ; turn off heatbed\nM107 ; turn off fan\nG1 X241 Y170 F3600 ; park\n{if layer_z < max_print_height}G1 Z{z_offset+min(layer_z+23, max_print_height)} F300 ; Move print head up{endif}\nG4 ; wait\nM572 S0 ; reset PA\nM593 X T2 F0 ; disable IS\nM593 Y T2 F0 ; disable IS\nM84 X Y E ; disable motors\n; max_layer_z = [max_layer_z]",

View file

@ -19,8 +19,8 @@
"5000"
],
"machine_max_acceleration_travel": [
"9000",
"9000"
"20000",
"20000"
],
"machine_max_acceleration_x": [
"9000",

View file

@ -28,8 +28,8 @@
"1500"
],
"machine_max_acceleration_travel": [
"500",
"500"
"3000",
"3000"
],
"machine_max_acceleration_x": [
"3000",

View file

@ -18,8 +18,8 @@
"5000"
],
"machine_max_acceleration_travel": [
"9000",
"9000"
"20000",
"20000"
],
"machine_max_acceleration_x": [
"20000",

View file

@ -18,8 +18,8 @@
"5000"
],
"machine_max_acceleration_travel": [
"9000",
"9000"
"20000",
"20000"
],
"machine_max_acceleration_x": [
"20000",

View file

@ -18,8 +18,8 @@
"5000"
],
"machine_max_acceleration_travel": [
"9000",
"9000"
"20000",
"20000"
],
"machine_max_acceleration_x": [
"20000",

View file

@ -2066,7 +2066,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
if (print.calib_params().mode == CalibMode::Calib_PA_Line) {
std::string gcode;
if ((m_config.default_acceleration.value > 0 && m_config.outer_wall_acceleration.value > 0)) {
gcode += m_writer.set_acceleration((unsigned int)floor(m_config.outer_wall_acceleration.value + 0.5));
gcode += m_writer.set_print_acceleration((unsigned int)floor(m_config.outer_wall_acceleration.value + 0.5));
}
if (m_config.default_jerk.value > 0) {
@ -3120,7 +3120,7 @@ GCode::LayerResult GCode::process_layer(
//BBS
if (first_layer) {
if (m_config.default_acceleration.value > 0 && m_config.initial_layer_acceleration.value > 0) {
gcode += m_writer.set_acceleration((unsigned int)floor(m_config.initial_layer_acceleration.value + 0.5));
gcode += m_writer.set_print_acceleration((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) {
@ -3147,7 +3147,7 @@ GCode::LayerResult GCode::process_layer(
}
// BBS: reset acceleration at sencond layer
if (m_config.default_acceleration.value > 0 && m_config.initial_layer_acceleration.value > 0) {
gcode += m_writer.set_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) {
@ -4158,7 +4158,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
} else {
acceleration = m_config.default_acceleration.value;
}
gcode += m_writer.set_acceleration((unsigned int)floor(acceleration + 0.5));
gcode += m_writer.set_print_acceleration((unsigned int)floor(acceleration + 0.5));
}
// adjust X Y jerk
@ -4613,14 +4613,14 @@ std::string GCode::travel_to(const Point &point, ExtrusionRole role, std::string
// SoftFever
if (this->on_first_layer()) {
if (m_config.default_acceleration.value > 0 && m_config.initial_layer_acceleration.value > 0) {
gcode += m_writer.set_acceleration((unsigned int)floor(m_config.initial_layer_acceleration.value + 0.5));
gcode += m_writer.set_travel_acceleration((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);
}
} else {
if (m_config.default_acceleration.value > 0 && m_config.travel_acceleration.value > 0) {
gcode += m_writer.set_acceleration((unsigned int)floor(m_config.travel_acceleration.value + 0.5));
gcode += m_writer.set_travel_acceleration((unsigned int)floor(m_config.travel_acceleration.value + 0.5));
}
if (m_config.default_jerk.value > 0 && m_config.travel_jerk.value > 0) {

View file

@ -418,36 +418,30 @@ public:
// Let the firmware back up the active speed override value.
WipeTowerWriter& speed_override_backup()
{
// BBS: BBL machine don't support speed backup
#if 0
// This is only supported by Prusa at this point (https://github.com/prusa3d/PrusaSlicer/issues/3114)
if (m_gcode_flavor == gcfMarlinLegacy || m_gcode_flavor == gcfMarlinFirmware)
m_gcode += "M220 B\n";
#endif
return *this;
}
// Let the firmware restore the active speed override value.
WipeTowerWriter& speed_override_restore()
{
// BBS: BBL machine don't support speed restore
#if 0
if (m_gcode_flavor == gcfMarlinLegacy || m_gcode_flavor == gcfMarlinFirmware)
m_gcode += "M220 R\n";
#endif
return *this;
}
// Set digital trimpot motor
WipeTowerWriter& set_extruder_trimpot(int current)
{
// BBS: don't control trimpot
#if 0
if (m_gcode_flavor == gcfKlipper)
return *this;
if (m_gcode_flavor == gcfRepRapSprinter || m_gcode_flavor == gcfRepRapFirmware)
m_gcode += "M906 E";
else
m_gcode += "M907 E";
m_gcode += std::to_string(current) + "\n";
#endif
return *this;
}

View file

@ -30,6 +30,10 @@ void GCodeWriter::apply_print_config(const PrintConfig &print_config)
bool use_mach_limits = print_config.gcode_flavor.value == gcfMarlinLegacy || print_config.gcode_flavor.value == gcfMarlinFirmware ||
print_config.gcode_flavor.value == gcfKlipper || print_config.gcode_flavor.value == gcfRepRapFirmware;
m_max_acceleration = std::lrint(use_mach_limits ? print_config.machine_max_acceleration_extruding.values.front() : 0);
m_max_travel_acceleration = static_cast<unsigned int>(
std::round((use_mach_limits && supports_separate_travel_acceleration(print_config.gcode_flavor.value)) ?
print_config.machine_max_acceleration_travel.values.front() :
0));
m_max_jerk = std::lrint(
use_mach_limits ? std::min(print_config.machine_max_jerk_x.values.front(), print_config.machine_max_jerk_y.values.front()) : 0);
m_max_jerk_z = print_config.machine_max_jerk_z.values.front();
@ -153,44 +157,40 @@ std::string GCodeWriter::set_bed_temperature(int temperature, bool wait)
return gcode.str();
}
std::string GCodeWriter::set_acceleration(unsigned int acceleration)
// copied from PrusaSlicer
std::string GCodeWriter::set_acceleration_internal(Acceleration type, unsigned int acceleration)
{
// Clamp the acceleration to the allowed maximum.
if (m_max_acceleration > 0 && acceleration > m_max_acceleration)
if (type == Acceleration::Print && m_max_acceleration > 0 && acceleration > m_max_acceleration)
acceleration = m_max_acceleration;
if (type == Acceleration::Travel && m_max_travel_acceleration > 0 && acceleration > m_max_travel_acceleration)
acceleration = m_max_travel_acceleration;
if (acceleration == 0 || acceleration == m_last_acceleration)
// Are we setting travel acceleration for a flavour that supports separate travel and print acc?
bool separate_travel = (type == Acceleration::Travel && supports_separate_travel_acceleration(this->config.gcode_flavor));
auto& last_value = separate_travel ? m_last_travel_acceleration : m_last_acceleration ;
if (acceleration == 0 || acceleration == last_value)
return std::string();
m_last_acceleration = acceleration;
last_value = acceleration;
std::ostringstream gcode;
if (FLAVOR_IS(gcfRepetier)) {
// M201: Set max printing acceleration
gcode << "M201 X" << acceleration << " Y" << acceleration;
//BBS
if (GCodeWriter::full_gcode_comment) gcode << " ; adjust acceleration";
gcode << "\n";
// M202: Set max travel acceleration
gcode << "M202 X" << acceleration << " Y" << acceleration;
} else if (FLAVOR_IS(gcfRepRapFirmware)) {
// M204: Set default acceleration
gcode << "M204 P" << acceleration;
} else if (FLAVOR_IS(gcfMarlinFirmware)) {
// This is new MarlinFirmware with separated print/retraction/travel acceleration.
// Use M204 P, we don't want to override travel acc by M204 S (which is deprecated anyway).
gcode << "M204 P" << acceleration;
} else if (FLAVOR_IS(gcfKlipper)) {
if (FLAVOR_IS(gcfRepetier))
gcode << (separate_travel ? "M202 X" : "M201 X") << acceleration << " Y" << acceleration;
else if (FLAVOR_IS(gcfRepRapFirmware) || FLAVOR_IS(gcfMarlinFirmware))
gcode << (separate_travel ? "M204 T" : "M204 P") << acceleration;
else if (FLAVOR_IS(gcfKlipper)) {
gcode << "SET_VELOCITY_LIMIT ACCEL=" << acceleration;
if (this->config.accel_to_decel_enable) {
gcode << " ACCEL_TO_DECEL=" << acceleration * this->config.accel_to_decel_factor / 100;
if (GCodeWriter::full_gcode_comment)
gcode << " ; adjust ACCEL_TO_DECEL";
}
} else
}
else
gcode << "M204 S" << acceleration;
//BBS
if (GCodeWriter::full_gcode_comment) gcode << " ; adjust acceleration";
gcode << "\n";

View file

@ -19,7 +19,7 @@ public:
GCodeWriter() :
multiple_extruders(false), m_extruder(nullptr),
m_single_extruder_multi_material(false),
m_last_acceleration(0), m_max_acceleration(0),
m_last_acceleration(0), m_max_acceleration(0),m_last_travel_acceleration(0), m_max_travel_acceleration(0),
m_last_jerk(0), m_max_jerk(0),
/*m_last_bed_temperature(0), */m_last_bed_temperature_reached(true),
m_lifted(0),
@ -45,7 +45,8 @@ public:
std::string postamble() const;
std::string set_temperature(unsigned int temperature, bool wait = false, int tool = -1) const;
std::string set_bed_temperature(int temperature, bool wait = false);
std::string set_acceleration(unsigned int acceleration);
std::string set_print_acceleration(unsigned int acceleration) { return set_acceleration_internal(Acceleration::Print, acceleration); }
std::string set_travel_acceleration(unsigned int acceleration) { return set_acceleration_internal(Acceleration::Travel, acceleration); }
std::string set_jerk_xy(double jerk);
std::string set_pressure_advance(double pa) const;
std::string reset_e(bool force = false);
@ -116,6 +117,9 @@ public:
bool m_single_extruder_multi_material;
Extruder* m_extruder;
unsigned int m_last_acceleration;
unsigned int m_last_travel_acceleration;
unsigned int m_max_travel_acceleration;
// Limit for setting the acceleration, to respect the machine limits set for the Marlin firmware.
// If set to zero, the limit is not in action.
unsigned int m_max_acceleration;
@ -154,9 +158,16 @@ public:
double m_current_speed;
bool m_is_first_layer = true;
enum class Acceleration {
Travel,
Print
};
std::string _travel_to_z(double z, const std::string &comment);
std::string _spiral_travel_to_z(double z, const Vec2d &ij_offset, const std::string &comment);
std::string _retract(double length, double restart_extra, const std::string &comment);
std::string set_acceleration_internal(Acceleration type, unsigned int acceleration);
};
class GCodeFormatter {

View file

@ -2321,11 +2321,11 @@ void PrintConfigDef::init_fff_params()
def = this->add("machine_max_acceleration_travel", coFloats);
def->full_label = L("Maximum acceleration for travel");
def->category = L("Machine limits");
def->tooltip = L("Maximum acceleration for travel (M204 T)");
def->tooltip = L("Maximum acceleration for travel (M204 T), it only applies to Marlin 2");
def->sidetext = L("mm/s²");
def->min = 0;
def->readonly = false;
def->mode = comDevelop;
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloats{ 1500., 1250. });
def = this->add("fan_max_speed", coInts);

View file

@ -118,15 +118,15 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUplo
});
txt_filename->SetFocus();
if (post_actions.has(PrintHostPostUploadAction::QueuePrint)) {
auto* btn_print = add_button(wxID_ADD, false, _L("Upload to Queue"));
btn_print->Bind(wxEVT_BUTTON, [this, validate_path](wxCommandEvent&) {
if (validate_path(txt_filename->GetValue())) {
post_upload_action = PrintHostPostUploadAction::QueuePrint;
EndDialog(wxID_OK);
}
});
}
// if (post_actions.has(PrintHostPostUploadAction::QueuePrint)) {
// auto* btn_print = add_button(wxID_ADD, false, _L("Upload to Queue"));
// btn_print->Bind(wxEVT_BUTTON, [this, validate_path](wxCommandEvent&) {
// if (validate_path(txt_filename->GetValue())) {
// post_upload_action = PrintHostPostUploadAction::QueuePrint;
// EndDialog(wxID_OK);
// }
// });
// }
if (post_actions.has(PrintHostPostUploadAction::StartPrint)) {
auto* btn_print = add_button(wxID_YES, false, _L("Upload and Print"));
@ -138,18 +138,18 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path, PrintHostPostUplo
});
}
if (post_actions.has(PrintHostPostUploadAction::StartSimulation)) {
// Using wxID_MORE as a button identifier to be different from the other buttons, wxID_MORE has no other meaning here.
auto* btn_simulate = add_button(wxID_MORE, false, _L("Upload and Simulate"));
btn_simulate->Bind(wxEVT_BUTTON, [this, validate_path](wxCommandEvent&) {
if (validate_path(txt_filename->GetValue())) {
post_upload_action = PrintHostPostUploadAction::StartSimulation;
EndDialog(wxID_OK);
}
});
}
// if (post_actions.has(PrintHostPostUploadAction::StartSimulation)) {
// // Using wxID_MORE as a button identifier to be different from the other buttons, wxID_MORE has no other meaning here.
// auto* btn_simulate = add_button(wxID_MORE, false, _L("Upload and Simulate"));
// btn_simulate->Bind(wxEVT_BUTTON, [this, validate_path](wxCommandEvent&) {
// if (validate_path(txt_filename->GetValue())) {
// post_upload_action = PrintHostPostUploadAction::StartSimulation;
// EndDialog(wxID_OK);
// }
// });
// }
add_button(wxID_CANCEL);
add_button(wxID_CANCEL,false, L("Cancel"));
finalize();
#ifdef __linux__

View file

@ -3,6 +3,7 @@
#include "Tab.hpp"
#include "PresetHints.hpp"
#include "libslic3r/PresetBundle.hpp"
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/Utils.hpp"
#include "libslic3r/Model.hpp"
#include "libslic3r/GCode/GCodeProcessor.hpp"
@ -3389,10 +3390,9 @@ PageShp TabPrinter::build_kinematics_page()
}
append_option_line(optgroup, "machine_max_acceleration_extruding");
append_option_line(optgroup, "machine_max_acceleration_retracting");
if (m_supports_travel_acceleration)
append_option_line(optgroup, "machine_max_acceleration_travel");
append_option_line(optgroup, "machine_max_acceleration_travel");
optgroup = page->new_optgroup(L("Jerk limitation"));
optgroup = page->new_optgroup(L("Jerk limitation"));
for (const std::string &axis : axes) {
append_option_line(optgroup, "machine_max_jerk_" + axis);
}
@ -3718,14 +3718,6 @@ void TabPrinter::toggle_options()
if (m_active_page->title() == "Basic information") {
toggle_option("single_extruder_multi_material", have_multiple_extruders);
auto flavor = m_config->option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor")->value;
bool is_marlin_flavor = flavor == gcfMarlinLegacy || flavor == gcfMarlinFirmware;
// Disable silent mode for non-marlin firmwares.
toggle_option("silent_mode", is_marlin_flavor);
//BBS: extruder clearance of BBL printer can't be edited.
//for (auto el : { "extruder_clearance_radius", "extruder_clearance_height_to_rod", "extruder_clearance_height_to_lid" })
// toggle_option(el, !is_BBL_printer);
// SoftFever: hide BBL specific settings
for (auto el :
{"scan_first_layer", "machine_load_filament_time", "machine_unload_filament_time", "bbl_calib_mark_logo"})
@ -3805,16 +3797,15 @@ void TabPrinter::toggle_options()
toggle_option("retract_restart_extra_toolchange", have_multiple_extruders && toolchange_retraction, i);
}
//auto gcf = m_config->option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor")->value;
//if (m_active_page->title() == "Motion ability") {
// assert(gcf == gcfMarlinLegacy || gcf == gcfMarlinFirmware || gcf == gcfKlipper);
// bool silent_mode = m_config->opt_bool("silent_mode");
// int max_field = silent_mode ? 2 : 1;
// //BBS: limits of BBL printer can't be edited.
// for (const std::string &opt : Preset::machine_limits_options())
// for (int i = 0; i < max_field; ++ i)
// toggle_option(opt, !is_BBL_printer, i);
//}
if (m_active_page->title() == "Motion ability") {
auto gcf = m_config->option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor")->value;
assert(gcf == gcfMarlinLegacy || gcf == gcfMarlinFirmware || gcf == gcfKlipper);
bool silent_mode = m_config->opt_bool("silent_mode");
int max_field = silent_mode ? 2 : 1;
for (int i = 0; i < max_field; ++i)
toggle_option("machine_max_acceleration_travel", gcf == gcfMarlinFirmware, i);
toggle_line("machine_max_acceleration_travel", gcf == gcfMarlinFirmware);
}
}
void TabPrinter::update()
@ -3839,14 +3830,6 @@ void TabPrinter::update_fff()
m_use_silent_mode = m_config->opt_bool("silent_mode");
}
auto gcf_ =
m_config->option<ConfigOptionEnum<GCodeFlavor>>("gcode_flavor")->value;
bool supports_travel_acceleration = (gcf_ == gcfMarlinFirmware || gcf_ == gcfMarlinLegacy || gcf_ == gcfKlipper);
if (m_supports_travel_acceleration != supports_travel_acceleration) {
m_rebuild_kinematics_page = true;
m_supports_travel_acceleration = supports_travel_acceleration;
}
toggle_options();
}

View file

@ -549,7 +549,6 @@ class TabPrinter : public Tab
private:
bool m_has_single_extruder_MM_page = false;
bool m_use_silent_mode = false;
bool m_supports_travel_acceleration = false;
void append_option_line(ConfigOptionsGroupShp optgroup, const std::string opt_key);
bool m_rebuild_kinematics_page = false;