DRO works properly with work offsets. Offsets can be zeroed.

This commit is contained in:
2023-05-04 15:57:34 +03:00
parent cacbe1b8aa
commit 3ea1ca5efa
3 changed files with 219 additions and 167 deletions
+154 -155
View File
@@ -51,7 +51,6 @@ public:
Window *window;
grbl::jog_state jog;
Label *m_pos_x, *m_pos_y, *m_pos_z;
TextArea *lblStatus, *lblSubstatus;
nanogui::Color colRed = nanogui::Color(255, 0, 0, 255);
nanogui::Color colGreen = nanogui::Color(0, 255, 0, 255);
@@ -60,7 +59,6 @@ public:
grbl::program pgm;
Button *btnLoadProgram, *btnCheckProgram, *btnRunProgram;
grbl::program_renderer renderer;
glm::vec3 cam_target = glm::vec3(0);
@@ -74,66 +72,10 @@ public:
VScrollPanel *parameters_vscroll;
Widget *parameters_layer;
TextBox *mpos_x_text, *mpos_y_text, *mpos_z_text;
void fill_in_settings() {
settings_vscroll = new VScrollPanel(tab_widget);
tab_widget->append_tab("Settings", settings_vscroll);
settings_layer = new Widget(settings_vscroll);
settings_layer->set_layout(new GridLayout(Orientation::Horizontal, 1, Alignment::Middle));
auto& settings = cnc.get_settings();
for (auto& s: settings) {
auto w = settings_layer->add<Widget>();
w->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 2, 2));
auto x = w->add<Label>(s.first, "sans-bold", 20);
x->set_fixed_width(40);
auto desc = grbl::setting_description(std::stoi(s.first.substr(1)));
auto y = w->add<TextBox>(s.second);
y->set_editable(true);
y->set_tooltip(desc);
y->set_fixed_width(200);
auto z = w->add<ToolButton>(FA_SAVE);
z->set_flags(Button::Flags::NormalButton); // no toggle, please
z->set_tooltip("save");
auto t = w->add<TextArea>();
t->set_fixed_width(200);
t->set_fixed_height(20);
t->clear();
t->append(desc.substr(0, desc.find_first_of('\n')));
}
}
void fill_in_parameters() {
parameters_vscroll = new VScrollPanel(tab_widget);
tab_widget->append_tab("Parameters", parameters_vscroll);
parameters_layer = new Widget(parameters_vscroll);
parameters_layer->set_layout(new GridLayout(Orientation::Horizontal, 1, Alignment::Middle));
auto& parameters = cnc.get_parameters();
for (auto& entry: parameters) {
auto w = parameters_layer->add<Widget>();
w->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 2, 2));
auto x = w->add<Label>(entry.first, "sans-bold", 20);
x->set_fixed_width(50);
auto y = w->add<TextBox>(entry.second);
y->set_editable(true);
y->set_fixed_width(200);
auto z = w->add<ToolButton>(FA_SAVE);
z->set_flags(Button::Flags::NormalButton); // no toggle, please
z->set_tooltip("save");
}
}
ComboBox *cboOffset, *cboTool;
float offset_x = 0;
float offset_y = 0;
float offset_z = 0;
SenderApp() : Screen(Vector2i(1024, 768), "GRBL Sender") {
inc_ref();
@@ -162,77 +104,107 @@ public:
layer->set_layout(new GroupLayout());
tab_widget->append_tab("Info", layer);
// Widget *layer3 = new Widget(tab_widget);
// tab_widget->append_tab("Offsets", layer3);
// layer3->set_layout(new GroupLayout());
// layer3->add<Label>("Parameters");
// layer3->add<TextBox>();
new Label(layer, "Status", "sans-bold");
Widget *status_holder = new Widget(layer);
status_holder->set_layout(new GridLayout());
lblStatus = new TextArea(layer);
lblStatus = layer->add<TextArea>();
lblStatus->set_fixed_height(20);
lblStatus->set_font("sans");
lblSubstatus = new TextArea(layer);
lblSubstatus = layer->add<TextArea>();
lblSubstatus->set_font("sans");
lblSubstatus->set_fixed_height(50);
// Machine pos
layer->add<Label>("Machine pos", "sans-bold");
// DRO
layer->add<Label>("DRO", "sans-bold", 20);
Widget *mpos = new Widget(layer);
mpos->set_layout(new GridLayout(Orientation::Horizontal, 1, Alignment::Middle));
mpos->set_layout(new GridLayout(Orientation::Horizontal, 1, Alignment::Middle, 0, 6));
auto x_holder = mpos->add<Widget>();
x_holder->set_layout(new BoxLayout(Orientation::Horizontal));
auto lbl = x_holder->add<Label>("X");
lbl->set_font_size(20);
lbl->set_fixed_width(50);
mpos_x_text = x_holder->add<TextBox>(std::to_string(cnc.get_status().work_pos[0]));
x_holder->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 6));
auto lbl = x_holder->add<Label>("X", "sans-bold", 20);
lbl->set_fixed_width(30);
mpos_x_text = x_holder->add<TextBox>(std::to_string(cnc.get_status().machine_pos[0]));
mpos_x_text->set_fixed_width(200);
auto zero_btn = x_holder->add<ToolButton>(FA_BAN);
zero_btn->set_flags(Button::Flags::NormalButton);
zero_btn->set_tooltip("Zero axis");
zero_btn->set_callback([&]() {
cnc.zero_offset_axis(cboOffset->selected_index(), 0);
});
auto y_holder = mpos->add<Widget>();
y_holder->set_layout(new BoxLayout(Orientation::Horizontal));
lbl = y_holder->add<Label>("Y");
lbl->set_font_size(20);
lbl->set_fixed_width(50);
mpos_y_text = y_holder->add<TextBox>(std::to_string(cnc.get_status().work_pos[1]));
y_holder->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 6));
lbl = y_holder->add<Label>("Y", "sans-bold", 20);
lbl->set_fixed_width(30);
mpos_y_text = y_holder->add<TextBox>(std::to_string(cnc.get_status().machine_pos[1]));
mpos_y_text->set_fixed_width(200);
zero_btn = y_holder->add<ToolButton>(FA_BAN);
zero_btn->set_flags(Button::Flags::NormalButton);
zero_btn->set_tooltip("Zero axis");
zero_btn->set_callback([&]() {
cnc.zero_offset_axis(cboOffset->selected_index(), 1);
});
auto z_holder = mpos->add<Widget>();
z_holder->set_layout(new BoxLayout(Orientation::Horizontal));
lbl = z_holder->add<Label>("Z");
lbl->set_font_size(20);
lbl->set_fixed_width(50);
mpos_z_text = z_holder->add<TextBox>(std::to_string(cnc.get_status().work_pos[0]));
z_holder->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 6));
lbl = z_holder->add<Label>("Z", "sans-bold", 20);
lbl->set_fixed_width(30);
mpos_z_text = z_holder->add<TextBox>(std::to_string(cnc.get_status().machine_pos[0]));
mpos_z_text->set_fixed_width(200);
zero_btn = z_holder->add<ToolButton>(FA_BAN);
zero_btn->set_flags(Button::Flags::NormalButton);
zero_btn->set_tooltip("Zero axis");
zero_btn->set_callback([&]() {
cnc.zero_offset_axis(cboOffset->selected_index(), 2);
});
auto zero_all_btn = mpos->add<Button>("Zero all");
zero_all_btn->set_callback([&]() {
cnc.zero_offset(cboOffset->selected_index());
});
// work parameters
layer->add<Label>("Work parameters", "sans-bold", 20);
auto x = new Widget(layer);
x->set_layout(new GridLayout(Orientation::Horizontal, 4, Alignment::Middle, 0, 6));
x->add<Label>("Offset:");
std::vector<std::string> offset_items = {"G54", "G55", "G56", "G57", "G58", "G59"};
cboOffset = x->add<ComboBox>(offset_items);
cboOffset->set_callback([&](int idx) {
refresh_offset();
update_dro();
});
x->add<Label>("Tool:");
std::vector<std::string> tool_items = {"None"};
cboTool = x->add<ComboBox>(tool_items);
// buttons to change state
new Label(layer, "Actions", "sans-bold");
Widget *actions = new Widget(layer);
auto *actions = new Widget(layer);
actions->set_layout(new BoxLayout(Orientation::Horizontal));
Button *btnUnlock = new Button(actions, "Unlock");
auto *btnUnlock = new Button(actions, "Unlock");
btnUnlock->set_callback([&] {
cnc.request_unlock();
});
Button *btnHome = new Button(actions, "Home");
auto *btnHome = new Button(actions, "Home");
btnHome->set_callback([&] {
cnc.request_home();
});
Button *btnReset = new Button(actions, "Reset");
auto *btnReset = new Button(actions, "Reset");
btnReset->set_background_color(colRed);
btnReset->set_callback([&] {
cnc.request_reset();
});
Button *btnCycleStart = new Button(actions, "Cycle Start");
auto *btnCycleStart = new Button(actions, "Cycle Start");
btnCycleStart->set_callback([&] {
cnc.request_cycle_start();
});
Button *btnFeedHold = new Button(actions, "Feed Hold");
auto *btnFeedHold = new Button(actions, "Feed Hold");
btnFeedHold->set_callback([&] {
cnc.request_feed_hold();
});
@@ -280,68 +252,83 @@ public:
});
btnRunProgram->set_tooltip("Execute program");
// // Alternative construction notation using variadic template
// btnLoadProgram = window->add<Button>("Styled", FA_ROCKET);
// btnLoadProgram->set_background_color(Color(0, 0, 255, 25));
// btnLoadProgram->set_callback([] { std::cout << "pushed!" << std::endl; });
// btnLoadProgram->set_tooltip("This button has a fairly long tooltip. It is so long, in "
// "fact, that the shown text will span several lines.");
//
// new Label(window, "Toggle buttons", "sans-bold");
// btnLoadProgram = new Button(window, "Toggle me");
// btnLoadProgram->set_flags(Button::ToggleButton);
// btnLoadProgram->set_change_callback([](bool state) { std::cout << "Toggle button state: " << state << std::endl; });
//
// new Label(window, "Radio buttons", "sans-bold");
// btnLoadProgram = new Button(window, "Radio button 1");
// btnLoadProgram->set_flags(Button::RadioButton);
// btnLoadProgram = new Button(window, "Radio button 2");
// btnLoadProgram->set_flags(Button::RadioButton);
//
// new Label(window, "A tool palette", "sans-bold");
// Widget *tools = new Widget(window);
// tools->set_layout(new BoxLayout(Orientation::Horizontal,
// Alignment::Middle, 0, 6));
//
// btnLoadProgram = new ToolButton(tools, FA_CLOUD);
// btnLoadProgram = new ToolButton(tools, FA_FAST_FORWARD);
// btnLoadProgram = new ToolButton(tools, FA_COMPASS);
// btnLoadProgram = new ToolButton(tools, FA_UTENSILS);
//
// new Label(window, "Popup buttons", "sans-bold");
// PopupButton *popup_btn = new PopupButton(window, "Popup", FA_FLASK);
// Popup *popup = popup_btn->popup();
// popup->set_layout(new GroupLayout());
// new Label(popup, "Arbitrary widgets can be placed here");
// new CheckBox(popup, "A check box");
// // popup right
// popup_btn = new PopupButton(popup, "Recursive popup", FA_CHART_PIE);
// Popup *popup_right = popup_btn->popup();
// popup_right->set_layout(new GroupLayout());
// new CheckBox(popup_right, "Another check box");
// // popup left
// popup_btn = new PopupButton(popup, "Recursive popup", FA_DNA);
// popup_btn->set_side(Popup::Side::Left);
// Popup *popup_left = popup_btn->popup();
// popup_left->set_layout(new GroupLayout());
// new CheckBox(popup_left, "Another check box");
perform_layout();
// All NanoGUI widgets are initialized at this point. Now
// create shaders to draw the main window contents.
//
// NanoGUI comes with a simple wrapper around OpenGL 3, which
// eliminates most of the tedious and error-prone shader and buffer
// object management.
m_render_pass = new RenderPass({this});
m_render_pass->set_clear_color(0, Color(0.3f, 0.3f, 0.32f, 1.f));
m_render_pass->set_depth_test(RenderPass::DepthTest::Always, true);
m_render_pass->set_cull_mode(RenderPass::CullMode::Disabled);
}
void refresh_offset() {
auto offset_name = "G" + std::to_string(cboOffset->selected_index() + 54);
auto offset_values = cnc.get_parameters().at(offset_name);
auto offset_pieces = split_string(offset_values, ",");
offset_x = std::stof(offset_pieces[0]);
offset_y = std::stof(offset_pieces[1]);
offset_z = std::stof(offset_pieces[2]);
}
void fill_in_parameters() {
parameters_vscroll = new VScrollPanel(tab_widget);
tab_widget->append_tab("Parameters", parameters_vscroll);
parameters_layer = new Widget(parameters_vscroll);
parameters_layer->set_layout(new GridLayout(Orientation::Horizontal, 1, Alignment::Middle));
auto& parameters = cnc.get_parameters();
for (auto& entry: parameters) {
auto w = parameters_layer->add<Widget>();
w->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 2, 2));
auto x = w->add<Label>(entry.first, "sans-bold", 20);
x->set_fixed_width(50);
auto y = w->add<TextBox>(entry.second);
y->set_editable(true);
y->set_fixed_width(200);
auto z = w->add<ToolButton>(FA_SAVE);
z->set_flags(Button::Flags::NormalButton); // no toggle, please
z->set_tooltip("save");
}
}
void fill_in_settings() {
settings_vscroll = new VScrollPanel(tab_widget);
tab_widget->append_tab("Settings", settings_vscroll);
settings_layer = new Widget(settings_vscroll);
settings_layer->set_layout(new GridLayout(Orientation::Horizontal, 1, Alignment::Middle));
auto& settings = cnc.get_settings();
for (auto& s: settings) {
auto w = settings_layer->add<Widget>();
w->set_layout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 2, 2));
auto x = w->add<Label>(s.first, "sans-bold", 20);
x->set_fixed_width(40);
auto desc = grbl::setting_description(std::stoi(s.first.substr(1)));
auto y = w->add<TextBox>(s.second);
y->set_editable(true);
y->set_tooltip(desc);
y->set_fixed_width(200);
auto z = w->add<ToolButton>(FA_SAVE);
z->set_flags(Button::Flags::NormalButton); // no toggle, please
z->set_tooltip("save");
auto t = w->add<TextArea>();
t->set_fixed_width(200);
t->set_fixed_height(20);
t->clear();
t->append(desc.substr(0, desc.find_first_of('\n')));
}
}
void init_program_geometry() {
renderer.update(pgm, cnc);
@@ -363,16 +350,26 @@ public:
void on_disconnected() override {
}
void on_settings_reloaded() override {
}
void on_parameters_reloaded() override {
refresh_offset();
update_dro();
}
grbl::realtime_status_report last_report;
void on_init_completed() override {
fill_in_settings();
fill_in_parameters();
refresh_offset();
update_dro();
}
void on_realtime_status_report(grbl::realtime_status_report report) override {
if (report == last_report) return;
// if (report == last_report) return;
if (last_report.status != report.status) {
lblStatus->clear();
@@ -386,14 +383,16 @@ public:
}
}
mpos_x_text->set_value(std::to_string(cnc.get_status().work_pos[0]));
mpos_y_text->set_value(std::to_string(cnc.get_status().work_pos[1]));
mpos_z_text->set_value(std::to_string(cnc.get_status().work_pos[2]));
update_dro();
last_report = report;
}
void update_dro() {
mpos_x_text->set_value(std::to_string(cnc.get_status().machine_pos[0] - offset_x));
mpos_y_text->set_value(std::to_string(cnc.get_status().machine_pos[1] - offset_y));
mpos_z_text->set_value(std::to_string(cnc.get_status().machine_pos[2] - offset_z));
}
void on_banner(std::string line) override {
}