Skip to content

Commit

Permalink
Add 3 new gcode settings
Browse files Browse the repository at this point in the history
- Add bool to set if the start_gcode needs to be the first gcode run.  Requires `machine_start_gcode_first` be added to the machine UI as a checkbox
- Add a prestart_gcode to extruders, this will allow use set temperatures before the change call so we can preheat the next extruder.  Requires `machine_extruder_prestart_code` text box be added to the extruder UI page.
- Add a time duration to calculate time required to change extruders. Requires `machine_extruder_change_duration` float box to be added to the exturder UI page.
  • Loading branch information
TheSin- committed Jul 5, 2024
1 parent d2851fd commit e05bad2
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/gcodeExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,11 @@ bool GCodeExport::initializeExtruderTrains(const SliceDataStorage& storage, cons

writeComment("Generated with Cura_SteamEngine " CURA_ENGINE_VERSION);

if (mesh_group_settings.get<bool>("machine_start_gcode_first"))
{
writeCode(mesh_group_settings.get<std::string>("machine_start_gcode").c_str());
}

if (getFlavor() == EGCodeFlavor::GRIFFIN)
{
std::ostringstream tmp;
Expand All @@ -693,8 +698,11 @@ bool GCodeExport::initializeExtruderTrains(const SliceDataStorage& storage, cons
processInitialLayerTemperature(storage, start_extruder_nr);
}

if (!mesh_group_settings.get<bool>("machine_start_gcode_first"))
{
writeCode(mesh_group_settings.get<std::string>("machine_start_gcode").c_str());
}
writeExtrusionMode(false); // ensure absolute extrusion mode is set before the start gcode
writeCode(mesh_group_settings.get<std::string>("machine_start_gcode").c_str());

// in case of shared nozzle assume that the machine-start gcode reset the extruders as per machine description
if (Application::getInstance().current_slice_->scene.settings.get<bool>("machine_extruders_share_nozzle"))
Expand Down Expand Up @@ -1267,6 +1275,29 @@ void GCodeExport::writeZhopEnd(Velocity speed /*= 0*/)

void GCodeExport::startExtruder(const size_t new_extruder)
{
const auto extruder_settings = Application::getInstance().current_slice_->scene.extruders[new_extruder].settings_;
const auto prestart_code = extruder_settings.get<std::string>("machine_extruder_prestart_code");
const auto start_code = extruder_settings.get<std::string>("machine_extruder_start_code");
const auto start_code_duration = extruder_settings.get<Duration>("machine_extruder_start_code_duration");
const auto extruder_change_duration = extruder_settings.get<Duration>("machine_extruder_change_duration");

// Be nice to be able to calculate the extruder change time verses time
// to heat and run this so it's run before the change call. **Future note**
if (! prestart_code.empty())
{
if (relative_extrusion_)
{
writeExtrusionMode(false); // ensure absolute extrusion mode is set before the prestart gcode
}

writeCode(prestart_code.c_str());

if (relative_extrusion_)
{
writeExtrusionMode(true); // restore relative extrusion mode
}
}

extruder_attr_[new_extruder].is_used_ = true;
if (new_extruder != current_extruder_) // wouldn't be the case on the very first extruder start if it's extruder 0
{
Expand All @@ -1278,15 +1309,16 @@ void GCodeExport::startExtruder(const size_t new_extruder)
{
*output_stream_ << "T" << new_extruder << new_line_;
}
// Only add time is we are actually changing extruders
estimate_calculator_.addTime(extruder_change_duration);
}

estimate_calculator_.addTime(start_code_duration);
current_extruder_ = new_extruder;

assert(getCurrentExtrudedVolume() == 0.0 && "Just after an extruder switch we haven't extruded anything yet!");
resetExtrusionValue(); // zero the E value on the new extruder, just to be sure

const auto extruder_settings = Application::getInstance().current_slice_->scene.extruders[new_extruder].settings_;
const auto start_code = extruder_settings.get<std::string>("machine_extruder_start_code");
if (! start_code.empty())
{
if (relative_extrusion_)
Expand All @@ -1302,9 +1334,6 @@ void GCodeExport::startExtruder(const size_t new_extruder)
}
}

const auto start_code_duration = extruder_settings.get<Duration>("machine_extruder_start_code_duration");
estimate_calculator_.addTime(start_code_duration);

Application::getInstance().communication_->setExtruderForSend(Application::getInstance().current_slice_->scene.extruders[new_extruder]);
Application::getInstance().communication_->sendCurrentPosition(getPositionXY());

Expand Down

0 comments on commit e05bad2

Please sign in to comment.