Added filament length estimation

This commit is contained in:
DocWibbleyWobbley 2021-11-02 13:15:30 +02:00
parent 3faea3e446
commit 62d379fd3b
3 changed files with 40 additions and 32 deletions

View File

@ -38,7 +38,7 @@ pair<char, double> extract_argument(const string& str)
} }
// Linear Move // Linear Move
double g1(const vector<string>& line_tokens, Point& pos, double& speed) double g1(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
double result; double result;
vector<string>::const_iterator it; vector<string>::const_iterator it;
@ -124,7 +124,7 @@ double g1(const vector<string>& line_tokens, Point& pos, double& speed)
} }
// Dwell // Dwell
double g4(const vector<string>& line_tokens, Point& pos, double& speed) double g4(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
double result; double result;
vector<string>::const_iterator it; vector<string>::const_iterator it;
@ -168,26 +168,26 @@ double g4(const vector<string>& line_tokens, Point& pos, double& speed)
} }
// Set Units to Milimeters // Set Units to Milimeters
double g21(const vector<string>& line_tokens, Point& pos, double& speed) double g21(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
return 0; return 0;
} }
// Move to Origin (Home) // Move to Origin (Home)
double g28(const vector<string>& line_tokens, Point& pos, double& speed) double g28(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
// Used only at beginning or end so not relevant // Used only at beginning or end so not relevant
return 0; return 0;
} }
// Set to Absolute Positioning // Set to Absolute Positioning
double g90(const vector<string>& line_tokens, Point& pos, double& speed) double g90(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
return 0; return 0;
} }
// Set Position // Set Position
double g92(const vector<string>& line_tokens, Point& pos, double& speed) double g92(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
vector<string>::const_iterator it; vector<string>::const_iterator it;
pair<char, double> arg; pair<char, double> arg;
@ -212,6 +212,8 @@ double g92(const vector<string>& line_tokens, Point& pos, double& speed)
switch (arg.first) switch (arg.first)
{ {
case 'E': case 'E':
e_total_offset += pos.e;
e_total_offset -= arg.second;
pos.e = arg.second; pos.e = arg.second;
break; break;
@ -244,56 +246,56 @@ double g92(const vector<string>& line_tokens, Point& pos, double& speed)
} }
// Set extruder to absolute mode // Set extruder to absolute mode
double m82(const vector<string>& line_tokens, Point& pos, double& speed) double m82(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
return 0; return 0;
} }
// Stop idle hold // Stop idle hold
double m84(const vector<string>& line_tokens, Point& pos, double& speed) double m84(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
return 0; return 0;
} }
// Set Extruder Temperature // Set Extruder Temperature
double m104(const vector<string>& line_tokens, Point& pos, double& speed) double m104(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
return 0; return 0;
} }
// Fan On // Fan On
double m106(const vector<string>& line_tokens, Point& pos, double& speed) double m106(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
return 0; return 0;
} }
// Fan Off // Fan Off
double m107(const vector<string>& line_tokens, Point& pos, double& speed) double m107(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
return 0; return 0;
} }
// Set Extruder Temperature and Wait // Set Extruder Temperature and Wait
double m109(const vector<string>& line_tokens, Point& pos, double& speed) double m109(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
// Assume everything is preheated // Assume everything is preheated
return 0; return 0;
} }
// Display Message // Display Message
double m117(const vector<string>& line_tokens, Point& pos, double& speed) double m117(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
return 0; return 0;
} }
// Set Bed Temperature (Fast) // Set Bed Temperature (Fast)
double m140(const vector<string>& line_tokens, Point& pos, double& speed) double m140(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
return 0; return 0;
} }
// Wait for bed temperature to reach target temp // Wait for bed temperature to reach target temp
double m190(const vector<string>& line_tokens, Point& pos, double& speed) double m190(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset)
{ {
// Assume everything is preheated // Assume everything is preheated
return 0; return 0;

32
gcode.h
View File

@ -9,24 +9,24 @@
using namespace std; using namespace std;
// Typedef of the function pointer // Typedef of the function pointer
typedef double (*gcode_cmd_t)(const vector<string>&, Point&, double&); typedef double (*gcode_cmd_t)(const vector<string>&, Point&, double&, double&);
// All handled gcode commands // All handled gcode commands
double g1(const vector<string>& line_tokens, Point& pos, double& speed); double g1(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double g4(const vector<string>& line_tokens, Point& pos, double& speed); double g4(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double g21(const vector<string>& line_tokens, Point& pos, double& speed); double g21(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double g28(const vector<string>& line_tokens, Point& pos, double& speed); double g28(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double g90(const vector<string>& line_tokens, Point& pos, double& speed); double g90(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double g92(const vector<string>& line_tokens, Point& pos, double& speed); double g92(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double m82(const vector<string>& line_tokens, Point& pos, double& speed); double m82(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double m84(const vector<string>& line_tokens, Point& pos, double& speed); double m84(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double m104(const vector<string>& line_tokens, Point& pos, double& speed); double m104(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double m106(const vector<string>& line_tokens, Point& pos, double& speed); double m106(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double m107(const vector<string>& line_tokens, Point& pos, double& speed); double m107(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double m109(const vector<string>& line_tokens, Point& pos, double& speed); double m109(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double m117(const vector<string>& line_tokens, Point& pos, double& speed); double m117(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double m140(const vector<string>& line_tokens, Point& pos, double& speed); double m140(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
double m190(const vector<string>& line_tokens, Point& pos, double& speed); double m190(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
#endif // GCODE_H_ #endif // GCODE_H_

View File

@ -142,6 +142,7 @@ int main(int argc, char **argv)
Point pos; Point pos;
double speed; double speed;
double total_time; double total_time;
double e_total;
int hours; int hours;
int minutes; int minutes;
@ -157,6 +158,7 @@ int main(int argc, char **argv)
pos.e = 0; pos.e = 0;
speed = 0; speed = 0;
total_time = 0; total_time = 0;
e_total = 0;
init_map(gcode_map); init_map(gcode_map);
@ -172,7 +174,7 @@ int main(int argc, char **argv)
if (0 != gcode_map.count(line_tokens[0])) if (0 != gcode_map.count(line_tokens[0]))
{ {
total_time += gcode_map[line_tokens[0]](line_tokens, pos, speed); total_time += gcode_map[line_tokens[0]](line_tokens, pos, speed, e_total);
} }
else else
{ {
@ -181,6 +183,10 @@ int main(int argc, char **argv)
} }
file.close(); file.close();
e_total += pos.e;
cout << "Filament - " << e_total << "mm" << endl;
cout << "Estimation - "; cout << "Estimation - ";
print_time(total_time); print_time(total_time);
cout << endl; cout << endl;