Heightmap probing is now rendered in real time.

This commit is contained in:
2023-05-10 14:08:14 +03:00
parent 8a1c7d7d89
commit 5748e3d5af
3 changed files with 55 additions and 41 deletions
+23 -21
View File
@@ -9,32 +9,33 @@ DONE - step every: 5mm?
- z final safety height: Z15
DONE - 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
DONE 2. probing
DONE - machine moves at grid start position (x, y)
DONE G0X0Y0
DONE - gets down for initial probing
DONE G38.2 Z-65 F100
DONE - step back a bit (1mm, relative)
DONE G91 G0 Z1
DONE - seek again with lower feed rate
DONE G38.2 Z-5 F5
DONE - after first probe ever, this Z becomes reference 0
DONE G10 L20 P0 Z0
DONE - all subsequent probes will be relative to this
DONE - for each probing location:
DONE - G0 Z"clearance height"
DONE - G0 XxxYyyy (next point location)
DONE - G0 Z"start probing at"
DONE - G38.2 Z-5 F5
DONE - 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
Solve bug in which the probing data does not get rendered properly as it gets probed.
Bug: query coordinate systems after first z probe.
Edge finding
- prerequisites
- which edge to find? -X/+X/-Y/+Y
@@ -50,8 +51,9 @@ Render arcs
Render quadratic splines
Render bezier splines
Synchronize executing program with render (show executed paths with different colors)
Show a progress bar when executing programs.
Add aggressive buffer execution policy and make it selectable.
Show a progress bar when executing programs.
Show a progress bar when probing.
DONE - Show program extents
+13 -6
View File
@@ -513,7 +513,7 @@ public:
return result;
}
void fill_heightmap_from_grid(const grbl::heightmap& grid) {
void fill_heightmap_controls_from_grid(const grbl::heightmap& grid) const {
txt_heightmap_from_x->set_value(std::to_string(grid.from_x));
txt_heightmap_from_y->set_value(std::to_string(grid.from_y));
txt_heightmap_to_x->set_value(std::to_string(grid.to_x));
@@ -562,7 +562,7 @@ public:
}, true);
if (!path.empty()) {
heightmap_grid = load_heightmap(path);
fill_heightmap_from_grid(heightmap_grid);
fill_heightmap_controls_from_grid(heightmap_grid);
renderer.update_grid(heightmap_grid);
}
});
@@ -639,7 +639,7 @@ public:
});
}
void fill_heightmap_from_model() {
void fill_heightmap_from_model() const {
auto min = renderer.get_extents_min();
auto max = renderer.get_extents_max();
txt_heightmap_from_x->set_value(std::to_string(min.x));
@@ -895,9 +895,12 @@ public:
new MessageDialog(this, MessageDialog::Type::Warning, "Probe result", ss.str());
}
volatile bool should_render_grid = false;
void on_heightmap_probe_acquired(grbl::heightmap *grid) override {
std::cout << "Updating grid" << std::endl;
renderer.update_grid(*grid);
// let's try to update this from the UI thread since the call is invoked from the
// grbl communicator thread.
should_render_grid = true;
}
void on_check_completed(bool success, size_t failed_index, size_t error) override {
@@ -1065,6 +1068,12 @@ public:
machine_initialized = false;
}
// TODO: change this to something prettier. make a pipe/queue for in-between threads comm
if (should_render_grid) {
renderer.update_grid(heightmap_grid);
should_render_grid = false;
}
Widget::draw(ctx);
}
@@ -1075,7 +1084,6 @@ public:
m_render_pass->resize(framebuffer_size());
m_render_pass->begin();
if (pgm.is_loaded) {
renderer.update(pgm, cnc);
// compute mvp
glm::mat4 projection = glm::perspective(45.0f * glm::pi<float>() / 180.0f,
@@ -1091,7 +1099,6 @@ public:
glm::mat3 normal_mat = glm::inverseTranspose(glm::mat3(view * model));
renderer.render(model, view, projection, normal_mat, glm::vec2(fb_size.x(), fb_size.y()));
}
m_render_pass->end();
}
+6 -1
View File
@@ -339,6 +339,8 @@ void grbl::program_renderer::initialize_program_buffers() {
}
GLsizei grbl::program_renderer::update_model_vbo(const grbl::program& pgm) {
if (!pgm.is_loaded) return 0;
static auto movement_re = std::regex(R"(([gG]0*1?\s+|[xXyYzZ]\s*[0-9\.\-]+))");
bool is_tool_on = false;
@@ -428,6 +430,9 @@ void grbl::program_renderer::update_grid(const grbl::heightmap& grid) {
glm::vec4 color = {0.5, 0.3, 0, 1};
// this should only be called whenever the grid changes
// therefor it should be called each and every time we
// probe a new location. let's check that.
std::vector<float> buffer_data;
for (int y = 0; y < grid.y_segments; y++) {
@@ -466,7 +471,7 @@ void grbl::program_renderer::update_grid(const grbl::heightmap& grid) {
heightmap_vertices_count = buffer_data.size() * sizeof(float) / size_of_vertex_in_bytes;
glBindBuffer(GL_ARRAY_BUFFER, heightmap_vbo_id);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * buffer_data.size(), buffer_data.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * buffer_data.size(), buffer_data.data(), GL_DYNAMIC_DRAW);
}
void grbl::program_renderer::initialize_heightmap_buffers() {