Compare commits

..

3 Commits

Author SHA1 Message Date
DocWibbleyWobbley
2f6865431f Fixed infinite loop on bad file 2024-08-08 11:26:12 +03:00
DocWibbleyWobbley
3108f7f6f1 Added support for relative mode 2023-12-04 17:01:58 +02:00
DocWibbleyWobbley
ede43194c4 TimeCalc reset no longer removes the printer settings. 2023-06-23 13:41:26 +03:00
4 changed files with 71 additions and 26 deletions

View File

@@ -197,22 +197,21 @@ TimeCalc::PrinterMove::PrinterMove()
} }
TimeCalc::TimeCalc() TimeCalc::TimeCalc()
: m_time(0.0), m_print_accel_max(0.0), m_travel_accel_max(0.0) : m_time(0.0), m_print_accel_max(0.0), m_travel_accel_max(0.0),
m_retract_accel_max(0.0)
{ {
fill_n(m_accel_max, AXIS_COUNT, 0.0);
fill_n(m_vel_max, AXIS_COUNT, 0.0);
fill_n(m_jerk_max, AXIS_COUNT, 0.0);
reset(); reset();
} }
void TimeCalc::reset() void TimeCalc::reset()
{ {
m_time = 0.0; m_time = 0.0;
m_print_accel_max = 0.0;
m_travel_accel_max = 0.0;
fill_n(m_extruder_length, EXTRUDER_COUNT, 0.0); fill_n(m_extruder_length, EXTRUDER_COUNT, 0.0);
fill_n(m_pos, AXIS_COUNT, 0.0); fill_n(m_pos, AXIS_COUNT, 0.0);
fill_n(m_accel_max, AXIS_COUNT, 0.0);
fill_n(m_vel_max, AXIS_COUNT, 0.0);
fill_n(m_jerk_max, AXIS_COUNT, 0.0);
m_moves.clear(); m_moves.clear();
} }

View File

@@ -37,12 +37,12 @@ pair<char, double> extract_argument(const string& str)
return result; return result;
} }
void gcode_dummy(const vector<string>&, TimeCalc&, double&) void gcode_dummy(const vector<string>&, TimeCalc&, double&, bool&)
{ {
} }
// Linear Move // Linear Move
void g1(const vector<string>& line_tokens, TimeCalc& calc, double& speed) void g1(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute)
{ {
double result; double result;
vector<string>::const_iterator it; vector<string>::const_iterator it;
@@ -62,7 +62,14 @@ void g1(const vector<string>& line_tokens, TimeCalc& calc, double& speed)
// Extruder // Extruder
case 'E': case 'E':
case 'e': case 'e':
if (is_absolute)
{
pos.e = arg.second; pos.e = arg.second;
}
else
{
pos.e += arg.second;
}
break; break;
// Feedrate (Speed) in units/min // Feedrate (Speed) in units/min
@@ -78,17 +85,38 @@ void g1(const vector<string>& line_tokens, TimeCalc& calc, double& speed)
case 'X': case 'X':
case 'x': case 'x':
if (is_absolute)
{
pos.x = arg.second; pos.x = arg.second;
}
else
{
pos.x += arg.second;
}
break; break;
case 'Y': case 'Y':
case 'y': case 'y':
if (is_absolute)
{
pos.y = arg.second; pos.y = arg.second;
}
else
{
pos.y += arg.second;
}
break; break;
case 'Z': case 'Z':
case 'z': case 'z':
if (is_absolute)
{
pos.z = arg.second; pos.z = arg.second;
}
else
{
pos.z += arg.second;
}
break; break;
default: default:
@@ -101,7 +129,7 @@ void g1(const vector<string>& line_tokens, TimeCalc& calc, double& speed)
} }
// Dwell // Dwell
void g4(const vector<string>& line_tokens, TimeCalc& calc, double& speed) void g4(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute)
{ {
double result; double result;
vector<string>::const_iterator it; vector<string>::const_iterator it;
@@ -137,7 +165,7 @@ void g4(const vector<string>& line_tokens, TimeCalc& calc, double& speed)
} }
// Move to Origin (Home) // Move to Origin (Home)
void g28(const vector<string>& line_tokens, TimeCalc& calc, double& speed) void g28(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute)
{ {
Point pos = calc.get_pos(); Point pos = calc.get_pos();
@@ -148,8 +176,20 @@ void g28(const vector<string>& line_tokens, TimeCalc& calc, double& speed)
calc.set_pos(pos); calc.set_pos(pos);
} }
// Set to Absolute Positioning
void g90(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute)
{
is_absolute = true;
}
// Set to Relative Positioning
void g91(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute)
{
is_absolute = false;
}
// Set Position // Set Position
void g92(const vector<string>& line_tokens, TimeCalc& calc, double& speed) void g92(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute)
{ {
vector<string>::const_iterator it; vector<string>::const_iterator it;
pair<char, double> arg; pair<char, double> arg;

14
gcode.h
View File

@@ -11,15 +11,17 @@ using namespace std;
// Typedef of the function pointer // Typedef of the function pointer
typedef void (*gcode_cmd_t)(const vector<string>&, TimeCalc&, double&); typedef void (*gcode_cmd_t)(const vector<string>&, TimeCalc&, double&, bool& is_absolute);
// Always returns 0 sec // Always returns 0 sec
void gcode_dummy(const vector<string>&, TimeCalc&, double&); void gcode_dummy(const vector<string>&, TimeCalc&, double&, bool&);
// All handled gcode commands // All handled gcode commands
void g1(const vector<string>& line_tokens, TimeCalc& calc, double& speed); void g1(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute);
void g4(const vector<string>& line_tokens, TimeCalc& calc, double& speed); void g4(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute);
void g28(const vector<string>& line_tokens, TimeCalc& calc, double& speed); void g28(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute);
void g92(const vector<string>& line_tokens, TimeCalc& calc, double& speed); void g90(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute);
void g91(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute);
void g92(const vector<string>& line_tokens, TimeCalc& calc, double& speed, bool& is_absolute);
#endif // GCODE_H_ #endif // GCODE_H_

View File

@@ -92,8 +92,11 @@ void init_map(map<string, gcode_cmd_t>& gcode_map)
gcode_map["G28"] = g28; gcode_map["G28"] = g28;
gcode_map["g28"] = g28; gcode_map["g28"] = g28;
gcode_map["G90"] = gcode_dummy; gcode_map["G90"] = g90;
gcode_map["g90"] = gcode_dummy; gcode_map["g90"] = g90;
gcode_map["G91"] = g91;
gcode_map["g91"] = g91;
gcode_map["G92"] = g92; gcode_map["G92"] = g92;
gcode_map["g92"] = g92; gcode_map["g92"] = g92;
@@ -259,6 +262,7 @@ int main(int argc, char **argv)
TimeCalc calc; TimeCalc calc;
double speed; double speed;
bool is_absolute = true;
double total_time; double total_time;
int hours; int hours;
int minutes; int minutes;
@@ -270,15 +274,15 @@ int main(int argc, char **argv)
} }
init_map(gcode_map); init_map(gcode_map);
init_calc(argv[0], calc);
for (string& fname : filenames) for (string& fname : filenames)
{ {
calc.reset(); calc.reset();
init_calc(argv[0], calc);
speed = 0; speed = 0;
file.open(fname); file.open(fname);
while (!file.eof()) while (file.good())
{ {
getline(file, line); getline(file, line);
if (!is_gcode(remove_comments(line))) if (!is_gcode(remove_comments(line)))
@@ -289,7 +293,7 @@ int main(int argc, char **argv)
if (0 != gcode_map.count(line_tokens[0])) if (0 != gcode_map.count(line_tokens[0]))
{ {
gcode_map[line_tokens[0]](line_tokens, calc, speed); gcode_map[line_tokens[0]](line_tokens, calc, speed, is_absolute);
} }
else else
{ {