From 71e51c50335fa9cfa88ce466349f9eeb4d6ec713 Mon Sep 17 00:00:00 2001 From: Adrian Scripca Date: Sun, 7 May 2023 11:05:01 +0300 Subject: [PATCH] Implemented showing program extents --- docs/todo.txt | 53 +++++++++++++++++++++++++++++ grbl_machine.cpp | 18 ++++++++++ grbl_machine.h | 3 ++ main.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 docs/todo.txt diff --git a/docs/todo.txt b/docs/todo.txt new file mode 100644 index 0000000..8c8d4a4 --- /dev/null +++ b/docs/todo.txt @@ -0,0 +1,53 @@ +Heightmap probing: + 1. define the grid: + - from: x, y + - to: x, y + - step every: 5mm? + - clearance height: Z1.5 + - start probing at: Z0.5 + - max negative z: Z-0.5 (when to fail probing) + - z final safety height: Z15 + + - from and to can be filled from current project bounding box + + 2. probing + - machine moves at grid start position (x, y) + G0X0Y0 + - gets down for initial probing + G38.2 Z-65 F100 + - step back a bit (1mm, relative) + G91 G0 Z1 + - seek again with lower feed rate + G38.2 Z-5 F5 + - after first probe ever, this Z becomes reference 0 + G10 L20 P0 Z0 + + - all subsequent probes will be relative to this + - for each probing location: + - G0 Z"clearance height" + - G0 XxxYyyy (next point location) + - G0 Z"start probing at" + - G38.2 Z-5 F5 + - store Z offset and place it in the heightmap + + 3. modify loaded program with heightmap data + - foreach line in program + - if line contains a Z coordinate, update the Z according to the X and Y + - if line does not contain a Z coordinate, add a Z coordinate according to the X and Y + +Edge finding + - prerequisites + - which edge to find? -X/+X/-Y/+Y + - bit diameter used + - put the + +Corner finding + - which corner are we probing: up left, up right, bottom left, bottom right + - need to know the bit diameter + - use G38.2 to probe X edge and set that as current X - diam/2 + + +DONE - Show program extents + +Render program extents + - show a blue bounding box for the program extents diff --git a/grbl_machine.cpp b/grbl_machine.cpp index 88942dc..aae2e8c 100644 --- a/grbl_machine.cpp +++ b/grbl_machine.cpp @@ -682,6 +682,12 @@ void grbl::machine::request_jog_fixed(grbl::jog_direction dir, float distance, f awaiting_responses++; } +void grbl::machine::start_z_probe(float min_z, float feed_rate) { + std::string command = "G38.2 Z" + std::to_string(min_z) + "F" + std::to_string(feed_rate); + pipe->send(command); + awaiting_responses++; +} + bool grbl::jog_state::no_jogging() const { return !(up_pressed || down_pressed || left_pressed || right_pressed || z_up_pressed || z_down_pressed); } @@ -812,6 +818,18 @@ void grbl::machine_state_idle::on_line_received(std::string line) { // TODO: some parameters have more than two : auto pieces = split_string(line, ":"); cnc->parameters[pieces[0]] = pieces[1]; + + if (starts_with(line, "PRB")) { + auto pieces = split_string(line, ":"); + auto coords_as_string = split_string(pieces[1], ","); + + float probe_coords[3]; + for (auto i = 0; i < 3; i++) { + probe_coords[i] = std::stof(coords_as_string[i]); + } + bool probe_touched = pieces[2] == "1"; + cnc->listener->on_probe_result(probe_touched, probe_coords); + } } } diff --git a/grbl_machine.h b/grbl_machine.h index 407270b..57639c8 100644 --- a/grbl_machine.h +++ b/grbl_machine.h @@ -126,6 +126,7 @@ struct machine_listener { virtual void on_check_completed(bool success, size_t failed_index, size_t error) = 0; virtual void on_settings_reloaded() = 0; virtual void on_parameters_reloaded() = 0; + virtual void on_probe_result(bool probe_touched, float probe_coords[3]) = 0; }; @@ -277,6 +278,8 @@ struct machine : public transport_callbacks { // 0 = G54, 1 = G55, etc axis 0=X, 1=Y, 2=Z void zero_offset_axis(int offset_index, int axis); + void start_z_probe(float min_z, float feed_rate); + protected: void on_connected(transport *transport) override; void on_disconnected(transport *transport) override; diff --git a/main.cpp b/main.cpp index 26c1488..6a7d1e7 100644 --- a/main.cpp +++ b/main.cpp @@ -98,16 +98,24 @@ public: }); info_layer = tab_widget->add(); - tab_widget->append_tab("Info", info_layer); - info_layer->set_layout(new GroupLayout(10, 20, 30, 0)); info_layer->add