Added print and travel acceleration.

This commit is contained in:
DocWibbleyWobbley 2023-06-22 20:48:59 +03:00
parent 24f16d2491
commit c2d49bbdf0
5 changed files with 150 additions and 61 deletions

View File

@ -13,8 +13,8 @@ v3.11.2
2. Execute `make` 2. Execute `make`
### Settings ### Settings
* Use as is to get linear calculations for time * Use without printer config to use linear moves. You should look at +10% Estimation
* Copy `config_example.json` to `config.json` and edit based on your printer settings * Alternatively copy `config_example.json` to `config.json` and edit based on your printer settings. You should look at -15% Estimation
### Usage ### Usage
`./gcode_time [file] ...` `./gcode_time [file] ...`
@ -24,6 +24,6 @@ v3.11.2
### Example output ### Example output
`Estimation - 05:20:10` `Estimation - 05:20:10`
`Adding 10% - 05:52:11` `+10% - 05:52:11`
`Removing 10% - 04:48:09` `-15% - 04:32:09`

View File

@ -15,7 +15,9 @@
#include <limits> #include <limits>
#include "math.h" #include "math.h"
#include <iostream> #if DEBUG_CALC
# include <iostream>
#endif
using namespace std; using namespace std;
@ -195,7 +197,7 @@ TimeCalc::PrinterMove::PrinterMove()
} }
TimeCalc::TimeCalc() TimeCalc::TimeCalc()
: m_time(0.0) : m_time(0.0), m_print_accel_max(0.0), m_travel_accel_max(0.0)
{ {
reset(); reset();
} }
@ -203,6 +205,8 @@ TimeCalc::TimeCalc()
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);
@ -222,6 +226,7 @@ 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;
static int counter = 0; static int counter = 0;
pos_new[0] = new_pos.x; pos_new[0] = new_pos.x;
@ -271,6 +276,34 @@ void TimeCalc::add_move(Point new_pos, double speed)
// Calculate acceleration // Calculate acceleration
temp.clear(); temp.clear();
// Is it a print move
is_print = false;
for (int i = 0; i < EXTRUDER_COUNT; ++i)
{
if (0.0 != move_new.delta[3 + i])
{
is_print = true;
break;
}
}
// Add max acceleration for specific move to be considered
if (is_print)
{
if (0.0 != m_print_accel_max)
{
temp.push_back(m_print_accel_max);
}
}
else
{
if (0.0 != m_travel_accel_max)
{
temp.push_back(m_travel_accel_max);
}
}
for (int i = 0 ; i < AXIS_COUNT; ++i) for (int i = 0 ; i < AXIS_COUNT; ++i)
{ {
if (0.0 != move_new.unit[i] && 0.0 != m_accel_max[i]) if (0.0 != move_new.unit[i] && 0.0 != m_accel_max[i])
@ -379,6 +412,7 @@ void TimeCalc::flush()
} }
max = vector_max(times); max = vector_max(times);
#if DEBUG_CALC
if (max < 0) if (max < 0)
{ {
printf("Dist - %10.5f - %10.5f\n", move.dist, max); printf("Dist - %10.5f - %10.5f\n", move.dist, max);
@ -413,6 +447,8 @@ void TimeCalc::flush()
printf("Accel [%d] - %10.5f\n", i, move.accel[i]); printf("Accel [%d] - %10.5f\n", i, move.accel[i]);
} }
} }
#endif
m_time += max; m_time += max;
} }
m_moves.clear(); m_moves.clear();
@ -466,3 +502,13 @@ void TimeCalc::set_max_jerk(int axis, double value)
m_jerk_max[axis] = value; m_jerk_max[axis] = value;
} }
} }
void TimeCalc::set_print_accel(double value)
{
m_print_accel_max = value;
}
void TimeCalc::set_travel_accel(double value)
{
m_travel_accel_max = value;
}

View File

@ -33,6 +33,9 @@ private:
double m_vel_max[AXIS_COUNT]; double m_vel_max[AXIS_COUNT];
double m_jerk_max[AXIS_COUNT]; double m_jerk_max[AXIS_COUNT];
double m_print_accel_max;
double m_travel_accel_max;
std::vector<PrinterMove> m_moves; std::vector<PrinterMove> m_moves;
public: public:
@ -51,6 +54,9 @@ public:
void set_max_acceleration(int axis, double value); void set_max_acceleration(int axis, double value);
void set_max_velocity(int axis, double value); void set_max_velocity(int axis, double value);
void set_max_jerk(int axis, double value); void set_max_jerk(int axis, double value);
void set_print_accel(double value);
void set_travel_accel(double value);
}; };
#endif // TIMECALC_H_ #endif // TIMECALC_H_

View File

@ -1,28 +1,31 @@
{ {
"x": "acceleration":
{ {
"acceleration": 500, "print": 500,
"velocity": 500, "travel": 1000,
"jerk": 10 "x": 500,
}, "y": 500,
"y": "z": 100,
{ "e": [
"acceleration": 500, 1000
"velocity": 500,
"jerk": 10
},
"z":
{
"acceleration": 100,
"velocity": 5,
"jerk": 0.4
},
"extruders":
[
{
"acceleration": 500,
"velocity": 50,
"jerk": 5
}
] ]
},
"velocity":
{
"x": 500,
"y": 500,
"z": 5,
"e": [
50
]
},
"jerk":
{
"x": 10,
"y": 10,
"z": 0.3,
"e": [
5
]
}
} }

View File

@ -137,8 +137,14 @@ void init_calc(TimeCalc& calc)
{ {
ifstream file("config.json"); ifstream file("config.json");
nlohmann::json conf; nlohmann::json conf;
vector<string> conf_keys = {"x", "y", "z"}; vector<string> conf_keys_types = {"acceleration", "velocity", "jerk"};
vector<string> conf_keys_axes = {"x", "y", "z"};
if (!file.is_open())
{
return;
}
try try
{ {
file >> conf; file >> conf;
@ -150,46 +156,74 @@ void init_calc(TimeCalc& calc)
} }
file.close(); file.close();
for (int i = 0; i < conf_keys.size(); ++i) for (int j = 0; j < conf_keys_types.size(); ++j)
{ {
string key = conf_keys[i]; string& key = conf_keys_types[j];
if (conf.contains(key) && conf[key].is_object())
{
if (conf[key].contains("acceleration") && conf[key]["acceleration"].is_number())
{
calc.set_max_acceleration(i, conf[key]["acceleration"]);
}
if (conf[key].contains("velocity") && conf[key]["velocity"].is_number()) if (conf.contains(key) && conf["key"].is_object())
{ {
calc.set_max_velocity(i, conf[key]["velocity"]); // Set 3D Axes
} for (int i = 0; i < conf_keys_axes.size(); ++i)
{
if (conf[key].contains(conf_keys_axes[i]) && conf[key][conf_keys_axes[i]].is_number())
{
switch (j)
{
case 0:
calc.set_max_acceleration(i, conf[key][conf_keys_axes[i]]);
break;
if (conf[key].contains("jerk") && conf[key]["jerk"].is_number()) case 1:
{ calc.set_max_velocity(i, conf[key][conf_keys_axes[i]]);
calc.set_max_jerk(i, conf[key]["jerk"]); break;
case 2:
calc.set_max_jerk(i, conf[key][conf_keys_axes[i]]);
break;
} }
} }
} }
if (conf.contains("extruders") && conf["extruders"].is_array()) // Set Extruders
if (conf[key].contains("e") && conf[key]["e"].is_array())
{ {
for (int i = 0; i < conf["extruders"].size(); ++i) for (int i = 0; i < conf[key]["e"].size(); ++i)
{ {
if (conf["extruders"][i].contains("acceleration") && conf["extruders"][i]["acceleration"].is_number()) if (conf[key]["e"][i].is_number())
{ {
calc.set_max_acceleration(3 + i, conf["extruders"][i]["acceleration"]); switch (j)
{
case 0:
calc.set_max_acceleration(3 + i, conf[key]["e"][i]);
break;
case 1:
calc.set_max_velocity(3 + i, conf[key]["e"][i]);
break;
case 2:
calc.set_max_jerk(3 + i, conf[key]["e"][i]);
break;
}
}
}
}
} }
if (conf["extruders"][i].contains("velocity") && conf["extruders"][i]["velocity"].is_number()) // Set Print Acceleration
if (conf.contains("acceleration") &&
conf["acceleration"].contains("print") &&
conf["acceleration"]["print"].is_number())
{ {
calc.set_max_velocity(3 + i, conf["extruders"][i]["velocity"]); calc.set_print_accel(conf["acceleration"]["print"]);
} }
if (conf["extruders"][i].contains("jerk") && conf["extruders"][i]["jerk"].is_number()) // Set Travel Acceleration
if (conf.contains("acceleration") &&
conf["acceleration"].contains("travel") &&
conf["acceleration"]["travel"].is_number())
{ {
calc.set_max_jerk(3 + i, conf["extruders"][i]["jerk"]); calc.set_travel_accel(conf["acceleration"]["travel"]);
}
} }
} }
} }
@ -257,12 +291,12 @@ int main(int argc, char **argv)
print_time(total_time); print_time(total_time);
cout << endl; cout << endl;
cout << "Adding 10% - "; cout << "+10% - ";
print_time(total_time * 1.1); print_time(total_time * 1.1);
cout << endl; cout << endl;
cout << "Removing 10% - "; cout << "-15% - ";
print_time(total_time * 0.9); print_time(total_time * 0.85);
cout << endl; cout << endl;
} }
return 0; return 0;