diff --git a/backend/src/gcode_from_vectors.cpp b/backend/src/gcode_from_vectors.cpp index f7cf610..8df64d0 100644 --- a/backend/src/gcode_from_vectors.cpp +++ b/backend/src/gcode_from_vectors.cpp @@ -8,8 +8,12 @@ #include #include #include "gcode_from_vectors.hpp" - - +void getAbsolutePositionGCode(std::ofstream &outFile) +{ + outFile << "G90" << std::endl; // Set to absolute positioning + outFile << "G1 X0 Y0 Z0 F80" << std::endl; // Move to origin at a specific feed rate + outFile << "G91" << std::endl; // Switch back to incremental positioning +} void generateGCode(const std::vector &tangentVectors, const std::string &outputPath) { std::ofstream outFile(outputPath); @@ -23,11 +27,15 @@ void generateGCode(const std::vector &tangentVectors, const std::string gp_Pnt currentPosition(0.0, 0.0, 0.0); // Constants const double zIncrement = 1.0; // Constant Z movement for each step - const double feedRate = 100.0; // Constant feed rate + const double feedRate = 150.0; // Constant feed rate int vectorCount = 0; // For logging progress // Iterate over each tangent vector for (const auto &vec : tangentVectors) { + if (vectorCount % 2 == 0) // After every two vectors, reset to absolute position + { + getAbsolutePositionGCode(outFile); // Call to reset position + } // Calculate the new position by adding the tangent vector to the current position gp_Pnt newPosition = currentPosition.Translated(vec); // Generate the G01 command @@ -47,4 +55,4 @@ void generateGCode(const std::vector &tangentVectors, const std::string } outFile.close(); std::cout << "G-code generated successfully at " << outputPath << std::endl; -} +} \ No newline at end of file