Got rid of segfault when uploading VBOs.

Added go-to-zero function.
Reworked how work pos is obtained.
This commit is contained in:
2023-05-05 15:42:30 +03:00
parent 05db38ec55
commit 3f9eb049b7
5 changed files with 86 additions and 26 deletions
+46 -5
View File
@@ -1,5 +1,7 @@
#include <iostream>
#include <sstream>
#include <utility>
#include <array>
#include "grbl_machine.h"
#include "string_utils.h"
@@ -96,15 +98,29 @@ void grbl::machine::check_program(const grbl::program& pgm) {
switch_to_state(grbl_machine_state::check_program);
}
void grbl::machine::run_program(const grbl::program& pgm, std::string work_offset) {
void grbl::machine::set_work_offset(std::string work_offset) {
std::cout << "Setting work offsset " << work_offset << std::endl;
// if (state != grbl_machine_state::disconnected) {
pipe->send(work_offset);
// awaiting_responses++;
// while (awaiting_responses > 0);
current_work_offset = work_offset;
auto pieces = split_string(parameters[work_offset], ",");
current_work_offset_values[0] = std::stof(pieces[0]);
current_work_offset_values[1] = std::stof(pieces[1]);
current_work_offset_values[2] = std::stof(pieces[2]);
// }
}
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"
<< " on work offset " << work_offset << std::endl;
// set desired offset
while (awaiting_responses > 0);
pipe->send(work_offset);
while (awaiting_responses > 0);
set_work_offset(work_offset);
switch_to_state(grbl_machine_state::run_program);
}
@@ -576,6 +592,31 @@ void grbl::machine::zero_offset_axis(int offset_index, int axis) {
listener->on_parameters_reloaded();
}
void grbl::machine::go_to_zero(bool x, bool y, bool z) {
std::string command = "G0";
if (x) command += "X0";
if (y) command += "Y0";
if (z) command += "Z0";
while (awaiting_responses > 0);
pipe->send(command);
awaiting_responses++;
while (awaiting_responses > 0);
}
const float *grbl::machine::get_current_work_offset_values() const {
return current_work_offset_values;
}
std::array<float, 3> grbl::machine::get_work_pos() const {
std::array<float, 3> result = {
last_report.machine_pos[0] - current_work_offset_values[0],
last_report.machine_pos[1] - current_work_offset_values[1],
last_report.machine_pos[2] - current_work_offset_values[2],
};
return result;
}
bool grbl::jog_state::no_jogging() const {
return !(up_pressed || down_pressed || left_pressed || right_pressed || z_up_pressed || z_down_pressed);
}