Exposed exaggeration factor when rendering heightmap.

Added checkbox to select whether to run autoleveled program or not.
Heightmap can handle non integer from_x and to_x.
This commit is contained in:
2023-05-23 14:28:08 +03:00
parent 4e7e059e22
commit b7b9fed0dd
8 changed files with 118 additions and 143 deletions
+35 -27
View File
@@ -38,7 +38,7 @@ void grbl::machine::on_disconnected(grbl::transport *transport) {
switch_to_state(grbl_machine_state::disconnected);
}
grbl::realtime_status_report grbl::parse_status_report(std::string line, grbl::realtime_status_report& result) {
grbl::realtime_status_report grbl::parse_status_report(std::string line, grbl::realtime_status_report &result) {
// grbl::realtime_status_report result;
// pin values are always reset when a report arrives
@@ -71,7 +71,7 @@ grbl::realtime_status_report grbl::parse_status_report(std::string line, grbl::r
result.buffers_free = std::stoi(p[0]);
result.rx_chars_free = std::stoi(p[1]);
} else if (elements[0] == "Pn") {
for (auto& c: elements[1]) {
for (auto &c: elements[1]) {
switch (c) {
case 'P':
result.signals.bit.probe = true;
@@ -111,7 +111,7 @@ grbl::realtime_status_report grbl::parse_status_report(std::string line, grbl::r
}
grbl::machine_status grbl::status_from_string(const std::string& status) {
grbl::machine_status grbl::status_from_string(const std::string &status) {
if (status == "Idle") return machine_status::idle;
if (status == "Run") return machine_status::run;
if (status == "Hold") return machine_status::hold;
@@ -125,9 +125,10 @@ grbl::machine_status grbl::status_from_string(const std::string& status) {
return machine_status::unknown;
}
void grbl::machine::check_program(const grbl::program& pgm) {
void grbl::machine::check_program(const grbl::program &pgm) {
running_program = pgm;
std::cout << "checking program (" << running_program.filename << ") with " << running_program.number_of_instructions()
std::cout << "checking program (" << running_program.filename << ") with "
<< running_program.number_of_instructions()
<< " instructions" << std::endl;
switch_to_state(grbl_machine_state::check_program);
}
@@ -149,9 +150,10 @@ void grbl::machine::set_work_offset(std::string work_offset) {
}
void grbl::machine::run_program(const grbl::program& pgm, const std::string& work_offset) {
void grbl::machine::run_program(const grbl::program &pgm, const std::string &work_offset) {
running_program = pgm;
std::cout << "running program (" << running_program.filename << ") with " << running_program.number_of_instructions() << " instructions"
std::cout << "running program (" << running_program.filename << ") with "
<< running_program.number_of_instructions() << " instructions"
<< " on work offset " << work_offset << std::endl;
set_work_offset(work_offset);
@@ -159,7 +161,7 @@ void grbl::machine::run_program(const grbl::program& pgm, const std::string& wor
switch_to_state(grbl_machine_state::run_program);
}
std::string grbl::status_to_string(const grbl::machine_status& status) {
std::string grbl::status_to_string(const grbl::machine_status &status) {
switch (status) {
case machine_status::idle:
return "Idle";
@@ -590,11 +592,11 @@ void grbl::machine::switch_to_state(grbl::grbl_machine_state new_state) {
states[state]->on_enter(this);
}
const std::map<std::string, std::string, grbl::settings_cmp>& grbl::machine::get_settings() const {
const std::map<std::string, std::string, grbl::settings_cmp> &grbl::machine::get_settings() const {
return settings;
}
const std::map<std::string, std::string, grbl::parameters_cmp>& grbl::machine::get_parameters() const {
const std::map<std::string, std::string, grbl::parameters_cmp> &grbl::machine::get_parameters() const {
return parameters;
}
@@ -683,7 +685,7 @@ void grbl::machine::start_z_probe(float min_z, float feed_rate) {
awaiting_responses++;
}
void grbl::machine::probe_heightmap(grbl::heightmap& grid) {
void grbl::machine::probe_heightmap(grbl::heightmap &grid) {
std::cout << "probing heightmap" << std::endl;
dynamic_cast<machine_state_heightmap_probing *>(states[grbl_machine_state::heightmap_probing])->grid = &grid;
switch_to_state(grbl_machine_state::heightmap_probing);
@@ -756,7 +758,8 @@ void grbl::machine_state_init::on_line_received(std::string line) {
if (starts_with(line, "$")) {
auto pieces = split_string(line, "=");
cnc->settings[pieces[0]] = pieces[1];
} else if (starts_with(line, "[G") || starts_with(line, "[H") || starts_with(line, "[T") || starts_with(line, "[P")) {
} else if (starts_with(line, "[G") || starts_with(line, "[H") || starts_with(line, "[T") ||
starts_with(line, "[P")) {
line = line.substr(1, line.size() - 2);
// TODO: some parameters have more than two :
auto pieces = split_string(line, ":");
@@ -833,7 +836,8 @@ void grbl::machine_state_idle::on_line_received(std::string line) {
} else if (starts_with(line, "$")) {
auto pieces = split_string(line, "=");
cnc->settings[pieces[0]] = pieces[1];
} else if (starts_with(line, "[G") || starts_with(line, "[H") || starts_with(line, "[T") || starts_with(line, "[P")) {
} else if (starts_with(line, "[G") || starts_with(line, "[H") || starts_with(line, "[T") ||
starts_with(line, "[P")) {
line = line.substr(1, line.size() - 2);
// TODO: some parameters have more than two :
auto pieces = split_string(line, ":");
@@ -948,7 +952,8 @@ bool grbl::machine_state_check_program::continue_program() {
instruction to_send;
do {
to_send = cnc->running_program.instruction_at(cnc->executed_instructions++);
} while (to_send.type != instruction_type::gcode && cnc->executed_instructions < cnc->running_program.number_of_instructions());
} while (to_send.type != instruction_type::gcode &&
cnc->executed_instructions < cnc->running_program.number_of_instructions());
if (to_send.type == instruction_type::gcode) {
cnc->pipe->send(to_send.command);
@@ -1014,7 +1019,8 @@ bool grbl::machine_state_run_program::continue_program() {
instruction to_send;
do {
to_send = cnc->running_program.instruction_at(cnc->executed_instructions++);
} while (to_send.type != instruction_type::gcode && cnc->executed_instructions < cnc->running_program.number_of_instructions());
} while (to_send.type != instruction_type::gcode &&
cnc->executed_instructions < cnc->running_program.number_of_instructions());
if (to_send.type == instruction_type::gcode) {
cnc->pipe->send(to_send.command);
@@ -1116,21 +1122,23 @@ bool grbl::machine_state_heightmap_probing::continue_program() {
void grbl::machine_state_heightmap_probing::move_to_next_stage() {
switch (stage) {
case heightmap_probing_stage::start:
cnc->pipe->send("G0X0Y0Z15");
cnc->pipe->send("G0 X" + std::to_string(grid->vertices[0].x) + " Y" +
std::to_string(grid->vertices[0].y) + "Z0.5");
stage = heightmap_probing_stage::goto_home;
break;
case heightmap_probing_stage::goto_home:
cnc->pipe->send("G38.2 Z-65 F100");
cnc->pipe->send("G38.2 Z-65 F5");
stage = heightmap_probing_stage::initial_probe_step_back;
break;
case heightmap_probing_stage::initial_probe_step_back:
// step back a bit (1mm, relative)
cnc->pipe->send("G91 G0 Z1");
cnc->pipe->send("G91 G0 Z0.3");
stage = heightmap_probing_stage::initial_probe_fine_seek;
break;
case heightmap_probing_stage::initial_probe_fine_seek:
// probe again but finer
cnc->pipe->send(" G38.2 Z-5 F5");
cnc->pipe->send("G38.2 Z-1 F5");
stage = heightmap_probing_stage::initial_probe;
break;
case heightmap_probing_stage::initial_probe:
@@ -1147,7 +1155,6 @@ void grbl::machine_state_heightmap_probing::move_to_next_stage() {
grid->vertices[probed_locations].z = 0;
}
stage = heightmap_probing_stage::goto_next_location;
break;
case heightmap_probing_stage::goto_next_location: {
@@ -1172,7 +1179,7 @@ void grbl::machine_state_heightmap_probing::move_to_next_stage() {
cnc->pipe->send("G0Z15"); // safe height
stage = heightmap_probing_stage::done;
} else {
cnc->pipe->send("G90 G0 Z1.5");
cnc->pipe->send("G90 G0 Z1");
stage = heightmap_probing_stage::goto_next_location_move;
}
break;
@@ -1182,13 +1189,13 @@ void grbl::machine_state_heightmap_probing::move_to_next_stage() {
stage = heightmap_probing_stage::goto_start_probing_at;
break;
case heightmap_probing_stage::goto_start_probing_at:
cnc->pipe->send("G0 Z0.5"); // this appears to move Z upwards instead of downwards. why?
cnc->pipe->send("G0 Z0.3"); // this appears to move Z upwards instead of downwards. why?
// faking the G0 Z0.5
// cnc->pipe->send("G91 G0 Z-1"); // 1.5 - 1 = 0.5.//
stage = heightmap_probing_stage::probing;
break;
case heightmap_probing_stage::probing:
cnc->pipe->send("G38.2 Z-5 F5");
cnc->pipe->send("G38.2 Z-1 F5");
stage = heightmap_probing_stage::goto_next_location;
break;
case heightmap_probing_stage::done:
@@ -1208,17 +1215,17 @@ grbl::machine_event_disconnect::machine_event_disconnect() {
machine_event::type = machine_event_type::disconnected;
}
grbl::machine_event_report_received::machine_event_report_received(const grbl::realtime_status_report& r)
grbl::machine_event_report_received::machine_event_report_received(const grbl::realtime_status_report &r)
: report(r) {
machine_event::type = machine_event_type::report_received;
}
grbl::machine_event_banner::machine_event_banner(const std::string& b)
grbl::machine_event_banner::machine_event_banner(const std::string &b)
: banner{b} {
machine_event::type = machine_event_type::banner;
}
grbl::machine_event_message::machine_event_message(const std::string& m)
grbl::machine_event_message::machine_event_message(const std::string &m)
: message{m} {
machine_event::type = machine_event_type::message;
}
@@ -1260,7 +1267,8 @@ grbl::machine_event_probe_result::machine_event_probe_result(bool touched, const
machine_event::type = machine_event_type::probe_result;
}
grbl::machine_event_heightmap_probe_acquired::machine_event_heightmap_probe_acquired(grbl::heightmap *g, size_t location)
grbl::machine_event_heightmap_probe_acquired::machine_event_heightmap_probe_acquired(grbl::heightmap *g,
size_t location)
: grid(g),
probed_location(location) {
machine_event::type = machine_event_type::heightmap_probe_acquired;