Skip to content

Commit

Permalink
Merge pull request #52 from GenerateNU/features/cad-to_gcode-recenter…
Browse files Browse the repository at this point in the history
…-anvil

Fixed gcode from vectors
  • Loading branch information
muneerlalji authored Apr 16, 2024
2 parents 0cf1c79 + 717773a commit 1ee9842
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions backend/src/gcode_from_vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
#include <gp_Vec.hxx>
#include <GeomAPI_PointsToBSpline.hxx>
#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<gp_Vec> &tangentVectors, const std::string &outputPath)
{
std::ofstream outFile(outputPath);
Expand All @@ -23,11 +27,15 @@ void generateGCode(const std::vector<gp_Vec> &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
Expand All @@ -47,4 +55,4 @@ void generateGCode(const std::vector<gp_Vec> &tangentVectors, const std::string
}
outFile.close();
std::cout << "G-code generated successfully at " << outputPath << std::endl;
}
}

0 comments on commit 1ee9842

Please sign in to comment.