Skip to content

Commit

Permalink
Fixed gcode from vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
gaikwadsid committed Apr 3, 2024
1 parent 04d3b7c commit 717773a
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 717773a

Please sign in to comment.