-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from GenerateNU/feature/manual-input-to-gcode
Converting Manual Input to GCode. NTD: Anvil Positions
- Loading branch information
Showing
3 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <vector> | ||
#include <cstring> | ||
#include "manual_input_to_gcode.hpp" | ||
|
||
std::string generateAnvilPosition(const int bendRadius) { | ||
return "8.907"; | ||
} | ||
|
||
void getAbsolutePositionGCode(std::ofstream &outFile){ | ||
outFile << "G90" << std::endl; | ||
outFile << "G1 X0 Y0 Z0 F80" << std::endl; | ||
outFile << "G91" << std::endl; | ||
} | ||
|
||
// NTD: Figure out + vs - for bend direction | ||
void generateGCode(const std::vector<Bend> &bends, const std::string &outputPath) { | ||
std::ofstream outFile(outputPath); | ||
if (!outFile.is_open()) { | ||
std::cerr << "Error opening output file." << std::endl; | ||
return; | ||
} | ||
std::cout << "Starting G-code generation..." << std::endl; | ||
// Constants | ||
const int anvilFeedRate = 80; // Avil feed rate | ||
const int tubeFeedRate = 150; // Tube feed rate | ||
// Iterate over each bend | ||
for (const auto &bend : bends) { | ||
// Set Anvil for Use | ||
getAbsolutePositionGCode(outFile); | ||
// Push Tube Striaght Through the Machine | ||
outFile << "G1 " | ||
<< "Z" << bend.tubeLengthBeforeBend << " " | ||
<< "F" << tubeFeedRate << std::endl; | ||
// Position the anvil | ||
char direction = bend.bendDirection[0]; | ||
char bendSign = bend.bendDirection[1]; | ||
outFile << "G1 " | ||
// << std::toupper(static_cast<unsigned char>(bend.bendDirection[0])) << generateAnvilPosition(bend.bendRadius) << " " | ||
<< char(toupper(direction)) << bendSign << generateAnvilPosition(bend.bendRadius) << " " | ||
<< "F" << anvilFeedRate << std::endl; | ||
// Push Tube Bend Through the Machine | ||
outFile << "G1 " | ||
<< "Z" << bend.bendArcLength << " " | ||
<< "F" << tubeFeedRate << std::endl; | ||
// Check if last bend | ||
if (&bend == &bends.back()) { | ||
// If last bend, push tube straight through the machine | ||
getAbsolutePositionGCode(outFile); | ||
outFile << "G1 " | ||
<< "Z" << bend.tubeLengthAfterBend << " " | ||
<< "F" << tubeFeedRate << std::endl; | ||
} | ||
} | ||
outFile.close(); | ||
std::cout << "G-code generated successfully at " << outputPath << std::endl; | ||
} | ||
|
||
|
||
int main(int argc, char *argv[]) { | ||
std::cout << "Program started." << std::endl; | ||
std::string outputPath = "output.gcode"; | ||
Bend bendsArray[2] = { | ||
{308.864, "y+", 4.25, 128.016, 333.502}, | ||
{333.502, "y-", 4.25, 55.372, 150.876} | ||
}; | ||
std::vector<Bend> bends(bendsArray, bendsArray + 2); | ||
// Generate G-code | ||
generateGCode(bends, outputPath); | ||
std::cout << "Program completed." << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef GCODE_FROM_MANUAL_INPUT | ||
#define GCODE_FROM_MANUAL_INPUT | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
struct Bend { | ||
double tubeLengthBeforeBend; | ||
std::string bendDirection; | ||
double bendRadius; | ||
double bendArcLength; | ||
double tubeLengthAfterBend; | ||
}; | ||
|
||
std::string generateAnvilPosition(const int bendRadius); | ||
void getAbsolutePositionGCode(std::ofstream &outFile); | ||
void generateGCode(const std::vector<Bend> &bends, const std::string &outputPath); | ||
|
||
#endif |