Added filament length estimation
This commit is contained in:
parent
3faea3e446
commit
62d379fd3b
32
gcode.cpp
32
gcode.cpp
@ -38,7 +38,7 @@ pair<char, double> extract_argument(const string& str)
|
||||
}
|
||||
|
||||
// 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;
|
||||
vector<string>::const_iterator it;
|
||||
@ -124,7 +124,7 @@ double g1(const vector<string>& line_tokens, Point& pos, double& speed)
|
||||
}
|
||||
|
||||
// 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;
|
||||
vector<string>::const_iterator it;
|
||||
@ -168,26 +168,26 @@ double g4(const vector<string>& line_tokens, Point& pos, double& speed)
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
pair<char, double> arg;
|
||||
@ -212,6 +212,8 @@ double g92(const vector<string>& line_tokens, Point& pos, double& speed)
|
||||
switch (arg.first)
|
||||
{
|
||||
case 'E':
|
||||
e_total_offset += pos.e;
|
||||
e_total_offset -= arg.second;
|
||||
pos.e = arg.second;
|
||||
break;
|
||||
|
||||
@ -244,56 +246,56 @@ double g92(const vector<string>& line_tokens, Point& pos, double& speed)
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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
|
||||
return 0;
|
||||
|
||||
32
gcode.h
32
gcode.h
@ -9,24 +9,24 @@
|
||||
using namespace std;
|
||||
|
||||
// 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
|
||||
double g1(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double g4(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double g21(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double g28(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double g90(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double g92(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& e_total_offset);
|
||||
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& e_total_offset);
|
||||
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& e_total_offset);
|
||||
|
||||
double m82(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double m84(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double m104(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double m106(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double m107(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double m109(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double m117(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double m140(const vector<string>& line_tokens, Point& pos, double& speed);
|
||||
double m190(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& e_total_offset);
|
||||
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& e_total_offset);
|
||||
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& e_total_offset);
|
||||
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& e_total_offset);
|
||||
double m190(const vector<string>& line_tokens, Point& pos, double& speed, double& e_total_offset);
|
||||
|
||||
#endif // GCODE_H_
|
||||
|
||||
8
main.cpp
8
main.cpp
@ -142,6 +142,7 @@ int main(int argc, char **argv)
|
||||
Point pos;
|
||||
double speed;
|
||||
double total_time;
|
||||
double e_total;
|
||||
int hours;
|
||||
int minutes;
|
||||
|
||||
@ -157,6 +158,7 @@ int main(int argc, char **argv)
|
||||
pos.e = 0;
|
||||
speed = 0;
|
||||
total_time = 0;
|
||||
e_total = 0;
|
||||
|
||||
init_map(gcode_map);
|
||||
|
||||
@ -172,7 +174,7 @@ int main(int argc, char **argv)
|
||||
|
||||
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
|
||||
{
|
||||
@ -181,6 +183,10 @@ int main(int argc, char **argv)
|
||||
}
|
||||
file.close();
|
||||
|
||||
e_total += pos.e;
|
||||
|
||||
cout << "Filament - " << e_total << "mm" << endl;
|
||||
|
||||
cout << "Estimation - ";
|
||||
print_time(total_time);
|
||||
cout << endl;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user