Compare commits
5 Commits
c2d49bbdf0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f6865431f | ||
|
|
3108f7f6f1 | ||
|
|
ede43194c4 | ||
|
|
a781743a45 | ||
|
|
5aecc2cc70 |
@@ -13,8 +13,8 @@ v3.11.2
|
|||||||
2. Execute `make`
|
2. Execute `make`
|
||||||
|
|
||||||
### Settings
|
### Settings
|
||||||
* Use without printer config to use linear moves. You should look at +10% Estimation
|
* Use without printer config to use linear moves. You should look at +10% Estimation. It's not reliable on prints with lots of infill.
|
||||||
* Alternatively copy `config_example.json` to `config.json` and edit based on your printer settings. You should look at -15% Estimation
|
* Alternatively copy `config_example.json` to `config.json` and edit based on your printer settings. You should look at -12.5% Estimation
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
`./gcode_time [file] ...`
|
`./gcode_time [file] ...`
|
||||||
@@ -26,4 +26,4 @@ v3.11.2
|
|||||||
|
|
||||||
`+10% - 05:52:11`
|
`+10% - 05:52:11`
|
||||||
|
|
||||||
`-15% - 04:32:09`
|
`-12.5% - 04:40:09`
|
||||||
|
|||||||
53
TimeCalc.cpp
53
TimeCalc.cpp
@@ -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();
|
||||||
}
|
}
|
||||||
@@ -226,7 +225,8 @@ void TimeCalc::add_move(Point new_pos, double speed)
|
|||||||
double vel;
|
double vel;
|
||||||
double accel;
|
double accel;
|
||||||
double prev_move_idx;
|
double prev_move_idx;
|
||||||
bool is_print;
|
double special_accel;
|
||||||
|
double de_sum;
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
|
|
||||||
pos_new[0] = new_pos.x;
|
pos_new[0] = new_pos.x;
|
||||||
@@ -274,34 +274,32 @@ void TimeCalc::add_move(Point new_pos, double speed)
|
|||||||
cout << "Vel - " << vel << endl;
|
cout << "Vel - " << vel << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Calculate acceleration
|
de_sum = 0.0;
|
||||||
temp.clear();
|
|
||||||
|
|
||||||
// Is it a print move
|
|
||||||
is_print = false;
|
|
||||||
for (int i = 0; i < EXTRUDER_COUNT; ++i)
|
for (int i = 0; i < EXTRUDER_COUNT; ++i)
|
||||||
{
|
{
|
||||||
if (0.0 != move_new.delta[3 + i])
|
de_sum += move_new.delta[3 + i];
|
||||||
{
|
|
||||||
is_print = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add max acceleration for specific move to be considered
|
// Set max acceleration for specific move to be considered
|
||||||
if (is_print)
|
special_accel = 0.0;
|
||||||
|
if (0.0 == de_sum)
|
||||||
{
|
{
|
||||||
if (0.0 != m_print_accel_max)
|
special_accel = m_travel_accel_max;
|
||||||
{
|
|
||||||
temp.push_back(m_print_accel_max);
|
|
||||||
}
|
}
|
||||||
|
else if (move_new.dist == de_sum)
|
||||||
|
{
|
||||||
|
special_accel = m_retract_accel_max;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (0.0 != m_travel_accel_max)
|
special_accel = m_print_accel_max;
|
||||||
{
|
|
||||||
temp.push_back(m_travel_accel_max);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate acceleration
|
||||||
|
temp.clear();
|
||||||
|
if (0.0 != special_accel)
|
||||||
|
{
|
||||||
|
temp.push_back(special_accel);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0 ; i < AXIS_COUNT; ++i)
|
for (int i = 0 ; i < AXIS_COUNT; ++i)
|
||||||
@@ -512,3 +510,8 @@ void TimeCalc::set_travel_accel(double value)
|
|||||||
{
|
{
|
||||||
m_travel_accel_max = value;
|
m_travel_accel_max = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TimeCalc::set_retract_accel(double value)
|
||||||
|
{
|
||||||
|
m_retract_accel_max = value;
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ private:
|
|||||||
|
|
||||||
double m_print_accel_max;
|
double m_print_accel_max;
|
||||||
double m_travel_accel_max;
|
double m_travel_accel_max;
|
||||||
|
double m_retract_accel_max;
|
||||||
|
|
||||||
std::vector<PrinterMove> m_moves;
|
std::vector<PrinterMove> m_moves;
|
||||||
|
|
||||||
@@ -57,6 +58,7 @@ public:
|
|||||||
|
|
||||||
void set_print_accel(double value);
|
void set_print_accel(double value);
|
||||||
void set_travel_accel(double value);
|
void set_travel_accel(double value);
|
||||||
|
void set_retract_accel(double value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TIMECALC_H_
|
#endif // TIMECALC_H_
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
{
|
{
|
||||||
"print": 500,
|
"print": 500,
|
||||||
"travel": 1000,
|
"travel": 1000,
|
||||||
|
"retract": 1000,
|
||||||
"x": 500,
|
"x": 500,
|
||||||
"y": 500,
|
"y": 500,
|
||||||
"z": 100,
|
"z": 100,
|
||||||
|
|||||||
50
gcode.cpp
50
gcode.cpp
@@ -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
14
gcode.h
@@ -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_
|
||||||
|
|||||||
42
main.cpp
42
main.cpp
@@ -9,6 +9,12 @@
|
|||||||
#include "gcode.h"
|
#include "gcode.h"
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
|
|
||||||
|
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||||
|
#define FOLDER_DELIM '\\'
|
||||||
|
#else
|
||||||
|
#define FOLDER_DELIM '/'
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void usage(char *name)
|
void usage(char *name)
|
||||||
@@ -86,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;
|
||||||
@@ -133,18 +142,24 @@ void print_time(double sec)
|
|||||||
printf("%02d:%02d:%02.0f", hours, min, sec);
|
printf("%02d:%02d:%02.0f", hours, min, sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_calc(TimeCalc& calc)
|
void init_calc(string arg0, TimeCalc& calc)
|
||||||
{
|
{
|
||||||
ifstream file("config.json");
|
ifstream file;
|
||||||
|
size_t pos;
|
||||||
nlohmann::json conf;
|
nlohmann::json conf;
|
||||||
vector<string> conf_keys_types = {"acceleration", "velocity", "jerk"};
|
vector<string> conf_keys_types = {"acceleration", "velocity", "jerk"};
|
||||||
vector<string> conf_keys_axes = {"x", "y", "z"};
|
vector<string> conf_keys_axes = {"x", "y", "z"};
|
||||||
|
|
||||||
|
pos = arg0.rfind(FOLDER_DELIM);
|
||||||
|
arg0.erase(pos + 1);
|
||||||
|
arg0 += "config.json";
|
||||||
|
file.open(arg0);
|
||||||
|
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
file >> conf;
|
file >> conf;
|
||||||
@@ -225,6 +240,14 @@ void init_calc(TimeCalc& calc)
|
|||||||
{
|
{
|
||||||
calc.set_travel_accel(conf["acceleration"]["travel"]);
|
calc.set_travel_accel(conf["acceleration"]["travel"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set Retract Acceleration
|
||||||
|
if (conf.contains("acceleration") &&
|
||||||
|
conf["acceleration"].contains("retract") &&
|
||||||
|
conf["acceleration"]["retract"].is_number())
|
||||||
|
{
|
||||||
|
calc.set_retract_accel(conf["acceleration"]["retract"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,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;
|
||||||
@@ -250,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(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)))
|
||||||
@@ -269,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
|
||||||
{
|
{
|
||||||
@@ -295,8 +319,8 @@ int main(int argc, char **argv)
|
|||||||
print_time(total_time * 1.1);
|
print_time(total_time * 1.1);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
cout << "-15% - ";
|
cout << "-12.5% - ";
|
||||||
print_time(total_time * 0.85);
|
print_time(total_time * 0.875);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user